use of jcog.pri.PriReference 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 jcog.pri.PriReference in project narchy by automenta.
the class Activate method premises.
/**
* hypothesize premises, up to a max specified #
*/
/*@NotNull*/
public void premises(NAR nar, BiPredicate<Task, PriReference<Term>> each, int _tasklinks, int _termlinksPerTasklink) {
nar.emotion.conceptFire.increment();
Bag<?, TaskLink> tasklinks = id.tasklinks();
float linkForgetting = nar.forgetRate.floatValue();
tasklinks.commit(tasklinks.forget(linkForgetting));
int ntasklinks = tasklinks.size();
if (ntasklinks == 0)
return;
final Bag<Term, PriReference<Term>> termlinks = id.termlinks();
termlinks.commit(termlinks.forget(linkForgetting));
int ntermlinks = termlinks.size();
if (ntermlinks == 0)
// TODO when can this happen
return;
int[] ttl = { _tasklinks * _termlinksPerTasklink };
Random rng = nar.random();
// ((TaskLinkCurveBag)tasklinks).compress(nar);
tasklinks.sample(rng, _tasklinks, tasklink -> {
Task task = tasklink.get(nar);
if (task != null) {
// if (priApplied > Pri.EPSILON)
Tasklinks.linkTaskTemplates(id, task, /*pri * */
task.priElseZero(), nar);
termlinks.sample(rng, _termlinksPerTasklink, (termlink) -> {
if (!each.test(task, termlink)) {
ttl[0] = 0;
return false;
} else {
return (--ttl[0] > 0);
}
});
} else {
tasklink.delete();
// safety misfire decrement
--ttl[0];
}
// ? Bag.BagSample.Next : Bag.BagSample.Stop;
return (ttl[0] > 0);
});
}
use of jcog.pri.PriReference in project narchy by automenta.
the class TermlinkTemplates method activate.
public void activate(Concept src, float budgeted, NAR nar) {
int n = this.size();
if (n == 0)
return;
float budgetedToEach = budgeted / n;
// if (budgetedToEach < Pri.EPSILON)
// return;
MutableFloat refund = new MutableFloat(0);
// int nextTarget = nar.random().nextInt(n);
Term srcTerm = src.term();
Bag<Term, PriReference<Term>> srcTermLinks = src.termlinks();
float balance = nar.termlinkBalance.floatValue();
for (int i = 0; i < n; i++) {
Term tgtTerm = get(i);
boolean reverseLinked = false;
boolean conceptualizable = i < concepts;
if (conceptualizable) {
@Nullable Concept tgt = nar.conceptualize(tgtTerm);
float budgetedForward = budgetedToEach * (1f - balance);
float budgetedReverse = budgetedToEach * balance;
if (tgt != null) {
// insert termlink
tgt.termlinks().put(new PLink<>(srcTerm, budgetedForward), refund);
nar.activate(tgt, // budgetedToEach
budgetedForward);
reverseLinked = true;
// use the concept's id
tgtTerm = tgt.term();
}
if (!reverseLinked)
refund.add(budgetedForward);
((Bag) srcTermLinks).put(new PLink(tgtTerm, budgetedReverse), refund);
}
// float r = refund.floatValue();
// float cost = budgeted - r;
// return cost;
}
}
use of jcog.pri.PriReference in project narchy by automenta.
the class QuerySpider method spider.
/**
* resource-constrained breadth first search
*/
private AdjGraph<Term, Float> spider(NAR nar, Termed t, AdjGraph<Term, Float> g, int recurse) {
Term tt = t.term();
if (tt.op().conceptualizable && g.addIfNew(tt) && recurse > 0) {
Concept c = nar.conceptualize(t);
if (c == null)
return g;
Bag<Term, PriReference<Term>> tl = c.termlinks();
if (!tl.isEmpty()) {
TermGraph.termlink(nar, tl.stream().map(PriReference::get), g);
} else {
TermGraph.termlink(nar, c.templates().stream(), g);
}
g.nodes.forEachKey(k -> {
spider(nar, k.v, g, recurse - 1);
});
} else {
g.addNode(tt);
}
return g;
}
Aggregations