Search in sources :

Example 1 with IntFloatPair

use of org.eclipse.collections.api.tuple.primitive.IntFloatPair in project narchy by automenta.

the class DynamicTruthBeliefTable method matchDT.

/**
 * returns an appropriate dt for the root term
 * of beliefs held in the table.  returns 0 if no other value can
 * be computed.
 */
protected int matchDT(long start, long end, boolean commutive, NAR nar) {
    int s = size();
    if (s == 0)
        return 0;
    int dur = nar.dur();
    IntFloatHashMap dtEvi = new IntFloatHashMap(s);
    forEachTask(t -> {
        int tdt = t.dt();
        if (tdt != DTERNAL) {
            if (tdt == XTERNAL)
                throw new RuntimeException("XTERNAL should not be present in " + t);
            if ((t.term().subs() > 2) == commutive)
                // maybe evi
                dtEvi.addToValue(tdt, t.evi(start, end, dur));
        }
    });
    int n = dtEvi.size();
    if (n == 0) {
        return 0;
    } else {
        MutableList<IntFloatPair> ll = dtEvi.keyValuesView().toList();
        int selected = n != 1 ? Roulette.decideRoulette(ll.size(), (i) -> ll.get(i).getTwo(), nar.random()) : 0;
        return ll.get(selected).getOne();
    }
}
Also used : CONJ(nars.Op.CONJ) DTERNAL(nars.time.Tense.DTERNAL) ArrayUtils(org.apache.commons.lang3.ArrayUtils) MutableList(org.eclipse.collections.api.list.MutableList) IntFloatPair(org.eclipse.collections.api.tuple.primitive.IntFloatPair) Roulette(jcog.decide.Roulette) Nullable(org.jetbrains.annotations.Nullable) Task(nars.Task) Truth(nars.truth.Truth) IntFloatHashMap(org.eclipse.collections.impl.map.mutable.primitive.IntFloatHashMap) NAR(nars.NAR) Op(nars.Op) TemporalBeliefTable(nars.table.TemporalBeliefTable) Bool(nars.term.atom.Bool) XTERNAL(nars.time.Tense.XTERNAL) Term(nars.term.Term) IntFloatHashMap(org.eclipse.collections.impl.map.mutable.primitive.IntFloatHashMap) IntFloatPair(org.eclipse.collections.api.tuple.primitive.IntFloatPair)

Aggregations

Roulette (jcog.decide.Roulette)1 NAR (nars.NAR)1 Op (nars.Op)1 CONJ (nars.Op.CONJ)1 Task (nars.Task)1 TemporalBeliefTable (nars.table.TemporalBeliefTable)1 Term (nars.term.Term)1 Bool (nars.term.atom.Bool)1 DTERNAL (nars.time.Tense.DTERNAL)1 XTERNAL (nars.time.Tense.XTERNAL)1 Truth (nars.truth.Truth)1 ArrayUtils (org.apache.commons.lang3.ArrayUtils)1 MutableList (org.eclipse.collections.api.list.MutableList)1 IntFloatPair (org.eclipse.collections.api.tuple.primitive.IntFloatPair)1 IntFloatHashMap (org.eclipse.collections.impl.map.mutable.primitive.IntFloatHashMap)1 Nullable (org.jetbrains.annotations.Nullable)1