Search in sources :

Example 1 with Activate

use of nars.control.Activate in project narchy by automenta.

the class ActivateTest method testTemplates.

static void testTemplates(String term, String expect) throws Narsese.NarseseException {
    NAR n = NARS.tmp(1);
    // n.believe(term + ".");
    Concept c = n.conceptualize($(term));
    Activate a = new Activate(c, 0.5f);
    Collection<Termed> t = new TreeSet(c.templates());
    assertEquals(expect, t.toString());
}
Also used : Termed(nars.term.Termed) Activate(nars.control.Activate) TreeSet(java.util.TreeSet)

Example 2 with Activate

use of nars.control.Activate in project narchy by automenta.

the class ActivateTest method testConceptFireLinkSelection.

@Test
public void testConceptFireLinkSelection() throws Narsese.NarseseException {
    int count = 8;
    NAR nar = new NARS().tmp();
    // low priority so it doesnt affect links
    nar.input("$0.01 a:b.");
    nar.run(1);
    System.out.println("inputs:\n");
    Concept c = nar.conceptualize("a:b");
    for (int n = 0; n < count; n++) {
        PLink<Term> inserted = new PLink<>($("x" + n + ":a"), ((1 + n) / ((float) count)));
        System.out.println(inserted);
        c.termlinks().put(inserted);
    }
    System.out.println();
    HashBag<String> termlinkHits = new HashBag();
    HashBag<String> taskHits = new HashBag();
    // HashBag<String> premiseHits = new HashBag();
    Activate cf = new Activate(c, 1f);
    Term A = $.the("a");
    // BatchActivation ba = new BatchActivation();
    for (int i = 0; i < 100; i++) {
        final int[] remain = { 9 };
        cf.premises(nar, (task, term) -> {
            Task ptask = task;
            Term pterm = term.get();
            System.out.println("tasklink=" + ptask + " termlink=" + pterm);
            if (pterm instanceof Atom || !A.equals(pterm.sub(0)))
                // ignore
                return true;
            String tls = pterm.toString();
            // premiseHits.addOccurrences(p.toString(), 1);
            termlinkHits.addOccurrences(/*tasklink.get() + " " +*/
            tls, 1);
            taskHits.addOccurrences(/*tasklink.get() + " " +*/
            (ptask + " " + pterm), 1);
            return --remain[0] > 0;
        }, 1, 3);
    // ba.commit(nar);
    }
    System.out.println("termlinks pri (after):\n");
    c.termlinks().print();
    System.out.println("\ntermlink hits:\n");
    termlinkHits.topOccurrences(termlinkHits.size()).forEach(System.out::println);
    // System.out.println("\ntask hits:\n");
    // taskHits.topOccurrences(taskHits.size()).forEach(System.out::println);
    // System.out.println("\npremise hits:\n");
    // premiseHits.topOccurrences(premiseHits.size()).forEach(System.out::println);
    // System.out.println();
    // c.print();
    // System.out.println();
    ObjectIntPair<String> top = termlinkHits.topOccurrences(1).get(0);
    ObjectIntPair<String> bottom = termlinkHits.bottomOccurrences(1).get(0);
    String min = bottom.getOne();
    // allow either 0 or 1
    assertTrue("(a-->x0)".equals(min) || "(a-->x1)".equals(min));
    assertEquals("(a-->x" + (count - 1) + ")", top.getOne());
}
Also used : PLink(jcog.pri.PLink) Term(nars.term.Term) Atom(nars.term.atom.Atom) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) Activate(nars.control.Activate) Test(org.junit.jupiter.api.Test)

Aggregations

Activate (nars.control.Activate)2 TreeSet (java.util.TreeSet)1 PLink (jcog.pri.PLink)1 Term (nars.term.Term)1 Termed (nars.term.Termed)1 Atom (nars.term.atom.Atom)1 HashBag (org.eclipse.collections.impl.bag.mutable.HashBag)1 Test (org.junit.jupiter.api.Test)1