Exemplo n.º 1
0
 @Override
 public void setParameterValues(double... params) {
   int nparams = Math.min(params.length, getNoOfParameters());
   for (int n = 0; n < nparams; n++) {
     parameterList.get(n).setValue(params[n]);
   }
   for (AFunction f : functionList) f.dirty = true;
   dirty = true;
 }
Exemplo n.º 2
0
  /**
   * Function that evaluates the whole function at a single point
   *
   * @param position The value to evaluate the function at
   * @return A double containing the evaluated value.
   */
  @Override
  public double val(double... position) {
    // Check x and a size for correctness
    double y = 0.;
    // Just sum over the individual functions
    for (AFunction f : functionList) y += f.val(position);

    return y;
  }
Exemplo n.º 3
0
  /**
   * Create a set of datasets each containing the composite function and its constituent parts
   * evaluated over the values
   *
   * @param XValues A dataset containing all the X values to calculate the data at
   * @param DataValues The data that is being fitted too, for visual help.
   * @return an array of datasets
   */
  public DoubleDataset[] display(DoubleDataset XValues, DoubleDataset DataValues) {
    int noOfFunctions = getNoOfFunctions();

    DoubleDataset[] outputs = new DoubleDataset[noOfFunctions + 4];

    outputs[0] = new DoubleDataset(DataValues);

    outputs[1] = makeDataset(XValues);
    outputs[1].setName("Composite function");
    // now add the data
    for (int i = 0; i < XValues.getSize(); i++) {
      double value = val(XValues.get(i));
      outputs[1].set(value, i);
    }

    // now add the errors to the graph, this should provide a good view to
    // how good the fit is quite nicely.
    outputs[2] = new DoubleDataset(XValues);
    outputs[2].setName("Error Value");
    double offset =
        DataValues.min().doubleValue()
            - ((DataValues.max().doubleValue() - DataValues.min().doubleValue()) / 5.0);
    for (int i = 0; i < XValues.getSize(); i++) {
      double value = (val(XValues.get(i)) - DataValues.get(i)) + offset;
      outputs[2].set(value, i);
    }

    outputs[3] = new DoubleDataset(XValues);
    outputs[3].setName("Error Offset");
    // centre for the error
    for (int i = 0; i < XValues.getSize(); i++) {
      double value = offset;
      outputs[3].set(value, i);
    }

    // now add the data for each bit in turn
    int j = 4;
    for (AFunction f : functionList) {
      outputs[j] = f.makeDataset(XValues);
      outputs[j++].setName(f.getName());
    }

    return outputs;
  }
Exemplo n.º 4
0
  /**
   * Create a set of datasets each containing the composite function and its constituent parts
   * evaluated over the values
   *
   * @param values datasets containing all the values to evaluate the function at
   * @return an array of datasets
   */
  public DoubleDataset[] display(DoubleDataset... values) {
    if (values == null || values.length == 0) {}

    int noOfFunctions = getNoOfFunctions();

    DoubleDataset[] outputs = new DoubleDataset[noOfFunctions + 1];

    outputs[0] = makeDataset(values);
    outputs[0].setName("Composite function");

    // now add the data for each bit in turn
    int j = 1;
    for (AFunction f : functionList) {
      outputs[j] = f.makeDataset(values);
      outputs[j++].setName(f.getName());
    }

    return outputs;
  }
Exemplo n.º 5
0
 /* function node */
 public void outAFunction(AFunction node) {
   setValue(
       node,
       getValue(node.getType())
           + node.getIdentifier().toString()
           + node.getLPar().toString()
           + getValue(node.getArguments())
           + node.getRPar().toString()
           + getValue(node.getCompoundstm()));
 }
Exemplo n.º 6
0
  @Test
  public void testFunction() {
    AFunction f = new StraightLine();
    Assert.assertEquals(2, f.getNoOfParameters());
    f.setParameterValues(23., -10.);
    Assert.assertArrayEquals(new double[] {23., -10.}, f.getParameterValues(), ABS_TOL);
    Assert.assertEquals(23. - 10., f.val(1), ABS_TOL);

    DoubleDataset xd = new DoubleDataset(new double[] {-1, 0, 2});
    DoubleDataset dx;
    dx = f.calculateValues(xd);
    Assert.assertArrayEquals(new double[] {-23. - 10, -10, 23. * 2 - 10.}, dx.getData(), ABS_TOL);

    dx = f.calculatePartialDerivativeValues(f.getParameter(0), xd);
    Assert.assertArrayEquals(new double[] {-1, 0, 2}, dx.getData(), ABS_TOL);

    dx = f.calculatePartialDerivativeValues(f.getParameter(1), xd);
    Assert.assertArrayEquals(new double[] {1, 1, 1}, dx.getData(), ABS_TOL);

    Assert.assertEquals(-1, f.partialDeriv(f.getParameter(0), -1), ABS_TOL);
    Assert.assertEquals(1, f.partialDeriv(f.getParameter(1), -1), ABS_TOL);
  }