use of nars.concept.Concept in project narchy by automenta.
the class LinkageTest method ProperlyLinkedIndirectlyTest.
// interlinked with an intermediate concept, this is needed in order to select one as task and the other as belief
public void ProperlyLinkedIndirectlyTest(@NotNull String spremise1, byte punc, @NotNull String spremise2) throws Exception {
test.requireConditions = false;
NAR nar = test.nar;
// nar.log();
Termed premise1 = $.$(spremise1);
assertEquals($.$(spremise1), premise1, "reparsed");
assertNotNull(premise1);
assertEquals($.$(spremise1), premise1);
Termed premise2 = $.$(spremise2);
assertEquals($.$(spremise2), premise2, "reparsed");
assertNotNull(premise2);
assertEquals($.$(spremise2), premise2);
String t1 = getTask(punc, premise1);
String t2 = getTask(punc, premise2);
nar.input(t1, t2).run(runCycles);
// List<String> fails = new ArrayList();
@Nullable Concept p1 = nar.concept(premise1);
assertNotNull(p1.state());
// p1.print(); System.out.println("------------------------");
Concept p2 = nar.concept(premise2);
assertNotNull(p2);
assertNotNull(p2.state());
// c2.print(); System.out.println("------------------------");
AdjGraph<Term, Float> g = TermGraph.termlink(nar);
boolean p12 = linksIndirectly(p1, p2, nar);
assertTrue(p12, why(nar, premise1, premise2));
boolean p21 = linksIndirectly(p2, p1, nar);
assertTrue(p21, why(nar, premise2, premise1));
System.err.println(premise1 + " not linked with " + premise2);
int numNodes = g.nodeCount();
assertTrue(numNodes > 0);
assertTrue(g.edgeCount() > 0, g.toString());
// for (Term x : g.nodes()) {
// assertEquals(x + " not reachable by all other nodes", numNodes, Graphs.reachableNodes(g.asGraph(), x).size());
// }
// //g.print(System.out);
// //System.out.println(g.isConnected() + " " + g.vertexSet().size() + " " + g.edgeSet().size());
// if (!g.isConnected()) {
// // if (!g.isStronglyConnected()) {
// // StrongConnectivityInspector ci =
// ConnectivityInspector ci = new ConnectivityInspector(g);
// // new StrongConnectivityInspector(g);
//
// System.out.println("premises: " + premise1 + " and " + premise2 + " termlink subgraph connectivity:");
//
// ci
// .connectedSets()
// //.stronglyConnectedSubgraphs()
// .forEach( s -> System.out.println("\t" + s));
//
// nar.forEachConceptActive(x -> x.get().print());
//
// }
// assertTrue(g.isConnected());
}
use of nars.concept.Concept in project narchy by automenta.
the class DynamicTruthBeliefTableTest method testDynamicIntersection.
@Test
public void testDynamicIntersection() throws Narsese.NarseseException {
NAR n = NARS.tmp();
n.believe("a:x", 1f, 0.9f);
n.believe("a:y", 1f, 0.9f);
n.believe("a:(--,y)", 0f, 0.9f);
n.believe("a:z", 0f, 0.9f);
n.believe("a:(--,z)", 1f, 0.9f);
n.believe("x:b", 1f, 0.9f);
n.believe("y:b", 1f, 0.9f);
n.believe("z:b", 0f, 0.9f);
n.run(2);
for (long now : new long[] { 0, n.time(), /* 2 */
ETERNAL }) {
assertTrue(n.conceptualize($("((x|y)-->a)")).beliefs() instanceof DynamicTruthBeliefTable);
assertEquals($.t(1f, 0.81f), n.beliefTruth("((x|y)-->a)", now));
assertEquals($.t(0f, 0.90f), n.beliefTruth(n.conceptualize($("((x|z)-->a)")), now));
assertEquals($.t(1f, 0.90f), n.beliefTruth(n.conceptualize($("((x&z)-->a)")), now));
assertEquals($.t(1f, 0.90f), n.beliefTruth(n.conceptualize($("(b --> (x|y))")), now));
assertEquals($.t(1f, 0.90f), n.beliefTruth(n.conceptualize($("(b --> (x|z))")), now));
assertEquals($.t(0f, 0.90f), n.beliefTruth(n.conceptualize($("(b --> (x&z))")), now));
Concept xIntNegY = n.conceptualize($("((x|--y)-->a)"));
assertTrue(xIntNegY.beliefs() instanceof DynamicTruthBeliefTable);
assertTrue(xIntNegY.goals() instanceof DynamicTruthBeliefTable);
assertEquals($.t(0f, 0.90f), n.beliefTruth(xIntNegY, now), now + " " + xIntNegY);
assertEquals($.t(1f, 0.81f), n.beliefTruth(n.conceptualize($("((x|--z)-->a)")), now));
}
}
use of nars.concept.Concept in project narchy by automenta.
the class DynamicTruthBeliefTableTest method testDynamicConjunction3.
@Test
public void testDynamicConjunction3() throws Narsese.NarseseException {
NAR n = NARS.tmp();
n.believe("a:x", 1f, 0.9f);
n.believe("a:y", 1f, 0.9f);
n.believe("a:z", 1f, 0.9f);
n.run(1);
TaskConcept cc = (TaskConcept) n.conceptualize($("(&&, a:x, a:y, a:z)"));
Truth now = n.beliefTruth(cc, n.time());
assertNotNull(now);
assertTrue($.t(1f, 0.73f).equals(now, 0.1f), now + " truth at " + n.time());
// the truth values were provided despite the belief tables being empty:
// test unknown:
{
TaskConcept ccn = (TaskConcept) n.conceptualize($("(&&, a:x, a:w)"));
Truth nown = n.beliefTruth(ccn, n.time());
assertNull(nown);
}
// test negation:
Concept ccn = n.conceptualize($("(&&, a:x, (--, a:y), a:z)"));
{
Task t = n.belief(ccn.term());
assertNotNull(t);
// the critical component
assertEquals($("a:y"), t.term());
assertEquals(1f, t.freq());
}
assertTrue(ccn instanceof TaskConcept);
Truth nown = n.beliefTruth(ccn, n.time());
assertEquals("%0.0;.90%", nown.toString());
n.clear();
// test change after a component's revision to negate the input freq
n.believe("a:y", 0, 0.95f);
n.run(1);
n.concept("a:y").print();
Task ay = n.belief($$("a:y"));
assertTrue(ay.freq() < 0.5f);
Task bb = n.belief(n.conceptualize($("(&&, a:x, a:y, a:z)")), n.time());
Truth now2 = bb.truth();
assertTrue(now2.freq() < 0.4f);
}
use of nars.concept.Concept in project narchy by automenta.
the class DynamicTruthBeliefTableTest method testDynamicIntVectorRange.
@Test
public void testDynamicIntVectorRange() throws Narsese.NarseseException {
NAR n = NARS.tmp();
n.believe("x(1,1)", 1f, 0.9f);
n.believe("x(1,2)", 0.5f, 0.9f);
n.believe("x(1,3)", 0f, 0.9f);
n.run(1);
Term t12 = $.inh($.p(Int.the(1), Int.range(1, 2)), $.the("x"));
assertEquals("x(1,1..2)", t12.toString());
Concept x12 = n.conceptualize(t12);
assertTrue(x12.beliefs() instanceof DynamicTruthBeliefTable);
Concept x23 = n.conceptualize($.inh($.p(Int.the(1), Int.range(2, 3)), $.the("x")));
Concept x123 = n.conceptualize($.inh($.p(Int.the(1), Int.range(1, 3)), $.the("x")));
assertEquals("%.50;.81%", n.beliefTruth(x12, ETERNAL).toString());
assertEquals("%0.0;.90%", n.beliefTruth(x23, ETERNAL).toString());
assertEquals("%0.0;.90%", n.beliefTruth(x123, ETERNAL).toString());
}
use of nars.concept.Concept in project narchy by automenta.
the class AtomicExec method update.
public void update(NAR n) {
// if (!busy.compareAndSet(false, true))
// return; //in-progress
// probe all active concepts.
// remove any below desire threshold
// execute any above desire-belief threshold
// if no active remain, disable update service
long[] focus = n.timeFocus();
// List<Task> evoke = $.newArrayList(0);
float exeThresh = this.exeThresh.floatValue();
List<Term> dispatch = new FasterList(active.size());
active.forEach(x -> {
Term xx = x.get();
Concept c = n.concept(xx);
if (c == null) {
// concept disappeared
x.delete();
return;
}
Truth goalTruth = c.goals().truth(focus, n);
if (goalTruth == null || goalTruth.expectation() < exeThresh) {
x.delete();
// undesired
return;
}
Truth beliefTruth = c.beliefs().truth(focus, n);
/* assume false with no evidence */
if (beliefTruth != null && beliefTruth.expectation() > exeThresh) {
// satisfied
return;
}
logger.info("{} EVOKE (b={},g={}) {}", n.time(), beliefTruth, goalTruth, xx);
dispatch.add(xx);
x.delete();
// MetaGoal.learn(MetaGoal.Action, goal.cause(), g, n);
});
dispatch.forEach(tt -> {
exe.accept(tt, n);
});
active.commit();
if (active.isEmpty()) {
disable();
}
}
Aggregations