Examples of NEFEnsemble


Examples of ca.nengo.model.nef.NEFEnsemble

    FunctionInput input = new FunctionInput("input", new Function[] { f }, Units.UNK);

    // uiViewer.addNeoNode(uiInput);

    NEFEnsembleFactory ef = new NEFEnsembleFactoryImpl();
    NEFEnsemble integrator = ef.make("integrator", 500, 1, "integrator1", false);
    Termination interm = integrator.addDecodedTermination("input",
        new float[][] { new float[] { tau } }, tau, false);
    Termination fbterm = integrator.addDecodedTermination("feedback",
        new float[][] { new float[] { 1f } }, tau, false);

    network.addNode(integrator);
    Thread.sleep(1000);
    network.addNode(input);
    Thread.sleep(1000);
    // UINEFEnsemble uiIntegrator = new UINEFEnsemble(integrator);
    // uiViewer.addNeoNode(uiIntegrator);
    // uiIntegrator.collectSpikes(true);

    // UITermination uiInterm =
    // uiIntegrator.showTermination(interm.getName());
    // UITermination uiFbterm =
    // uiIntegrator.showTermination(fbterm.getName());

    network.addProjection(input.getOrigin(FunctionInput.ORIGIN_NAME), interm);
    Thread.sleep(500);
    network.addProjection(integrator.getOrigin(NEFEnsemble.X), fbterm);
    Thread.sleep(500);

    /*
     * Test removing projections
     */
 
View Full Code Here

Examples of ca.nengo.model.nef.NEFEnsemble

        Units.UNK);

    // uiViewer.addNeoNode(uiInput);

    NEFEnsembleFactory ef = new NEFEnsembleFactoryImpl();
    NEFEnsemble integrator = ef.make("integrator", 500, 1, "integrator1",
        false);
    Termination interm = integrator.addDecodedTermination("input",
        new float[][] { new float[] { tau } }, tau, false);
    Termination fbterm = integrator.addDecodedTermination("feedback",
        new float[][] { new float[] { 1f } }, tau, false);

    network.addNode(integrator);
    Thread.sleep(1000);
    network.addNode(input);
    Thread.sleep(1000);
    // UINEFEnsemble uiIntegrator = new UINEFEnsemble(integrator);
    // uiViewer.addNeoNode(uiIntegrator);
    // uiIntegrator.collectSpikes(true);

    // UITermination uiInterm =
    // uiIntegrator.showTermination(interm.getName());
    // UITermination uiFbterm =
    // uiIntegrator.showTermination(fbterm.getName());

    network.addProjection(input.getOrigin(FunctionInput.ORIGIN_NAME),
        interm);
    Thread.sleep(500);
    network.addProjection(integrator.getOrigin(NEFEnsemble.X), fbterm);
    Thread.sleep(500);

    /*
     * Add probes
     */
 
View Full Code Here

Examples of ca.nengo.model.nef.NEFEnsemble

    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

Examples of ca.nengo.model.nef.NEFEnsemble

     * @return Whether to apply tau filters in timeseries plots for that probe
     */
    public boolean isApplyTauFilterByDefault(Probe probe) {

        if (probe.getTarget() instanceof NEFEnsemble) {
            NEFEnsemble e = (NEFEnsemble) probe.getTarget();
            if ((e.getMode() == SimulationMode.DEFAULT )
                || (e.getMode() == SimulationMode.PRECISE)
                || (e.getMode() == SimulationMode.APPROXIMATE)
                || (e.getMode() == SimulationMode.EXPRESS)) {
                return true;
            }
        }
        return false;
    }
View Full Code Here

Examples of ca.nengo.model.nef.NEFEnsemble

    PDF maxRatePDF = excitatoryProjection ? new IndicatorPDF(200f, 500f) : new IndicatorPDF(400f, 800f);
    ef.setNodeFactory(new LIFNeuronFactory(.02f, .0001f, maxRatePDF, interceptPDF));
    ef.setApproximatorFactory(new GradientDescentApproximator.Factory(
        new GradientDescentApproximator.CoefficientsSameSign(true), false));

    NEFEnsemble result = ef.make(name, num, 1);

    //TODO: bounding neurons for inhibitory projection
    //set intercepts of first few neurons to 1 (outside normal range)
    int n = 10;
    for (int i = 0; i < n; i++) {
      SpikingNeuron neuron = (SpikingNeuron) result.getNodes()[i];
      neuron.setBias(1-neuron.getScale());
    }

    DecodedOrigin o = (DecodedOrigin) result.addDecodedOrigin(NEFEnsemble.X, new Function[]{f}, Neuron.AXON);

    float[][] decoders = o.getDecoders();
    for (int i = 0; i < n; i++) {
      decoders[i] = new float[]{1f / n / 300};
    }
View Full Code Here

