Search in sources :

Example 1 with LongInterval

use of jcog.math.LongInterval 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 LongInterval

use of jcog.math.LongInterval in project narchy by automenta.

the class RTreeBeliefTable method truth.

@Override
public Truth truth(long start, long end, EternalTable eternal, int dur) {
    assert (end >= start);
    final Task ete = eternal != null ? eternal.strongest() : null;
    int s = size();
    x: if (s > 0) {
        if (start == ETERNAL) {
            LongInterval r = ((LongInterval) root().bounds());
            if (r == null)
                break x;
            // return ete != null ? ete.truth() : null;
            start = r.start();
            end = r.end();
        }
        int maxTruths = TRUTHPOLATION_LIMIT;
        int maxTries = (int) Math.max(1, Math.ceil(capacity * SCAN_QUALITY));
        maxTries = Math.min(s * 2, /* in case the same task is encountered twice HACK*/
        maxTries);
        ScanFilter tt = new ScanFilter(maxTruths, maxTruths, task(// taskRelevance(start, end)
        taskStrength(start, end, dur)), maxTries).scan(this, start - dur, end + dur);
        if (!tt.isEmpty()) {
            return new TruthPolation(start, end, dur, tt).truth(ete);
        // PreciseTruth pt = Param.truth(null, start, end, dur, tt);
        // if (pt!=null && (ete == null || (pt.evi() >= ete.evi())))
        // return pt;
        }
    }
    return ete != null ? ete.truth() : null;
}
Also used : SignalTask(nars.task.signal.SignalTask) NALTask(nars.task.NALTask) Task(nars.Task) LongInterval(jcog.math.LongInterval) TruthPolation(nars.task.TruthPolation)

Example 3 with LongInterval

use of jcog.math.LongInterval in project narchy by automenta.

the class TaskRegion method range.

// /**
// * TODO see if this can be made faster
// */
// default long distanceTo(long start, long end) {
// assert (start != ETERNAL);
// 
// if (start == end) {
// return distanceTo(start);
// } else {
// long s = this.start();
// if (s == ETERNAL) return 0;
// 
// 
// long e = this.end();
// 
// if (Interval.intersectLength(s, e, start, end) >= 0)
// return 0; //intersects
// else {
// return Interval.unionLength(s, e, start, end) - (end - start) - (e - s);
// }
// }
// }
static long[] range(List<? extends LongInterval> ie) {
    long start = Long.MAX_VALUE, end = Long.MIN_VALUE;
    int n = ie.size();
    for (int i = 0; i < n; i++) {
        LongInterval x = ie.get(i);
        long s = x.start();
        if (s != ETERNAL) {
            if (s < start)
                start = s;
            long e = x.end();
            if (e > end)
                end = e;
        }
    }
    if (// nothing or all eternal
    start == Long.MAX_VALUE)
        return Tense.ETERNAL_ETERNAL;
    else
        return new long[] { start, end };
}
Also used : LongInterval(jcog.math.LongInterval)

Aggregations

LongInterval (jcog.math.LongInterval)3 NALTask (nars.task.NALTask)2 Task (nars.Task)1 EviDensity (nars.task.EviDensity)1 TruthPolation (nars.task.TruthPolation)1 SignalTask (nars.task.signal.SignalTask)1 Term (nars.term.Term)1 PreciseTruth (nars.truth.PreciseTruth)1 Truth (nars.truth.Truth)1 Nullable (org.jetbrains.annotations.Nullable)1