Search in sources :

Example 51 with Truth

use of nars.truth.Truth in project narchy by automenta.

the class BeliefTableChart method renderTable.

private void renderTable(Concept c, long minT, long maxT, long now, GL2 gl, TruthWave wave, boolean beliefOrGoal) {
    if (c == null)
        return;
    float nowX = xTime(minT, maxT, now);
    // Present axis line
    if ((now <= maxT) && (now >= minT)) {
        gl.glColor4f(1f, 1f, 1f, 0.5f);
        Draw.line(gl, nowX, 0, nowX, 1);
    // float nowLineWidth = 0.005f;
    // Draw.rect(gl, nowX - nowLineWidth / 2f, 0, nowLineWidth, 1);
    }
    /**
     * drawn "pixel" dimensions
     */
    renderWave(nowX, minT, maxT, gl, wave, beliefOrGoal);
    // draw projections
    if (projections > 0 && minT != maxT) {
        for (boolean freqOrExp : new boolean[] { true, false }) {
            TruthWave pwave = beliefOrGoal ? beliefProj : goalProj;
            // HACK dont show expectation for beliefs
            if (beliefOrGoal && !freqOrExp)
                continue;
            Colorize colorize;
            if (freqOrExp) {
                colorize = beliefOrGoal ? (ggl, frq, cnf) -> {
                    float a = 0.65f + 0.2f * cnf;
                    ggl.glColor4f(0.25f + 0.75f * cnf, 0.1f * (1f - cnf), 0, a);
                } : (ggl, frq, cnf) -> {
                    float a = 0.65f + 0.2f * cnf;
                    ggl.glColor4f(0.1f * (1f - cnf), 0.25f + 0.75f * cnf, 0, a);
                };
            } else {
                colorize = beliefOrGoal ? (ggl, frq, cnf) -> {
                    ggl.glColor4f(cnf, cnf / 2f, 0.25f, 0.85f);
                } : (ggl, frq, cnf) -> {
                    ggl.glColor4f(cnf / 2f, cnf, 0.25f, 0.85f);
                };
            }
            FloatFloatToFloatFunction y = freqOrExp ? (frq, cnf) -> frq : TruthFunctions::expectation;
            // HACK show goal freq in thinner line
            gl.glLineWidth((freqOrExp && !beliefOrGoal) ? 2f : 4f);
            renderWaveLine(nowX, minT, maxT, gl, pwave, y, colorize);
        }
    }
    float chSize = 0.1f;
    Truth bc = wave.current;
    if (bc != null) {
        float theta;
        float expectation = bc.expectation();
        float dTheta = (expectation - 0.5f) * angleSpeed;
        float conf = bc.conf();
        if (beliefOrGoal) {
            this.beliefTheta += dTheta;
            theta = beliefTheta;
            gl.glColor4f(1f, 0f, 0, 0.2f + 0.8f * conf);
            drawCrossHair(gl, nowX, chSize, bc.freq(), conf, theta);
        } else {
            this.goalTheta += dTheta;
            theta = goalTheta;
            // //freq
            // gl.glColor4f(0f, 1f, 0, 0.2f + 0.8f * conf);
            // drawCrossHair(gl, nowX, chSize, bc.freq(), conf, theta);
            // expectation
            gl.glColor4f(0f, 1f, 0, 0.2f + 0.8f * conf);
            drawCrossHair(gl, nowX, chSize, expectation, expectation, theta);
        }
    }
}
Also used : GL2(com.jogamp.opengl.GL2) DurService(nars.control.DurService) PushButton(spacegraph.space2d.widget.button.PushButton) BiFunction(java.util.function.BiFunction) Surface(spacegraph.space2d.Surface) ETERNAL(nars.time.Tense.ETERNAL) Draw(spacegraph.video.Draw) Util(jcog.Util) RectFloat2D(jcog.tree.rtree.rect.RectFloat2D) TruthWave(nars.truth.TruthWave) MetaFrame(spacegraph.space2d.widget.meta.MetaFrame) TruthFunctions(nars.truth.TruthFunctions) BeliefTable(nars.table.BeliefTable) Task(nars.Task) Truth(nars.truth.Truth) NAR(nars.NAR) Gridding(spacegraph.space2d.container.Gridding) Termed(nars.term.Termed) PI(java.lang.Math.PI) TaskConcept(nars.concept.TaskConcept) Concept(nars.concept.Concept) Label(spacegraph.space2d.widget.text.Label) FloatFloatToFloatFunction(jcog.util.FloatFloatToFloatFunction) Term(nars.term.Term) FloatFloatToFloatFunction(jcog.util.FloatFloatToFloatFunction) TruthFunctions(nars.truth.TruthFunctions) TruthWave(nars.truth.TruthWave) Truth(nars.truth.Truth)

Example 52 with Truth

use of nars.truth.Truth 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 53 with Truth

use of nars.truth.Truth in project narchy by automenta.

the class BeliefActionConcept method update.

