Examples of NEFEnsemble


Examples of ca.nengo.model.nef.NEFEnsemble

                }
                ef.setEncoderFactory(vectorGen);
            }

            if (radius==null) {
                NEFEnsemble ensemble = ef.make(name, numOfNeurons, dimensions);
                return ensemble;
            } else {
                float[] radii=new float[dimensions];
                for (int i=0; i<dimensions; i++) {
                    radii[i]=radius.floatValue();
                }
                NEFEnsemble ensemble = ef.make(name, numOfNeurons, radii);
                return ensemble;
            }
        } catch (StructuralException e) {
          Util.debugMsg("StructuralException: " + e.toString());
View Full Code Here

Examples of ca.nengo.model.nef.NEFEnsemble

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

Examples of ca.nengo.model.nef.NEFEnsemble

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

Examples of ca.nengo.model.nef.NEFEnsemble

    Network network = new NetworkImpl();
    FunctionInput input = new FunctionInput("input", new Function[]{new IdentityFunction(1, 0)}, Units.UNK);
    network.addNode(input);
    NEFEnsembleFactory ef = new NEFEnsembleFactoryImpl();
    int n = 300;
    NEFEnsemble pre = ef.make("pre", n, 2);
    pre.addDecodedTermination("input", MU.uniform(2, 1, 1), .005f, false);
    network.addNode(pre);
    network.addProjection(input.getOrigin(FunctionInput.ORIGIN_NAME), pre.getTermination("input"));
    NEFEnsemble post = ef.make("post", n, 2);
    network.addNode(post);
    post.addDecodedTermination("input", MU.I(2), .01f, false);
    Projection p = network.addProjection(pre.getOrigin(NEFEnsemble.X), post.getTermination("input"));

    DecodedOrigin o = (DecodedOrigin) pre.getOrigin(NEFEnsemble.X);
    DecodedTermination t = (DecodedTermination) post.getTermination("input");
    float[][] directWeights = MU.prod(post.getEncoders(), MU.prod(t.getTransform(), MU.transpose(o.getDecoders())));
    System.out.println("Direct weights: " + MU.min(directWeights) + " to " + MU.max(directWeights));

    Probe probe = network.getSimulator().addProbe(post.getName(), NEFEnsemble.X, true);
    network.setMode(SimulationMode.CONSTANT_RATE);
    network.run(-1.5f, 1);
    network.setMode(SimulationMode.DEFAULT);
    float[] reference = MU.transpose(DataUtils.filter(probe.getData(), .01f).getValues())[0];

    network.run(-1.5f, 1);
//    Plotter.plot(probe.getData(), "mixed weights");
    float[] mixed = MU.transpose(DataUtils.filter(probe.getData(), .01f).getValues())[0];
    getError(reference, mixed);

    p.addBias(300, .005f, .01f, true, false);
    BiasOrigin bo = (BiasOrigin) pre.getOrigin("post_input");
    BiasTermination bt = (BiasTermination) post.getTermination("input (bias)");
    assertTrue(MU.min(getNetWeights(directWeights, bo, bt)) > -1e-10);
    network.run(-1.5f, 1);
//    Plotter.plot(probe.getData(), "positive non-optimal");
//    float[] positiveNonOptimal = MU.transpose(DataUtils.filter(probe.getData(), .01f).getValues())[0];
//    float error = getError(reference, positiveNonOptimal);
//    assertTrue(error > 1e-10 && error < 5e-4);
    p.removeBias();

    p.addBias(300, .005f, .01f, true, true);
    bo = (BiasOrigin) pre.getOrigin("post_input");
    bt = (BiasTermination) post.getTermination("input (bias)");
    assertTrue(MU.min(getNetWeights(directWeights, bo, bt)) > -1e-10);
    network.run(-1.5f, 1);
//    Plotter.plot(probe.getData(), "positive optimal");
//    float[] positiveOptimal = MU.transpose(DataUtils.filter(probe.getData(), .01f).getValues())[0];
//    float error2 = getError(reference, positiveOptimal);
View Full Code Here

Examples of ca.nengo.model.nef.NEFEnsemble

   
    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);
    Plotter.plot(sorted);
  }
