Search in sources :

Example 11 with IntArrayList

use of org.eclipse.collections.impl.list.mutable.primitive.IntArrayList in project eclipse-collections by eclipse.

the class ImmutableEmptySortedBagTest method collectInt.

@Override
@Test
public void collectInt() {
    ImmutableSortedBag<Integer> bag = this.classUnderTest();
    Assert.assertEquals(new IntArrayList(), bag.collectInt(PrimitiveFunctions.unboxIntegerToInt()));
}
Also used : IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList) Test(org.junit.Test)

Example 12 with IntArrayList

use of org.eclipse.collections.impl.list.mutable.primitive.IntArrayList in project eclipse-collections by eclipse.

the class ImmutableEmptySortedBagTest method collectInt_target.

@Override
@Test
public void collectInt_target() {
    ImmutableSortedBag<Integer> bag = this.classUnderTest();
    Assert.assertEquals(new IntArrayList(), bag.collectInt(PrimitiveFunctions.unboxIntegerToInt(), new IntArrayList()));
    ImmutableSortedBag<Integer> bag2 = this.classUnderTest();
    Assert.assertEquals(new IntHashBag(), bag2.collectInt(PrimitiveFunctions.unboxIntegerToInt(), new IntHashBag()));
}
Also used : IntHashBag(org.eclipse.collections.impl.bag.mutable.primitive.IntHashBag) IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList) Test(org.junit.Test)

Example 13 with IntArrayList

use of org.eclipse.collections.impl.list.mutable.primitive.IntArrayList in project narchy by automenta.

the class Subterms method indicesOf.

@Nullable
default IntArrayList indicesOf(Predicate<Term> t) {
    IntArrayList a = new IntArrayList(1);
    int s = subs();
    for (int i = 0; i < s; i++) {
        if (t.test(sub(i)))
            a.add(i);
    }
    if (!a.isEmpty())
        return a;
    else
        return null;
}
Also used : IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with IntArrayList

use of org.eclipse.collections.impl.list.mutable.primitive.IntArrayList in project narchy by automenta.

the class FastUndirGraph method initGraph.

// -----------------------------------------------------------------
@Override
protected void initGraph() {
    final int max = g.size();
    triangle = new BitSet[max];
    for (int i = 0; i < max; ++i) {
        in[i] = new IntArrayList();
        triangle[i] = new BitSet(i);
    }
    for (int i = 0; i < max; ++i) {
        int ii = i;
        g.neighbors(i).forEach(out -> {
            if (!g.isEdge(out, ii))
                in[out].add(ii);
            // But always add the link to the triangle
            if (// make sure i>j
            ii > out)
                triangle[ii].set(out);
            else
                triangle[out].set(ii);
        });
    }
}
Also used : BitSet(java.util.BitSet) IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList)

Example 15 with IntArrayList

use of org.eclipse.collections.impl.list.mutable.primitive.IntArrayList in project narchy by automenta.

the class UCTNode method actionSelect.

/**
 * determine the next action to play
 *
 * @param agent
 * @param dfr
 * @return
 */
private int actionSelect(Agent agent, int dfr) {
    assert (agent.numActions() >= children.size());
    final double[] maxValue = { Double.MIN_VALUE };
    final int[] selectedAction = { 0 };
    // at random
    if (children.size() < agent.numActions()) {
        IntArrayList unexplored = new IntArrayList();
        for (int a = 0; a < agent.numActions(); a++) {
            if (!children.containsKey(a)) {
                unexplored.add(a);
            }
        }
        selectedAction[0] = unexplored.get(Util.randRange(unexplored.size()));
    } else {
        // The general idea is to explore the most promising(with the
        // highest expected reward) actions. But also
        // explore other actions not to get stuck with wrong decisions.
        children.forEachKeyValue((i, currNode) -> {
            double value = 1.0 / (double) (dfr * (agent.maxReward() - agent.minReward())) * currNode.expectation() + explorationRatio * Math.sqrt(Math.log((double) visits) / (double) currNode.visits);
            if (value > maxValue[0]) {
                maxValue[0] = value;
                selectedAction[0] = i;
            }
        });
    }
    return selectedAction[0];
}
Also used : IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList)

Aggregations

IntArrayList (org.eclipse.collections.impl.list.mutable.primitive.IntArrayList)35 Test (org.junit.Test)10 MutableIntList (org.eclipse.collections.api.list.primitive.MutableIntList)8 MutableIntCollection (org.eclipse.collections.api.collection.primitive.MutableIntCollection)3 ArrayList (java.util.ArrayList)2 BooleanArrayList (org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList)2 ByteArrayList (org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList)2 CharArrayList (org.eclipse.collections.impl.list.mutable.primitive.CharArrayList)2 DoubleArrayList (org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList)2 FloatArrayList (org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList)2 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)2 ShortArrayList (org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList)2 Nullable (org.jetbrains.annotations.Nullable)2 FingerPrint (il.technion.tinytable.hash.FingerPrint)1 java.io (java.io)1 BigInteger (java.math.BigInteger)1 java.util (java.util)1 BitSet (java.util.BitSet)1 Predicate (java.util.function.Predicate)1 ScriptException (javax.script.ScriptException)1