org.apache.commons.math3.analysis.MultivariateMatrixFunction Java Examples

The following examples show how to use org.apache.commons.math3.analysis.MultivariateMatrixFunction. 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: DifferentiableMultivariateVectorMultiStartOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test(expected=TestException.class)
public void testNoOptimum() {
    DifferentiableMultivariateVectorOptimizer underlyingOptimizer =
        new GaussNewtonOptimizer(true,
                                 new SimpleVectorValueChecker(1.0e-6, 1.0e-6));
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(12373523445l);
    RandomVectorGenerator generator =
        new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g));
    DifferentiableMultivariateVectorMultiStartOptimizer optimizer =
        new DifferentiableMultivariateVectorMultiStartOptimizer(underlyingOptimizer,
                                                                   10, generator);
    optimizer.optimize(100, new DifferentiableMultivariateVectorFunction() {
            public MultivariateMatrixFunction jacobian() {
                return null;
            }
            public double[] value(double[] point) {
                throw new TestException();
            }
        }, new double[] { 2 }, new double[] { 1 }, new double[] { 0 });
}
 
Example #2
Source File: LevenbergMarquardtOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public MultivariateMatrixFunction getModelFunctionJacobian() {
    return new MultivariateMatrixFunction() {
        public double[][] value(double[] params) {
            double[][] jacobian = new double[time.size()][5];

            for (int i = 0; i < jacobian.length; ++i) {
                final double t = time.get(i);
                jacobian[i][0] = 1;

                final double p3 =  params[3];
                final double p4 =  params[4];
                final double tOp3 = t / p3;
                final double tOp4 = t / p4;
                jacobian[i][1] = FastMath.exp(-tOp3);
                jacobian[i][2] = FastMath.exp(-tOp4);
                jacobian[i][3] = params[1] * FastMath.exp(-tOp3) * tOp3 / p3;
                jacobian[i][4] = params[2] * FastMath.exp(-tOp4) * tOp4 / p4;
            }
            return jacobian;
        }
    };
}
 
Example #3
Source File: LevenbergMarquardtOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public MultivariateMatrixFunction getModelFunctionJacobian() {
    return new MultivariateMatrixFunction() {
        public double[][] value(double[] params) {
            double[][] jacobian = new double[time.size()][5];

            for (int i = 0; i < jacobian.length; ++i) {
                final double t = time.get(i);
                jacobian[i][0] = 1;

                final double p3 =  params[3];
                final double p4 =  params[4];
                final double tOp3 = t / p3;
                final double tOp4 = t / p4;
                jacobian[i][1] = Math.exp(-tOp3);
                jacobian[i][2] = Math.exp(-tOp4);
                jacobian[i][3] = params[1] * Math.exp(-tOp3) * tOp3 / p3;
                jacobian[i][4] = params[2] * Math.exp(-tOp4) * tOp4 / p4;
            }
            return jacobian;
        }
    };
}
 
Example #4
Source File: LevenbergMarquardtOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public ModelFunctionJacobian getModelFunctionJacobian() {
    return new ModelFunctionJacobian(new MultivariateMatrixFunction() {
            public double[][] value(double[] params) {
                double[][] jacobian = new double[time.size()][5];

                for (int i = 0; i < jacobian.length; ++i) {
                    final double t = time.get(i);
                    jacobian[i][0] = 1;

                    final double p3 =  params[3];
                    final double p4 =  params[4];
                    final double tOp3 = t / p3;
                    final double tOp4 = t / p4;
                    jacobian[i][1] = Math.exp(-tOp3);
                    jacobian[i][2] = Math.exp(-tOp4);
                    jacobian[i][3] = params[1] * Math.exp(-tOp3) * tOp3 / p3;
                    jacobian[i][4] = params[2] * Math.exp(-tOp4) * tOp4 / p4;
                }
                return jacobian;
            }
        });
}
 
