Package ca.nengo.model.impl

Examples of ca.nengo.model.impl.NetworkImpl


  }
 
  public void functionalTestBiasOriginError() throws StructuralException, SimulationException {
    float tauPSC = .01f;
   
    Network network = new NetworkImpl();
   
    Function f = new AbstractFunction(1) {
      private static final long serialVersionUID = 1L;
      public float map(float[] from) {
        return from[0] - 1;
      }
    };
   
    FunctionInput input = new FunctionInput("input", new Function[]{f}, Units.UNK);
    network.addNode(input);
   
    NEFEnsembleFactory ef = new NEFEnsembleFactoryImpl();
    NEFEnsemble pre = ef.make("pre", 400, 1, "nefe_pre", false);
    pre.addDecodedTermination("input", MU.I(1), tauPSC, false);
//    DecodedOrigin baseOrigin = (DecodedOrigin) pre.getOrigin(NEFEnsemble.X);
    network.addNode(pre);
   
    NEFEnsemble post = ef.make("post", 200, 1, "nefe_post", false);
//    DecodedTermination baseTermination = (DecodedTermination) post.addDecodedTermination("pre", MU.I(1), tauPSC, false);
    network.addNode(post);
   
    network.addProjection(input.getOrigin(FunctionInput.ORIGIN_NAME), pre.getTermination("input"));
    Projection projection = network.addProjection(pre.getOrigin(NEFEnsemble.X), post.getTermination("pre"));
   
    Probe pPost = network.getSimulator().addProbe("post", NEFEnsemble.X, true);
    network.run(0, 2);
    TimeSeries ideal = pPost.getData();
    Plotter.plot(pPost.getData(), .005f, "mixed weights result");   
   
    //remove negative weights ...
    System.out.println("Minimum weight without bias: " + MU.min(projection.getWeights()));
    projection.addBias(100, .005f, tauPSC, true, false);
    System.out.println("Minimum weight with bias: " + MU.min(projection.getWeights()));
    pPost.reset();
    network.run(0, 2);
    TimeSeries diff = new TimeSeriesImpl(ideal.getTimes(), MU.difference(ideal.getValues(), pPost.getData().getValues()), ideal.getUnits());
    Plotter.plot(diff, .01f, "positive weights");
   
    projection.removeBias();
    projection.addBias(100, tauPSC/5f, tauPSC, true, true);
    pPost.reset();
    Probe pInter = network.getSimulator().addProbe("post:pre:interneurons", NEFEnsemble.X, true);
    network.run(0, 2);
    diff = new TimeSeriesImpl(ideal.getTimes(), MU.difference(ideal.getValues(), pPost.getData().getValues()), ideal.getUnits());
    Plotter.plot(diff, .01f, "positive weights optimized");
    Plotter.plot(pInter.getData(), .01f, "interneurons");

   
View Full Code Here


    assertTrue(spikeCount + " spikes in simulation, " + rate + " expected",
        spikeCount > rate-tolerance && spikeCount < rate+tolerance);
  }

  public void testAdaptation() throws StructuralException, SimulationException {
    NetworkImpl network = new NetworkImpl();
    LinearSynapticIntegrator integrator = new LinearSynapticIntegrator(.001f, Units.ACU);
    Termination t = integrator.addTermination("input", new float[]{1}, .005f, false);
    ALIFSpikeGenerator generator = new ALIFSpikeGenerator(.0005f, .02f, .2f, .05f);
    SpikingNeuron neuron = new SpikingNeuron(integrator, generator, 2, 5, "neuron");
    network.addNode(neuron);

    Function f = new PiecewiseConstantFunction(new float[]{1, 2}, new float[]{0, 1, -1});
//    Function f = new SineFunction((float) Math.PI, 1f / (float) Math.PI);
//    Plotter.plot(f, 0, .01f, 3, "input");
    FunctionInput input = new FunctionInput("input", new Function[]{f}, Units.UNK);
    network.addNode(input);

    network.addProjection(input.getOrigin(FunctionInput.ORIGIN_NAME), t);

//    Probe rate = network.getSimulator().addProbe("neuron", "rate", true);
//    Probe N = network.getSimulator().addProbe("neuron", "N", true);
//    Probe dNdt = network.getSimulator().addProbe("neuron", "dNdt", true);
//    Probe I = network.getSimulator().addProbe("neuron", "I", true);

    setTau(neuron, .1f);
    network.setMode(SimulationMode.RATE);
    network.run(0, 3);

//    Plotter.plot(rate.getData(), "rate");
//    Plotter.plot(N.getData(), "N");
  }
