Search in sources :

Example 1 with GoalActionConcept

use of nars.concept.action.GoalActionConcept in project narchy by automenta.

the class NAct method actionTriStatePWM.

@Nullable
default ActionConcept actionTriStatePWM(@NotNull Term s, @NotNull IntConsumer i) {
    ActionConcept m = new GoalActionConcept(s, this, (b, d) -> {
        int ii;
        if (d == null) {
            ii = 0;
        } else {
            float f = d.freq();
            if (f == 1f) {
                ii = +1;
            } else if (f == 0) {
                ii = -1;
            } else if (f > 0.5f) {
                ii = nar().random().nextFloat() <= ((f - 0.5f) * 2f) ? +1 : 0;
            } else if (f < 0.5f) {
                ii = nar().random().nextFloat() <= ((0.5f - f) * 2f) ? -1 : 0;
            } else
                ii = 0;
        }
        i.accept(ii);
        float f;
        switch(ii) {
            case 1:
                f = 1f;
                break;
            case 0:
                f = 0.5f;
                break;
            case -1:
                f = 0f;
                break;
            default:
                throw new RuntimeException();
        }
        return // d!=null ?
        $.t(f, // d.conf()
        nar().confDefault(BELIEF));
    });
    return addAction(m);
}
Also used : GoalActionConcept(nars.concept.action.GoalActionConcept) GoalActionConcept(nars.concept.action.GoalActionConcept) ActionConcept(nars.concept.action.ActionConcept) BeliefActionConcept(nars.concept.action.BeliefActionConcept) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with GoalActionConcept

use of nars.concept.action.GoalActionConcept in project narchy by automenta.

the class NAct method actionTriStateContinuous.

@Nullable
default GoalActionConcept actionTriStateContinuous(@NotNull Term s, @NotNull IntPredicate i) {
    GoalActionConcept m = new GoalActionConcept(s, this, (b, d) -> {
        // radius of center dead zone; diameter = 2x this
        // 1f/4;
        // 1f/3f;
        int ii;
        if (d == null) {
            ii = 0;
        } else {
            float f = d.freq();
            float deadZoneFreqRadius = 1f / 6;
            if (f > 0.5f + deadZoneFreqRadius)
                ii = +1;
            else if (f < 0.5f - deadZoneFreqRadius)
                ii = -1;
            else
                ii = 0;
        }
        boolean accepted = i.test(ii);
        if (!accepted)
            // HACK
            ii = 0;
        float f;
        switch(ii) {
            case 1:
                f = 1f;
                break;
            case 0:
                f = 0.5f;
                break;
            case -1:
                f = 0f;
                break;
            default:
                throw new RuntimeException();
        }
        return $.t(f, nar().confDefault(BELIEF));
    });
    return addAction(m);
}
Also used : GoalActionConcept(nars.concept.action.GoalActionConcept) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with GoalActionConcept

use of nars.concept.action.GoalActionConcept in project narchy by automenta.

the class NAct method actionPushButton.

default void actionPushButton(@NotNull Term t, @NotNull BooleanProcedure on) {
    float thresh = nar().freqResolution.get();
    // 0f;
    GoalActionConcept b = actionUnipolar(t, true, (x) -> 0, (f) -> {
        boolean positive = f >= 0.5f + thresh;
        on.value(positive);
        return positive ? 1f : 0f;
    });
    b.resolution.set(1f);
// float thresh =
// //0.5f + Param.TRUTH_EPSILON;
// 0.6f;
// //0.75f;
// //0.6f;
// actionToggle(s, thresh, 0, 0f, () -> onChange.value(true), () -> onChange.value(false));
}
Also used : GoalActionConcept(nars.concept.action.GoalActionConcept)

Aggregations

GoalActionConcept (nars.concept.action.GoalActionConcept)3 Nullable (org.jetbrains.annotations.Nullable)2 ActionConcept (nars.concept.action.ActionConcept)1 BeliefActionConcept (nars.concept.action.BeliefActionConcept)1