View Full Code Here

Examples of ca.nengo.model.nef.NEFEnsemble

        LinearNeuronFactory lnf = new LinearNeuronFactory(new IndicatorPDF(200, 400), new IndicatorPDF(-1, 1), true);
        NEFEnsembleFactory ef = new NEFEnsembleFactoryImpl();
        ef.setNodeFactory(lnf);

        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");
View Full Code Here

Examples of ca.nengo.model.nef.NEFEnsemble

      return;

    // Put the data in a format appropriate for passing to the GPU.
    // Most of this function is devoted to this task.
    int i = 0, j = 0, k = 0, numEnsemblesCollectingSpikes = 0;
    NEFEnsemble workingNode;
    Termination[] terminations;
    DecodedOrigin[] origins;

    float[][][][] terminationTransforms = new float[myGPUEnsembles.length][][][];
    int[][] isDecodedTermination = new int[myGPUEnsembles.length][];
    float[][] terminationTau = new float[myGPUEnsembles.length][];
    float[][][] encoders = new float[myGPUEnsembles.length][][];
    float[][][][] decoders = new float[myGPUEnsembles.length][][][];
    float[][] neuronData = new float[myGPUEnsembles.length][];
    EnsembleData ensembleData = new EnsembleData();
    int[][] ensembleDataArray = new int[myGPUEnsembles.length][];
    int[] collectSpikes = new int[myGPUEnsembles.length];
    int[][] outputRequiredOnCPU = new int[myGPUNetworkArrays.length][];
    int[] isSpikingEnsemble = new int[myGPUEnsembles.length];
    float maxTimeStep = ((LIFSpikeGenerator) ((SpikingNeuron) ((NEFEnsembleImpl) myGPUEnsembles[0])
        .getNodes()[0]).getGenerator()).getMaxTimeStep();
   
   

   
    // We put the list of projections in terms of the GPU nodes
    // For each projection we record 4 numbers: the index of the origin
    // ensemble, the index of the origin in its ensemble, the index of
    // the termination ensemble and the index of the termination in its ensemble
    int[][] adjustedProjections = new int[myGPUProjections.length][6];
   
   
    inputOnGPU = new boolean[myGPUNetworkArrays.length][];
   
    Node workingArray;
    int networkArrayOffset = 0;

    NetworkArrayData networkArrayData = new NetworkArrayData();
    int[][] networkArrayDataArray = new int[myGPUNetworkArrays.length][];

    int totalInputSize = 0;
   
    // store networkArray data
    for(i = 0; i < myGPUNetworkArrays.length; i++){
     
      networkArrayData.reset();
      workingArray = myGPUNetworkArrays[i];
     
      networkArrayData.indexOfFirstNode = networkArrayOffset;
     
      if(workingArray instanceof NEFEnsembleImpl){
        networkArrayOffset++;
      }else{
        networkArrayOffset += ((NetworkImpl) workingArray).getNodes().length;
      }
     
      networkArrayData.endIndex = networkArrayOffset;
       
      Termination[] networkArrayTerminations = workingArray.getTerminations();
      networkArrayData.numTerminations = networkArrayTerminations.length;
     
     
      for(j = 0; j < networkArrayTerminations.length; j++){
        networkArrayData.totalInputSize += networkArrayTerminations[j].getDimensions();
      }
     
      totalInputSize += networkArrayData.totalInputSize;
     
      Origin[] networkArrayOrigins;
      if(workingArray instanceof NEFEnsembleImpl)
      {
        networkArrayOrigins = ((NEFEnsembleImpl) workingArray).getDecodedOrigins();
      }else{
        networkArrayOrigins = workingArray.getOrigins();
      }
      networkArrayData.numOrigins = networkArrayOrigins.length;
     
      for(j = 0; j < networkArrayOrigins.length; j++){
        networkArrayData.totalOutputSize += networkArrayOrigins[j].getDimensions();
      }
     
      if(workingArray instanceof NEFEnsembleImpl){
        networkArrayData.numNeurons = ((NEFEnsembleImpl) workingArray).getNeurons();
      }else{
        Node[] subNodes = ((NetworkImpl) workingArray).getNodes();
        for(j = 0; j < subNodes.length; j++){
          networkArrayData.numNeurons += ((NEFEnsembleImpl) subNodes[j]).getNeurons();
        }
      }

      networkArrayDataArray[i] = networkArrayData.getAsArray();
     
      inputOnGPU[i] = new boolean[networkArrayTerminations.length];
      outputRequiredOnCPU[i] = new int[networkArrayOrigins.length];
     
      for(j = 0; j < networkArrayTerminations.length; j++){
        Termination termination = networkArrayTerminations[j];
        boolean terminationWrapped = termination instanceof TerminationWrapper;
        if(terminationWrapped)
          termination = ((TerminationWrapper) termination).getBaseTermination();
       
        k = 0;
        boolean projectionMatches = false;
       
        while(!projectionMatches && k < myGPUProjections.length){
          Termination projectionTermination = myGPUProjections[k].getTermination();
          boolean projectionTerminationWrapped = projectionTermination instanceof TerminationWrapper;
          if(projectionTerminationWrapped)
            projectionTermination = ((TerminationWrapper) projectionTermination).getBaseTermination();
         
          projectionMatches = termination == projectionTermination;
         
          if(projectionMatches)
            break;
         
          k++;
        }
 
        if (projectionMatches) {
          adjustedProjections[k][2] = i;
          adjustedProjections[k][3] = j;
          adjustedProjections[k][4] = termination.getDimensions();
          adjustedProjections[k][5] = -1;
 
          inputOnGPU[i][j] = true;
        } else {
          inputOnGPU[i][j] = false;
        }
      }
     
      for (j = 0; j < networkArrayOrigins.length; j++) {
        Origin origin = networkArrayOrigins[j];
        boolean originWrapped = origin instanceof OriginWrapper;
        if(originWrapped)
          origin = ((OriginWrapper) origin).getWrappedOrigin();
       
        for (k = 0; k < myGPUProjections.length; k++) {
          Origin projectionOrigin = myGPUProjections[k].getOrigin();
          boolean projectionOriginWrapped = projectionOrigin instanceof OriginWrapper;
         
          if(projectionOriginWrapped)
            projectionOrigin = ((OriginWrapper) projectionOrigin).getWrappedOrigin();
         
          if (origin == projectionOrigin) {
            adjustedProjections[k][0] = i;
            adjustedProjections[k][1] = j;
          }
        }
       
        outputRequiredOnCPU[i][j] = (origin.getRequiredOnCPU() || requireAllOutputsOnCPU) ? 1 : 0;
       
        // even if its not explicitly required on the CPU, it might be implicitly
        // if it is attached to a projection whose termination is on the CPU
        if(outputRequiredOnCPU[i][j] == 0){
            for (k = 0; k < nonGPUProjections.length; k++) {
              Origin projectionOrigin = nonGPUProjections[k].getOrigin();
                        boolean projectionOriginWrapped = projectionOrigin instanceof OriginWrapper;
                       
                        if(projectionOriginWrapped)
                            projectionOrigin = ((OriginWrapper) projectionOrigin).getWrappedOrigin();
                   
                        if (origin == projectionOrigin){
                            outputRequiredOnCPU[i][j] = 1;
                        }
            }
        }
      }
    }
   
    nonGPUProjections = null;
   
    // store NEFEnsemble data
    for (i = 0; i < myGPUEnsembles.length; i++) {
     
      workingNode = myGPUEnsembles[i];
     
      ensembleData.reset();

      ensembleData.dimension = workingNode.getDimension();
      ensembleData.numNeurons = workingNode.getNodeCount();
     
      isSpikingEnsemble[i] = (workingNode.getMode() == SimulationMode.DEFAULT) ? 1 : 0;

      terminations = workingNode.getTerminations();

      int terminationDim = 0;
      ensembleData.maxTransformDimension = 0;

      terminationTransforms[i] = new float[terminations.length][][];
      terminationTau[i] = new float[terminations.length];
      isDecodedTermination[i] = new int[terminations.length];
     
      for (j = 0; j < terminations.length; j++) {

        if (terminations[j] instanceof DecodedTermination) {
          terminationTransforms[i][j] = ((DecodedTermination) terminations[j])
              .getTransform();
          terminationTau[i][j] = terminations[j].getTau();

          terminationDim = terminations[j].getDimensions();
          ensembleData.totalInputSize += terminationDim;

          if (terminationDim > ensembleData.maxTransformDimension) {
            ensembleData.maxTransformDimension = terminationDim;
          }

          isDecodedTermination[i][j] = 1;
         
          ensembleData.numDecodedTerminations++;
        } else if (terminations[j] instanceof EnsembleTermination) {
          terminationTransforms[i][j] = new float[1][1];
         
         
          // when we do learning, this will have to be changed, as well as some code in the NengoGPU library.
          // currently it assumes all neurons in the ensemble have the same weight for each non-decoded termination
          // (mainly just to support gates which have uniform negative weights).
          // When we do learning, will have to extract the whole weight matrix.
          Termination[] neuronTerminations = ((EnsembleTermination) terminations[j]).getNodeTerminations();
          terminationTransforms[i][j][0] = ((PlasticNodeTermination) neuronTerminations[0]).getWeights();
          terminationTau[i][j] = terminations[j].getTau();
          isDecodedTermination[i][j] = 0;

          terminationDim = terminations[j].getDimensions();
         
          ensembleData.totalInputSize += terminationDim;
          ensembleData.nonDecodedTransformSize += terminationDim;
          ensembleData.numNonDecodedTerminations++;
        }
      }

      encoders[i] = workingNode.getEncoders();
      float[] radii = workingNode.getRadii();
      for (j = 0; j < encoders[i].length; j++) {
        for (k = 0; k < encoders[i][j].length; k++)
          encoders[i][j][k] = encoders[i][j][k] / radii[k];
      }

      origins = ((NEFEnsembleImpl) workingNode).getDecodedOrigins();

      ensembleData.numOrigins = origins.length;
      ensembleData.maxDecoderDimension = 0;

      decoders[i] = new float[origins.length][][];
      int originDim;
      for (j = 0; j < origins.length; j++) {
        decoders[i][j] = origins[j].getDecoders();
        originDim = origins[j].getDimensions();

        ensembleData.totalOutputSize += originDim;

        if (originDim > ensembleData.maxDecoderDimension) {
          ensembleData.maxDecoderDimension = originDim;
        }
      }

      neuronData[i] = ((NEFEnsembleImpl) workingNode).getStaticNeuronData();

      //collectSpikes[i] = (workingNode.isCollectingSpikes() || requireAllOutputsOnCPU) ? 1 : 0;
      collectSpikes[i] = workingNode.isCollectingSpikes() ? 1 : 0;
      numEnsemblesCollectingSpikes++;

      ensembleDataArray[i] = ensembleData.getAsArray();
    }
   
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", 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

Examples of ca.nengo.model.nef.NEFEnsemble

  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() {
          @Override
          public void run() {
            Plotter.plot(ensemble.getSpikePattern());
          }
        };
        pt.start();
       
        try {
View Full Code Here

Examples of ca.nengo.model.nef.NEFEnsemble

  public void functionalTestAddBiasOrigin() throws StructuralException, SimulationException {
    NEFEnsembleFactory ef = new NEFEnsembleFactoryImpl();

    boolean regenerate = false;
    NEFEnsemble source = ef.make("source", 300, 1, "nefeTest_source", regenerate);
    NEFEnsemble dest = ef.make("dest", 300, 1, "nefeTest_dest", regenerate);
   
    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);
//    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]);
   
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.