Search in sources :

Example 6 with PriReference

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;
}
Also used : TaskLink(nars.link.TaskLink) Term(nars.term.Term) PriReference(jcog.pri.PriReference) Truth(nars.truth.Truth)

Example 7 with PriReference

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);
    });
}
Also used : Task(nars.Task) Random(java.util.Random) TaskLink(nars.link.TaskLink) Term(nars.term.Term) PriReference(jcog.pri.PriReference)

Example 8 with PriReference

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;
    }
}
Also used : Concept(nars.concept.Concept) PLink(jcog.pri.PLink) MutableFloat(org.apache.commons.lang3.mutable.MutableFloat) Bag(jcog.bag.Bag) Term(nars.term.Term) PriReference(jcog.pri.PriReference) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with PriReference

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;
}
Also used : Concept(nars.concept.Concept) Term(nars.term.Term) PriReference(jcog.pri.PriReference)

Aggregations

PriReference (jcog.pri.PriReference)9 Term (nars.term.Term)5 PLink (jcog.pri.PLink)4 Concept (nars.concept.Concept)3 DefaultHijackBag (jcog.bag.impl.hijack.DefaultHijackBag)2 TaskLink (nars.link.TaskLink)2 Nullable (org.jetbrains.annotations.Nullable)2 Test (org.junit.jupiter.api.Test)2 java.io (java.io)1 java.util (java.util)1 Random (java.util.Random)1 TreeSet (java.util.TreeSet)1 Predicate (java.util.function.Predicate)1 ScriptException (javax.script.ScriptException)1 TODO (jcog.TODO)1 Texts (jcog.Texts)1 User (jcog.User)1 Bag (jcog.bag.Bag)1 BagTest (jcog.bag.BagTest)1 PLinkArrayBag (jcog.bag.impl.PLinkArrayBag)1