Package ca.nengo.util

Examples of ca.nengo.util.TimeSeries


  /**
   * @see ca.nengo.model.Probeable#getHistory(java.lang.String)
   */
  public TimeSeries getHistory(String stateName) throws SimulationException {
    TimeSeries result = null;

    if (myJointDefinitions.containsKey(stateName)) {
      Function[] definition = myJointDefinitions.get(stateName);
      float[] jointCoordinates = new float[definition.length];
      float[] genCoordinates = myDynamics.getState();
View Full Code Here


  /**
   * @see ca.nengo.model.Probeable#getHistory(java.lang.String)
   */
  public TimeSeries getHistory(String stateName) throws SimulationException {
    TimeSeries result = null;

    if (stateName.equals(SkeletalMuscle.ACTIVATION)) {
      result = myActivationHistory;
    } else if (stateName.equals(SkeletalMuscle.FORCE)) {
      result = myForceHistory;
View Full Code Here

    Integrator i = new EulerIntegrator(.0001f);

//    TimeSeries input = new TimeSeriesImpl(new float[]{0f, 1f},
//        new float[][]{new float[]{1, rl, 0f}, new float[]{1, rl, 0f}},
//        new Units[]{Units.UNK, Units.M, Units.M_PER_S});
    TimeSeries input = new TimeSeriesImpl(new float[]{0f, .001f, .5f},
        new float[][]{new float[]{1, rl, 0f}, new float[]{0, rl, 0f}, new float[]{0, rl, 0f}},
        new Units[]{Units.UNK, Units.M, Units.M_PER_S});

    long startTime = System.currentTimeMillis();
    TimeSeries output = i.integrate(d, input);
    ourLogger.info("Elapsed time: " + (System.currentTimeMillis() - startTime));

    Plotter.plot(output, "Force");
  }
View Full Code Here

  private void doCollect() {
    if (myTarget == null) {
      throw new IllegalStateException("This Recorder has not been connected to a Probeable");
    }
   
    TimeSeries stepData;
    try {
      stepData = myTarget.getHistory(myStateName);
    } catch (SimulationException e) {
      throw new RuntimeException("Target appears not to have the state "
          + myStateName + ", although this problem should have been detected on connect()", e);
    }
   
    float[] times = stepData.getTimes();
    float[][] values = stepData.getValues();
    int len = times.length;   
   
    if (myRecord) {
      if (myValues.size() + len >= myTimes.length) {
        grow();
      }   
      System.arraycopy(times, 0, myTimes, myValues.size(), len); //don't move this to after the values update     
    } else {
      myTimes = times;
      myValues = new ArrayList<float[]>(10);
    }
   
    for (int i = 0; i < len; i++) {
      myValues.add(values[i]);
    }
   
    if (myUnits == null) {
      myUnits = stepData.getUnits();
    }
  }
View Full Code Here

  /*
   * Test method for 'ca.bpt.cn.model.impl.LIFSpikeGenerator.getHistory(String)'
   */
  public void testGetHistory() throws SimulationException {
    LIFSpikeGenerator sg = new LIFSpikeGenerator(.0005f, .02f, .002f);
    TimeSeries history = sg.getHistory("V");
    assertTrue(history instanceof TimeSeries1D);
    assertEquals(0, history.getTimes().length);
    assertEquals(0, history.getValues().length);
   
    sg.run(new float[]{0f, .002f}, new float[]{1f, 1f});
    history = sg.getHistory("V");
    assertEquals(4, history.getTimes().length);
    assertEquals(4, history.getValues().length);
    assertTrue(history.getTimes()[1] > history.getTimes()[0]);
    assertTrue(history.getValues()[1][0] > history.getValues()[0][0]);

    try {
      sg.getHistory("X");
      fail("Should have thrown exception");
    } catch (SimulationException e) {} //exception is expected
View Full Code Here

    }
    String[] labels = new String[myLabels.length];
    for (int i = 0; i < labels.length; i++) {
      labels[i] = myLabels[i];     
    }
    TimeSeries result = new TimeSeriesImpl(myTimes.clone(), myValues.clone(), units, labels);

    return result;
  }
View Full Code Here

    myExporter = new DelimitedFileExporter();
    myFile = new File("./delimited_file_exporter_test.txt");
  }

  public void testExportTimeSeriesFile() throws IOException {
    TimeSeries ts = new TimeSeriesImpl(new float[]{1, 2, 3},
        new float[][]{new float[]{4, 7}, new float[]{5, 8}, new float[]{6, 9}},
        Units.uniform(Units.UNK, 2));
    myExporter.export(ts, myFile);
    float[][] imported = myExporter.importAsMatrix(myFile);
    TestUtil.assertClose(imported[0][0], 1, .0001f);
View Full Code Here

    TestUtil.assertClose(imported[0][1], 4, .0001f);
    TestUtil.assertClose(imported[0][2], 7, .0001f);
  }

  public void testExportTimeSeriesFileFloat() throws IOException {
    TimeSeries ts = new TimeSeriesImpl(new float[]{1, 2, 3},
        new float[][]{new float[]{4, 7}, new float[]{5, 8}, new float[]{6, 9}},
        Units.uniform(Units.UNK, 2));
    myExporter.export(ts, myFile, .5f);
    TimeSeries filtered = Plotter.filter(ts, .5f);
    float[][] imported = myExporter.importAsMatrix(myFile);
    TestUtil.assertClose(imported[0][0], filtered.getTimes()[0], .0001f);
    TestUtil.assertClose(imported[1][0], filtered.getTimes()[1], .0001f);
    TestUtil.assertClose(imported[0][1], filtered.getValues()[0][0], .0001f);
    TestUtil.assertClose(imported[0][2], filtered.getValues()[0][1], .0001f);
  }
View Full Code Here

   
    myTolerance = .00001f;
  }

  public void testExtractDimension() {
    TimeSeries ts = DataUtils.extractDimension(myOriginalSeries, 0);
    assertEquals(myOriginalSeries.getTimes().length, ts.getTimes().length);
    TestUtil.assertClose(myOriginalSeries.getTimes()[0], ts.getTimes()[0], myTolerance);
    TestUtil.assertClose(myOriginalSeries.getTimes()[1], ts.getTimes()[1], myTolerance);

    assertEquals(myOriginalSeries.getValues().length, ts.getValues().length);
    assertEquals(1, ts.getValues()[0].length);
    TestUtil.assertClose(myOriginalSeries.getValues()[0][0], ts.getValues()[0][0], myTolerance);
    TestUtil.assertClose(myOriginalSeries.getValues()[1][0], ts.getValues()[1][0], myTolerance);
   
    ts = DataUtils.extractDimension(myOriginalSeries, 1);
    TestUtil.assertClose(myOriginalSeries.getValues()[0][1], ts.getValues()[0][0], myTolerance);
    TestUtil.assertClose(myOriginalSeries.getValues()[1][1], ts.getValues()[1][0], myTolerance);
  }
View Full Code Here

    TestUtil.assertClose(myOriginalSeries.getValues()[0][1], ts.getValues()[0][0], myTolerance);
    TestUtil.assertClose(myOriginalSeries.getValues()[1][1], ts.getValues()[1][0], myTolerance);
  }

  public void testExtractTime() {
    TimeSeries ts = DataUtils.extractTime(myOriginalSeries, 3, 7);   
    assertEquals(5, ts.getTimes().length);
    TestUtil.assertClose(3, ts.getTimes()[0], myTolerance);
    TestUtil.assertClose(4, ts.getTimes()[1], myTolerance);
   
    assertEquals(5, ts.getValues().length);
    assertEquals(3, ts.getValues()[0].length);
    TestUtil.assertClose(.3f, ts.getValues()[0][0], myTolerance);
    TestUtil.assertClose(.4f, ts.getValues()[1][0], myTolerance);
    TestUtil.assertClose(1.3f, ts.getValues()[0][1], myTolerance);
  }
View Full Code Here

TOP

Related Classes of ca.nengo.util.TimeSeries

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.