Package ca.nengo.math.impl

Examples of ca.nengo.math.impl.ConstantFunction


  /*
   * Test method for 'ca.nengo.math.impl.ConstantFunction.getDimension()'
   */
  public void testGetDimension() {
    ConstantFunction f = new ConstantFunction(1, 1f);
    assertEquals(1, f.getDimension());

    f = new ConstantFunction(10, 1f);
    assertEquals(10, f.getDimension());
  }
View Full Code Here


  /*
   * Test method for 'ca.nengo.math.impl.ConstantFunction.map(float[])'
   */
  public void testMap() {
    ConstantFunction f = new ConstantFunction(1, 1f);
    assertClose(1f, f.map(new float[]{0f}), .00001f);
    assertClose(1f, f.map(new float[]{1f}), .00001f);
  }
View Full Code Here

  /*
   * Test method for 'ca.nengo.math.impl.ConstantFunction.multiMap(float[][])'
   */
  public void testMultiMap() {
    ConstantFunction f = new ConstantFunction(1, 1f);
    float[] result = f.multiMap(new float[][]{new float[]{0f}, new float[]{1f}});
   
    assertEquals(2, result.length);
    assertClose(1f, result[0], .00001f);
    assertClose(1f, result[1], .00001f);
  }
View Full Code Here

    NEFEnsembleImpl a = (NEFEnsembleImpl)ef.make("a", 10, 1);
    a.addDecodedTermination("input", new float[][]{new float[]{1}}, 0.01f, false);
   
    net.addNode(a);
   
    FunctionInput fin = new FunctionInput("fin", new Function[]{new ConstantFunction(1,0)}, Units.UNK);
    net.addNode(fin);
   
    net.addProjection(fin.getOrigin("origin"), a.getTermination("input"));
   
    Probe p = net.getSimulator().addProbe("a", "rate", true);
View Full Code Here

     
      NetworkImpl test2 = (NetworkImpl)test1.clone();
      test2.setName("test2");
      top.addNode(test2);
     
      FunctionInput fin = new FunctionInput("fin", new Function[]{new ConstantFunction(1,0.5f)}, Units.UNK);
      top.addNode(fin);
     
      top.addProjection(fin.getOrigin("origin"), test1.getTermination("in"));
      top.addProjection(fin.getOrigin("origin"), test2.getTermination("in"));
     
View Full Code Here

   */
  public void testFindRoot() {
    float root = -1f;
    NewtonRootFinder nrf = new NewtonRootFinder(20, false);
   
    Function func = new ConstantFunction(1, 1f);
    try {
      root = nrf.findRoot(func, -5, 15, 0.0001f);
    } catch (RuntimeException e) { // failure after too many attempts
    }
   
    func = new FourierFunction(new float[]{1, 0.5f, 1}, new float[]{1, 1, 0.5f}, new float[]{0, -0.5f, 0.2f});
    root = nrf.findRoot(func, -5, 5, 0.0001f);
    TestUtil.assertClose(func.map(new float[]{root}), 0, 0.001f);
   
    func = new IdentityFunction(1, 0);
    root = nrf.findRoot(func, -5, 5, 0.0001f);
    TestUtil.assertClose(func.map(new float[]{root}), 0, 0.001f);
   
    func = new PiecewiseConstantFunction(new float[]{-1,1}, new float[]{2,0,-2});
    try {
      root = nrf.findRoot(func, -5, 15, 0.0001f);
    } catch (RuntimeException e) { // failure after too many attempts
    }
   
    func = new Polynomial(new float[]{4f, 2f, -3f, 1f});
    root = nrf.findRoot(func, -5, 15, 0.0001f);
    TestUtil.assertClose(func.map(new float[]{root}), 0, 0.001f);
   
    func = new SigmoidFunction(-1f, 0.3f, -0.5f, 1f);
    root = nrf.findRoot(func, -5, 5, 0.0001f);
    TestUtil.assertClose(func.map(new float[]{root}), 0, 0.001f);
   
    func = new SineFunction(0.5f);
    root = nrf.findRoot(func, -5, 5, 0.0001f);
    TestUtil.assertClose(func.map(new float[]{root}), 0, 0.001f);
  }
View Full Code Here

    LinearSynapticIntegrator integrator = new LinearSynapticIntegrator();
    IzhikevichSpikeGenerator generator = new IzhikevichSpikeGenerator(IzhikevichSpikeGenerator.Preset.REGULAR_SPIKING);
    ExpandableSpikingNeuron neuron = new ExpandableSpikingNeuron(integrator, generator, 1, 0, "neuron");   
    Termination t = neuron.addTermination("input", MU.I(1), .001f, false);
   
    FunctionInput input = new FunctionInput("input", new Function[]{new ConstantFunction(1, I)}, Units.UNK);
   
    Network network = new NetworkImpl();
    network.addNode(input);
    network.addNode(neuron);
    network.addProjection(input.getOrigin(FunctionInput.ORIGIN_NAME), t);
View Full Code Here

  /*
   * Test method for 'ca.nengo.math.impl.DefaultFunctionInterpreter.registerFunction(String, Function)'
   */
  public void testRegisterFunction() {
    Function c = new ConstantFunction(2, 1f);
    DefaultFunctionInterpreter interpreter = new DefaultFunctionInterpreter();
    interpreter.registerFunction("const", c);
    PostfixFunction f = (PostfixFunction) interpreter.parse("const(x0, x1)", 2);
    List<Serializable> l = f.getExpressionList();
    assertEquals(Integer.valueOf(0), l.get(0));
    assertEquals(Integer.valueOf(1), l.get(1));
    assertEquals(c, l.get(2));
   
    try {
      interpreter.registerFunction("const", new ConstantFunction(1, 1f));
      fail("Should have thrown exception due to duplicate name");     
    } catch (Exception e) {} //exception is expected
  }
View Full Code Here

    /**
     * Default zero noise.
     */
    public NoiseImplFunction() {
      myFunction = new ConstantFunction(1, 0);
    }
View Full Code Here

   * Test method for 'ca.nengo.math.impl.WeightedCostApproximator.pseudoInverse()'
   */
  public void testPseudoInverse() {
    WeightedCostApproximator a = new WeightedCostApproximator(new float[][]{new float[]{0f},new float[]{1f},new float[]{2f}},
        new float[][]{new float[]{3f,2f,3f},new float[]{1f,2f,3f}},
        new ConstantFunction(1,1f), 0.02f, -1);
    double[][] ps = a.pseudoInverse(new double[][]{new double[]{1,2},new double[]{3,4}}, 0f, -1);
    Matrix psM = new Matrix(ps);
    Matrix aM = new Matrix(new double[][]{new double[]{1,2},new double[]{3,4}});
    Matrix apsaM = aM.times(psM.times(aM));
   
View Full Code Here

TOP

Related Classes of ca.nengo.math.impl.ConstantFunction

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.