Exemplo n.º 1
0
 /**
  * Initiates the fit with function constructed weights and a JAMA matrix. N is the number of
  * y-data points, K is the dimension of the fit function and M is the number of fit parameters.
  * Call <code>this.fit()</code> to start the actual fitting.
  *
  * @param function The model function to be fitted. Input parameter sizes K and M.
  * @param parameters The initial guess for the fit parameters, length M.
  * @param dataPoints The data points in two dimensional array where each array, dataPoints[i],
  *     contains one y-value followed by the corresponding x-array values. I.e., the arrays should
  *     look like this:
  *     <p>dataPoints[0] = y0 x00 x01 x02 ... x0[K-1]<br>
  *     dataPoints[1] = y1 x10 x11 x12 ... x1[K-1]<br>
  *     . ..<br>
  *     dataPoints[N] = yN xN0 xN1 xN2 ... x[N-1][K-1]
  */
 public LMA(LMAMultiDimFunction function, float[] parameters, float[][] dataPoints) {
   this(
       function,
       ArrayConverter.asDoubleArray(parameters),
       ArrayConverter.asDoubleArray(dataPoints),
       function.constructWeights(ArrayConverter.asDoubleArray(dataPoints)),
       new JAMAMatrix(parameters.length, parameters.length));
 }
Exemplo n.º 2
0
 /**
  * One dimensional convenience constructor for LMAFunction. You can also implement the same
  * function using LMAMultiDimFunction.
  *
  * <p>Initiates the fit with function constructed weights and a JAMA matrix. N is the number of
  * data points, M is the number of fit parameters. Call <code>fit()</code> to start the actual
  * fitting.
  *
  * @param function The model function to be fitted. Must be able to take M input parameters.
  * @param parameters The initial guess for the fit parameters, length M.
  * @param dataPoints The data points in an * array, <code>float[0 = x, 1 = y][point index]</code>.
  *     Size must * be <code>float[2][N]</code>.
  * @param weights The weights, normally given * as: <code>weights[i] = 1 / sigma_i^2</code>. If
  *     you have a bad data point, set its weight to zero. If the given array is null, a new array
  *     is created with all elements set to 1.
  */
 public LMA(
     final LMAFunction function, float[] parameters, float[][] dataPoints, float[] weights) {
   this(
       function,
       ArrayConverter.asDoubleArray(parameters),
       ArrayConverter.asDoubleArray(dataPoints),
       ArrayConverter.asDoubleArray(weights));
 }
Exemplo n.º 3
0
 /**
  * Initiates the fit. N is the number of y-data points, K is the dimension of the fit function and
  * M is the number of fit parameters. Call <code>this.fit()</code> to start the actual fitting.
  *
  * @param function The model function to be fitted. Input parameter sizes K and M.
  * @param parameters The initial guess for the fit parameters, length M.
  * @param dataPoints The data points in two dimensional array where each array, dataPoints[i],
  *     contains one y-value followed by the corresponding x-array values. I.e., the arrays should
  *     look like this:
  *     <p>dataPoints[0] = y0 x00 x01 x02 ... x0[K-1]<br>
  *     dataPoints[1] = y1 x10 x11 x12 ... x1[K-1]<br>
  *     . ..<br>
  *     dataPoints[N] = yN xN0 xN1 xN2 ... x[N-1][K-1]
  *     <p>
  * @param weights The weights, normally given * as: <code>weights[i] = 1 / sigma_i^2</code>. If
  *     you have a bad data point, set its weight to zero. If the given array is null, a new array
  *     is created with all elements set to 1.
  * @param alpha An LMAMatrix instance. Must be initiated to (M x M) size.
  */
 public LMA(
     LMAMultiDimFunction function,
     float[] parameters,
     float[][] dataPoints,
     float[] weights,
     LMAMatrix alpha) {
   this(
       function,
       ArrayConverter.asDoubleArray(parameters),
       ArrayConverter.asDoubleArray(dataPoints),
       ArrayConverter.asDoubleArray(weights),
       alpha);
 }
