Search in sources :

Example 1 with TaskLink

use of nars.link.TaskLink 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 2 with TaskLink

use of nars.link.TaskLink 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 3 with TaskLink

use of nars.link.TaskLink in project narchy by automenta.

the class RevisionTest method testRevisionBudgeting.

/**
 * test that budget is conserved during a revision between
 * the input tasks and the result
 */
@Test
public void testRevisionBudgeting() {
    NAR n = newNAR(6);
    BeliefAnalysis b = new BeliefAnalysis(n, x);
    assertEquals(0, b.priSum(), 0.01f);
    b.believe(1.0f, 0.5f).run(1);
    Bag<?, TaskLink> tasklinks = b.concept().tasklinks();
    assertEquals(0.5f, b.beliefs().match(ETERNAL, null, n).truth().conf(), 0.01f);
    printTaskLinks(b);
    System.out.println("--------");
    float linksBeforeRevisionLink = tasklinks.priSum();
    b.believe(0.0f, 0.5f).run(1);
    // assertEquals(2, tasklinks.size());
    printTaskLinks(b);
    System.out.println("--------");
    // allow enough time for tasklinks bag to commit
    b.run(1);
    tasklinks.commit();
    printTaskLinks(b);
    System.out.println("--------");
    System.out.println("Beliefs: ");
    b.print();
    System.out.println("\tSum Priority: " + b.priSum());
    float beliefAfter2;
    assertEquals(1.0f, beliefAfter2 = b.priSum(), 0.1f);
    // assertEquals(linksBeforeRevisionLink, tasklinks.priSum(), 0.01f);
    // the revised task on top
    assertEquals(0.71f, b.beliefs().match(ETERNAL, null, n).truth().conf(), 0.06f);
    b.print();
    // revised:
    assertEquals(3, b.size(true));
    // 3 if a non-revised eternal task (which creates a revision) revised eternal task is also input/processed. 2 if it is not
    // assertEquals(3, tasklinks.size());
    // CONSERVED BELIEF BUDGET
    assertEquals(beliefAfter2, b.priSum(), 0.01f);
// tasklinks.commit();
// tasklinks.print();
// without tasklink balancing: 1.24 - 0.97
// with balancing: 1.10 - 0.97
// assertEquals( linksBeforeRevisionLink, tasklinks.priSum(), 0.1f); //CONSERVED LINK BUDGET
}
Also used : BeliefAnalysis(nars.test.analyze.BeliefAnalysis) TaskLink(nars.link.TaskLink) Test(org.junit.jupiter.api.Test)

Aggregations

TaskLink (nars.link.TaskLink)3 PriReference (jcog.pri.PriReference)2 Term (nars.term.Term)2 Random (java.util.Random)1 Task (nars.Task)1 BeliefAnalysis (nars.test.analyze.BeliefAnalysis)1 Truth (nars.truth.Truth)1 Test (org.junit.jupiter.api.Test)1