Example #5
Source File: BiplaneEllipticGaussianPSF.java    From thunderstorm with GNU General Public License v3.0 6 votes vote down vote up
private MultivariateMatrixFunction getNumericJacobianFunction(final double[] xgrid1, final double[] ygrid1, final double[] xgrid2, final double[] ygrid2) {
    final MultivariateVectorFunction valueFunction = getValueFunction(xgrid1, ygrid1, xgrid2, ygrid2);
    return new MultivariateMatrixFunction() {
        static final double step = 0.01;

        @Override
        public double[][] value(double[] point) throws IllegalArgumentException {
            double[][] retVal = new double[xgrid1.length + xgrid2.length][point.length];

            for(int i = 0; i < point.length; i++) {
                double[] newPoint = point.clone();
                newPoint[i] = newPoint[i] + step;
                double[] f1 = valueFunction.value(newPoint);
                double[] f2 = valueFunction.value(point);
                for(int j = 0; j < f1.length; j++) {
                    retVal[j][i] = (f1[j] - f2[j]) / step;
                }
            }
            return retVal;
        }
    };
}
 
Example #6
Source File: PSFModel.java    From thunderstorm with GNU General Public License v3.0 6 votes vote down vote up
public MultivariateMatrixFunction getNumericJacobianFunction(final double[] xgrid, final double[] ygrid) {
    final MultivariateVectorFunction valueFunction = getValueFunction(xgrid, ygrid);
    return new MultivariateMatrixFunction() {
        static final double step = 0.01;

        @Override
        public double[][] value(double[] point) throws IllegalArgumentException {
            double[][] retVal = new double[xgrid.length][point.length];

            for(int i = 0; i < point.length; i++) {
                double[] newPoint = point.clone();
                newPoint[i] = newPoint[i] + step;
                double[] f1 = valueFunction.value(newPoint);
                double[] f2 = valueFunction.value(point);
                for(int j = 0; j < f1.length; j++) {
                    retVal[j][i] = (f1[j] - f2[j]) / step;
                }
            }
            return retVal;
        }
    };
}
 
Example #7
Source File: MultiPSF.java    From thunderstorm with GNU General Public License v3.0 6 votes vote down vote up
@Override
public MultivariateMatrixFunction getJacobianFunction(final double[] xgrid, final double[] ygrid) {
    return new MultivariateMatrixFunction() {
        @Override
        public double[][] value(double[] point) throws IllegalArgumentException {
            fixParams(point);
            //
            double[][] retVal = new double[xgrid.length][point.length];
            for(int i = 0; i < nmol; i++) {
                double [] tmp = Arrays.copyOfRange(point, i*Params.PARAMS_LENGTH, (i+1)*Params.PARAMS_LENGTH);
                double [][] J = psf.getNumericJacobianFunction(xgrid, ygrid).value(tmp);
                for(int j = 0; j < J.length; j++) {
                    for(int k = 0, l = i*Params.PARAMS_LENGTH; k < J[j].length; k++, l++) {
                        retVal[j][l] = J[j][k];
                    }
                }
            }
            return retVal;
        }
    };
}
 
Example #8
Source File: DifferentiableMultivariateVectorMultiStartOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test(expected=TestException.class)
public void testNoOptimum() {
    DifferentiableMultivariateVectorOptimizer underlyingOptimizer =
        new GaussNewtonOptimizer(true,
                                 new SimpleVectorValueChecker(1.0e-6, 1.0e-6));
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(12373523445l);
    RandomVectorGenerator generator =
        new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g));
    DifferentiableMultivariateVectorMultiStartOptimizer optimizer =
        new DifferentiableMultivariateVectorMultiStartOptimizer(underlyingOptimizer,
                                                                   10, generator);
    optimizer.optimize(100, new DifferentiableMultivariateVectorFunction() {
            public MultivariateMatrixFunction jacobian() {
                return null;
            }
            public double[] value(double[] point) {
                throw new TestException();
            }
        }, new double[] { 2 }, new double[] { 1 }, new double[] { 0 });
}
 
Example #9
Source File: LevenbergMarquardtOptimizerTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public MultivariateMatrixFunction getModelFunctionJacobian() {
    return new MultivariateMatrixFunction() {
        public double[][] value(double[] params) {
            double[][] jacobian = new double[time.size()][5];

            for (int i = 0; i < jacobian.length; ++i) {
                final double t = time.get(i);
                jacobian[i][0] = 1;

                final double p3 =  params[3];
                final double p4 =  params[4];
                final double tOp3 = t / p3;
                final double tOp4 = t / p4;
                jacobian[i][1] = FastMath.exp(-tOp3);
                jacobian[i][2] = FastMath.exp(-tOp4);
                jacobian[i][3] = params[1] * FastMath.exp(-tOp3) * tOp3 / p3;
                jacobian[i][4] = params[2] * FastMath.exp(-tOp4) * tOp4 / p4;
            }
            return jacobian;
        }
    };
}
 
