Search in sources :

Example 1 with Bag

use of jcog.bag.Bag 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)

Aggregations

Bag (jcog.bag.Bag)1 PLink (jcog.pri.PLink)1 PriReference (jcog.pri.PriReference)1 Concept (nars.concept.Concept)1 Term (nars.term.Term)1 MutableFloat (org.apache.commons.lang3.mutable.MutableFloat)1 Nullable (org.jetbrains.annotations.Nullable)1