Search in sources :

Example 1 with XoRoShiRo128PlusRandom

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));
    }
}
Also used : XoRoShiRo128PlusRandom(jcog.math.random.XoRoShiRo128PlusRandom) AnonVector(nars.term.anon.AnonVector) Random(java.util.Random) XoRoShiRo128PlusRandom(jcog.math.random.XoRoShiRo128PlusRandom) UnitSubterm(nars.subterm.UnitSubterm) ArrayTermVector(nars.subterm.ArrayTermVector) TermVector2(nars.subterm.TermVector2) Test(org.junit.jupiter.api.Test)

Example 2 with XoRoShiRo128PlusRandom

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;
}
Also used : User(jcog.User) NativeSpeechDispatcher(spacegraph.audio.speech.NativeSpeechDispatcher) XoRoShiRo128PlusRandom(jcog.math.random.XoRoShiRo128PlusRandom) PoolMultiExec(nars.exe.PoolMultiExec) ConjClustering(nars.op.stm.ConjClustering) NARVideo(nars.video.NARVideo) NARSpeak(nars.op.language.NARSpeak) RealTime(nars.time.RealTime) NARAudio(nars.audio.NARAudio)

Example 3 with XoRoShiRo128PlusRandom

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);
    }
}
Also used : Gridding(spacegraph.space2d.container.Gridding) XoRoShiRo128PlusRandom(jcog.math.random.XoRoShiRo128PlusRandom) Random(java.util.Random) XoRoShiRo128PlusRandom(jcog.math.random.XoRoShiRo128PlusRandom) TensorFunc(jcog.math.tensor.TensorFunc) AutoUpdateMatrixView(spacegraph.space2d.widget.meter.AutoUpdateMatrixView) XYSlider(spacegraph.space2d.widget.slider.XYSlider) FloatRange(jcog.math.FloatRange) Port(spacegraph.space2d.widget.windo.Port) LabeledPane(spacegraph.space2d.widget.text.LabeledPane) TensorLERP(jcog.math.tensor.TensorLERP)

Example 4 with XoRoShiRo128PlusRandom

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);
}
Also used : XoRoShiRo128PlusRandom(jcog.math.random.XoRoShiRo128PlusRandom) XorShift128PlusRandom(jcog.math.random.XorShift128PlusRandom) XoRoShiRo128PlusRandom(jcog.math.random.XoRoShiRo128PlusRandom) Frequency(org.apache.commons.math3.stat.Frequency) ArrayTensor(jcog.math.tensor.ArrayTensor)

Example 5 with XoRoShiRo128PlusRandom

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);
}
Also used : PLink(jcog.pri.PLink) XoRoShiRo128PlusRandom(jcog.math.random.XoRoShiRo128PlusRandom) XorShift128PlusRandom(jcog.math.random.XorShift128PlusRandom) XoRoShiRo128PlusRandom(jcog.math.random.XoRoShiRo128PlusRandom)

Aggregations

XoRoShiRo128PlusRandom (jcog.math.random.XoRoShiRo128PlusRandom)8 Random (java.util.Random)2 XorShift128PlusRandom (jcog.math.random.XorShift128PlusRandom)2 ConjClustering (nars.op.stm.ConjClustering)2 RealTime (nars.time.RealTime)2 java.awt (java.awt)1 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 HashSet (java.util.HashSet)1 Function (java.util.function.Function)1 IntConsumer (java.util.function.IntConsumer)1 Supplier (java.util.function.Supplier)1 User (jcog.User)1 Util (jcog.Util)1 Loop (jcog.exe.Loop)1 FloatRange (jcog.math.FloatRange)1 ArrayTensor (jcog.math.tensor.ArrayTensor)1 TensorFunc (jcog.math.tensor.TensorFunc)1 TensorLERP (jcog.math.tensor.TensorLERP)1