use of nars.concept.TaskConcept in project narchy by automenta.
the class TemporalInductionTest method testTemporalRevision.
@Test
public void testTemporalRevision() throws Narsese.NarseseException {
NAR n = NARS.tmp();
n.time.dur(1);
n.log();
// TextOutput.out(n);
n.input("a:b. %1.0|0.9%");
n.run(5);
n.input("a:b. %0.0|0.9%");
n.run(5);
n.input("a:b. %0.5|0.9%");
n.run(1);
// n.forEachConcept(Concept::print);
TaskConcept c = (TaskConcept) n.conceptualize("a:b");
assertNotNull(c);
// assertEquals("(b-->a). 5+0 %.50;.95%", c.getBeliefs().top(n.time()).toStringWithoutBudget());
BeliefTable b = c.beliefs();
b.print();
assertTrue(3 <= b.size());
// when originality is considered:
// assertEquals("(b-->a). 5+0 %0.0;.90%", c.beliefs().top(n.time()).toStringWithoutBudget());
// most current relevant overall:
assertEquals("(b-->a). 5 %0.0;.90%", n.belief(c.term(), 5).toStringWithoutBudget());
// least relevant
assertEquals("(b-->a). 0 %1.0;.90%", n.belief(c.term(), 0).toStringWithoutBudget());
}
use of nars.concept.TaskConcept in project narchy by automenta.
the class TemporalTermTest method testConceptualization.
@Test
public void testConceptualization() throws Narsese.NarseseException {
Term t = $("(x==>y)");
Term x = t.root();
assertEquals(DTERNAL, x.dt());
assertEquals("(x==>y)", x.toString());
n.input("(x ==>+0 y).", "(x ==>+1 y).").run(2);
TaskConcept xImplY = (TaskConcept) n.conceptualize(t);
assertNotNull(xImplY);
assertEquals("(x==>y)", xImplY.toString());
assertEquals(3, xImplY.beliefs().size());
int indexSize = n.concepts.size();
n.concepts.print(System.out);
// present
n.input("(x ==>+1 y). :|:");
n.run();
// d.concept("(x==>y)").print();
assertEquals(4, xImplY.beliefs().size());
n.concepts.print(System.out);
// remains same amount
assertEquals(indexSize, n.concepts.size());
n.conceptualize("(x==>y)").print();
}
use of nars.concept.TaskConcept in project narchy by automenta.
the class CameraSensorView method update.
@Override
public int update(int x, int y) {
TaskConcept s = cam.get(x, y);
Truth b = s.beliefs().truth(start, end, nar);
float bf = b != null ? b.freq() : 0.5f;
Truth d = s.goals().truth(start, end, nar);
float R = bf * 0.75f, G = bf * 0.75f, B = bf * 0.75f;
if (d != null) {
float f = d.expectation();
// float c = d.conf();
if (f > 0.5f) {
G += 0.25f * (f - 0.5f) * 2f;
} else {
R += 0.25f * (0.5f - f) * 2f;
}
}
return Draw.rgbInt(Util.unitize(R), Util.unitize(G), Util.unitize(B));
}
use of nars.concept.TaskConcept in project narchy by automenta.
the class TaskAdd method run.
@Override
public final ITask run(NAR n) {
n.emotion.onInput(task, n);
@Nullable Concept c = task.concept(n, true);
if (c == null) {
// may not have capacity in the concept index
return null;
} else if (!(c instanceof TaskConcept)) {
if (task.isBeliefOrGoal() || Param.DEBUG_EXTRA) {
throw new RuntimeException(task + " does not resolve a TaskConcept");
} else
return null;
}
((TaskConcept) c).add(task, n);
return null;
}
use of nars.concept.TaskConcept in project narchy by automenta.
the class NAL6MultistepTest method testBurglarEarthquake2.
/**
* https://dtai.cs.kuleuven.be/problog/tutorial/basic/02_bayes.html
*/
@Test
public void testBurglarEarthquake2() throws Narsese.NarseseException {
// 0.7::burglary.
// 0.2::earthquake.
//
// 0.9::alarm :- burglary, earthquake.
// 0.8::alarm :- burglary, \+earthquake.
// 0.1::alarm :- \+burglary, earthquake.
//
// evidence(alarm,true).
// query(burglary).
// query(earthquake).
NAR n = new NARS().get();
// d.log();
n.input("(burglary). %0.7;0.9%", "(earthquake). %0.2;0.9%", "((&&, (burglary), (earthquake)) ==> (alarm)). %0.9;0.9%", "((&&, (burglary), (--,(earthquake))) ==> (alarm)). %0.8;0.9%", "((&&, (--,(burglary)), (earthquake)) ==> (alarm)). %0.1;0.9%", "(alarm).", "(burglary)?", "(earthquake)?");
TaskConcept burglary = null, earthquake = null;
for (int i = 0; i < 5; i++) {
// burglary.print(); earthquake.print();
// long now = d.time();
n.run(100);
burglary = (TaskConcept) n.conceptualize("(burglary)");
// burglary.print(); earthquake.print();
earthquake = (TaskConcept) n.conceptualize("(earthquake)");
System.out.println("burglary=" + n.beliefTruth(burglary, 0) + "\tearthquake=" + earthquake.beliefs().truth(Tense.ETERNAL, n));
}
// result from Probcog: earthquake=23%, burglary=99%
assertEquals(0.99f, n.beliefTruth(burglary, 0).freq(), 0.33f);
assertEquals(0.23f, n.beliefTruth(earthquake, 0).freq(), 0.1f);
}
Aggregations