Package ca.nengo.math

Examples of ca.nengo.math.Function


  public void testMap() throws StructuralException {
    float[][] sig = new float[3][1];
    sig[0][0] = 0;
    sig[1][0] = 1;
    sig[2][0] = 2;
    Function f = new FixedSignalFunction(sig , 0);

    TestUtil.assertClose(0f, f.map(new float[]{0f}), .00001f);
    TestUtil.assertClose(1f, f.map(new float[]{0f}), .00001f);
    TestUtil.assertClose(2f, f.map(new float[]{0f}), .00001f);
    TestUtil.assertClose(0f, f.map(new float[]{0f}), .00001f);
    TestUtil.assertClose(1f, f.map(new float[]{0f}), .00001f);
    TestUtil.assertClose(2f, f.map(new float[]{0f}), .00001f);
  }
View Full Code Here


    float[][] evalPoints = new float[100][];
    for (int i = 0; i < evalPoints.length; i++) {
      evalPoints[i] = new float[]{(float) i / (float) evalPoints.length};
    }
   
    Function target = new FourierFunction(frequencies, amplitudes, phases);
    float[][] values = new float[frequencies.length][];
    for (int i = 0; i < frequencies.length; i++) {
      Function component = new FourierFunction(new float[]{frequencies[i]}, new float[]{1}, new float[]{phases[i]});
      values[i] = new float[evalPoints.length];
      for (int j = 0; j < evalPoints.length; j++) {
        values[i][j] = component.map(evalPoints[j]);
      }
    }
   
    GradientDescentApproximator.Constraints constraints = new GradientDescentApproximator.Constraints() {
      private static final long serialVersionUID = 1L;
View Full Code Here

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

  public void functionalTestBiasOriginError() throws StructuralException, SimulationException {
    float tauPSC = .01f;
   
    Network network = new NetworkImpl();
   
    Function f = new AbstractFunction(1) {
      private static final long serialVersionUID = 1L;
      public float map(float[] from) {
        return from[0] - 1;
      }
    };
View Full Code Here

    public static class PoiraziDendriteSigmoidFactory implements SpikeGeneratorFactory
    {
        private static final long serialVersionUID = 1L;

        public SpikeGenerator make() {
            Function ps = new PoiraziDendriteSigmoid();
            return new RateFunctionSpikeGenerator(ps);
        }
View Full Code Here

    public void testNothing() {
    }

    //functional test ...
    public static void main(String[] args) {
        Function one = new PiecewiseConstantFunction(new float[]{0.1f}, new float[]{0, 1});
        Function two = new AbstractFunction(1) {
            private static final long serialVersionUID = 1L;
            public float map(float[] from) {
                float t = from[0];
                float tau = .05f;
                return (1 - t/tau) * (float) Math.exp(-t/tau);
            }
        };

        Function conv = new Convolution(one, two, .0001f, .5f);

        Plotter.plot(conv, 0, .001f, 1f, "convolution of step and differentiator impulse response");
    }
View Full Code Here

    Termination t = integrator.addTermination("input", new float[]{1}, .005f, false);
    ALIFSpikeGenerator generator = new ALIFSpikeGenerator(.0005f, .02f, .2f, .05f);
    SpikingNeuron neuron = new SpikingNeuron(integrator, generator, 2, 5, "neuron");
    network.addNode(neuron);

    Function f = new PiecewiseConstantFunction(new float[]{1, 2}, new float[]{0, 1, -1});
//    Function f = new SineFunction((float) Math.PI, 1f / (float) Math.PI);
//    Plotter.plot(f, 0, .01f, 3, "input");
    FunctionInput input = new FunctionInput("input", new Function[]{f}, Units.UNK);
    network.addNode(input);
View Full Code Here

          stack.push(o);
        } else if (o instanceof Integer) {
          int index = ((Integer) o).intValue();
          stack.push(new Float(from[index]));
        } else {
          Function f = (Function) o;

          float[] args = new float[f.getDimension()];
          for (int dim = args.length-1; dim >= 0; dim--) {
            args[dim] = ((Float) stack.pop()).floatValue();
          }

          stack.push(new Float(f.map(args)));
        }
      }

      result = ((Float) stack.pop()).floatValue();
View Full Code Here

      countSpikes(myCurrents[i], dt, myTransientTime);
      rates[i] = countSpikes(myCurrents[i], dt, simTime) / simTime;
    }

    CurveFitter cf = new LinearCurveFitter();
    Function result = cf.fit(myCurrents, rates);
    myConstantRateFunction = result;
    myConstantRateFunctionOK = true;
    myMode = mode;
  }
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

TOP

Related Classes of ca.nengo.math.Function

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.