Examples of ca.nengo.model.nef.NEFEnsemble

  /**
   * @see ca.nengo.model.nef.NEFEnsembleFactory#make(java.lang.String, int, int, java.lang.String, boolean)
   */
  public NEFEnsemble make(String name, int n, float[] radii, String storageName, boolean overwrite) throws StructuralException {
        int dim = radii.length;
    NEFEnsemble result = null;

        if( storageName.length() > 0 ){
            File ensembleFile = new File(myDatabase, storageName + "." + FileManager.ENSEMBLE_EXTENSION);

            FileManager fm = new FileManager();

            if (!overwrite && ensembleFile.exists() && ensembleFile.canRead()) {
                try {
                    result = (NEFEnsemble) fm.load(ensembleFile);

                    result.setName(name);
                    if(result.getNodes().length != n) {
                        ourLogger.warn("Number of nodes in ensemble loaded from file does not match requested number of nodes");
                    }
                    if(result.getDimension() != dim) {
                        ourLogger.warn("Dimension of ensemble loaded from file does not match requested dimension");
                    }
                } catch (Exception e) {
                    ourLogger.error("Failed to load file " + ensembleFile.getAbsolutePath() + ". New ensemble will be created.", e);
                }
            }
            if (result == null) {
                result = doMake(name, n, radii, 0);

                try {
                    // Set the ensemble's factory to null to allow saving with customized ensemble factories
                    result.setEnsembleFactory(null);
                    fm.save(result, ensembleFile);
                } catch (IOException e) {
                    ourLogger.error("Failed to save file " + ensembleFile.getAbsolutePath(), e);
                }
            }
    }
        else{
            result = doMake(name, n, radii, 0);
        }

        // Set the resulting ensemble's factory to this. It must be noted that this can be a good thing or
        // bad thing. It is possible that you want the original ensemble factory, in which case this will
        // fail. Although, with this implementation, it is possible to change the ensemble factory of the
        // ensemble after loading, which might be a good thing.
    result.setEnsembleFactory(this);
    return result;
  }
View Full Code Here

Examples of ca.nengo.model.nef.NEFEnsemble

  public float[] getError(int samples){
    float[] result = new float[getDimensions()];

    if (myNode instanceof NEFEnsemble) {
      NEFEnsemble ensemble = (NEFEnsemble) myNode;

      VectorGenerator vg = new RandomHypersphereVG(false, 1, 0);
      float[][] unscaled = vg.genVectors(samples, ensemble.getDimension());
      float[][] input = new float[unscaled.length][];
      for (int i = 0; i < input.length; i++) {
        input[i] = MU.prodElementwise(unscaled[i], ensemble.getRadii());
      }

      float[][] idealOutput = NEFUtil.getOutput(this, input, SimulationMode.DIRECT);
      float[][] actualOutput = NEFUtil.getOutput(this, input, SimulationMode.CONSTANT_RATE);
View Full Code Here

Examples of ca.nengo.model.nef.NEFEnsemble

    try {
      if ( !(origin.getNode() instanceof NEFEnsemble) ) {
        throw new RuntimeException("This calculation can only be performed with origins that belong to NEFEnsembles.");
      }
     
      NEFEnsemble ensemble = (NEFEnsemble) origin.getNode();
      float[][] encoders = ensemble.getEncoders();

      output = new float[input.length][];

      NEFNode[] nodes = (NEFNode[]) ensemble.getNodes();
     
      synchronized (ensemble){
        SimulationMode oldMode = ensemble.getMode();     
        ensemble.setMode(mode);
       
        for (int i = 0; i < input.length; i++) {
          if (mode.equals(SimulationMode.DIRECT) || mode.equals(SimulationMode.EXPRESS)) {
            origin.run(input[i], 0f, 1f);
            output[i] = ((RealOutput) origin.getValues()).getValues();         
          } else {
            for (int j = 0; j < nodes.length; j++) {
              float radialInput = 0;
              if (ensemble instanceof NEFEnsembleImpl) {
                NEFEnsembleImpl impl = (NEFEnsembleImpl) ensemble;
                radialInput = impl.getRadialInput(input[i], j);
              } else {
                radialInput = MU.prod(input[i], encoders[j]);
              }
              ((NEFNode) nodes[j]).setRadialInput(radialInput);
              if (mode.equals(SimulationMode.CONSTANT_RATE)) {
                nodes[j].run(0f, 0f);
              } else {
                nodes[j].run((float) i * dt, (float) (i+1) * dt);
              }
            }
            origin.run(null, (float) i * dt, (float) (i+1) * dt);
            output[i] = ((RealOutput) origin.getValues()).getValues();
          }       
        }
        ensemble.setMode(oldMode);
      }
     
    } catch (SimulationException e) {
      throw new RuntimeException("Can't plot origin error", e);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.