Search in sources :

Example 11 with DoubleArrayList

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

the class DistributorTest method testDistributorProbabilities.

@Test
public void testDistributorProbabilities() {
    int levels = 20;
    Distributor d = Distributor.get(levels);
    int[] count = new int[levels];
    double total = 0;
    for (short x : d.order) {
        count[x]++;
        total++;
    }
    List<Double> probability = new ArrayList(levels);
    for (int i = 0; i < levels; i++) {
        probability.add(count[i] / total);
    }
    List<Double> probabilityActiveAdjusted = new ArrayList(levels);
    double activeIncrease = 0.009;
    double dormantDecrease = ((0.1 * levels) * activeIncrease) / ((1.0 - 0.1) * levels);
    for (int i = 0; i < levels; i++) {
        double p = count[i] / total;
        double pd = i < ((1.0 - 0.1) * levels) ? -dormantDecrease : activeIncrease;
        p += pd;
        probabilityActiveAdjusted.add(p);
    // System.out.println((i / ((double) levels)) + "\t" + p);
    }
    // System.out.println(probabilityActiveAdjusted);
    DoubleArrayList a = new DoubleArrayList(probabilityActiveAdjusted.size());
    probabilityActiveAdjusted.forEach(a::add);
    double[] aa = a.toArray();
    assertArrayEquals(new double[] { 0.0037619047619047623, 0.008523809523809524, 0.013285714285714286, 0.01804761904761905, 0.022809523809523807, 0.02757142857142857, 0.03233333333333333, 0.0370952380952381, 0.04185714285714286, 0.046619047619047616, 0.05138095238095238, 0.05614285714285714, 0.060904761904761906, 0.06566666666666666, 0.07042857142857142, 0.0751904761904762, 0.07995238095238096, 0.08471428571428571, 0.09947619047619047, 0.10423809523809523 }, aa, 0.05);
}
Also used : Distributor(jcog.math.Distributor) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) ArrayList(java.util.ArrayList) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) Test(org.junit.jupiter.api.Test)

Example 12 with DoubleArrayList

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

the class AbstractImmutableSortedMap method collectDouble.

@Override
public ImmutableDoubleList collectDouble(DoubleFunction<? super V> doubleFunction) {
    DoubleArrayList result = new DoubleArrayList(this.size());
    this.forEach(new CollectDoubleProcedure<>(doubleFunction, result));
    return result.toImmutable();
}
Also used : DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList)

Example 13 with DoubleArrayList

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

the class ArrayIterateTest method collectDoubleWithTarget.

@Test
public void collectDoubleWithTarget() {
    Integer[] objectArray = { -1, 0, 42 };
    DoubleArrayList target = new DoubleArrayList();
    DoubleArrayList result = ArrayIterate.collectDouble(objectArray, PrimitiveFunctions.unboxIntegerToDouble(), target);
    Assert.assertEquals(this.getExpectedDoubleResults(), result);
    Assert.assertSame("Target List not returned as result", target, result);
}
Also used : BigInteger(java.math.BigInteger) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) Test(org.junit.Test)

Example 14 with DoubleArrayList

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

the class SortedSetAdapter method collectDouble.

@Override
public MutableDoubleList collectDouble(DoubleFunction<? super T> doubleFunction) {
    DoubleArrayList result = new DoubleArrayList(this.size());
    this.forEach(new CollectDoubleProcedure<>(doubleFunction, result));
    return result;
}
Also used : DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList)

Example 15 with DoubleArrayList

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

the class TreeSortedSet method collectDouble.

@Override
public MutableDoubleList collectDouble(DoubleFunction<? super T> doubleFunction) {
    DoubleArrayList result = new DoubleArrayList(this.size());
    this.forEach(new CollectDoubleProcedure<>(doubleFunction, result));
    return result;
}
Also used : DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList)

Aggregations

DoubleArrayList (org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList)20 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)3 MutableDoubleCollection (org.eclipse.collections.api.collection.primitive.MutableDoubleCollection)3 MutableDoubleList (org.eclipse.collections.api.list.primitive.MutableDoubleList)3 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 FloatArrayList (org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList)2 IntArrayList (org.eclipse.collections.impl.list.mutable.primitive.IntArrayList)2 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)2 ShortArrayList (org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList)2 Test (org.junit.jupiter.api.Test)2 BigInteger (java.math.BigInteger)1 Distributor (jcog.math.Distributor)1 RectDouble1D (jcog.tree.rtree.rect.RectDouble1D)1 Stats (jcog.tree.rtree.util.Stats)1 DoubleIterable (org.eclipse.collections.api.DoubleIterable)1 DoubleHashBag (org.eclipse.collections.impl.bag.mutable.primitive.DoubleHashBag)1