use of nars.Op in project narchy by automenta.
the class BoolTest method testIntersectionTautologies.
@Test
public void testIntersectionTautologies() {
for (Op o : new Op[] { SECTe, SECTi }) {
String sect = o.str;
// raw
assertEquals(x, o.the(x, x));
// unchanged
assertReduction("((--,x)" + sect + "x)", o.the(x, x.neg()));
assertEquals(x, o.the(x, True));
assertEquals(Null, /* False ? */
o.the(x, False));
assertEquals(Null, o.the(x, Null));
}
}
use of nars.Op in project narchy by automenta.
the class BoolTest method testStatementTautologies.
@Test
public void testStatementTautologies() {
for (Op o : new Op[] { INH, SIM, IMPL }) {
assertEquals(True, o.the(True, True));
assertEquals(True, o.the(False, False));
assertEquals(Null, o.the(Null, Null));
}
// ??
assertEquals("(x-->†)", INH.the(x, True).toString());
assertEquals(Null, INH.the(True, x));
assertEquals("((--,x)-->†)", INH.the(x.neg(), True).toString());
}
use of nars.Op in project narchy by automenta.
the class BoolTest method testDiffTautologies.
@Test
public void testDiffTautologies() {
for (Op o : new Op[] { DIFFe, DIFFi }) {
String diff = o.str;
// raw
assertReduction(False, "(x" + diff + "x)");
assertReduction(// "(x" + diff + "(--,x))",
True, // unchanged
"(x" + diff + "(--,x))");
// subj
assertReduction(Null, "((x" + diff + "x)-->y)");
assertReduction(Null, "(--(x" + diff + "x)-->y)");
// assertReduction("((x" + diff + "(--,x))-->y)", "((x" + diff + "(--,x))-->y)"); //unchanged
// assertReduction("(((--,x)" + diff + "x)-->y)", "(((--,x)" + diff + "x)-->y)"); //unchanged
// pred
assertReduction("(y-->Ⅎ)", "(y --> (x" + diff + "x))");
assertReduction("(y-->†)", "(y --> --(x" + diff + "x))");
// assertReduction("(y-->(x" + diff + "(--,x)))", "(y-->(x" + diff + "(--,x)))"); //unchanged
// assertReduction("(y-->((--,x)" + diff + "x))", "(y-->((--,x)" + diff + "x))"); //unchanged
assertEquals(False, o.the(x, x));
assertEquals(Null, o.the(x, False));
assertEquals(Null, o.the(x, True));
}
}
use of nars.Op in project narchy by automenta.
the class NAR method stats.
/**
* creates a snapshot statistics object
* TODO extract a Method Object holding the snapshot stats with the instances created below as its fields
*/
public SortedMap<String, Object> stats() {
LongSummaryStatistics beliefs = new LongSummaryStatistics();
LongSummaryStatistics goals = new LongSummaryStatistics();
LongSummaryStatistics questions = new LongSummaryStatistics();
LongSummaryStatistics quests = new LongSummaryStatistics();
Histogram termlinkCount = new Histogram(1);
Histogram tasklinkCount = new Histogram(1);
// Frequency complexity = new Frequency();
HashBag clazz = new HashBag();
HashBag policy = new HashBag();
HashBag rootOp = new HashBag();
ShortCountsHistogram volume = new ShortCountsHistogram(2);
// AtomicInteger i = new AtomicInteger(0);
// LongSummaryStatistics termlinksCap = new LongSummaryStatistics();
// LongSummaryStatistics tasklinksCap = new LongSummaryStatistics();
SortedMap<String, Object> x = new TreeMap();
synchronized (exe) {
concepts().filter(xx -> !(xx instanceof Functor)).forEach(c -> {
// complexity.addValue(c.complexity());
volume.recordValue(c.volume());
rootOp.add(c.op());
clazz.add(c.getClass().toString());
ConceptState p = c.state();
policy.add(p != null ? p.toString() : "null");
// termlinksCap.accept(c.termlinks().capacity());
termlinkCount.recordValue(c.termlinks().size());
// tasklinksCap.accept(c.tasklinks().capacity());
tasklinkCount.recordValue(c.tasklinks().size());
beliefs.accept(c.beliefs().size());
goals.accept(c.goals().size());
questions.accept(c.questions().size());
quests.accept(c.quests().size());
});
// x.put("time real", new Date());
if (loop.isRunning()) {
loop.stats("loop", x);
}
x.put("time", time());
// x.put("term index", terms.summary());
x.put("concept count", concepts.size());
}
x.put("belief count", ((double) beliefs.getSum()));
x.put("goal count", ((double) goals.getSum()));
Util.decode(tasklinkCount, "tasklink count", 4, x::put);
// x.put("tasklink usage", ((double) tasklinkCount.getTotalCount()) / tasklinksCap.getSum());
x.put("tasklink total", ((double) tasklinkCount.getTotalCount()));
Util.decode(termlinkCount, "termlink count", 4, x::put);
// x.put("termlink usage", ((double) termlinkCount.getTotalCount()) / termlinksCap.getSum());
x.put("termlink total", ((double) termlinkCount.getTotalCount()));
// DoubleSummaryStatistics pos = new DoubleSummaryStatistics();
// DoubleSummaryStatistics neg = new DoubleSummaryStatistics();
// causes.forEach(c -> pos.accept(c.pos()));
// causes.forEach(c -> neg.accept(c.neg()));
// x.put("value count", pos.getCount());
// x.put("value pos mean", pos.getAverage());
// x.put("value pos min", pos.getMin());
// x.put("value pos max", pos.getMax());
// x.put("value neg mean", neg.getAverage());
// x.put("value neg min", neg.getMin());
// x.put("value neg max", neg.getMax());
// x.put("volume mean", volume.);
//
// x.put("termLinksCapacity", termlinksCap);
// x.put("taskLinksUsed", tasklinksUsed);
// x.put("taskLinksCapacity", tasklinksCap);
Util.toMap(policy, "concept state", x::put);
Util.toMap(rootOp, "concept op", x::put);
Util.decode(volume, "concept volume", 4, x::put);
Util.toMap(clazz, "concept class", x::put);
x.put("term cache (eternal)", Op.cache.summary());
x.put("term cache (temporal)", Op.cacheTemporal.summary());
return x;
}
use of nars.Op in project narchy by automenta.
the class IO method readTerm.
/**
* called by readTerm after determining the op type
*/
@NotNull
public static Term readTerm(DataInput in) throws IOException {
byte ob = in.readByte();
if (ob == SPECIAL_OP)
return readSpecialTerm(in);
Op o = Op.values()[ob];
if (o.var)
return readVariable(in, o);
else if (o.atomic)
return readAtomic(in, o);
else
return readCompound(in, o);
}
Aggregations