Example usage for org.apache.commons.math3.analysis.interpolation SplineInterpolator SplineInterpolator

List of usage examples for org.apache.commons.math3.analysis.interpolation SplineInterpolator SplineInterpolator

Introduction

In this page you can find the example usage for org.apache.commons.math3.analysis.interpolation SplineInterpolator SplineInterpolator.

Prototype

SplineInterpolator

Source Link

Usage

From source file:uk.ac.ed.bio.SynthSys.SBMLDataTools.SBMLTimeCourseDataHelperTest.java

/**
 * Tests that the correct exception is produced when passing times data that is not in 
 * ascending order./*from  www  .j a  v a  2s. com*/
 */
@Test
public void timesDataNotAscending() {
    boolean caughtException = false;

    _times = new double[] { -3.0, -2.0, -1.0, 0, -1.0 };
    _values = new double[_times.length];

    for (int i = 0; i < _times.length; ++i) {
        _values[i] = Math.sin(_times[i]);
    }

    SBMLDocument doc = new SBMLDocument(3, 1);
    Model model = doc.createModel("test_model");

    try {
        SBMLTimeCourseDataHelper.addParameter(model, "myParam", _times, _values,
                new PolynomialInterpolator(new SplineInterpolator()));
    } catch (IllegalArgumentException iae) {
        caughtException = true;
        assertEquals("Data in times parameter must be in ascending order", iae.getMessage());
    }
    if (!caughtException)
        fail("Expected IllegalArgumentException");
}

From source file:uk.ac.ed.bio.SynthSys.SBMLDataTools.SBMLTimeCourseDataHelperTest.java

/**
 * Tests that correct execution produced fitted data that closely matches the function that
 * was sampled to produce the external data.  Here the sine function is used.
 *//*  w w  w  .  ja  v  a2s.  c  o m*/
@Test
public void normalExcecution() {
    setSinData();
    SBMLDocument doc = new SBMLDocument(3, 1);
    Model model = doc.createModel("test_model");

    SBMLTimeCourseDataHelper.addParameter(model, "myParam", _times, _values,
            new PolynomialInterpolator(new SplineInterpolator()));

    // Model must now have a parameter called myParam with specific properties
    assertEquals("Model must have one parameter", 1, model.getParameterCount());
    Parameter param = model.getParameter(0);
    assertEquals("Parameter id: ", "myParam", param.getId());
    assertEquals("Parameter name: ", "myParam", param.getName());
    assertEquals("Parameter isConstant: ", false, param.isConstant());

    // Model must have an assignment rule that is associated with the parameter
    assertEquals("Model must have one rule", 1, model.getRuleCount());
    Rule rule = model.getRule(0);
    assertTrue("Rule must be assignment rule", rule instanceof AssignmentRule);
    AssignmentRule assignmentRule = (AssignmentRule) rule;
    assertEquals("Variable of assignment rule", "myParam", assignmentRule.getVariable());

    // Now we can compare data with the fitted data - for the sine function the spline
    // should fit quite well
    for (double t = _times[0]; t < _times[_times.length - 1]; t += 0.005) {
        double sin = Math.sin(t);
        double fitted = evaluateMathML(assignmentRule.getMath(), t);

        assertTrue("Fitted must be close to actual, t=" + t + " sine=" + sin + " fitted=" + fitted + " diff="
                + Math.abs(sin - fitted), Math.abs(sin - fitted) < 0.01);
    }
}