Search in sources :

Example 26 with Op

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));
    }
}
Also used : Op(nars.Op) Test(org.junit.jupiter.api.Test)

Example 27 with Op

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());
}
Also used : Op(nars.Op) Test(org.junit.jupiter.api.Test)

Example 28 with Op

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));
    }
}
Also used : Op(nars.Op) Test(org.junit.jupiter.api.Test)

Example 29 with Op

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;
}
Also used : Atom(nars.term.atom.Atom) Ansi(org.fusesource.jansi.Ansi) GZIPInputStream(java.util.zip.GZIPInputStream) Exec(nars.exe.Exec) ConceptBuilder(nars.concept.util.ConceptBuilder) MutableInteger(jcog.math.MutableInteger) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) ConceptState(nars.concept.util.ConceptState) Truth(nars.truth.Truth) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) Op(nars.Op) Topic(jcog.event.Topic) ListTopic(jcog.event.ListTopic) TaskConcept(nars.concept.TaskConcept) TruthFunctions.c2w(nars.truth.TruthFunctions.c2w) Term(nars.term.Term) Longs(com.google.common.primitives.Longs) TriConsumer(jcog.util.TriConsumer) ShortToObjectFunction(org.eclipse.collections.api.block.function.primitive.ShortToObjectFunction) Twin(org.eclipse.collections.api.tuple.Twin) Service(jcog.Service) PreciseTruth(nars.truth.PreciseTruth) Functor.f(nars.term.Functor.f) Util(jcog.Util) BeliefTable(nars.table.BeliefTable) Nullable(org.jetbrains.annotations.Nullable) Stream(java.util.stream.Stream) ConceptIndex(nars.index.term.ConceptIndex) GZIPOutputStream(java.util.zip.GZIPOutputStream) java.util.function(java.util.function) NotNull(org.jetbrains.annotations.NotNull) Operator(nars.concept.Operator) nars.control(nars.control) java.util(java.util) Tense(nars.time.Tense) Prioritized(jcog.pri.Prioritized) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ShortCountsHistogram(org.HdrHistogram.ShortCountsHistogram) ETERNAL(nars.time.Tense.ETERNAL) AtomicReference(java.util.concurrent.atomic.AtomicReference) InvalidTaskException(nars.task.util.InvalidTaskException) nars.$.$(nars.$.$) Pri(jcog.pri.Pri) On(jcog.event.On) Cycles(nars.util.Cycles) Pair(org.eclipse.collections.api.tuple.Pair) Concept(nars.concept.Concept) Time(nars.time.Time) Ansi.ansi(org.fusesource.jansi.Ansi.ansi) NarseseException(nars.Narsese.NarseseException) Logger(org.slf4j.Logger) FasterList(jcog.list.FasterList) Functor(nars.term.Functor) Cycler(jcog.exe.Cycler) ITask(nars.task.ITask) NALTask(nars.task.NALTask) Histogram(org.HdrHistogram.Histogram) ArrayIterator(jcog.util.ArrayIterator) java.io(java.io) Subterms(nars.subterm.Subterms) Atomic(nars.term.atom.Atomic) Termed(nars.term.Termed) Services(jcog.Services) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) ShortCountsHistogram(org.HdrHistogram.ShortCountsHistogram) Histogram(org.HdrHistogram.Histogram) ShortCountsHistogram(org.HdrHistogram.ShortCountsHistogram) ConceptIndex(nars.index.term.ConceptIndex) Functor(nars.term.Functor) ConceptState(nars.concept.util.ConceptState)

Example 30 with Op

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);
}
Also used : Op(nars.Op) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Op (nars.Op)36 Term (nars.term.Term)13 Subterms (nars.subterm.Subterms)11 Nullable (org.jetbrains.annotations.Nullable)8 Atomic (nars.term.atom.Atomic)4 Test (org.junit.jupiter.api.Test)4 FasterList (jcog.list.FasterList)3 NAR (nars.NAR)3 Termed (nars.term.Termed)3 Atom (nars.term.atom.Atom)3 Bool (nars.term.atom.Bool)3 Pair (org.eclipse.collections.api.tuple.Pair)3 NotNull (org.jetbrains.annotations.NotNull)3 java.io (java.io)2 java.util (java.util)2 List (java.util.List)2 Map (java.util.Map)2 Stream (java.util.stream.Stream)2 nars.$ (nars.$)2 Concept (nars.concept.Concept)2