Search in sources :

Example 1 with Longerval

use of jcog.math.Longerval in project narchy by automenta.

the class DeriveTime method solveRaw.

/**
 * as a backup option
 */
private Term solveRaw(Term x) {
    long s, e;
    /*if (task.isQuestOrQuestion() && (!task.isEternal() || belief == null)) {
            //inherit question's specific time directly
            s = task.start();
            e = task.end();
        } else*/
    {
        boolean taskEvent = // !task.term().op().temporal;
        !(task.term().op() == CONJ);
        if (task.isEternal()) {
            if (belief == null || belief.isEternal()) {
                // entirely eternal
                s = e = ETERNAL;
            } else {
                if (taskEvent) {
                    s = belief.start();
                    e = belief.end();
                } else {
                    // transformed task term, should have been solved
                    return null;
                }
            }
        } else {
            if (belief == null) {
                // inherit task time
                s = task.start();
                e = task.end();
            } else if (belief.isEternal()) {
                if (!task.isEternal()) {
                    // inherit task time
                    s = task.start();
                    e = task.end();
                } else {
                    s = e = ETERNAL;
                }
            // //event: inherit task time
            // boolean beliefEvent = belief == null || (
            // !belief.term().op().temporal
            // );
            // if (beliefEvent) {
            // s = task.start();
            // e = task.end();
            // } else {
            // return null; //should have calculated solution normally
            // }
            // }
            } else {
                if (!task.isQuestOrQuestion() && !belief.isQuestOrQuestion()) {
                    EviDensity density = new EviDensity(task, belief);
                    s = density.unionStart;
                    e = density.unionEnd;
                    d.concEviFactor *= density.factor();
                } else {
                    Longerval u = Longerval.union(task.start(), task.end(), belief.start(), belief.end());
                    s = u.start();
                    e = u.end();
                }
            }
        }
    }
    if (!eternalCheck(s))
        return null;
    long[] occ = d.concOcc;
    occ[0] = s;
    occ[1] = e;
    return x;
}
Also used : Longerval(jcog.math.Longerval) EviDensity(nars.task.EviDensity)

Example 2 with Longerval

use of jcog.math.Longerval in project narchy by automenta.

the class EviDensity method add.

void add(long xStart, long xEnd, float evi, float eviInteg) {
    if (sumEviIntegrals != sumEviIntegrals) {
        // first add
        if (xStart > xEnd)
            throw new RuntimeException("out of order interval");
        if (xStart != ETERNAL) {
            unionStart = xStart;
            unionEnd = xEnd;
        }
        sumEviAvg = sumEviIntegrals = 0;
    } else {
        if (xStart != ETERNAL) {
            Longerval uu = new Longerval(unionStart, unionEnd).union(xStart, xEnd);
            this.unionStart = uu.a;
            this.unionEnd = uu.b;
        }
    }
    sumEviAvg += evi;
    sumEviIntegrals += eviInteg;
}
Also used : Longerval(jcog.math.Longerval)

Example 3 with Longerval

use of jcog.math.Longerval in project narchy by automenta.

the class RevectionTest method testTimeFusion_Pairs.

@Test
public void testTimeFusion_Pairs() {
    // point overlap
    assertTimeFusion(1, 1, 1f, new Longerval(1), new Longerval(1));
    // range overlap
    assertTimeFusion(1, 2, 1f, new Longerval(1, 2), new Longerval(1, 2));
    // partial range overlap
    assertTimeFusion(1, 2, 0.75f, new Longerval(1, 1), new Longerval(1, 2));
    // end-to-end point joint
    assertTimeFusion(1, 2, 0.5f, new Longerval(1), new Longerval(2));
    // end-to-end range joint
    assertTimeFusion(1, 4, 0.5f, new Longerval(1, 2), new Longerval(3, 4));
    // gap
    assertTimeFusion(1, 3, 1 / 3f, new Longerval(1, 1), new Longerval(3, 3));
}
Also used : Longerval(jcog.math.Longerval) Test(org.junit.jupiter.api.Test)

Example 4 with Longerval

use of jcog.math.Longerval in project narchy by automenta.

the class RevectionTest method testTimeFusion_Triples.

@Test
public void testTimeFusion_Triples() {
    // point overlap
    assertTimeFusion(1, 1, 1f, new Longerval(1), new Longerval(1), new Longerval(1));
    // range overlap
    assertTimeFusion(1, 2, 1f, new Longerval(1, 2), new Longerval(1, 2), new Longerval(1, 2));
    // partial range overlap
    assertTimeFusion(1, 2, 0.833f, new Longerval(1, 1), new Longerval(1, 2), new Longerval(1, 2));
    assertTimeFusion(1, 2, 2 / 3f, new Longerval(1, 1), new Longerval(1, 1), new Longerval(1, 2));
    // end-to-end point joint
    assertTimeFusion(1, 3, 1 / 3f, new Longerval(1), new Longerval(2), new Longerval(3));
    // end-to-end range joint
    assertTimeFusion(1, 6, 1 / 3f, new Longerval(1, 2), new Longerval(3, 4), new Longerval(5, 6));
    // gap
    assertTimeFusion(1, 5, 1 / 5f, new Longerval(1), new Longerval(3), new Longerval(5));
}
Also used : Longerval(jcog.math.Longerval) Test(org.junit.jupiter.api.Test)

Example 5 with Longerval

use of jcog.math.Longerval in project narchy by automenta.

the class IntervalTreeTest method testIntersectionAdjacent.

@Test
public void testIntersectionAdjacent() {
    // two adjacent but non-overlapping intervals create a zero
    Longerval x = Longerval.intersect(1, 2, 2, 3);
    assertNotNull(x);
    assertEquals(1, x.range());
}
Also used : Longerval(jcog.math.Longerval) Test(org.junit.jupiter.api.Test)

Aggregations

Longerval (jcog.math.Longerval)6 Test (org.junit.jupiter.api.Test)3 EviDensity (nars.task.EviDensity)1