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;
}
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));
}
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;
});
}
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;
}
Aggregations