Search in sources :

Example 1 with TruthletTask

use of nars.task.signal.TruthletTask in project narchy by automenta.

the class Signal method taskStart.

public TruthletTask taskStart(Concept c, SignalTask last, Truth t, long start, long end, long stamp, int dur) {
    // boolean smooth = false;
    float fNext = t.freq();
    // if (last != null) {
    // //use a sloped connector to the previous task if it happens soon enough again (no temporal gap between them) and if its range is right
    // long gap = Math.abs(last.end() - start);
    // if ((smooth || gap > 0) && (gap <= dur / 2f)) {
    // float lastTruth = last.truth(last.end(), dur).freq();
    // long r = last.range();
    // float fPrevEnd;
    // if (smooth && (r > dur && r < dur*2))
    // fPrevEnd = fNext; //smoothing
    // else
    // fPrevEnd = lastTruth;
    // 
    // if (gap > 0 || Math.abs(lastTruth-fPrevEnd) >= Param.TRUTH_EPSILON) {
    // ((TruthletTask) last).update(c, (tt) -> {
    // //((LinearTruthlet)tt.truthlet).freqEnd = fNext;
    // LinearTruthlet l = (LinearTruthlet) ((((ProxyTruthlet) tt.truthlet)).ref);
    // l.freqEnd = fPrevEnd;
    // l.end = start;
    // });
    // }
    // }
    // }
    TruthletTask s = new TruthletTask(c.term(), punc, new SustainTruthlet(new LinearTruthlet(start, fNext, end, fNext, t.evi()), 1), start, stamp);
    s.priMax(pri.asFloat());
    return s;
}
Also used : LinearTruthlet(nars.task.signal.LinearTruthlet) TruthletTask(nars.task.signal.TruthletTask) SustainTruthlet(nars.task.signal.SustainTruthlet)

Example 2 with TruthletTask

use of nars.task.signal.TruthletTask in project narchy by automenta.

the class NARHear method hear.

private void hear(Term prev, Term next) {
    Term term = context != null ? $.func("hear", next, context) : $.func("hear", next);
    long now = nar.time();
    nar.input(new TruthletTask(// 1 word
    term, BELIEF, Truthlet.impulse(now, now + 1, /* TODO use realtime to translate wordDelayMS to cycles */
    1f, 0f, c2w(nar.confDefault(BELIEF) * confFactor)), nar).pri(nar.priDefault(BELIEF) * priorityFactor));
}
Also used : TruthletTask(nars.task.signal.TruthletTask) Term(nars.term.Term)

Example 3 with TruthletTask

use of nars.task.signal.TruthletTask 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 4 with TruthletTask

use of nars.task.signal.TruthletTask in project narchy by automenta.

the class Signal method set.

public Task set(Concept c, @Nullable Truth nextTruth, LongSupplier stamper, long now, int dur, NAR nar) {
    @Nullable Truth tt = // nextTruth;
    nextTruth != null ? nextTruth.dither(nar) : null;
    final boolean[] keep = { false };
    Task cur = current.updateAndGet((last) -> {
        if (last == null && nextTruth == null)
            return null;
        TruthletTask next;
        int gapFillTolerance = dur * 2;
        if (tt == null) {
            // no signal
            next = null;
        } else {
            if (last == null || last.isDeleted() || ((!tt.equals(last.truth(last.end()), nar) || (now - last.end() > gapFillTolerance)) || (Param.SIGNAL_LATCH_TIME_MAX != Integer.MAX_VALUE && now - last.start() >= dur * Param.SIGNAL_LATCH_TIME_MAX))) {
                long beforeNow = (last != null && (now - last.end()) < gapFillTolerance) ? last.end() : now;
                // TODO move the task construction out of this critical update section?
                next = taskStart(c, last, tt, beforeNow, now + lookAheadDurs * dur, stamper.getAsLong(), dur);
            } else {
                // nothing, keep as-is
                next = last;
            }
        }
        if (last == next) {
            if (last != null) {
                last.pri(pri.asFloat());
                last.updateEnd(c, now + lookAheadDurs * dur);
                keep[0] = true;
            }
            // dont re-input the task, just stretch it where it is in the temporal belief table
            return last;
        } else {
            // new or null input; stretch will be assigned on first insert to the belief table (if this happens)
            return next;
        }
    // } finally {
    // busy.set(false);
    // }
    });
    return keep[0] ? null : cur;
}
Also used : SignalTask(nars.task.signal.SignalTask) Task(nars.Task) TruthletTask(nars.task.signal.TruthletTask) TruthletTask(nars.task.signal.TruthletTask) Nullable(org.jetbrains.annotations.Nullable) Truth(nars.truth.Truth)

Aggregations

TruthletTask (nars.task.signal.TruthletTask)4 Term (nars.term.Term)2 Truth (nars.truth.Truth)2 Nullable (org.jetbrains.annotations.Nullable)2 BiConsumer (java.util.function.BiConsumer)1 Consumer (java.util.function.Consumer)1 LongFunction (java.util.function.LongFunction)1 Predicate (java.util.function.Predicate)1 BELIEF (nars.Op.BELIEF)1 GOAL (nars.Op.GOAL)1 Task (nars.Task)1 DurService (nars.control.DurService)1 ActiveQuestionTask (nars.task.ActiveQuestionTask)1 ITask (nars.task.ITask)1 LinearTruthlet (nars.task.signal.LinearTruthlet)1 SignalTask (nars.task.signal.SignalTask)1 SustainTruthlet (nars.task.signal.SustainTruthlet)1 Truthlet (nars.task.signal.Truthlet)1 NotNull (org.jetbrains.annotations.NotNull)1