Package ca.nengo.model

Examples of ca.nengo.model.Network


                Ensemble ensemble = (Ensemble)node;
                UIEnsemble ensembleUI = new UIEnsemble(ensemble);
                addUINode(ensembleUI,false,false);
               
              } else if (node instanceof Network) {
                Network network = (Network)node;
                UINetwork networkUI = new UINetwork(network);
                addUINode(networkUI, false, false);
              } else {
                UserMessages.showError("Unsupported node type " + node.getClass().getSimpleName()
                    + " in EnsembleViewer");
View Full Code Here


    }
  }

  protected String getExposedName() {
    if (getNodeParent() != null && getNodeParent().getNetworkParent() != null) {
      Network network = getNodeParent().getNetworkParent().getModel();
      if (network != null) {
        String exposedName = getExposedName(network);
        if (exposedName != null) {
          return exposedName;
        }
View Full Code Here

  /**
   * UnExposes this origin/termination outside the Network
   */
  protected void unExpose() {
    UINetwork networkUI = getNodeParent().getNetworkParent();
    Network network = networkUI.getModel();
    if (network != null) {
      unExpose(network);
      showPopupMessage(getName() + " is UN-exposed on Network: " + network.getName());
    } else {
      UserMessages.showWarning("Cannot expose because no external network is available");
    }
  }
View Full Code Here

        setName(term.getName());
    }

    @Override
    protected void destroyTerminationModel() {
        Network network = ((UINetwork) getParent()).getModel();
        network.hideTermination(getModel().getName());
        showPopupMessage("termination removed from network");
    }
View Full Code Here

    try {
      if (nodeAttachedTo.getParentViewer() instanceof EnsembleViewer) {
        EnsembleViewer ensembleViewer = (EnsembleViewer) nodeAttachedTo.getParentViewer();

        UIEnsemble ensemble = ensembleViewer.getViewerParent();
        Network network = ensemble.getNetworkParent().getModel();

        probe = network.getSimulator().addProbe(ensemble.getName(),
            (Probeable) node,
            state,
            true);

      } else if (nodeAttachedTo.getNetworkParent() != null) {
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

    @SuppressWarnings("unchecked")
  protected void post(Node node)
  {
        if (node instanceof Network && inTemplateNetwork <= 0)
        {
            Network net = (Network)node;
            parentNetwork.pop();

            HashMap<String, Object> toScriptArgs = new HashMap<String, Object>();
            toScriptArgs.put("prefix", prefixes.get(node) + spaceDelimiter);
            toScriptArgs.put("isSubnet", !topLevel);
            toScriptArgs.put("netName", prefixes.get(node));
            toScriptArgs.put("spaceDelim", spaceDelimiter);
           
            try {
                String code = net.toPostScript(toScriptArgs);
                script.append(code);
            } catch(ScriptGenException e) {
                System.out.println(e.getMessage());
            }
View Full Code Here

        Ensemble ensemble = (Ensemble)node;
        for (int i = 0; i < myNodeOrigins.length; i++)
          origins[i] = ensemble.getNodes()[i].getOrigin(myNodeOrigins[i].getName());
      }
      if (node instanceof Network) {
        Network network = (Network)node;
        for (int i = 0; i < myNodeOrigins.length; i++)
          origins[i] = network.getNodes()[i].getOrigin(myNodeOrigins[i].getName());
      }
      result.myNodeOrigins = origins;
      return result;
    } catch (StructuralException e) {
      throw new CloneNotSupportedException("Error cloning EnsembleOrigin: " + e.getMessage());
View Full Code Here

//    error2 = getError(reference, negativeOptimal);
//    assertTrue(error2 > 1e-10 && error2 < 3.5e-4 && error2 < error);
//  }

  public void testAddBias2D() throws StructuralException, SimulationException {
    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);
//    assertTrue(error2 > 1e-10 && error2 < 2.5e-4 && error2 < error);
    p.removeBias();
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.