Example #10
Source File: CircleProblem.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public MultivariateMatrixFunction jacobian() {
    return new MultivariateMatrixFunction() {
        public double[][] value(double[] point) {
            return jacobian(point);
        }
    };
}
 
Example #11
Source File: AbstractLeastSquaresOptimizerAbstractTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunctionJacobian getModelFunctionJacobian() {
    return new ModelFunctionJacobian(new MultivariateMatrixFunction() {
            public double[][] value(double[] params) {
                return factors.getData();
            }
        });
}
 
Example #12
Source File: LevenbergMarquardtOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public MultivariateMatrixFunction getModelFunctionJacobian() {
    return new MultivariateMatrixFunction() {
        public double[][] value(double[] params) {                    
            double[][] jacobian = new double[x.size()][3];
            for (int i = 0; i < jacobian.length; ++i) {
                jacobian[i][0] = x.get(i) * x.get(i);
                jacobian[i][1] = x.get(i);
                jacobian[i][2] = 1.0;
            }
            return jacobian;
        }
    };
}
 
Example #13
Source File: LevenbergMarquardtOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public MultivariateMatrixFunction jacobian() {
    return new MultivariateMatrixFunction() {
        public double[][] value(double[] point) {
            return jacobian(point);
        }
    };
}
 
Example #14
Source File: StatisticalReferenceDataset.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunctionJacobian getModelFunctionJacobian() {
    return new ModelFunctionJacobian(new MultivariateMatrixFunction() {
            public double[][] value(final double[] a)
                throws IllegalArgumentException {
                final int n = getNumObservations();
                final double[][] j = new double[n][];
                for (int i = 0; i < n; i++) {
                    j[i] = getModelDerivatives(getX(i), a);
                }
                return j;
            }
        });
}
 
Example #15
Source File: CircleVectorial.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunctionJacobian getModelFunctionJacobian() {
    return new ModelFunctionJacobian(new MultivariateMatrixFunction() {
            public double[][] value(double[] params) {
                final int n = points.size();
                final Vector2D center = new Vector2D(params[0], params[1]);

                double dRdX = 0;
                double dRdY = 0;
                for (Vector2D pk : points) {
                    double dk = pk.distance(center);
                    dRdX += (center.getX() - pk.getX()) / dk;
                    dRdY += (center.getY() - pk.getY()) / dk;
                }
                dRdX /= n;
                dRdY /= n;

                // Jacobian of the radius residuals.
                double[][] jacobian = new double[n][2];
                for (int i = 0; i < n; i++) {
                    final Vector2D pi = points.get(i);
                    final double di = pi.distance(center);
                    jacobian[i][0] = (center.getX() - pi.getX()) / di - dRdX;
                    jacobian[i][1] = (center.getY() - pi.getY()) / di - dRdY;
                }

                return jacobian;
            }
    });
}
 
Example #16
Source File: CircleProblem.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public MultivariateMatrixFunction getModelFunctionJacobian() {
    return new MultivariateMatrixFunction() {
        public double[][] value(double[] point) {
            return jacobian(point);
        }
    };
}
 
Example #17
Source File: StatisticalReferenceDataset.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public MultivariateMatrixFunction getModelFunctionJacobian() {
    return new MultivariateMatrixFunction() {
        public double[][] value(final double[] a)
            throws IllegalArgumentException {
            final int n = getNumObservations();
            final double[][] j = new double[n][];
            for (int i = 0; i < n; i++) {
                j[i] = getModelDerivatives(getX(i), a);
            }
            return j;
        }
    };
}
 
Example #18
Source File: StraightLineProblem.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public MultivariateMatrixFunction getModelFunctionJacobian() {
    return new MultivariateMatrixFunction() {
        public double[][] value(double[] point) {
            return jacobian(point);
        }
    };
}
 
Example #19
Source File: CircleProblem.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunctionJacobian getModelFunctionJacobian() {
    return new ModelFunctionJacobian(new MultivariateMatrixFunction() {
            public double[][] value(double[] point) {
                return jacobian(point);
            }
    });
}
 
