use of nars.truth.Truth in project narchy by automenta.
the class BeliefTableChart method renderTable.
private void renderTable(Concept c, long minT, long maxT, long now, GL2 gl, TruthWave wave, boolean beliefOrGoal) {
if (c == null)
return;
float nowX = xTime(minT, maxT, now);
// Present axis line
if ((now <= maxT) && (now >= minT)) {
gl.glColor4f(1f, 1f, 1f, 0.5f);
Draw.line(gl, nowX, 0, nowX, 1);
// float nowLineWidth = 0.005f;
// Draw.rect(gl, nowX - nowLineWidth / 2f, 0, nowLineWidth, 1);
}
/**
* drawn "pixel" dimensions
*/
renderWave(nowX, minT, maxT, gl, wave, beliefOrGoal);
// draw projections
if (projections > 0 && minT != maxT) {
for (boolean freqOrExp : new boolean[] { true, false }) {
TruthWave pwave = beliefOrGoal ? beliefProj : goalProj;
// HACK dont show expectation for beliefs
if (beliefOrGoal && !freqOrExp)
continue;
Colorize colorize;
if (freqOrExp) {
colorize = beliefOrGoal ? (ggl, frq, cnf) -> {
float a = 0.65f + 0.2f * cnf;
ggl.glColor4f(0.25f + 0.75f * cnf, 0.1f * (1f - cnf), 0, a);
} : (ggl, frq, cnf) -> {
float a = 0.65f + 0.2f * cnf;
ggl.glColor4f(0.1f * (1f - cnf), 0.25f + 0.75f * cnf, 0, a);
};
} else {
colorize = beliefOrGoal ? (ggl, frq, cnf) -> {
ggl.glColor4f(cnf, cnf / 2f, 0.25f, 0.85f);
} : (ggl, frq, cnf) -> {
ggl.glColor4f(cnf / 2f, cnf, 0.25f, 0.85f);
};
}
FloatFloatToFloatFunction y = freqOrExp ? (frq, cnf) -> frq : TruthFunctions::expectation;
// HACK show goal freq in thinner line
gl.glLineWidth((freqOrExp && !beliefOrGoal) ? 2f : 4f);
renderWaveLine(nowX, minT, maxT, gl, pwave, y, colorize);
}
}
float chSize = 0.1f;
Truth bc = wave.current;
if (bc != null) {
float theta;
float expectation = bc.expectation();
float dTheta = (expectation - 0.5f) * angleSpeed;
float conf = bc.conf();
if (beliefOrGoal) {
this.beliefTheta += dTheta;
theta = beliefTheta;
gl.glColor4f(1f, 0f, 0, 0.2f + 0.8f * conf);
drawCrossHair(gl, nowX, chSize, bc.freq(), conf, theta);
} else {
this.goalTheta += dTheta;
theta = goalTheta;
// //freq
// gl.glColor4f(0f, 1f, 0, 0.2f + 0.8f * conf);
// drawCrossHair(gl, nowX, chSize, bc.freq(), conf, theta);
// expectation
gl.glColor4f(0f, 1f, 0, 0.2f + 0.8f * conf);
drawCrossHair(gl, nowX, chSize, expectation, expectation, theta);
}
}
}
use of nars.truth.Truth in project narchy by automenta.
the class Recog2D method conceptTraining.
Surface conceptTraining(BeliefVector tv, NAR nar) {
// LinkedHashMap<TaskConcept, BeliefVector.Neuron> out = tv.out;
Plot2D p;
int history = 256;
Gridding g = new Gridding(p = new Plot2D(history, Plot2D.Line).add("Reward", () -> reward), new AspectAlign(new CameraSensorView(sp, this), AspectAlign.Align.Center, sp.width, sp.height), new Gridding(beliefTableCharts(nar, List.of(tv.concepts), 16)), new Gridding(IntStream.range(0, tv.concepts.length).mapToObj(i -> new spacegraph.space2d.widget.text.Label(String.valueOf(i)) {
@Override
protected void paintBelow(GL2 gl) {
Concept c = tv.concepts[i];
BeliefVector.Neuron nn = tv.neurons[i];
float freq, conf;
Truth t = nar.beliefTruth(c, nar.time());
if (t != null) {
conf = t.conf();
freq = t.freq();
} else {
conf = nar.confMin.floatValue();
float defaultFreq = // interpret no-belief as maybe
0.5f;
// Float.NaN //use NaN to force learning of negation as separate from no-belief
freq = defaultFreq;
}
Draw.colorBipolar(gl, 2f * (freq - 0.5f));
float m = 0.5f * conf;
Draw.rect(gl, bounds);
if (tv.verify) {
float error = nn.error;
if (error != error) {
// training phase
// Draw.rect(gl, m / 2, m / 2, 1 - m, 1 - m);
} else {
// verification
// draw backgroudn/border
// gl.glColor3f(error, 1f - error, 0f);
//
// float fontSize = 0.08f;
// gl.glColor3f(1f, 1f, 1f);
// Draw.text(gl, c.term().toString(), fontSize, m / 2, 1f - m / 2, 0);
// Draw.text(gl, "err=" + n2(error), fontSize, m / 2, m / 2, 0);
}
}
}
}).toArray(Surface[]::new)));
final int[] frames = { 0 };
onFrame(() -> {
if (frames[0]++ % imagePeriod == 0) {
nextImage();
}
redraw();
// if (neural.get()) {
// if (nar.time() < trainFrames) {
outs.expect(image);
if (neural.get()) {
train.update(mlpLearn, mlpSupport);
}
p.update();
// s.update();
});
return g;
}
use of nars.truth.Truth in project narchy by automenta.
the class BeliefActionConcept method update.
// @Override
// public @Nullable Task curiosity(float conf, long next, NAR nar) {
// return ActionConcept.curiosity(term(), BELIEF, conf, next, nar);
// }
@Override
public Stream<ITask> update(long start, long end, int dur, NAR nar) {
long nowStart = // now;
start - dur / 2;
long nowEnd = // now + dur;
start + dur / 2;
Truth belief = this.beliefs().truth(nowStart, nowEnd, nar);
// if (nar.random().nextFloat() < curiosity) {
// float f = nar.random().nextFloat();
// float c = nar.confDefault(BELIEF);
// nar.believe(term(), Tense.Present, f, c);
// belief = $.t(f, c);
// } else {
// beliefIntegrated.commitAverage();
// }
// Truth goal =
// this.goals().truth(nowStart, nowEnd, nar);
// // //goalIntegrated.commitAverage();
// if (goal!=null) {
// if (belief!=null)
// belief = Revision.revise(belief, goal,1f, 0f);
// else
// belief = goal;
//
// }
// Task x;
// if (belief!=null) {
// x = feedback.set(this, belief, nar.time::nextStamp, nowStart, dur, nar);
// } else {
// x = feedback.get(); //latch
// }
action.accept(belief == null ? null : belief.truth());
return Stream.empty();
}
use of nars.truth.Truth in project narchy by automenta.
the class IO method readTask.
@NotNull
public static NALTask readTask(DataInput in) throws IOException {
Term preterm = readTerm(in);
final Term term = preterm.normalize();
if (term == null)
throw new IOException("un-normalizable task term");
byte punc = in.readByte();
Truth truth = hasTruth(punc) ? readTruth(in) : null;
long start = in.readLong();
long end = in.readLong();
long[] evi = readEvidence(in);
float pri = in.readFloat();
long cre = in.readLong();
NALTask mm = new NALTask(term, punc, truth, cre, start, end, evi);
mm.priSet(pri);
return mm;
}
use of nars.truth.Truth in project narchy by automenta.
the class RelationClustering method link.
@Override
protected void link(Task tx, Task ty) {
// TODO abstract
assert (tx.isBelief() && ty.isBelief());
// TODO Allen interval
String relation;
if (tx.intersects(ty.start(), ty.end())) {
relation = "simul";
} else if (ty.isAfter(tx.end(), dur / 2)) {
relation = "seq";
} else if (tx.isAfter(ty.end(), dur / 2)) {
Task z = tx;
tx = ty;
ty = z;
relation = "seq";
} else {
relation = null;
}
if (relation != null) {
Term x = tx.term();
Truth truX = tx.truth();
if (truX.isNegative()) {
x = x.neg();
truX = truX.neg();
}
Term y = ty.term();
Truth truY = ty.truth();
if (truY.isNegative()) {
y = y.neg();
truY = truY.neg();
}
if (x.volume() + y.volume() < nar.termVolumeMax.intValue() - 2) {
Truth tru = TruthFunctions.intersection(truX, truY, nar.confMin.floatValue());
if (tru == null)
return;
// TODO enum
Term t;
switch(relation) {
case "simul":
t = $.inh(SETe.the(x, y), $.the("simul"));
break;
case "seq":
t = $.func(relation, x, y);
break;
default:
throw new UnsupportedOperationException();
}
if (t instanceof Bool)
return;
t = t.normalize();
long now = nar.time();
NALTask tt = new NALTask(t, BELIEF, tru, now, Math.min(tx.start(), ty.start()), Math.max(tx.end(), ty.end()), nar.time.nextStampArray());
tt.pri(tx.priElseZero() * ty.priElseZero());
in.input(tt);
}
}
}
Aggregations