use of jcog.pri.PLink in project narchy by automenta.
the class ArrayBagTest method populated.
@NotNull
private CurveBag<PLink<String>> populated(int n, @NotNull DoubleSupplier random) {
CurveBag<PLink<String>> a = curveBag(n, plus);
// fill with uniform randomness
for (int i = 0; i < n; i++) {
a.put(new PLink("x" + i, (float) random.getAsDouble()));
}
a.commit();
return a;
}
use of jcog.pri.PLink in project narchy by automenta.
the class ArrayBagTest method testInsertOrBoostDoesntCauseSort.
@Disabled
@Test
public void testInsertOrBoostDoesntCauseSort() {
final int[] sorts = { 0 };
@NotNull CurveBag<PLink<String>> x = new CurveBag(PriMerge.plus, new HashMap<>(), 4) {
@Override
protected void sort(int from, int to) {
sorts[0]++;
super.sort(from, to);
}
};
x.put(new PLink("x", 0.2f));
x.put(new PLink("y", 0.1f));
x.put(new PLink("z", 0f));
assertEquals(0, sorts[0]);
x.commit();
assertEquals(0, sorts[0]);
assertSorted(x);
}
use of jcog.pri.PLink in project narchy by automenta.
the class ArrayBagTest method testBudgetMerge.
@Test
public void testBudgetMerge() {
PLinkArrayBag<String> a = new PLinkArrayBag<String>(4, plus, new HashMap<>(4));
assertEquals(0, a.size());
a.put(new PLink("x", 0.1f));
a.put(new PLink("x", 0.1f));
a.commit(null);
assertEquals(1, a.size());
PriReference<String> agx = a.get("x");
Pri expect = new Pri(0.2f);
assertTrue(Util.equals(expect.priElseNeg1(), agx.priElseNeg1(), 0.01f), agx + "==?==" + expect);
}
use of jcog.pri.PLink in project narchy by automenta.
the class ArrayBagTest method testCapacity.
@Test
public void testCapacity() {
PLinkArrayBag a = new PLinkArrayBag(2, plus, new HashMap<>(2));
a.put(new PLink("x", 0.1f));
a.put(new PLink("y", 0.2f));
a.print();
System.out.println();
assertEquals(2, a.size());
a.commit(null);
assertSorted(a);
assertEquals(0.1f, a.priMin(), 0.01f);
a.put(new PLink("z", 0.05f));
a.print();
System.out.println();
assertEquals(2, a.size());
assertTrue(a.contains("x") && a.contains("y"));
assertFalse(a.contains("z"));
}
use of jcog.pri.PLink in project narchy by automenta.
the class HijackBagTest method testHijackFlatBagRemainsRandomInNormalizedSampler.
@Test
public void testHijackFlatBagRemainsRandomInNormalizedSampler() {
int n = 256;
Bag<String, PriReference<String>> a = new DefaultHijackBag<>(max, n, 4);
for (int i = 0; i < n * 8; i++) {
a.put(new PLink("x" + Integer.toString(Float.floatToIntBits(1f / i), 5), ((float) (i)) / (n)));
}
a.commit();
int size = a.size();
// assertTrue(size >= 20 && size <= 30);
// TreeSet<String> keys = new TreeSet();
// Iterators.transform(a.iterator(), x -> x.get()).forEachRemaining(keys::add);
// System.out.println( keys.size() + " " + Joiner.on(' ').join(keys) );
TreeSet<String> keys2 = new TreeSet();
a.forEach((b) -> {
if (!keys2.add(b.get()))
throw new RuntimeException("duplicate detected");
});
System.out.println(keys2.size() + " " + Joiner.on(' ').join(keys2));
assertEquals(size, keys2.size());
// int b = 20;
// EmpiricalDistribution e = BagTest.getSamplingPriorityDistribution(a, n * 500, b);
//
// printDist(e);
//
// //monotonically increasing:
// assertTrue(e.getBinStats().get(0).getMean() < e.getBinStats().get(b-1).getMean());
// assertTrue(e.getBinStats().get(0).getMean() < e.getBinStats().get(b/2).getMean());
// assertTrue(e.getBinStats().get(b/2).getMean() < e.getBinStats().get(b-2).getMean());
// a.print();
}
Aggregations