Package ca.nengo.util.impl

Examples of ca.nengo.util.impl.LinearInterpolatorND


  public TimeSeries integrate(DynamicalSystem system, TimeSeries input) {
    float[] inTimes = input.getTimes();
    float timespan = inTimes[inTimes.length-1] - inTimes[0];
    int steps = (int) Math.ceil(timespan*SHRINK / h);

    LinearInterpolatorND interpolator = new LinearInterpolatorND(input);

    float[] times = new float[steps+1];
    float[][] values = new float[steps+1][];
    times[0] = inTimes[0];
    values[0] = system.g(times[0], input.getValues()[0]);

    float t = inTimes[0];
    for (int i = 1; i <= steps; i++) {
      float dt = (i < steps) ? h : (inTimes[inTimes.length-1] - t);
      t = t + dt;
      times[i] = t;

      float[] u = interpolator.interpolate(t);
      float[] dxdt = system.f(t, u);
      system.setState(MU.sum(system.getState(), MU.prod(dxdt, dt)));
      values[i] = system.g(t, u);
    }

View Full Code Here


    TimeSeries result = integrator.integrate(system, input);
   
    assertTrue(result.getTimes().length < 60);
   
    //check results against selected hard-coded values from matlab solution ...
    InterpolatorND interpolator = new LinearInterpolatorND(result);
    float tolerance = 0.005f;
    float[] time2 = interpolator.interpolate(2);
    TestUtil.assertClose(time2[0], 0.053f, tolerance);
    TestUtil.assertClose(time2[1], -0.157f, tolerance);
    float[] time5 = interpolator.interpolate(5);
    TestUtil.assertClose(time5[0], -0.128f, tolerance);
    TestUtil.assertClose(time5[1], 0.223f, tolerance);
    float[] time8 = interpolator.interpolate(8);
    TestUtil.assertClose(time8[0], 0.257f, tolerance);
    TestUtil.assertClose(time8[1], -0.297f, tolerance);
   
//    Plotter.plot(result, "Van der Pol Oscillator");
  }
View Full Code Here

     * @see ca.nengo.dynamics.Integrator#integrate(ca.nengo.dynamics.DynamicalSystem, ca.nengo.util.TimeSeries)
     */
  public TimeSeries integrate(DynamicalSystem system, TimeSeries input) {   
    MU.VectorExpander times = new MU.VectorExpander();
    MU.MatrixExpander values = new MU.MatrixExpander();   
    LinearInterpolatorND interpolator = new LinearInterpolatorND(input);   

    float t0 = input.getTimes()[0];
    float tfinal = input.getTimes()[input.getTimes().length - 1];   
    float hmax = (tfinal - t0) / 2.5f;
    float hmin = (tfinal - t0) / 1e9f;
    float h = (tfinal - t0) / 100f; //initial guess at step size
    float t = t0;
    float[] x = system.getState();
   
    times.add(t);
    values.add(x);

    float[][] k = new float[7][]; //7 stages for each step (although one of them is shared by adjacent steps)
    for (int i = 0; i < k.length; i++) {
      k[i] = new float[x.length];
    }

    //Compute the first stage prior to the main loop (subsequently the first stage is assigned from the previous
    //step's last stage).
    float[] u = interpolator.interpolate(t);
    k[0] = system.f(t, u);
   
    while (t < tfinal && h >= hmin) {
      if (t + h > tfinal) h = tfinal - t;

      for (int j = 0; j < 6; j++) {
        float stageTime = t + c[j+1]*h;
        u = interpolator.interpolate(stageTime);
               
        float[] ka = new float[x.length];
        for (int q = 0; q < x.length; q++) {
          for (int r = 0; r <= j; r++) {
            ka[q] += k[r][q] * a[j+1][r]; //note: this doesn't look like a matrix-vector product because our k is transposed
View Full Code Here

  /**
   * @param series TimeSeries from which to obtain Function of time
   */
  public void setTimeSeries(TimeSeries series) {
    myTimeSeries = series;
    myInterpolator = new LinearInterpolatorND(series);
  }
View Full Code Here

  /**
   * @see ca.nengo.math.impl.AbstractFunction#map(float[])
   */
  public float map(float[] from) {
    if (myInterpolator == null) {
            myInterpolator = new LinearInterpolatorND(myTimeSeries);
        }
    return myInterpolator.interpolate(from[0])[myDimension];
  }
View Full Code Here

TOP

Related Classes of ca.nengo.util.impl.LinearInterpolatorND

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.