Package ca.nengo.model

Examples of ca.nengo.model.Network


   *
   * @throws StructuralException
   * @throws SimulationException
   */
  public void functionalTestSort() throws StructuralException, SimulationException {
    Network network = new NetworkImpl();
   
    FunctionInput input = new FunctionInput("input", new Function[]{new SineFunction(5)}, Units.UNK);
    network.addNode(input);
   
    NEFEnsembleFactory ef = new NEFEnsembleFactoryImpl();
    NEFEnsemble ensemble = ef.make("ensemble", 100, 1);
    ensemble.addDecodedTermination("input", MU.I(1), .005f, false);
    ensemble.collectSpikes(true);
    network.addNode(ensemble);
   
    network.addProjection(input.getOrigin(FunctionInput.ORIGIN_NAME), ensemble.getTermination("input"));
    network.run(0, 2);
   
    SpikePattern unsorted = ensemble.getSpikePattern();
    SpikePattern sorted = DataUtils.sort(unsorted, ensemble);
   
    Plotter.plot(unsorted);
View Full Code Here


        try {
            NEFEnsemble ensemble = ef.make("test", 20, 1);
            ensemble.addDecodedTermination("input", MU.I(1), .01f, false);
            Plotter.plot(ensemble);

            Network network = new NetworkImpl();
            network.addNode(ensemble);
            FunctionInput input = new FunctionInput("input", new Function[]{new SineFunction(3)}, Units.UNK);
            network.addNode(input);
            network.addProjection(input.getOrigin(FunctionInput.ORIGIN_NAME), ensemble.getTermination("input"));

            network.setMode(SimulationMode.RATE);
            Probe rates = network.getSimulator().addProbe("test", "rate", true);
            network.run(0, 2);
            //          Plotter.plot(rates.getData(), .05f, "rates");
            Plotter.plot(rates.getData(), "rates");
        } catch (StructuralException e) {
            e.printStackTrace();
        } catch (SimulationException e) {
View Full Code Here

public class IntegratorExample {

  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", true)
    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

   
 
  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";
     
      Plotter.plot(inputRecorder.getData(), "Input");
      Plotter.plot(integratorData, .005f, "Integrator");
      Plotter.plot(neuronRecorder.getData(), "Neuron #0");
     
      Plotter.plot(((Ensemble) network.getNode("integrator")).getSpikePattern());
     
      MatlabExporter me = new MatlabExporter();
      me.add("input", inputRecorder.getData());
      me.add("integrator", integratorRecorder.getData(), .01f);
      me.add("neuron", neuronRecorder.getData());
View Full Code Here

public class ScopeExample {

  public static void main(String[] args) throws Exception {
   
    try {
      Network network = new NetworkImpl();
     
      //this "function input" is Probeable ...    
      Function[] funcs = new Function[2];
      for(int i=0; i<funcs.length; ++i) {
        funcs[i] = new PostfixFunction("sin(x0)^"+(i+1), 1);
      }
      String name = "functions of time";
      FunctionInput fi = new FunctionInput(name, funcs, Units.uAcm2);
      network.addNode(fi);
     
      //we can add a probe to it and run the simulator ...
      Probe p = network.getSimulator().addProbe(name, FunctionInput.STATE_NAME, true);     
      network.run(0, 10);
     
      JFrame frame = makeAnimPlotFrame("vector plot");
      frame.setLayout(new BorderLayout());
      Scope scope = new Scope(p);
      frame.getContentPane().add(scope.getGraphPanel(), BorderLayout.CENTER);
View Full Code Here

    Plotter.plot(series, patterns, "multi series");
  }
 
  public static void rasterMemoryTest() {
    try {
      Network network = new NetworkImpl();
     
      NEFEnsembleFactory ef = new NEFEnsembleFactoryImpl();
      final NEFEnsemble ensemble = ef.make("ensemble", 200, 1);
      ensemble.collectSpikes(true);
      network.addNode(ensemble);
     
      FunctionInput input = new FunctionInput("input", new Function[]{new ConstantFunction(1, 1)}, Units.UNK);
      network.addNode(input);
     
      network.run(0, 1);
     
      Environment.setUserInterface(true);
      Memory.report("Before plots");
      for (int i = 0; i < 5; i++) {
        Thread pt = new Thread() {
View Full Code Here

      }
    };
    FunctionInput input = new FunctionInput("input", new Function[]{f}, Units.UNK);
//    FunctionInput zero = new FunctionInput("zero", new Function[]{new ConstantFunction(1, 0f)}, Units.UNK);
   
    Network network = new NetworkImpl();
    network.addNode(input);
    network.addNode(source);
    network.addNode(dest);

    source.addDecodedTermination("input", MU.I(1), .005f, false); //OK
    BiasOrigin bo = source.addBiasOrigin(source.getOrigin(NEFEnsemble.X), 200, "interneurons", true); //should have -ve bias decoders
    network.addNode(bo.getInterneurons()); //should be backwards response functions
//**    bo.getInterneurons().addDecodedTermination("source", MU.I(1), .005f, false);
   
//    Plotter.plot(bo.getInterneurons());
//    Plotter.plot(bo.getInterneurons(), NEFEnsemble.X);
   
//    DecodedTermination t = (DecodedTermination) dest.addDecodedTermination("source", MU.I(1), .005f, false);
//**    BiasTermination[] bt = dest.addBiasTerminations(t, .002f, bo.getDecoders()[0][0], ((DecodedOrigin) source.getOrigin(NEFEnsemble.X)).getDecoders());
//**    bt[1].setStaticBias(-1); //creates intrinsic current needed to counteract interneuron activity at 0
   
//    float[][] weights = MU.prod(dest.getEncoders(), MU.transpose(((DecodedOrigin) source.getOrigin(NEFEnsemble.X)).getDecoders()));
//*    float[][] biasEncoders = MU.transpose(new float[][]{bt[0].getBiasEncoders()});
//*    float[][] biasDecoders = MU.transpose(bo.getDecoders());
//*    float[][] weightBiases = MU.prod(biasEncoders, biasDecoders);
//*    float[][] biasedWeights = MU.sum(weights, weightBiases);
//    Plotter.plot(weights[0], "some weights");
//    Plotter.plot(biasedWeights[0], "some biased weights");
//    Plotter.plot(weights[1], "some more weights");
   
//    Plotter.plot(bt[0].getBiasEncoders(), "bias decoders");
   
    network.addProjection(input.getOrigin(FunctionInput.ORIGIN_NAME), source.getTermination("input"));
    network.addProjection(source.getOrigin(NEFEnsemble.X), dest.getTermination("source"));
//*    network.addProjection(bo, bo.getInterneurons().getTermination("source"));
//*    network.addProjection(bo, bt[0]);
//*    network.addProjection(bo.getInterneurons().getOrigin(NEFEnsemble.X), bt[1]);
//    network.addProjection(zero.getOrigin(FunctionInput.ORIGIN_NAME), bt[1]);
   
//    Probe sourceProbe = network.getSimulator().addProbe("source", NEFEnsemble.X, true);
//    Probe destProbe = network.getSimulator().addProbe("dest", NEFEnsemble.X, true);
//    Probe interProbe = network.getSimulator().addProbe("source_X_bias_interneurons", NEFEnsemble.X, true);
   
    network.run(0, 2);
   
//    Plotter.plot(sourceProbe.getData(), "source");
//    Plotter.plot(destProbe.getData(), "dest");
//    Plotter.plot(interProbe.getData(), "interneurons");
  }
View Full Code Here

  }
 
  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

          for (int i = 0; i < result.myNodeTerminations.length; i++){
            result.myNodeTerminations[i] = ensemble.getNodes()[i].getTermination(myNodeTerminations[i].getName());
          }
        }
        if (node instanceof Network) {
          Network network = (Network)node;
          for (int i = 0; i < result.myNodeTerminations.length; i++){
            result.myNodeTerminations[i] = network.getNodes()[i].getTermination(myNodeTerminations[i].getName());
          }
        }
      } catch (StructuralException e) {
        throw new CloneNotSupportedException("Error cloning EnsembleTermination: " + e.getMessage());
      }
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

TOP

Related Classes of ca.nengo.model.Network

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.