use of nars.concept.TaskConcept in project narchy by automenta.
the class RTreeBeliefTableTest method testProjection.
@Test
public void testProjection() throws Narsese.NarseseException {
NAR n = NARS.shell();
Term ab = nars.$.$("a:b");
TaskConcept X = (TaskConcept) n.conceptualize(ab);
RTreeBeliefTable r = RTreeBeliefTable.build(ab);
r.setCapacity(4);
add(r, X, 1f, 0.9f, 0, 1, n);
add(r, X, 0f, 0.9f, 2, 3, n);
assertEquals(1f, r.truth(0, 0, null, 1).freq());
assertEquals("%.65;.93%", r.truth(0, 1, null, 1).toString());
assertEquals("%.65;.93%", r.truth(1, 1, null, 1).toString());
assertEquals("%.50;.95%", r.truth(1, 2, null, 1).toString());
assertEquals("%.35;.93%", r.truth(2, 3, null, 1).toString());
assertEquals(0f, r.truth(3, 3, null, 1).freq());
assertEquals("%0.0;.83%", r.truth(4, 4, null, 1).toString());
assertEquals("%0.0;.83%", r.truth(4, 5, null, 1).toString());
assertEquals("%0.0;.78%", r.truth(5, 5, null, 1).toString());
}
use of nars.concept.TaskConcept in project narchy by automenta.
the class RevisionTest method testRevision2EternalImpl.
@Test
public void testRevision2EternalImpl() throws Narsese.NarseseException {
NAR n = newNAR(3).input("(x ==> y). %1.0;0.9%", "(x ==> y). %0.0;0.9%");
n.run(1);
TaskConcept c = (TaskConcept) n.conceptualize("(x ==> y)");
c.print();
Task t = n.match(c.term(), BELIEF, ETERNAL);
assertEquals(0.5f, t.freq(), 0.01f);
assertEquals(0.947f, t.conf(), 0.01f);
}
use of nars.concept.TaskConcept in project narchy by automenta.
the class TemporalTermTest method testCommutiveTemporalityConcepts.
@Test
public void testCommutiveTemporalityConcepts() throws Narsese.NarseseException {
NAR n = NARS.shell();
n.log();
n.input("(goto(#1) &&+5 ((SELF,#1)-->at)).");
// n.step();
n.input("(goto(#1) &&-5 ((SELF,#1)-->at)).");
// n.step();
n.input("(goto(#1) &&+0 ((SELF,#1)-->at)).");
// n.step();
n.input("(((SELF,#1)-->at) &&-3 goto(#1)).");
// n.step();
// n.input("(((SELF,#1)-->at) &&+3 goto(#1)).");
// n.step();
// n.input("(((SELF,#1)-->at) &&+0 goto(#1)).");
n.run(2);
TaskConcept a = (TaskConcept) n.conceptualize("(((SELF,#1)-->at) && goto(#1)).");
Concept a0 = n.conceptualize("(goto(#1) && ((SELF,#1)-->at)).");
assertNotNull(a);
assertSame(a, a0);
a.beliefs().print();
assertTrue(a.beliefs().size() >= 4);
}
use of nars.concept.TaskConcept 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.concept.TaskConcept in project narchy by automenta.
the class ConceptIndex method onRemove.
protected final void onRemove(Termed value) {
if (value instanceof Concept) {
if (value instanceof PermanentConcept) {
// refuse deletion
nar.runLater(() -> {
set(value);
});
} else {
Concept c = (Concept) value;
if (c instanceof TaskConcept)
forget((TaskConcept) c);
c.delete(nar);
}
}
}
Aggregations