View Full Code Here

    //functional test
    public static void main2(String[] args) {

        try {
            Network network = new NetworkImpl();

            //x, .3: varying x keeps time constant, changes adapted rate
//          ALIFSpikeGenerator generator = new ALIFSpikeGenerator(.002f, .02f, .5f, .01f);  //.2: .01 to .3 (150 to 20ms)
//          SynapticIntegrator integrator = new LinearSynapticIntegrator(.001f, Units.ACU);
//          PlasticExpandableSpikingNeuron neuron = new PlasticExpandableSpikingNeuron(integrator, generator, 15f, 0f, "alif");

            ALIFNeuronFactory factory = new ALIFNeuronFactory(new IndicatorPDF(200, 400), new IndicatorPDF(-2.5f, -1.5f),
                    new IndicatorPDF(.1f, .1001f), .0005f, .02f, .2f);

//          VectorGenerator vg = new RandomHypersphereVG(false, 1, 0);
//          ApproximatorFactory factory = new WeightedCostApproximator.Factory(.1f);
//          NEFEnsemble ensemble = new NEFEnsembleImpl("ensemble", new NEFNode[]{neuron}, new float[][]{new float[]{1}}, factory, vg.genVectors(100, 1));

            Node[] neurons = new Node[50];
            float[][] weights = new float[neurons.length][];
            for (int i = 0; i < neurons.length; i++) {
                neurons[i] = factory.make("neuron"+i);
                weights[i] = new float[]{1};
            }
            EnsembleImpl ensemble = new EnsembleImpl("ensemble", neurons);
            ensemble.addTermination("input", weights, .005f, false);
            ensemble.collectSpikes(true);
            network.addNode(ensemble);

            FunctionInput input = new FunctionInput("input", new Function[]{new PiecewiseConstantFunction(new float[]{0.2f}, new float[]{0, 0.5f})}, Units.UNK);
            network.addNode(input);

            network.addProjection(input.getOrigin(FunctionInput.ORIGIN_NAME), ensemble.getTermination("input"));

//          Probe vProbe = network.getSimulator().addProbe("ensemble", 0, "V", true);
//          Probe nProbe = network.getSimulator().addProbe("ensemble", 0, "N", true);
//          Probe iProbe = network.getSimulator().addProbe("ensemble", 0, "I", true);
            Probe rProbe = network.getSimulator().addProbe("ensemble", "rate", true);

            network.setMode(SimulationMode.RATE);
            network.run(0, 1);

//          Plotter.plot(ensemble.getSpikePattern());
//          Plotter.plot(vProbe.getData(), "V");
//          Plotter.plot(nProbe.getData(), "N");
//          Plotter.plot(iProbe.getData(), "I");
View Full Code Here

  private NetworkImpl myNetwork;

  protected void setUp() throws Exception {
    super.setUp();

    myNetwork = new NetworkImpl();
  }
View Full Code Here

  {
    NEFEnsembleFactoryImpl ef = new NEFEnsembleFactoryImpl();
    NEFEnsembleImpl nef1 = (NEFEnsembleImpl)ef.make("nef1", 1000, 1);
    NEFEnsembleImpl nef2 = (NEFEnsembleImpl)ef.make("nef2", 1000, 1);
    NEFEnsembleImpl nef3 = (NEFEnsembleImpl)ef.make("nef3", 1, 1);
    NetworkImpl net = new NetworkImpl();
   
    net.addNode(nef1);
    myNetwork.addNode(net);
    myNetwork.addNode(nef2);
    myNetwork.addNode(nef3);
   
    myNetwork.killNeurons(0.0f,true);
View Full Code Here

    myNetwork.addNode(a);
   
    if(myNetwork.getNode("a") != a)
      fail("Ensemble not added correctly");
   
    NetworkImpl b = new NetworkImpl();
    b.setName("b");
    myNetwork.addNode(b);
   
    if(myNetwork.getNode("b") != b)
      fail("Network not added correctly");
   
View Full Code Here

    }
    catch(StructuralException se)
    {
    }
     
    NetworkImpl b = new NetworkImpl();
    b.setName("b");
    myNetwork.addNode(b);
   
    NEFEnsembleFactoryImpl ef = new NEFEnsembleFactoryImpl();
    NEFEnsembleImpl c = (NEFEnsembleImpl)ef.make("c", 10, 1);
    b.addNode(c);
    b.getSimulator().addProbe("c", "X", true);
   
    b.exposeOrigin(c.getOrigin("X"), "exposed");
   
    if(!b.getExposedOriginName(c.getOrigin("X")).equals("exposed"))
      fail("Origin not exposed correctly");
   
    if(myNetwork.getNode("b") == null)
      fail("Network not added");
   
    myNetwork.removeNode("b");
   
    try
    {
      myNetwork.getNode("b");
      fail("Network not removed");
    }
    catch(StructuralException se)
    {
    }
   
    try
    {
      b.getNode("c");
      fail("Ensemble not recursively removed from network");
    }
    catch(StructuralException se)
    {
    }

    if(b.getSimulator().getProbes().length != 0)
      fail("Probes not removed correctly");
   
    if(b.getExposedOriginName(c.getOrigin("X")) != null)
      fail("Origin not unexposed correctly");
  }
View Full Code Here

//    myNetwork.removeNode("b");
//  }
 
  public void testGetNodeTerminations() throws StructuralException
  {
    NetworkImpl net = new NetworkImpl();
   
    if(net.getNodeTerminations().size() != 0)
      fail("Network has terminations when it shouldn't");
   
    NEFEnsembleFactoryImpl ef = new NEFEnsembleFactoryImpl();
    NEFEnsembleImpl a = (NEFEnsembleImpl)ef.make("a", 10, 1);
    float[][] tmp = new float[1][1];
    tmp[0][0] = 1;
    a.addDecodedTermination("in", tmp, 0.007f, false);
   
    net.addNode(a);
   
    if(net.getNodeTerminations().size() != 1)
      fail("Network hasn't found node termination");
  }
View Full Code Here

      fail("Network hasn't found node termination");
  }
 
  public void testGetNodeOrigins() throws StructuralException
  {
    NetworkImpl net = new NetworkImpl();
   
    if(net.getNodeOrigins().size() != 0)
      fail("Network has origins when it shouldn't");
   
    NEFEnsembleFactoryImpl ef = new NEFEnsembleFactoryImpl();
    NEFEnsembleImpl a = (NEFEnsembleImpl)ef.make("a", 10, 1);
   
    net.addNode(a);
   
    if(net.getNodeOrigins().size() != a.getOrigins().length)
      fail("Network hasn't found node origin");
   
  }
View Full Code Here

   
  }
 
  public void testReset() throws StructuralException, SimulationException
  {
    NetworkImpl net = new NetworkImpl();
   
    NEFEnsembleFactoryImpl ef = new NEFEnsembleFactoryImpl();
    NEFEnsembleImpl a = (NEFEnsembleImpl)ef.make("a", 10, 1);
    a.addDecodedTermination("input", new float[][]{new float[]{1}}, 0.01f, false);
   
    net.addNode(a);
   
    FunctionInput fin = new FunctionInput("fin", new Function[]{new ConstantFunction(1,0)}, Units.UNK);
    net.addNode(fin);
   
    net.addProjection(fin.getOrigin("origin"), a.getTermination("input"));
   
    Probe p = net.getSimulator().addProbe("a", "rate", true);
   
    net.getSimulator().run(0.0f, 1.0f, 0.001f);
   
    float[][] results1 = p.getData().getValues();
   
    net.reset(false);
   
    net.getSimulator().run(0.0f, 1.0f, 0.001f);
   
    float[][] results2 = p.getData().getValues();
   
    for(int i=0; i < results1.length; i++)
      for(int j=0; j < results1[i].length; j++)
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.