33 functionGradient = gsl::vector( size );
34 functionHessian = gsl::matrix { size, size };
40 size_t const SIZE {
getSize() };
41 size_t const VSIZE { vector.size() };
43 if( 0 == VSIZE )
return 0;
44 if( 0 != SIZE and SIZE != VSIZE )
return 0;
48 auto subvector = vector.subvector( 0, VSIZE - 1 );
49 double const& s { vector[VSIZE - 1] };
50 double const f {
function( subvector ) };
59 size_t const SIZE {
getSize() };
60 size_t const VSIZE { vector.size() };
63 functionGradient = gsl::vector( VSIZE );
66 functionGradient.set_all( 0 );
69 if( 0 != SIZE and SIZE != VSIZE ){
70 functionGradient.set_all( 0 );
73 if( 0 == SIZE and functionGradient.size() != VSIZE )
74 functionGradient = gsl::vector( VSIZE );
78 auto subvector = vector.subvector( 0, VSIZE - 1 );
79 auto f =
function.gradient( subvector );
80 for(
size_t i { 0 }; i + 1 < VSIZE; ++i )
81 functionGradient[i] =
upperBound ? f[i] : -f[i];
82 functionGradient[VSIZE - 1] = -1;
88 size_t const SIZE {
getSize() };
89 size_t const VSIZE { vector.size() };
92 functionHessian = gsl::matrix { VSIZE, VSIZE };
95 functionHessian.set_all( 0 );
98 if( 0 != SIZE and SIZE != VSIZE ){
99 functionHessian.set_all( 0 );
102 if( 0 == SIZE and (functionHessian.size1() != VSIZE
103 or functionHessian.size2() != VSIZE) )
104 functionHessian = gsl::matrix { VSIZE, VSIZE };
108 auto subvector = vector.subvector( 0, VSIZE - 1 );
109 auto h =
function.hessian( subvector );
111 for(
size_t i { 0 }; i < VSIZE; ++i )
112 for(
size_t j { i }; j < VSIZE; ++j ){
113 double const value { (i + 1 == VSIZE or j + 1 == VSIZE) ? 0 :
h.get( i, j ) };
114 functionHessian.set( i, j,
value );
115 if( j > i ) functionHessian.set( j, i,
value );
118 for(
size_t i { 0 }; i < VSIZE; ++i )
119 for(
size_t j { i }; j < VSIZE; ++j ){
120 double const value { (i + 1 == VSIZE or j + 1 == VSIZE) ? 0 : -
h.get( i, j ) };
121 functionHessian.set( i, j,
value );
122 if( j > i ) functionHessian.set( j, i,
value );
130 size_t const SIZE {
getSize() };
131 size_t const VSIZE { vector.size() };
134 functionGradient = gsl::vector( VSIZE );
136 functionHessian = gsl::matrix( VSIZE, VSIZE );
139 functionGradient.set_all( 0 );
140 functionHessian.set_all( 0 );
143 if( 0 != SIZE and SIZE != VSIZE ){
144 functionGradient.set_all( 0 );
145 functionHessian.set_all( 0 );
148 if( 0 == SIZE and functionGradient.size() != VSIZE )
149 functionGradient = gsl::vector( VSIZE );
150 if( 0 == SIZE and (functionHessian.size1() != VSIZE
151 or functionHessian.size2() != VSIZE) )
152 functionHessian = gsl::matrix { VSIZE, VSIZE };
161 auto subvector = vector.subvector( 0, VSIZE - 1 );
162 de->setVector( subvector );
163 double const& s { vector[VSIZE - 1] };
168 for(
size_t i { 0 }; i < VSIZE; ++i ){
169 auto fG = de->gradient();
170 auto fH = de->hessian();
171 if( i + 1 < VSIZE ) functionGradient[i] =
upperBound ? fG[i] : -fG[i];
172 else functionGradient[i] = -1;
174 for(
size_t j { i }; j < VSIZE; ++j ){
175 double const h { (i + 1 == VSIZE or j + 1 == VSIZE) ? 0 : fH.get( i, j ) };
176 functionHessian.set( i, j,
h );
177 if( j > i ) functionHessian.set( j, i,
h );
180 for(
size_t j { i }; j < VSIZE; ++j ){
181 double const h { (i + 1 == VSIZE or j + 1 == VSIZE) ? 0 : -fH.get( i, j ) };
182 functionHessian.set( i, j,
h );
183 if( j > i ) functionHessian.set( j, i,
h );
double functionValue
The function value.
double h
Value used for default gradient estimates.
double operator()(gsl::vector const &vector)
The function operator: computes or according as is an upper or lower bound.
gsl::vector functionGradient
The gradient value.
Function & function
The function.
Namespace for details of ipo_function that are not normally needed to construct and solve a convex op...
virtual gsl::matrix hessian() const
virtual gsl::vector gradient() const
virtual double value() const
Base class for derivative estimates with Hessian.
gsl::matrix functionHessian
The Hessian value.
size_t getSize() const
Get size of vector for function arguments or zero for arbitrary size.
PhaseIFunctionAndDerivatives(Function &function, double const b, bool const upperBound)
Construct from a function and bound.
This class computes a function at a vector.
bool const upperBound
A boolean value: true or false according as b is an upper bound or lower.
Base class for Function and DerivativesEstimates.
void setVector(gsl::vector const &vector)
Set a vector and compute function value, gradient and Hessian efficiently.