/** * Apply a dense weight matrix to the {@link LeastSquaresProblem}. * * @param problem the unweighted problem * @param weights the matrix of weights * @return a new {@link LeastSquaresProblem} with the weights applied. The original * {@code problem} is not modified. */ public static LeastSquaresProblem weightMatrix(final LeastSquaresProblem problem, final RealMatrix weights) { final RealMatrix weightSquareRoot = squareRoot(weights); return new LeastSquaresAdapter(problem) { /** {@inheritDoc} */ @Override public Evaluation evaluate(final RealVector point) { return new DenseWeightedEvaluation(super.evaluate(point), weightSquareRoot); } }; }
/** * Apply a dense weight matrix to the {@link LeastSquaresProblem}. * * @param problem the unweighted problem * @param weights the matrix of weights * @return a new {@link LeastSquaresProblem} with the weights applied. The original * {@code problem} is not modified. */ public static LeastSquaresProblem weightMatrix(final LeastSquaresProblem problem, final RealMatrix weights) { final RealMatrix weightSquareRoot = squareRoot(weights); return new LeastSquaresAdapter(problem) { /** {@inheritDoc} */ @Override public Evaluation evaluate(final RealVector point) { return new DenseWeightedEvaluation(super.evaluate(point), weightSquareRoot); } }; }
/** * Apply a dense weight matrix to the {@link LeastSquaresProblem}. * * @param problem the unweighted problem * @param weights the matrix of weights * @return a new {@link LeastSquaresProblem} with the weights applied. The original * {@code problem} is not modified. */ public static LeastSquaresProblem weightMatrix(final LeastSquaresProblem problem, final RealMatrix weights) { final RealMatrix weightSquareRoot = squareRoot(weights); return new LeastSquaresAdapter(problem) { /** {@inheritDoc} */ @Override public Evaluation evaluate(final RealVector point) { return new DenseWeightedEvaluation(super.evaluate(point), weightSquareRoot); } }; }