Package ca.nengo.model.impl

Examples of ca.nengo.model.impl.NetworkImpl


    ExpandableSpikingNeuron neuron = new ExpandableSpikingNeuron(integrator, generator, 1, 0, "neuron");   
    Termination t = neuron.addTermination("input", MU.I(1), .001f, false);
   
    FunctionInput input = new FunctionInput("input", new Function[]{new ConstantFunction(1, I)}, Units.UNK);
   
    Network network = new NetworkImpl();
    network.addNode(input);
    network.addNode(neuron);
    network.addProjection(input.getOrigin(FunctionInput.ORIGIN_NAME), t);
   
    Probe v = network.getSimulator().addProbe("neuron", IzhikevichSpikeGenerator.V, true);
    Probe u = network.getSimulator().addProbe("neuron", IzhikevichSpikeGenerator.U, true);
   
    network.run(0, 1);
   
    Plotter.plot(v.getData(), "voltage");
    Plotter.plot(u.getData(), "recovery");
  }
View Full Code Here


        TestUtil.assertClose(results1[i][j], results2[i][j], 0.0001f);
   
  }
 
  public void testClone() throws StructuralException, CloneNotSupportedException{
    NetworkImpl top = new NetworkImpl();
     
      NetworkImpl test1 = new NetworkImpl();
      test1.setName("test1");
      top.addNode(test1);
     
      NEFEnsembleFactoryImpl fac = new NEFEnsembleFactoryImpl();
      NEFEnsembleImpl testens = (NEFEnsembleImpl)fac.make("test", 100, 1);
      testens.addDecodedTermination("input", new float[][]{new float[]{1}}, 0.01f, false);
      test1.addNode(testens);
     
      test1.exposeTermination(testens.getTermination("input"), "in");
     
      NetworkImpl test2 = (NetworkImpl)test1.clone();
      test2.setName("test2");
      top.addNode(test2);
     
      FunctionInput fin = new FunctionInput("fin", new Function[]{new ConstantFunction(1,0.5f)}, Units.UNK);
      top.addNode(fin);
     
      top.addProjection(fin.getOrigin("origin"), test1.getTermination("in"));
      top.addProjection(fin.getOrigin("origin"), test2.getTermination("in"));
     
      if(test1.getTermination("in") == test2.getTermination("in"))
        fail("Exposed terminations did not clone correctly");
      if(test1.getNode("test") == test2.getNode("test"))
        fail("Network nodes did not clone correctly");
  }
View Full Code Here

      e.printStackTrace();
    }
  }

  public BrainViewExample() throws StructuralException {
    super(new NetworkImpl());
  }
View Full Code Here

* @author Bryan Tripp
*/
public class FuzzyLogicExample {

  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
     */
 
View Full Code Here

  private UINetwork network;

  public void createUINetwork(NengoGraphics nengoGraphics) throws StructuralException,
      SimulationException {

    network = new UINetwork(new NetworkImpl());
    nengoGraphics.getWorld().getGround().addChild(network);
    network.openViewer();
    network.getViewer().getGround().setElasticEnabled(true);

    (new Thread(new Runnable() {
View Full Code Here

    super(CreateNetwork());
  }
 
 
  public static Network CreateNetwork() throws StructuralException {
    NetworkImpl network = new NetworkImpl();
   
    Function f = new ConstantFunction(1, 1f);
    FunctionInput input = new FunctionInput("input", new Function[] { f }, Units.UNK);
   
    network .addNode(input);
   
    return network;
  }
View Full Code Here

//  private static Window window;

  // private static Window[] windows;
  public static Network createNetwork() throws StructuralException {

    Network network = new NetworkImpl();

    Function f = new ConstantFunction(1, 1f);
    // Function f = new SineFunction();
    FunctionInput input = new FunctionInput("input", new Function[] { f }, Units.UNK);
    network.addNode(input);

    NEFEnsembleFactory ef = new NEFEnsembleFactoryImpl();

    NEFEnsemble integrator = ef.make("integrator", 500, 1, "integrator1", false);
    network.addNode(integrator);
    integrator.collectSpikes(true);

    // Plotter.plot(integrator);
    // Plotter.plot(integrator, NEFEnsemble.X);

    float tau = .05f;

    Termination interm = integrator.addDecodedTermination("input",
        new float[][] { new float[] { tau } }, tau, false);
    // Termination interm = integrator.addDecodedTermination("input", new
    // float[][]{new float[]{1f}}, tau);
    network.addProjection(input.getOrigin(FunctionInput.ORIGIN_NAME), interm);

    Termination fbterm = integrator.addDecodedTermination("feedback",
        new float[][] { new float[] { 1f } }, tau, false);
    network.addProjection(integrator.getOrigin(NEFEnsemble.X), fbterm);

    // System.out.println("Network creation: " + (System.currentTimeMillis()
    // - start));
    return network;
  }
View Full Code Here

  private UINetwork network;

  public void createUINetwork(NengoGraphics nengoGraphics)
      throws StructuralException, SimulationException {

    network = new UINetwork(new NetworkImpl());
    nengoGraphics.getWorld().getGround().addChild(network);
    network.openViewer();
    network.getViewer().getGround().setElasticEnabled(true);

View Full Code Here

TOP

Related Classes of ca.nengo.model.impl.NetworkImpl

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.