Package ca.nengo.sim

Examples of ca.nengo.sim.Simulator


 
  public static void main(String[] args) {
       
    try {
      Network network = createNetwork();
      Simulator simulator = network.getSimulator();
     
      Probe inputRecorder = simulator.addProbe("input", "input", true);
      Probe integratorRecorder = simulator.addProbe("integrator", NEFEnsemble.X, true);
      Probe neuronRecorder = simulator.addProbe("integrator", 0, "V", true);

      long startTime = System.currentTimeMillis();
      simulator.run(0f, 1f, .0002f);
      System.out.println("Run time: " + ((System.currentTimeMillis() - startTime)/1000f) );
   
      TimeSeries integratorData = integratorRecorder.getData();
      integratorData.getLabels()[0] = "decoded output";
     
View Full Code Here


  public static Network createNetwork() throws StructuralException {
    NetworkImpl net = new NetworkImpl();
    net.setName("FuzzyLogic");
   
    Simulator simulator = net.getSimulator();
    // Rules:
    // 1) if A and (B or C) then 1
    // 2) if D then 2
    FunctionInterpreter fi = new DefaultFunctionInterpreter();

    Function[] functions = new Function[] { fi.parse("x0 < .2", 1),
        new ConstantFunction(1, .5f), new ConstantFunction(1, .2f),
        new ConstantFunction(1, .3f) };
    FunctionInput in = new FunctionInput("input", functions, Units.UNK);

    NEFEnsembleFactory ef = new NEFEnsembleFactoryImpl();

    NEFEnsemble A = ef.make("A", 100, 1, "A", false);
    NEFEnsemble B = ef.make("B", 100, 1, "B", false);
    NEFEnsemble C = ef.make("C", 100, 1, "C", false);
    NEFEnsemble D = ef.make("D", 100, 1, "D", false);

    NEFEnsemble rule1a = ef.make("rule1a", 500, 2, "rule1a", false);
    NEFEnsemble rule1b = ef.make("rule1b", 500, 2, "rule1b", false);
    NEFEnsemble rule2 = ef.make("rule2", 200, 1, "rule2", false);
    rule2.collectSpikes(true);

    rule1a.addDecodedOrigin("OR", new Function[] { new MAX(2) },
        Neuron.AXON);
    rule1b.addDecodedOrigin("AND", new Function[] { new MIN(2) },
        Neuron.AXON);
    rule1a.doneOrigins();
    rule1b.doneOrigins();
    rule2.doneOrigins();

    NEFEnsemble output = ef.make("output", 500, 5, "fuzzyoutput", false);

    net.addNode(in);
    net.addNode(A);
    net.addNode(B);
    net.addNode(C);
    net.addNode(D);
    net.addNode(rule1a);
    net.addNode(rule1b);
    net.addNode(rule2);
    net.addNode(output);

    A.addDecodedTermination("in", new float[][] { new float[] { 1f, 0f, 0f,
        0f } }, .005f, false);
    B.addDecodedTermination("in", new float[][] { new float[] { 0f, 1f, 0f,
        0f } }, .005f, false);
    C.addDecodedTermination("in", new float[][] { new float[] { 0f, 0f, 1f,
        0f } }, .005f, false);
    D.addDecodedTermination("in", new float[][] { new float[] { 0f, 0f, 0f,
        1f } }, .005f, false);

    net.addProjection(in.getOrigin(FunctionInput.ORIGIN_NAME), A
        .getTermination("in"));
    net.addProjection(in.getOrigin(FunctionInput.ORIGIN_NAME), B
        .getTermination("in"));
    net.addProjection(in.getOrigin(FunctionInput.ORIGIN_NAME), C
        .getTermination("in"));
    net.addProjection(in.getOrigin(FunctionInput.ORIGIN_NAME), D
        .getTermination("in"));

    rule1a.addDecodedTermination("B", new float[][] { new float[] { 1f },
        new float[] { 0f } }, .005f, false);
    rule1a.addDecodedTermination("C", new float[][] { new float[] { 0f },
        new float[] { 1f } }, .005f, false);
    rule1b.addDecodedTermination("A", new float[][] { new float[] { 1f },
        new float[] { 0f } }, .005f, false);
    rule1b.addDecodedTermination("B or C", new float[][] {
        new float[] { 0f }, new float[] { 1f } }, .005f, false);
    rule2.addDecodedTermination("D", new float[][] { new float[] { 1f } },
        .005f, false);

    net.addProjection(B.getOrigin(NEFEnsemble.X), rule1a
        .getTermination("B"));
    net.addProjection(C.getOrigin(NEFEnsemble.X), rule1a
        .getTermination("C"));
    net.addProjection(A.getOrigin(NEFEnsemble.X), rule1b
        .getTermination("A"));
    net.addProjection(rule1a.getOrigin("OR"), rule1b
        .getTermination("B or C"));
    net
        .addProjection(D.getOrigin(NEFEnsemble.X), rule2
            .getTermination("D"));

    output.addDecodedTermination("rule1", new float[][] {
        new float[] { .4f }, new float[] { .3f }, new float[] { .2f },
        new float[] { .1f }, new float[] { 0f } }, .005f, false);
    output.addDecodedTermination("rule2", new float[][] {
        new float[] { 0f }, new float[] { .1f }, new float[] { .2f },
        new float[] { .3f }, new float[] { .4f } }, .005f, false);

    net.addProjection(rule1b.getOrigin("AND"), output
        .getTermination("rule1"));
    net.addProjection(rule2.getOrigin(NEFEnsemble.X), output
        .getTermination("rule2"));

    float neg = -.3f;
    float pos = .9f;
    float[][] m = new float[][] { new float[] { pos, neg, neg, neg, neg },
        new float[] { neg, pos, neg, neg, neg },
        new float[] { neg, neg, pos, neg, neg },
        new float[] { neg, neg, neg, pos, neg },
        new float[] { neg, neg, neg, neg, pos }, };
    output.addDecodedTermination("recurrent", m, .005f, false);

    Function[] clipped = new Function[] { new Clip(5, 0, 0f, 1f),
        new Clip(5, 1, 0f, 1f), new Clip(5, 2, 0f, 1f),
        new Clip(5, 3, 0f, 1f), new Clip(5, 4, 0f, 1f) };
    output.addDecodedOrigin("recurrent", clipped, Neuron.AXON);

    net.addProjection(output.getOrigin("recurrent"), output
        .getTermination("recurrent"));

    /*
     * Add probes
     */
    try {
      simulator.addProbe(C.getName(), "in", true);
      simulator.addProbe(A.getName(), "in", true);
      simulator.addProbe(B.getName(), "in", true);
      simulator.addProbe(D.getName(), "in", true);
    } catch (SimulationException e) {
      e.printStackTrace();
    }

    return net;
View Full Code Here

        }

        @Override
        protected void action() throws ActionException {
            try {
                Simulator simulator = uiNetwork.getSimulator();

                simulator.resetNetwork(false, true);
                simulator.addSimulatorListener(NengoGraphics.getInstance().getProgressIndicator());
               
                try {
                    simulator.run(startTime, endTime, stepTime);
                } finally {
                    simulator.removeSimulatorListener(NengoGraphics.getInstance().getProgressIndicator());
                }

                ((NengoGraphics) (UIEnvironment.getInstance())).captureInDataViewer(uiNetwork
                        .getModel());
View Full Code Here

        super("Run interactive plots","Interactive Plots");
        this.uiNetwork = uiNetwork;
    }

    protected void action() throws ActionException {
        Simulator simulator = uiNetwork.getSimulator();
        PythonInterpreter pi = NengoGraphics.getInstance().getPythonInterpreter();

        simulator.resetNetwork(false, true);
        pi.set("_interactive_network", uiNetwork);
        pi.exec("import timeview");
        pi.exec("reload(timeview)");
        pi.exec("timeview.View(_interactive_network.model,ui=_interactive_network.viewerEnsured)");
        pi.exec("del _interactive_network");
View Full Code Here

TOP

Related Classes of ca.nengo.sim.Simulator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.