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