use of jcog.math.random.XoRoShiRo128PlusRandom in project narchy by automenta.
the class AnonTest method testMixedAnonVector.
@Test
public void testMixedAnonVector() {
Term[] x = { $.varDep(1), $.varIndep(2), $.varQuery(3), Anom.the(4) };
Random rng = new XoRoShiRo128PlusRandom(1);
for (int i = 0; i < 4; i++) {
ArrayUtils.shuffle(x, rng);
assertEqual(new UnitSubterm(x[0]), new AnonVector(x[0]));
assertEqual(new TermVector2(x[0], x[1]), new AnonVector(x[0], x[1]));
assertEqual(new ArrayTermVector(x), new AnonVector(x));
}
}
use of jcog.math.random.XoRoShiRo128PlusRandom in project narchy by automenta.
the class NARchy method ui.
public static NAR ui() {
// u.forEach(System.out::println);
// u.put("boot", new Date().toString());
// Util.pause(100);
// u.get("boot", (b)->{
// System.out.println(b);
// });
NAR nar = new DefaultNAR(8, true).exe(new PoolMultiExec(/*WorkerMultiExec*/
new Focus.AERevaluator(new XoRoShiRo128PlusRandom(1)), 512)).time(new RealTime.CS().durFPS(10f)).get();
ConjClustering conjClusterB = new ConjClustering(nar, BELIEF, (Task::isInput), 16, 64);
// ConjClustering conjClusterG = new ConjClustering(nar, GOAL, true, false, 16, 64);
// auxiliary modules, load in background thread
nar.runLater(() -> {
User u = User.the();
new NARAudio(nar);
new NARVideo(nar);
NARHear.readURL(nar);
{
NARSpeak s = new NARSpeak(nar);
s.spoken.on(new NativeSpeechDispatcher()::speak);
// new NativeSpeechDispatcher(s);
}
// //new NoteFS("/tmp/nal", nar);
// InterNAR i = new InterNAR(nar, 8, 0);
// i.recv.preAmp(0.1f);
// i.runFPS(2);
});
return nar;
}
use of jcog.math.random.XoRoShiRo128PlusRandom in project narchy by automenta.
the class TensorRL1 method noiseChip.
static void noiseChip(PhyWall p) {
{
final Random rng = new XoRoShiRo128PlusRandom(1);
final TensorFunc randomVector = Tensor.randomVectorGauss(16, 0, 1, rng);
final FloatRange lerpRate = new FloatRange(0.01f, 0, 1f);
final TensorLERP lerpVector = new TensorLERP(randomVector, lerpRate);
p.put(new Gridding(0.25f, // ),
new LabeledPane("rng", new AutoUpdateMatrixView(lerpVector.data)), new LabeledPane("lerp", new XYSlider().on((x, y) -> {
lerpRate.set(x);
})), new LabeledPane("out", new Port() {
@Override
public void prePaint(int dtMS) {
super.prePaint(dtMS);
lerpVector.update();
out(lerpVector.data);
}
})), 0.5f, 0.5f);
}
}
use of jcog.math.random.XoRoShiRo128PlusRandom in project narchy by automenta.
the class BagTest method samplingPriDist.
public static Tensor samplingPriDist(@NotNull Bag<PLink<String>, PLink<String>> b, int batches, int batchSize, int bins) {
assert (bins > 1);
Set<String> hit = new TreeSet();
Frequency hits = new Frequency();
ArrayTensor f = new ArrayTensor(bins);
assertFalse(b.isEmpty());
Random rng = new XoRoShiRo128PlusRandom(1);
for (int i = 0; i < batches; i++) {
b.sample(rng, batchSize, x -> {
f.data[Util.bin(b.pri(x), bins)]++;
String s = x.get();
hits.addValue(s);
hit.add(s);
});
}
int total = batches * batchSize;
assertEquals(total, Util.sum(f.data), 0.001f);
if (hits.getUniqueCount() != b.size()) {
System.out.println(hits.getUniqueCount() + " != " + b.size());
Set<String> items = b.stream().map(PLink::get).collect(Collectors.toSet());
items.removeAll(hit);
System.out.println("not hit: " + items);
System.out.println(hits);
fail("all elements must have been sampled at least once");
}
return f.scale(1f / total);
}
use of jcog.math.random.XoRoShiRo128PlusRandom in project narchy by automenta.
the class BagTest method fillRandom.
public static void fillRandom(CurveBag<PLink<String>> bag) {
assertTrue(bag.isEmpty());
int c = bag.capacity();
Random rng = new XoRoShiRo128PlusRandom(1);
// insert biggest items first
for (int i = c - 1; i >= 0; i--) {
PLink inserted = bag.put(new PLink(i + "x", rng.nextFloat()));
if (inserted == null) {
fail("");
}
}
bag.commit(null);
assertEquals(c, bag.size());
assertSorted(bag);
}
Aggregations