Search in sources :

Example 11 with TaskConcept

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());
}
Also used : TaskConcept(nars.concept.TaskConcept) RTreeBeliefTable(nars.table.RTreeBeliefTable) Term(nars.term.Term) Test(org.junit.jupiter.api.Test)

Example 12 with TaskConcept

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

Example 13 with TaskConcept

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

Example 14 with TaskConcept

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;
}
Also used : GL2(com.jogamp.opengl.GL2) IntStream(java.util.stream.IntStream) Iterables(com.google.common.collect.Iterables) Tense(nars.time.Tense) BeliefTableChart(nars.gui.BeliefTableChart) Bitmap2DSensor(nars.util.signal.Bitmap2DSensor) nars(nars) Rectangle2D(java.awt.geom.Rectangle2D) Surface(spacegraph.space2d.Surface) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AspectAlign(spacegraph.space2d.container.AspectAlign) Draw(spacegraph.video.Draw) MLPMap(jcog.learn.MLPMap) Truth(nars.truth.Truth) Lists(com.google.common.collect.Lists) IntToFloatFunction(org.eclipse.collections.api.block.function.primitive.IntToFloatFunction) Gridding(spacegraph.space2d.container.Gridding) Plot2D(spacegraph.space2d.widget.meter.Plot2D) TaskConcept(nars.concept.TaskConcept) Concept(nars.concept.Concept) CameraSensorView(nars.video.CameraSensorView) Term(nars.term.Term) IntFunction(java.util.function.IntFunction) BufferedImage(java.awt.image.BufferedImage) Collection(java.util.Collection) PixelBag(nars.video.PixelBag) Util(jcog.Util) java.awt(java.awt) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Scale(nars.video.Scale) SpaceGraph(spacegraph.SpaceGraph) BELIEF(nars.Op.BELIEF) Termed(nars.term.Termed) TaskConcept(nars.concept.TaskConcept) Concept(nars.concept.Concept) GL2(com.jogamp.opengl.GL2) CameraSensorView(nars.video.CameraSensorView) Gridding(spacegraph.space2d.container.Gridding) AspectAlign(spacegraph.space2d.container.AspectAlign) Plot2D(spacegraph.space2d.widget.meter.Plot2D) Truth(nars.truth.Truth)

Example 15 with TaskConcept

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);
        }
    }
}
Also used : TaskConcept(nars.concept.TaskConcept) Concept(nars.concept.Concept) PermanentConcept(nars.concept.PermanentConcept) PermanentConcept(nars.concept.PermanentConcept) TaskConcept(nars.concept.TaskConcept)

Aggregations

TaskConcept (nars.concept.TaskConcept)16 Test (org.junit.jupiter.api.Test)11 Concept (nars.concept.Concept)5 Term (nars.term.Term)4 Truth (nars.truth.Truth)4 RTreeBeliefTable (nars.table.RTreeBeliefTable)3 Collectors.toList (java.util.stream.Collectors.toList)2 nars (nars)2 NAR (nars.NAR)2 BELIEF (nars.Op.BELIEF)2 BeliefTable (nars.table.BeliefTable)2 Termed (nars.term.Termed)2 TestNAR (nars.test.TestNAR)2 Tense (nars.time.Tense)2 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 GL2 (com.jogamp.opengl.GL2)1 java.awt (java.awt)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedImage (java.awt.image.BufferedImage)1