Search in sources :

Example 36 with Truth

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

the class NARIn method taskWhile.

default DurService taskWhile(Term term, byte punc, Truth tru, Predicate<Task> cond) {
    // HACK
    NAR n = (NAR) this;
    long start = n.time();
    float activeFreq = tru.freq();
    float inactiveFreq = 0f;
    float evi = tru.evi();
    LongFunction<Truthlet> stepUntil = (toWhen) -> {
        return Truthlet.step(inactiveFreq, start, activeFreq, toWhen, activeFreq, evi);
    };
    TruthletTask t = new TruthletTask(term, punc, stepUntil.apply(start), n);
    float pri = n.priDefault(punc);
    t.priMax(pri);
    n.input(t);
    return DurService.onWhile(n, (nn) -> {
        // nn.runLater(()->{
        // t.concept(nn, false).goals().print();
        // System.out.println();
        // });
        long now = nn.time();
        boolean kontinue;
        Truthlet tt;
        if (!cond.test(t)) {
            // convert from step function to impulse function which
            // stops at the current time and end the service
            tt = Truthlet.impulse(start, now, activeFreq, inactiveFreq, evi);
            kontinue = false;
        } else {
            // stretch the step function to current time
            tt = stepUntil.apply(now);
            kontinue = true;
        }
        t.priMax(pri);
        t.truth(tt, true, nn);
        return kontinue;
    });
}
Also used : DurService(nars.control.DurService) LongFunction(java.util.function.LongFunction) Predicate(java.util.function.Predicate) ITask(nars.task.ITask) ActiveQuestionTask(nars.task.ActiveQuestionTask) Truthlet(nars.task.signal.Truthlet) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) TruthletTask(nars.task.signal.TruthletTask) Truth(nars.truth.Truth) BiConsumer(java.util.function.BiConsumer) BELIEF(nars.Op.BELIEF) NotNull(org.jetbrains.annotations.NotNull) Term(nars.term.Term) GOAL(nars.Op.GOAL) Truthlet(nars.task.signal.Truthlet) TruthletTask(nars.task.signal.TruthletTask)

Example 37 with Truth

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

the class ScalarBeliefTable method eval.

protected Truthed eval(boolean taskOrJustTruth, long start, long end, NAR nar) {
    int dur = nar.dur();
    DynTruth d = series.truth(start, end, dur, nar);
    if (d == null)
        return null;
    TruthPolation p = new TruthPolation(start, end, dur, d);
    Truth pp = p.truth(false);
    if (pp == null)
        return null;
    float freqRes = taskOrJustTruth ? Math.max(nar.freqResolution.floatValue(), res.asFloat()) : 0;
    float confRes = // nar.confResolution.floatValue();
    0;
    float eviMin = Truth.EVI_MIN;
    return d.eval(term, (dd, n) -> pp, taskOrJustTruth, beliefOrGoal, freqRes, confRes, eviMin, nar);
}
Also used : TruthPolation(nars.task.TruthPolation) Truth(nars.truth.Truth)

Example 38 with Truth

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

the class PriMapConceptIndex method value.

private float value(Concept c) {
    // float maxAdmit = -victims.minAdmission();
    float score = 0;
    // score += ((float) c.beliefs().stream().mapToDouble(taskScore).average().orElse(0));
    // score += ((float) c.goals().stream().mapToDouble(taskScore).average().orElse(0));
    long now = nar.time();
    if (c.op().beliefable) {
        // ,nar.dur()*8 /* dilated duration perspective */);
        Truth bt = c.beliefs().truth(now, nar);
        if (bt != null)
            score += bt.conf();
    }
    if (c.op().goalable) {
        Truth gt = c.goals().truth(now, nar);
        if (gt != null)
            score += gt.conf();
    } else {
        // double any belief score, ie. for ==>
        score = score * 2;
    }
    // link value is divided by the complexity,
    // representing increassed link 'maintenance cost'
    // involved in terms with higher complexity
    // that were ultimately necessary to
    // form and supporting the beliefs and goals counted above,
    // (they are not divided like this)
    int complexity = c.complexity();
    Bag<?, TaskLink> ta = c.tasklinks();
    score += (ta.size() / (1f + ta.capacity())) / complexity;
    Bag<Term, PriReference<Term>> te = c.termlinks();
    score += (te.size() / (1f + te.capacity())) / complexity;
    return score;
}
Also used : TaskLink(nars.link.TaskLink) Term(nars.term.Term) PriReference(jcog.pri.PriReference) Truth(nars.truth.Truth)

Example 39 with Truth

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

the class Taskify method test.

/**
 * note: the return value here shouldnt matter so just return true anyway
 */