Exemplo n.º 4
0
 /**
  * Initiates the fit with function constructed weights and a JAMA matrix. N is the number of
  * y-data points, K is the dimension of the fit function and M is the number of fit parameters.
  * Call <code>this.fit()</code> to start the actual fitting.
  *
  * @param function The model function to be fitted. Input parameter sizes K and M.
  * @param parameters The initial guess for the fit parameters, length M.
  * @param yDataPoints The y-data points in an array.
  * @param xDataPoints The x-data points for each y data point, double[y-index][x-index]
  */
 public LMA(
     LMAMultiDimFunction function,
     double[] parameters,
     float[] yDataPoints,
     float[][] xDataPoints) {
   this(
       function,
       parameters,
       ArrayConverter.asDoubleArray(yDataPoints),
       ArrayConverter.asDoubleArray(xDataPoints),
       function.constructWeights(
           ArrayConverter.combineMultiDimDataPoints(yDataPoints, xDataPoints)),
       new JAMAMatrix(parameters.length, parameters.length));
 }
Exemplo n.º 5
0
 /**
  * Initiates the fit. N is the number of y-data points, K is the dimension of the fit function and
  * M is the number of fit parameters. Call <code>this.fit()</code> to start the actual fitting.
  *
  * @param function The model function to be fitted. Input parameter sizes K and M.
  * @param parameters The initial guess for the fit parameters, length M.
  * @param dataPoints The data points in two dimensional array where each array, dataPoints[i],
  *     contains one y-value followed by the corresponding x-array values. I.e., the arrays should
  *     look like this:
  *     <p>dataPoints[0] = y0 x00 x01 x02 ... x0[K-1]<br>
  *     dataPoints[1] = y1 x10 x11 x12 ... x1[K-1]<br>
  *     . ..<br>
  *     dataPoints[N] = yN xN0 xN1 xN2 ... x[N-1][K-1]
  *     <p>
  * @param weights The weights, normally given * as: <code>weights[i] = 1 / sigma_i^2</code>. If
  *     you have a bad data point, set its weight to zero. If the given array is null, a new array
  *     is created with all elements set to 1.
  * @param alpha An LMAMatrix instance. Must be initiated to (M x M) size.
  */
 public LMA(
     LMAMultiDimFunction function,
     double[] parameters,
     double[][] dataPoints,
     double[] weights,
     LMAMatrix alpha) {
   SeparatedData s = ArrayConverter.separateMultiDimDataToXY(dataPoints);
   this.yDataPoints = s.yDataPoints;
   this.xDataPoints = s.xDataPoints;
   init(function, parameters, yDataPoints, xDataPoints, weights, alpha);
 }
Exemplo n.º 6
0
  /**
   * One dimensional convenience constructor for LMAFunction. You can also implement the same
   * function using LMAMultiDimFunction.
   *
   * <p>Initiates the fit with function constructed weights and a JAMA matrix. N is the number of
   * data points, M is the number of fit parameters. Call <code>fit()</code> to start the actual
   * fitting.
   *
   * @param function The model function to be fitted. Must be able to take M input parameters.
   * @param parameters The initial guess for the fit parameters, length M.
   * @param dataPoints The data points in an * array, <code>double[0 = x, 1 = y][point index]</code>
   *     . Size must * be <code>double[2][N]</code>.
   */
  public LMA(
      final LMAFunction function, double[] parameters, double[][] dataPoints, double[] weights) {
    this(
        // convert LMAFunction to LMAMultiDimFunction
        new LMAMultiDimFunction() {
          private LMAFunction f = function;

          @Override
          public double getPartialDerivate(double[] x, double[] a, int parameterIndex) {
            return f.getPartialDerivate(x[0], a, parameterIndex);
          }

          @Override
          public double getY(double[] x, double[] a) {
            return f.getY(x[0], a);
          }
        },
        parameters,
        dataPoints[1], // y-data
        ArrayConverter.transpose(dataPoints[0]), // x-data
        weights,
        new JAMAMatrix(parameters.length, parameters.length));
  }
Exemplo n.º 7
0
 /**
  * Computes Chinese Reminder Theorem: x == congs[i] mod moduli[i]
  *
  * @param congs
  * @param moduli
  * @return
  */
 public static BigInteger CRT(List<BigInteger> congs, List<BigInteger> moduli) {
   BigInteger[] cs = ArrayConverter.convertListToArray(congs);
   BigInteger[] ms = ArrayConverter.convertListToArray(moduli);
   return CRT(cs, ms);
 }