25#ifndef quantlib_optimization_costfunction_h
26#define quantlib_optimization_costfunction_h
40 std::transform(
v.begin(),
v.end(),
v.begin(), [](
Real x) ->
Real { return x*x; });
41 return std::sqrt(std::accumulate(
v.begin(),
v.end(),
Real(0.0)) /
42 static_cast<Real>(
v.size()));
57 grad[i] = 0.5*(fp - fm)/eps;
65 const Array& x)
const {
81 jac[j][i] = 0.5*(fp[j]-fm[j])/eps;
90 const Array &x)
const {
1-D array used in linear algebra.
1-D array used in linear algebra.
Size size() const
dimension of the array
Cost function abstract class for optimization problem.
virtual Array values(const Array &x) const =0
method to overload to compute the cost function values in x
virtual Real value(const Array &x) const
method to overload to compute the cost function value in x
virtual Array valuesAndJacobian(Matrix &jac, const Array &x) const
method to overload to compute J_f, the jacobian of
virtual ~CostFunction()=default
virtual void gradient(Array &grad, const Array &x) const
method to overload to compute grad_f, the first derivative of
virtual void jacobian(Matrix &jac, const Array &x) const
method to overload to compute J_f, the jacobian of
virtual Real valueAndGradient(Array &grad, const Array &x) const
method to overload to compute grad_f, the first derivative of
virtual Real finiteDifferenceEpsilon() const
Default epsilon for finite difference method :
Matrix used in linear algebra.
std::size_t Size
size of a container
matrix used in linear algebra.
ext::shared_ptr< BlackVolTermStructure > v