// @Override
// public @Nullable Task curiosity(float conf, long next, NAR nar) {
// return ActionConcept.curiosity(term(), BELIEF, conf, next, nar);
// }
@Override
public Stream<ITask> update(long start, long end, int dur, NAR nar) {
    long nowStart = // now;
    start - dur / 2;
    long nowEnd = // now + dur;
    start + dur / 2;
    Truth belief = this.beliefs().truth(nowStart, nowEnd, nar);
    // if (nar.random().nextFloat() < curiosity) {
    // float f = nar.random().nextFloat();
    // float c = nar.confDefault(BELIEF);
    // nar.believe(term(), Tense.Present, f, c);
    // belief = $.t(f, c);
    // } else {
    // beliefIntegrated.commitAverage();
    // }
    // Truth goal =
    // this.goals().truth(nowStart, nowEnd, nar);
    // //                //goalIntegrated.commitAverage();
    // if (goal!=null) {
    // if (belief!=null)
    // belief = Revision.revise(belief, goal,1f, 0f);
    // else
    // belief = goal;
    // 
    // }
    // Task x;
    // if (belief!=null) {
    // x = feedback.set(this, belief, nar.time::nextStamp, nowStart, dur, nar);
    // } else {
    // x = feedback.get(); //latch
    // }
    action.accept(belief == null ? null : belief.truth());
    return Stream.empty();
}
Also used : Truth(nars.truth.Truth)

Example 54 with Truth

use of nars.truth.Truth in project narchy by automenta.

the class IO method readTask.

@NotNull
public static NALTask readTask(DataInput in) throws IOException {
    Term preterm = readTerm(in);
    final Term term = preterm.normalize();
    if (term == null)
        throw new IOException("un-normalizable task term");
    byte punc = in.readByte();
    Truth truth = hasTruth(punc) ? readTruth(in) : null;
    long start = in.readLong();
    long end = in.readLong();
    long[] evi = readEvidence(in);
    float pri = in.readFloat();
    long cre = in.readLong();
    NALTask mm = new NALTask(term, punc, truth, cre, start, end, evi);
    mm.priSet(pri);
    return mm;
}
Also used : NALTask(nars.task.NALTask) Term(nars.term.Term) Truth(nars.truth.Truth) NotNull(org.jetbrains.annotations.NotNull)

Example 55 with Truth

use of nars.truth.Truth in project narchy by automenta.

the class RelationClustering method link.

@Override
protected void link(Task tx, Task ty) {
    // TODO abstract
    assert (tx.isBelief() && ty.isBelief());
    // TODO Allen interval
    String relation;
    if (tx.intersects(ty.start(), ty.end())) {
        relation = "simul";
    } else if (ty.isAfter(tx.end(), dur / 2)) {
        relation = "seq";
    } else if (tx.isAfter(ty.end(), dur / 2)) {
        Task z = tx;
        tx = ty;
        ty = z;
        relation = "seq";
    } else {
        relation = null;
    }
    if (relation != null) {
        Term x = tx.term();
        Truth truX = tx.truth();
        if (truX.isNegative()) {
            x = x.neg();
            truX = truX.neg();
        }
        Term y = ty.term();
        Truth truY = ty.truth();
        if (truY.isNegative()) {
            y = y.neg();
            truY = truY.neg();
        }
        if (x.volume() + y.volume() < nar.termVolumeMax.intValue() - 2) {
            Truth tru = TruthFunctions.intersection(truX, truY, nar.confMin.floatValue());
            if (tru == null)
                return;
            // TODO enum
            Term t;
            switch(relation) {
                case "simul":
                    t = $.inh(SETe.the(x, y), $.the("simul"));
                    break;
                case "seq":
                    t = $.func(relation, x, y);
                    break;
                default:
                    throw new UnsupportedOperationException();
            }
            if (t instanceof Bool)
                return;
            t = t.normalize();
            long now = nar.time();
            NALTask tt = new NALTask(t, BELIEF, tru, now, Math.min(tx.start(), ty.start()), Math.max(tx.end(), ty.end()), nar.time.nextStampArray());
            tt.pri(tx.priElseZero() * ty.priElseZero());
            in.input(tt);
        }
    }
}
Also used : ITask(nars.task.ITask) NALTask(nars.task.NALTask) Task(nars.Task) Bool(nars.term.atom.Bool) NALTask(nars.task.NALTask) Term(nars.term.Term) Truth(nars.truth.Truth)

Aggregations

Truth (nars.truth.Truth)65 Term (nars.term.Term)31 Test (org.junit.jupiter.api.Test)22 Nullable (org.jetbrains.annotations.Nullable)20 NAR (nars.NAR)18 Task (nars.Task)14 BeliefTable (nars.table.BeliefTable)13 Concept (nars.concept.Concept)9 NALTask (nars.task.NALTask)9 TaskConcept (nars.concept.TaskConcept)7 PreciseTruth (nars.truth.PreciseTruth)7 NotNull (org.jetbrains.annotations.NotNull)7 FasterList (jcog.list.FasterList)6 ITask (nars.task.ITask)6 Tense (nars.time.Tense)6 Util (jcog.Util)5 BELIEF (nars.Op.BELIEF)5 Consumer (java.util.function.Consumer)4 Predicate (java.util.function.Predicate)4 Param (nars.Param)4