Package ca.nengo.model.impl

Examples of ca.nengo.model.impl.NetworkImpl


  }

  @Override
  protected Object createNode(ConfigResult configuredProperties, String name)
      throws ConfigException {
    NetworkImpl network = new NetworkImpl();

    try {
      network.setName(name);
    } catch (StructuralException e) {
      throw new ConfigException(e.getMessage());
    }

    return network;
View Full Code Here


  /*
   * Test method for 'ca.nengo.sim.impl.WriteToDiskSimulatorListener'
   */
  public void testBasicWriting() throws StructuralException, SimulationException {
    Network network = new NetworkImpl();
    NEFEnsembleFactory factory = new NEFEnsembleFactoryImpl();
    NEFEnsemble ensemble = factory.make("Ensemble",100,2);
    File file = new File("testWTDSL.csv");
   
    network.addNode(ensemble);
   
    Probe probe = network.getSimulator().addProbe("Ensemble", "X", true);
    WriteToDiskSimulatorListener listener = new WriteToDiskSimulatorListener(file,probe,0.005f);
   
    network.getSimulator().addSimulatorListener(listener);
    network.getSimulator().run(0.0f, 1.0f, 0.001f);
   
    assertTrue(file.exists());
    assertTrue(file.length() > 0);
    assertTrue(file.delete());
  }
View Full Code Here

 
  /*
   * Test method for 'ca.nengo.sim.impl.WriteToDiskSimulatorListener'
   */
  public void testInterval() throws StructuralException, SimulationException, FileNotFoundException {
    Network network = new NetworkImpl();
    NEFEnsembleFactory factory = new NEFEnsembleFactoryImpl();
    NEFEnsemble ensemble = factory.make("Ensemble",100,2);
    File file = new File("testWTDSL.csv");
   
    network.addNode(ensemble);
   
    float interval = 0.005f;
    float simLength = 1.0f;
    int numIntervals = (int)(simLength / interval);
    Probe probe = network.getSimulator().addProbe("Ensemble", "X", true);
    WriteToDiskSimulatorListener listener = new WriteToDiskSimulatorListener(file,probe,interval);
       
    network.getSimulator().addSimulatorListener(listener);
    network.getSimulator().run(0.0f, simLength, 0.001f);
   
        Scanner fileReader = new Scanner(file);
        int lineCount = 0;
     
        while (fileReader.hasNextLine()) {
          fileReader.nextLine();
          lineCount++;
        }
       
        assertEquals(numIntervals,lineCount);
        fileReader.close();
        network.getSimulator().removeSimulatorListener(listener);
       
        // Also tests multiple runs
        interval = 0.0f;
    numIntervals = 1000;
    listener = new WriteToDiskSimulatorListener(file,probe,interval);
   
    network.getSimulator().addSimulatorListener(listener);
    network.getSimulator().run(0.0f, simLength, 0.001f);
   
        fileReader = new Scanner(file);
        lineCount = 0;
     
        while (fileReader.hasNextLine()) {
View Full Code Here

   *
   * @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 void save(Node node, File destination) throws IOException {
    saveObject(node, destination);
  }

  public void generate(Node node, String destination) throws IOException {
    NetworkImpl network = (NetworkImpl) node;
    network.dumpToScript(destination);
  }
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 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

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.