org.apache.commons.math3.optim.nonlinear.vector.ModelFunction Java Examples

The following examples show how to use org.apache.commons.math3.optim.nonlinear.vector.ModelFunction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CurveFitter.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @return the model function values.
 */
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            /** {@inheritDoc} */
            public double[] value(double[] point) {
                // compute the residuals
                final double[] values = new double[observations.size()];
                int i = 0;
                for (WeightedObservedPoint observed : observations) {
                    values[i++] = f.value(observed.getX(), point);
                }

                return values;
            }
        });
}
 
Example #2
Source File: LSQFitter.java    From thunderstorm with GNU General Public License v3.0 6 votes vote down vote up
protected Molecule fit(ILsqFunctions functions) {
    // init
    double[] weights = functions.calcWeights(useWeighting);
    double[] observations = functions.getObservations();

    // fit
    LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer(
            new SimplePointChecker<PointVectorValuePair>(10e-10, 10e-10, maxIter));

    PointVectorValuePair pv;
    pv = optimizer.optimize(
            MaxEval.unlimited(),
            new MaxIter(MAX_ITERATIONS + 1),
            new ModelFunction(functions.getValueFunction()),
            new ModelFunctionJacobian(functions.getJacobianFunction()),
            new Target(observations),
            new InitialGuess(psfModel.transformParametersInverse(functions.getInitialParams())),
            new Weight(weights));

    // estimate background and return an instance of the `Molecule`
    fittedParameters = pv.getPointRef();
    if (bkgStdColumn >= 0) {
        fittedParameters[bkgStdColumn] = VectorMath.stddev(sub(observations, functions.getValueFunction().value(fittedParameters)));
    }
    return psfModel.newInstanceFromParams(psfModel.transformParameters(fittedParameters), functions.getImageUnits(), true);
}
 
Example #3
Source File: CurveFitter.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @return the model function values.
 */
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            /** {@inheritDoc} */
            public double[] value(double[] point) {
                // compute the residuals
                final double[] values = new double[observations.size()];
                int i = 0;
                for (WeightedObservedPoint observed : observations) {
                    values[i++] = f.value(observed.getX(), point);
                }

                return values;
            }
        });
}
 
Example #4
Source File: CurveFitter.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @return the model function values.
 */
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            /** {@inheritDoc} */
            public double[] value(double[] point) {
                // compute the residuals
                final double[] values = new double[observations.size()];
                int i = 0;
                for (WeightedObservedPoint observed : observations) {
                    values[i++] = f.value(observed.getX(), point);
                }

                return values;
            }
        });
}
 
Example #5
Source File: CurveFitter.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @return the model function values.
 */
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            /** {@inheritDoc} */
            public double[] value(double[] point) {
                // compute the residuals
                final double[] values = new double[observations.size()];
                int i = 0;
                for (WeightedObservedPoint observed : observations) {
                    values[i++] = f.value(observed.getX(), point);
                }

                return values;
            }
        });
}
 
Example #6
Source File: CurveFitter.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @return the model function values.
 */
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            /** {@inheritDoc} */
            public double[] value(double[] point) {
                // compute the residuals
                final double[] values = new double[observations.size()];
                int i = 0;
                for (WeightedObservedPoint observed : observations) {
                    values[i++] = f.value(observed.getX(), point);
                }

                return values;
            }
        });
}
 
Example #7
Source File: StraightLineProblem.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(double[] params) {
                final Model line = new Model(params[0], params[1]);

                final double[] model = new double[points.size()];
                for (int i = 0; i < points.size(); i++) {
                    final double[] p = points.get(i);
                    model[i] = line.value(p[0]);
                }

                return model;
            }
        });
}
 
Example #8
Source File: StatisticalReferenceDataset.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(final double[] a) {
                final int n = getNumObservations();
                final double[] yhat = new double[n];
                for (int i = 0; i < n; i++) {
                    yhat[i] = getModelValue(getX(i), a);
                }
                return yhat;
            }
        });
}
 
Example #9
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(double[] point) {
                return computeValue(point);
            }
        });
}
 
Example #10
Source File: StatisticalReferenceDataset.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(final double[] a) {
                final int n = getNumObservations();
                final double[] yhat = new double[n];
                for (int i = 0; i < n; i++) {
                    yhat[i] = getModelValue(getX(i), a);
                }
                return yhat;
            }
        });
}
 
Example #11
Source File: LevenbergMarquardtOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(double[] variables) {
                double[] values = new double[x.size()];
                for (int i = 0; i < values.length; ++i) {
                    values[i] = (variables[0] * x.get(i) + variables[1]) * x.get(i) + variables[2];
                }
                return values;
            }
        });
}
 
Example #12
Source File: LevenbergMarquardtOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(double[] params) {
                double[] values = new double[time.size()];
                for (int i = 0; i < values.length; ++i) {
                    final double t = time.get(i);
                    values[i] = params[0] +
                        params[1] * Math.exp(-t / params[3]) +
                        params[2] * Math.exp(-t / params[4]);
                }
                return values;
            }
        });
}
 