Example #20
Source File: MultiStartMultivariateVectorOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunctionJacobian getModelFunctionJacobian() {
    return new ModelFunctionJacobian(new MultivariateMatrixFunction() {
            public double[][] value(double[] point) {
                return factors.getData();
            }
        });
}
 
Example #21
Source File: AbstractLeastSquaresOptimizerAbstractTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public MultivariateMatrixFunction getModelFunctionJacobian() {
    return new MultivariateMatrixFunction() {
        public double[][] value(double[] params) {
            return factors.getData();
        }
    };
}
 
Example #22
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunctionJacobian getModelFunctionJacobian() {
    return new ModelFunctionJacobian(new MultivariateMatrixFunction() {
            public double[][] value(double[] point) {
                return computeJacobian(point);
            }
        });
}
 
Example #23
Source File: LevenbergMarquardtOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public MultivariateMatrixFunction getModelFunctionJacobian() {
    return new MultivariateMatrixFunction() {
        public double[][] value(double[] params) {                    
            double[][] jacobian = new double[x.size()][3];
            for (int i = 0; i < jacobian.length; ++i) {
                jacobian[i][0] = x.get(i) * x.get(i);
                jacobian[i][1] = x.get(i);
                jacobian[i][2] = 1.0;
            }
            return jacobian;
        }
    };
}
 
Example #24
Source File: StraightLineProblem.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunctionJacobian getModelFunctionJacobian() {
    return new ModelFunctionJacobian(new MultivariateMatrixFunction() {
            public double[][] value(double[] point) {
                return jacobian(point);
            }
        });
}
 
Example #25
Source File: CurveFitter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return the model function Jacobian.
 */
public ModelFunctionJacobian getModelFunctionJacobian() {
    return new ModelFunctionJacobian(new MultivariateMatrixFunction() {
            public double[][] value(double[] point) {
                final double[][] jacobian = new double[observations.size()][];
                int i = 0;
                for (WeightedObservedPoint observed : observations) {
                    jacobian[i++] = f.gradient(observed.getX(), point);
                }
                return jacobian;
            }
        });
}
 
Example #26
Source File: DifferentiableMultivariateVectorMultiStartOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public MultivariateMatrixFunction jacobian() {
    return new MultivariateMatrixFunction() {
        public double[][] value(double[] point) {
            return factors.getData();
        }
    };
}
 
Example #27
Source File: MultiStartMultivariateVectorOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunctionJacobian getModelFunctionJacobian() {
    return new ModelFunctionJacobian(new MultivariateMatrixFunction() {
            public double[][] value(double[] point) {
                return factors.getData();
            }
        });
}
 
Example #28
Source File: CircleProblem.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public MultivariateMatrixFunction jacobian() {
    return new MultivariateMatrixFunction() {
        public double[][] value(double[] point) {
            return jacobian(point);
        }
    };
}
 
Example #29
Source File: StraightLineProblem.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public MultivariateMatrixFunction jacobian() {
    return new MultivariateMatrixFunction() {
        public double[][] value(double[] point) {
            return jacobian(point);
        }
    };
}
 
Example #30
Source File: CircleVectorial.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public ModelFunctionJacobian getModelFunctionJacobian() {
    return new ModelFunctionJacobian(new MultivariateMatrixFunction() {
            public double[][] value(double[] params) {
                final int n = points.size();
                final Vector2D center = new Vector2D(params[0], params[1]);

                double dRdX = 0;
                double dRdY = 0;
                for (Vector2D pk : points) {
                    double dk = pk.distance(center);
                    dRdX += (center.getX() - pk.getX()) / dk;
                    dRdY += (center.getY() - pk.getY()) / dk;
                }
                dRdX /= n;
                dRdY /= n;

                // Jacobian of the radius residuals.
                double[][] jacobian = new double[n][2];
                for (int i = 0; i < n; i++) {
                    final Vector2D pi = points.get(i);
                    final double di = pi.distance(center);
                    jacobian[i][0] = (center.getX() - pi.getX()) / di - dRdX;
                    jacobian[i][1] = (center.getY() - pi.getY()) / di - dRdY;
                }

                return jacobian;
            }
    });
}