Search in sources :

Example 1 with FloatFloatToObjectFunction

use of org.eclipse.collections.api.block.function.primitive.FloatFloatToObjectFunction in project narchy by automenta.

the class NAgent method run.

@Override
public void run() {
    if (!enabled.get())
        return;
    this.last = this.now;
    this.now = nar.time();
    if (now <= last)
        return;
    // stretched perceptual duration to the NAgent's effective framerate
    int dur = Math.max(nar.dur(), (int) (now - last));
    reward = act();
    happy.update(last, now, dur, nar);
    FloatFloatToObjectFunction<Truth> truther = (prev, next) -> $.t(next, nar.confDefault(BELIEF));
    sensors.forEach((key, value) -> value.input(key.update(last, now, truther, dur, nar)));
    always(motivation.floatValue());
    // HACK TODO compile this to re-used array on init like before
    Map.Entry<ActionConcept, CauseChannel<ITask>>[] aa = actions.entrySet().toArray(new Map.Entry[actions.size()]);
    // fair chance of ordering to all motors
    ArrayUtils.shuffle(aa, random());
    for (Map.Entry<ActionConcept, CauseChannel<ITask>> ac : aa) {
        Stream<ITask> s = ac.getKey().update(last, now, dur, NAgent.this.nar);
        if (s != null)
            ac.getValue().input(s);
    }
    Truth happynowT = nar.beliefTruth(happy, last, now);
    float happynow = happynowT != null ? (happynowT.freq() - 0.5f) * 2f : 0;
    nar.emotion.happy(motivation.floatValue() * dexterity(last, now) * happynow);
    if (trace)
        logger.info(summary());
}
Also used : Iterables(com.google.common.collect.Iterables) DurService(nars.control.DurService) java.util(java.util) Bitmap2DSensor(nars.util.signal.Bitmap2DSensor) LoggerFactory(org.slf4j.LoggerFactory) Scalar(nars.concept.scalar.Scalar) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayUtils(org.apache.commons.lang3.ArrayUtils) ETERNAL(nars.time.Tense.ETERNAL) Supplier(java.util.function.Supplier) Variable(nars.term.var.Variable) Truth(nars.truth.Truth) Tuples.pair(org.eclipse.collections.impl.tuple.Tuples.pair) Op(nars.Op) ActionConcept(nars.concept.action.ActionConcept) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) On(jcog.event.On) Activate(nars.control.Activate) FloatFloatToObjectFunction(org.eclipse.collections.api.block.function.primitive.FloatFloatToObjectFunction) Concept(nars.concept.Concept) Term(nars.term.Term) Util.compose(jcog.Util.compose) Loop(jcog.exe.Loop) Logger(org.slf4j.Logger) Texts.n2(jcog.Texts.n2) Predicate(java.util.function.Predicate) FasterList(jcog.list.FasterList) Stamp(nars.truth.Stamp) NARService(nars.control.NARService) ITask(nars.task.ITask) NALTask(nars.task.NALTask) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) TODO(jcog.TODO) FilteredScalar(nars.concept.scalar.FilteredScalar) Stream(java.util.stream.Stream) Atomic(nars.term.atom.Atomic) jcog.math(jcog.math) Termed(nars.term.Termed) CauseChannel(nars.control.CauseChannel) NotNull(org.jetbrains.annotations.NotNull) DigitizedScalar(nars.concept.scalar.DigitizedScalar) ITask(nars.task.ITask) CauseChannel(nars.control.CauseChannel) Truth(nars.truth.Truth) ActionConcept(nars.concept.action.ActionConcept)

Aggregations

Iterables (com.google.common.collect.Iterables)1 java.util (java.util)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Consumer (java.util.function.Consumer)1 Predicate (java.util.function.Predicate)1 Supplier (java.util.function.Supplier)1 Stream (java.util.stream.Stream)1 TODO (jcog.TODO)1 Texts.n2 (jcog.Texts.n2)1 Util.compose (jcog.Util.compose)1 On (jcog.event.On)1 Loop (jcog.exe.Loop)1 FasterList (jcog.list.FasterList)1 jcog.math (jcog.math)1 Op (nars.Op)1 Concept (nars.concept.Concept)1 ActionConcept (nars.concept.action.ActionConcept)1 DigitizedScalar (nars.concept.scalar.DigitizedScalar)1 FilteredScalar (nars.concept.scalar.FilteredScalar)1