Search in sources :

Example 1 with EviDensity

use of nars.task.EviDensity in project narchy by automenta.

the class DynTruth method eval.

/**
 * TODO make Task truth dithering optional
 */
public Truthed eval(@NotNull Term superterm, @Deprecated BiFunction<DynTruth, NAR, Truth> truthModel, boolean taskOrJustTruth, boolean beliefOrGoal, float freqRes, float confRes, float eviMin, NAR nar) {
    Truth t = truthModel.apply(this, nar);
    if (t == null)
        return null;
    float evi = t.evi();
    if (evi < eviMin)
        return null;
    // this may have already been done in truth calculation
    // //TODO compute max valid overlap to terminate the zip early
    ObjectFloatPair<long[]> ss = Stamp.zip((List) this, Param.STAMP_CAPACITY);
    // evi = evi * Param.overlapFactor(ss.getTwo());
    // if (evi < eviMin)
    // return null;
    float freq = t.freq();
    float f;
    long start, end;
    if (taskOrJustTruth) {
        if (size() > 1) {
            if (superterm.op() == CONJ) {
                long min = TIMELESS;
                long maxRange = 0;
                boolean eternals = false;
                for (int i = 0, thisSize = size(); i < thisSize; i++) {
                    LongInterval ii = get(i);
                    long iis = ii.start();
                    if (iis != ETERNAL) {
                        min = Math.min(min, iis);
                        maxRange = Math.max(maxRange, ii.end() - iis);
                    } else {
                        eternals = true;
                    }
                }
                if (eternals && min == TIMELESS) {
                    start = end = ETERNAL;
                } else {
                    assert (min != TIMELESS);
                    // if (min == Long.MAX_VALUE)
                    // start = end = ETERNAL; //all eternal
                    // else {
                    start = min;
                    end = (min + maxRange);
                }
            // }
            } else {
                // dilute the evidence in proportion to temporal sparseness for non-temporal results
                EviDensity se = new EviDensity(this);
                evi *= se.factor();
                if (evi != evi || evi < eviMin)
                    return null;
                start = se.unionStart;
                end = se.unionEnd;
            }
        } else {
            // only one task
            LongInterval only = get(0);
            start = only.start();
            end = only.end();
        }
        if (superterm.op() == NEG) {
            // unneg if constructing a task, but dont if just returning the truth
            superterm = superterm.unneg();
            f = 1f - freq;
        } else {
            f = freq;
        }
    } else {
        // not used
        start = end = XTERNAL;
        f = freq;
    }
    if (!taskOrJustTruth)
        return Truth.theDithered(f, freqRes, evi, confRes, w2cSafe(eviMin));
    // undithered until final step for max precision
    PreciseTruth tr = new PreciseTruth(f, evi, false);
    // then if the term is valid, see if it is valid for a task
    Term content = truthModel instanceof DynamicTruthModel ? ((DynamicTruthModel) truthModel).construct(superterm, this) : superterm;
    @Nullable ObjectBooleanPair<Term> r = Task.tryContent(// otherwise consider the superterm argument as the task content
    content, beliefOrGoal ? BELIEF : GOAL, !Param.DEBUG_EXTRA);
    if (r == null)
        return null;
    NALTask dyn = new DynamicTruthTask(r.getOne(), beliefOrGoal, tr.negIf(r.getTwo()).dither(freqRes, confRes, w2cSafe(eviMin)), nar, start, end, ss.getOne());
    // if (ss.getTwo() > 0) dyn.setCyclic(true);
    dyn.cause = cause();
    dyn.priSet(pri());
    if (Param.DEBUG_EXTRA)
        dyn.log("Dynamic");
    return dyn;
}
Also used : EviDensity(nars.task.EviDensity) Term(nars.term.Term) PreciseTruth(nars.truth.PreciseTruth) LongInterval(jcog.math.LongInterval) NALTask(nars.task.NALTask) Truth(nars.truth.Truth) PreciseTruth(nars.truth.PreciseTruth) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with EviDensity

use of nars.task.EviDensity in project narchy by automenta.

the class DeriveTime method solveRaw.

/**
 * as a backup option
 */
private Term solveRaw(Term x) {
    long s, e;
    /*if (task.isQuestOrQuestion() && (!task.isEternal() || belief == null)) {
            //inherit question's specific time directly
            s = task.start();
            e = task.end();
        } else*/
    {
        boolean taskEvent = // !task.term().op().temporal;
        !(task.term().op() == CONJ);
        if (task.isEternal()) {
            if (belief == null || belief.isEternal()) {
                // entirely eternal
                s = e = ETERNAL;
            } else {
                if (taskEvent) {
                    s = belief.start();
                    e = belief.end();
                } else {
                    // transformed task term, should have been solved
                    return null;
                }
            }
        } else {
            if (belief == null) {
                // inherit task time
                s = task.start();
                e = task.end();
            } else if (belief.isEternal()) {
                if (!task.isEternal()) {
                    // inherit task time
                    s = task.start();
                    e = task.end();
                } else {
                    s = e = ETERNAL;
                }
            // //event: inherit task time
            // boolean beliefEvent = belief == null || (
            // !belief.term().op().temporal
            // );
            // if (beliefEvent) {
            // s = task.start();
            // e = task.end();
            // } else {
            // return null; //should have calculated solution normally
            // }
            // }
            } else {
                if (!task.isQuestOrQuestion() && !belief.isQuestOrQuestion()) {
                    EviDensity density = new EviDensity(task, belief);
                    s = density.unionStart;
                    e = density.unionEnd;
                    d.concEviFactor *= density.factor();
                } else {
                    Longerval u = Longerval.union(task.start(), task.end(), belief.start(), belief.end());
                    s = u.start();
                    e = u.end();
                }
            }
        }
    }
    if (!eternalCheck(s))
        return null;
    long[] occ = d.concOcc;
    occ[0] = s;
    occ[1] = e;
    return x;
}
Also used : Longerval(jcog.math.Longerval) EviDensity(nars.task.EviDensity)

Aggregations

EviDensity (nars.task.EviDensity)2 LongInterval (jcog.math.LongInterval)1 Longerval (jcog.math.Longerval)1 NALTask (nars.task.NALTask)1 Term (nars.term.Term)1 PreciseTruth (nars.truth.PreciseTruth)1 Truth (nars.truth.Truth)1 Nullable (org.jetbrains.annotations.Nullable)1