@Override
public boolean test(Derivation d) {
    Truth tru = d.concTruth;
    if (tru != null) {
        float finalEvi = tru.evi() * d.concEviFactor;
        if (d.eviMin > finalEvi) {
            d.use(Param.TTL_EVI_INSUFFICIENT);
            return true;
        }
        tru = tru.withEvi(finalEvi);
    }
    Term x0 = d.derivedTerm.get();
    Term x = d.anon.get(x0).normalize();
    long[] occ = d.concOcc;
    byte punc = d.concPunc;
    assert (punc != 0) : "no punctuation assigned";
    DerivedTask t = (DerivedTask) Task.tryTask(x, punc, tru, (C, tr) -> {
        int dither = d.ditherTime;
        long start = Tense.dither(occ[0], dither);
        long end = Tense.dither(occ[1], dither);
        assert (end >= start) : "task has reversed occurrence: " + start + ".." + end;
        return Param.DEBUG ? new DebugDerivedTask(C, punc, tr, start, end, d) : new DerivedTask(C, punc, tr, start, end, d);
    });
    if (t == null) {
        d.nar.emotion.deriveFailTaskify.increment();
        return spam(d, Param.TTL_DERIVE_TASK_FAIL);
    }
    if (same(t, d._task, d.freqRes) || (d._belief != null && same(t, d._belief, d.freqRes))) {
        d.nar.emotion.deriveFailParentDuplicate.increment();
        return spam(d, Param.TTL_DERIVE_TASK_SAME);
    }
    if (d.single)
        t.setCyclic(true);
    float priority = d.deriver.prioritize.pri(t, d);
    if (priority != priority) {
        d.nar.emotion.deriveFailPrioritize.increment();
        return spam(d, Param.TTL_DERIVE_TASK_PRIORITIZE);
    }
    t.priSet(priority);
    t.cause = ArrayUtils.addAll(d.parentCause, channel.id);
    if (d.add(t) != t) {
        d.nar.emotion.deriveFailDerivationDuplicate.increment();
        spam(d, Param.TTL_DERIVE_TASK_REPEAT);
    } else {
        if (Param.DEBUG)
            t.log(channel.ruleString);
        d.use(Param.TTL_DERIVE_TASK_SUCCESS);
    }
    return true;
}
Also used : DebugDerivedTask(nars.task.DebugDerivedTask) Tense(nars.time.Tense) Logger(org.slf4j.Logger) DerivedTask(nars.task.DerivedTask) FILTER_SIMILAR_DERIVATIONS(nars.Param.FILTER_SIMILAR_DERIVATIONS) LoggerFactory(org.slf4j.LoggerFactory) ArrayUtils(org.apache.commons.lang3.ArrayUtils) BOOL(nars.Op.BOOL) nars.$(nars.$) Util(jcog.Util) NALTask(nars.task.NALTask) Param(nars.Param) AbstractPred(nars.term.pred.AbstractPred) Task(nars.Task) Truth(nars.truth.Truth) VAR_PATTERN(nars.Op.VAR_PATTERN) Term(nars.term.Term) Term(nars.term.Term) DebugDerivedTask(nars.task.DebugDerivedTask) DerivedTask(nars.task.DerivedTask) DebugDerivedTask(nars.task.DebugDerivedTask) Truth(nars.truth.Truth)

Example 40 with Truth

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

the class Solve method test.

@Override
public final boolean test(Derivation d) {
    d.truthFunction = null;
    byte punc = punc(d);
    boolean single;
    Truth t;
    switch(punc) {
        case BELIEF:
        case GOAL:
            TruthOperator f = (punc == BELIEF) ? belief : goal;
            d.truthFunction = f;
            if (f == null)
                // there isnt a truth function for this punctuation
                return false;
            single = f.single();
            Truth beliefTruth = d.beliefTruth;
            if (!single && beliefTruth == null)
                // double premise requiring a belief, but belief is null
                return false;
            if ((t = f.apply(// task truth is not involved in the outcome of this; set task truth to be null to prevent any negations below:
            d.taskTruth, single ? null : beliefTruth, d.nar, d.confMin)) == null)
                return false;
            float overlap = f.allowOverlap() ? 0 : single ? d.overlapSingle : d.overlapDouble;
            if (overlap > 0) {
                return false;
            // float e = t.evi() * (1f-overlap);
            // if (e < Pri.EPSILON) //yes Pri epsilon
            // return false;
            // 
            // t = t.withEvi(e);
            // if (t.conf() < confMin)
            // return false;
            // if (d.random.nextFloat() <= overlap)
            // return false;
            }
            break;
        case QUEST:
        case QUESTION:
            float o = d.overlapSingle;
            if (o > 0 && d.random.nextFloat() <= o)
                return false;
            // byte tp = d.taskPunct;
            // if ((tp == QUEST) || (tp == GOAL))
            // punc = QUEST; //use QUEST in relation to GOAL or QUEST task
            single = true;
            t = null;
            break;
        default:
            throw new InvalidPunctuationException(punc);
    }
    d.concTruth = t;
    d.concPunc = punc;
    d.single = single;
    return true;
}
Also used : TruthOperator(nars.truth.func.TruthOperator) 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