Example #13
Source File: AbstractLeastSquaresOptimizerAbstractTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(double[] params) {
                return factors.operate(params);
            }
        });
}
 
Example #14
Source File: CircleVectorial.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(double[] params) {
                Vector2D center = new Vector2D(params[0], params[1]);
                double radius = getRadius(center);
                double[] residuals = new double[points.size()];
                for (int i = 0; i < residuals.length; i++) {
                    residuals[i] = points.get(i).distance(center) - radius;
                }

                return residuals;
            }
    });
}
 
Example #15
Source File: StraightLineProblem.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(double[] params) {
                final Model line = new Model(params[0], params[1]);

                final double[] model = new double[points.size()];
                for (int i = 0; i < points.size(); i++) {
                    final double[] p = points.get(i);
                    model[i] = line.value(p[0]);
                }

                return model;
            }
        });
}
 
Example #16
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(double[] point) {
                return computeValue(point);
            }
        });
}
 
Example #17
Source File: StatisticalReferenceDataset.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(final double[] a) {
                final int n = getNumObservations();
                final double[] yhat = new double[n];
                for (int i = 0; i < n; i++) {
                    yhat[i] = getModelValue(getX(i), a);
                }
                return yhat;
            }
        });
}
 
Example #18
Source File: LevenbergMarquardtOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(double[] params) {
                double[] values = new double[time.size()];
                for (int i = 0; i < values.length; ++i) {
                    final double t = time.get(i);
                    values[i] = params[0] +
                        params[1] * FastMath.exp(-t / params[3]) +
                        params[2] * FastMath.exp(-t / params[4]);
                }
                return values;
            }
        });
}
 
Example #19
Source File: AbstractLeastSquaresOptimizerAbstractTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(double[] params) {
                return factors.operate(params);
            }
        });
}
 
Example #20
Source File: CircleVectorial.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(double[] params) {
                Vector2D center = new Vector2D(params[0], params[1]);
                double radius = getRadius(center);
                double[] residuals = new double[points.size()];
                for (int i = 0; i < residuals.length; i++) {
                    residuals[i] = points.get(i).distance(center) - radius;
                }

                return residuals;
            }
    });
}
 
Example #21
Source File: StraightLineProblem.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(double[] params) {
                final Model line = new Model(params[0], params[1]);

                final double[] model = new double[points.size()];
                for (int i = 0; i < points.size(); i++) {
                    final double[] p = points.get(i);
                    model[i] = line.value(p[0]);
                }

                return model;
            }
        });
}
 
Example #22
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(double[] point) {
                return computeValue(point);
            }
        });
}
 
Example #23
Source File: LevenbergMarquardtOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(double[] params) {
                double[] values = new double[time.size()];
                for (int i = 0; i < values.length; ++i) {
                    final double t = time.get(i);
                    values[i] = params[0] +
                        params[1] * Math.exp(-t / params[3]) +
                        params[2] * Math.exp(-t / params[4]);
                }
                return values;
            }
        });
}
 
Example #24
Source File: LevenbergMarquardtOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(double[] params) {
                double[] values = new double[time.size()];
                for (int i = 0; i < values.length; ++i) {
                    final double t = time.get(i);
                    values[i] = params[0] +
                        params[1] * FastMath.exp(-t / params[3]) +
                        params[2] * FastMath.exp(-t / params[4]);
                }
                return values;
            }
        });
}
 
Example #25
Source File: AbstractLeastSquaresOptimizerAbstractTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(double[] params) {
                return factors.operate(params);
            }
        });
}
 
Example #26
Source File: CircleVectorial.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(double[] params) {
                Vector2D center = new Vector2D(params[0], params[1]);
                double radius = getRadius(center);
                double[] residuals = new double[points.size()];
                for (int i = 0; i < residuals.length; i++) {
                    residuals[i] = points.get(i).distance(center) - radius;
                }

                return residuals;
            }
    });
}
 
Example #27
Source File: StraightLineProblem.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(double[] params) {
                final Model line = new Model(params[0], params[1]);

                final double[] model = new double[points.size()];
                for (int i = 0; i < points.size(); i++) {
                    final double[] p = points.get(i);
                    model[i] = line.value(p[0]);
                }

                return model;
            }
        });
}
 
Example #28
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(double[] point) {
                return computeValue(point);
            }
        });
}
 
Example #29
Source File: StatisticalReferenceDataset.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(final double[] a) {
                final int n = getNumObservations();
                final double[] yhat = new double[n];
                for (int i = 0; i < n; i++) {
                    yhat[i] = getModelValue(getX(i), a);
                }
                return yhat;
            }
        });
}
 
Example #30
Source File: LevenbergMarquardtOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            public double[] value(double[] variables) {
                double[] values = new double[x.size()];
                for (int i = 0; i < values.length; ++i) {
                    values[i] = (variables[0] * x.get(i) + variables[1]) * x.get(i) + variables[2];
                }
                return values;
            }
        });
}