Package ca.nengo.math

Examples of ca.nengo.math.Function


    float[] evalPoints = new float[100];
    for (int i = 0; i < evalPoints.length; i++) {
      evalPoints[i] = -10 + 20 * (float)i / evalPoints.length;
    }

    Function target = new IdentityFunction(1,0);

    float[][] values = new float[polyCoeffs.length][];
    for (int i = 0; i < values.length; i++) {
      Function component = new Polynomial(polyCoeffs[i]);
      values[i] = new float[evalPoints.length];
      for (int j = 0; j < evalPoints.length; j++) {
        values[i][j] = component.map(new float[]{evalPoints[j]});
      }
    }

    LinearApproximator approximator = new IndependentDimensionApproximator(evalPoints, values, new int[]{0,1,0}, 2, new ConstantFunction(1,1f), 0f);
    float[] coefficients = approximator.findCoefficients(target);
View Full Code Here


  /*
   *   Test method for 'ca.nengo.math.impl.NumericallyDifferentiableFunction.getDerivative()'
   */
  public void testGetDerivative() {
    SigmoidFunction f = new SigmoidFunction(-1f,0.5f,1f,2f);
    Function g = f.getDerivative();
    NumericallyDifferentiableFunction wrap = new NumericallyDifferentiableFunction(f, 0, 0.01f);
    Function gWrap = wrap.getDerivative();
   
    assertEquals(gWrap.getDimension(), g.getDimension());
    TestUtil.assertClose(gWrap.map(new float[]{0f}), g.map(new float[]{0f}), .0001f);
    TestUtil.assertClose(gWrap.map(new float[]{-1f}), g.map(new float[]{-1f}), .0001f);
    TestUtil.assertClose(gWrap.map(new float[]{3f}), g.map(new float[]{3f}), .0001f);
  }
View Full Code Here

  }

    public static void main(String args[]) {
//      Function f = new PiecewiseConstantFunction(new float[]{0, 1, 3, 7}, new float[]{5, 2});
//      Function f = new PiecewiseConstantFunction(new float[]{0, 1, 3, 7}, new float[]{5, 2, -3, 6, 7});
        Function f = new PiecewiseConstantFunction(new float[0], new float[]{5});
        Plotter.plot(f, -1, .01f, 10, "");
    }
View Full Code Here

  /*
   * Test method for 'ca.nengo.math.impl.PolynomialCurveFitter.fit()'
   */
  public void testFindCoefficients() {
    Function target = new Polynomial(new float[]{1f,4f,-3f,0.5f,0.01f});
    PolynomialCurveFitter pcf = new PolynomialCurveFitter(3);
    float[][] values = new float[2][10];

    for (int i=0; i<values[0].length; i++) {
      values[0][i] = -9 + i * 2;
      values[1][i] = target.map(new float[]{values[0][i]});
    }

    Function fitted = pcf.fit(values[0], values[1]);

//    Plotter.plot(target, -10, 0.05f, 10, "target");
//    Plotter.plot(fitted, -10, 0.05f, 10, "fitted");

    float targetVal = 0f;
    float fittedVal = 0f;
    for (int i=-8; i<9; i=i+2) {
      targetVal = target.map(new float[]{i});
      fittedVal = fitted.map(new float[]{i});
      TestUtil.assertClose(targetVal, fittedVal, 10f);
    }

    pcf = new PolynomialCurveFitter(2);

    float[] examplex = new float[]{1f, 2f, 3f, 4f};
    float[] exampley = new float[]{3f, 2f, 1f, 2f};
    fitted = pcf.fit(examplex, exampley);

    float[] x = new float[50];
    float[] y = new float[50];
    float dx = 0.1f;
    for (int i = 0; i < x.length; i++) {
      x[i] = i*dx;
      y[i] = fitted.map(new float[]{x[i]});
    }

//    TimeSeries1D approx = new TimeSeries1DImpl(x, y, Units.UNK);
//    TimeSeries1D actual = new TimeSeries1DImpl(examplex, exampley, Units.UNK);

    for (int i = 0; i < examplex.length; i++) {
      TestUtil.assertClose(exampley[i], fitted.map(new float[]{examplex[i]}), 0.5f);
    }

  }
View Full Code Here

    public static void main(String[] args) {
        PolynomialCurveFitter fitter = new PolynomialCurveFitter(2);

        float[] examplex = new float[]{1f, 2f, 3f, 4f};
        float[] exampley = new float[]{3f, 2f, 1f, 2f};
        Function f = fitter.fit(examplex, exampley);

        float[] x = new float[50];
        float[] y = new float[50];
        float dx = 0.1f;
        for (int i = 0; i < x.length; i++) {
            x[i] = i*dx;
            y[i] = f.map(new float[]{x[i]});
        }

        TimeSeries1D approx = new TimeSeries1DImpl(x, y, Units.UNK);
        TimeSeries1D actual = new TimeSeries1DImpl(examplex, exampley, Units.UNK);
        Plotter.plot(approx, actual, "polynomial");
View Full Code Here

  /**
   * Test method for {@link ca.nengo.math.impl.PDFFunction#map(float[])}.
   * @throws StructuralException
   */
  public void testMap() throws StructuralException {
    Function f = new PDFFunction(new IndicatorPDF(0,10));
   
    int[] counts = new int[10];
    for(int i=0; i < 10000; i++)
      counts[(int)f.map(new float[]{0f})]++;
    for(int i=0; i < 10; i++)
      TestUtil.assertClose(1000, counts[i], 100);
  }
View Full Code Here

    public void testNothing() {
    }

    //functional test
    public static void main(String[] args) {
        Function current = new FourierFunction(1f, 5f, 1f, (long) Math.random());
        Function rate = new SigmoidFunction(0, 5, 0, 40);
        PoissonSpikeGenerator generator = new PoissonSpikeGenerator(rate);

        float T = 1;
        float dt = .0005f;
        int steps = (int) Math.floor(T/dt);
View Full Code Here

  /*
   *   Test method for 'ca.nengo.math.impl.NumericallyDifferentiableFunction.getDerivative()'
   */
  public void testGetDerivative() {
    SigmoidFunction f = new SigmoidFunction(-1f,0.5f,1f,2f);
    Function g = f.getDerivative();
    NumericallyDifferentiableFunction wrap = new NumericallyDifferentiableFunction(f, 0, 0.01f);
    Function gWrap = wrap.getDerivative();
   
    assertEquals(gWrap.getDimension(), g.getDimension());
    TestUtil.assertClose(gWrap.map(new float[]{0f}), g.map(new float[]{0f}), .0001f);
    TestUtil.assertClose(gWrap.map(new float[]{-1f}), g.map(new float[]{-1f}), .0001f);
    TestUtil.assertClose(gWrap.map(new float[]{3f}), g.map(new float[]{3f}), .0001f);
  }
View Full Code Here

  public static Network createNetwork() throws StructuralException {
   
    Network network = new NetworkImpl();
   
    Function f = new ConstantFunction(1, 1f);
//    Function f = new SineFunction();
    FunctionInput input = new FunctionInput("input", new Function[]{f}, Units.UNK);
    network.addNode(input);
   
    NEFEnsembleFactory ef = new NEFEnsembleFactoryImpl();
View Full Code Here

      //... and plot the probed data from the simulation ...
      //Plotter.plot(p.getData(), "function output");
     
      //now here are a couple of function bases ...
      Function g1 = new GaussianPDF(0, 1);
      Function g2 = new GaussianPDF(0.5f, 1);     
      FunctionBasis gaussianBasis = new FunctionBasisImpl(new Function[]{g1, g2});
     
      //here is a plot of the probed vector X the gaussian basis (value at time 4.5s) ...      
      gaussianBasis.setCoefficients(p.getData().getValues()[4500]);
      //Plotter.plot(gaussianBasis, -3, .001f, 3, "gaussian basis plot");
     
     
      Function s1 = new SigmoidFunction(0, 1, 0, 1);
      Function s2 = new SigmoidFunction(0.5f, -1, 0, 1);
      FunctionBasis sigmoidBasis = new FunctionBasisImpl(new Function[]{s1, s2});
     
      //here is a plot of the probed vector X the sigmoid basis (value at time 0.5s) ...            
      sigmoidBasis.setCoefficients(p.getData().getValues()[500]);
      //Plotter.plot(sigmoidBasis, -3, .001f, 3, "sigmoid basis plot");
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.