29 : FunctionBase { size }, coefficients { size, size }{ coefficients.set_all( 0.0 ); }
34 if( OLDSIZE != size ){
35 size_t const MIN { std::min( size, OLDSIZE ) };
39 for(
size_t row { 0 }; row < MIN; ++row )
40 for(
size_t col { 0 }; col < MIN; ++col )
41 coefficients.set( row, col, oldCoefficients.get( row, col ) );
43 for(
size_t row { MIN }; row <
size; ++row )
44 for(
size_t col { 0 }; col <
size; ++col ){
55 throw IPOE(
"ipo_function::concrete::QuadraticCombination::setCoefficient(): "
56 "index out of range." );
69 throw IPOE(
"ipo_function::concrete::QuadraticCombination::setCoefficient(): "
70 "row out of range." );
74 throw IPOE(
"ipo_function::concrete::QuadraticCombination::setCoefficient(): "
75 "col out of range." );
85 throw IPOE(
"ipo_function::concrete::QuadraticCombination::getCoefficient(): "
86 "index out of range." );
96 throw IPOE(
"ipo_function::concrete::QuadraticCombination::getCoefficient(): "
97 "row out of range." );
101 throw IPOE(
"ipo_function::concrete::QuadraticCombination::getCoefficient(): "
102 "col out of range." );
117 ost {
"ipo_function::concrete::QuadraticCombination::setCoefficients(): " };
118 ost <<
"number of rows " << matrix.size1();
119 ost <<
" and number of columns " << matrix.size2();
120 ost <<
" of matrix do not match.";
121 throw IPOE( ost.str() );
126 ost {
"ipo_function::concrete::QuadraticCombination::setCoefficients(): " };
127 ost <<
"matrix size " << matrix.size1();
128 ost <<
" and coefficients size " <<
coefficients.size1();
129 ost <<
" do not match.";
130 throw IPOE( ost.str() );
132 for(
size_t row { 0 }; row < matrix.size1(); ++row ){
133 for(
size_t col { row }; col < matrix.size1(); ++col ){
134 if( matrix.get( row, col ) != matrix.get( col, row ) ){
137 ost {
"ipo_function::concrete::QuadraticCombination::setCoefficients(): " };
138 ost <<
"matrix is not symmetric.";
139 throw IPOE( ost.str() );
150 std::ostringstream ost {
"ipo_function::concrete::QuadraticCombination::operator()(): " };
151 ost <<
"vector size " << vector.size();
152 ost <<
" and coefficients size " <<
coefficients.size1();
153 ost <<
" do not match.";
154 throw IPOE( ost.str() );
156 double result { 0.0 };
157 gsl::vector temp( vector.size() );
158 gsl::blas::dsymv( gsl::blas::Upper, 1,
coefficients, vector, 0, temp );
159 gsl::blas::ddot( temp, vector, &result );
165 size_t const SIZE = vector.size();
168 std::ostringstream ost(
"ipo_function::concrete::QuadraticCombination::gradient(): " );
169 ost <<
"vector size " << vector.size();
170 ost <<
" and coefficients size " <<
coefficients.size1();
171 ost <<
" do not match.";
172 throw IPOE( ost.str() );
177 for(
size_t i { 0 }; i < SIZE; ++ i ){
179 double result { 0.0 };
180 gsl::blas::ddot( row, vector, &result );
188 size_t const SIZE = vector.size();
191 std::ostringstream ost(
"ipo_function::concrete::QuadraticCombination::hessian(): " );
192 ost <<
"vector size " << vector.size();
193 ost <<
" and coefficients size " <<
coefficients.size1();
194 ost <<
" do not match.";
195 throw IPOE( ost.str() );
206 size_t const SIZE = vector.size();
209 std::ostringstream ost(
"ipo_function::concrete::QuadraticaticCombination::setVector(): " );
210 ost <<
"vector size " << vector.size();
211 ost <<
" and coefficients size " <<
coefficients.size1();
212 ost <<
" do not match.";
213 throw IPOE( ost.str() );
215 gsl::vector temp( vector.size() );
216 gsl::blas::dsymv( gsl::blas::Upper, 1.0,
coefficients, vector, 0.0, temp );
220 for(
size_t i { 0 }; i < SIZE; ++ i ){
222 double result { 0.0 };
223 gsl::blas::ddot( row, vector, &result );
double functionValue
The function value.
gsl::matrix const & getCoefficients() const
Get the coefficients as a matrix by reference.
gsl::vector functionGradient
The gradient value.
virtual gsl::matrix hessian() const
virtual gsl::vector gradient() const
virtual double value() const
gsl::matrix functionHessian
The Hessian value.
void resize(size_t const size)
Resize the matrix of coefficients.
Namespace to hold concrete functions.
#define IPOE(message)
Macro to allow file and line names in exceptions.
void setCoefficients(gsl::matrix const &matrix)
Set coefficients from a matrix.
QuadraticCombination(size_t const size=0)
The constructor sets up function as a quadratic combination of size entries.
gsl::matrix coefficients
The matrix of coefficients;.
double getCoefficient(size_t const index) const
Get the value of a coefficient on the diagonal.
virtual double operator()(gsl::vector const &vector)
The function operator: computes the sum of the vector entries.
virtual void setVector(gsl::vector const &vector)
Set a vector and compute function value, gradient and Hessian efficiently.
size_t const size
Size of vector arguments to supply to subclass functions.
void setCoefficient(size_t const index, double const value)
Set the value of a coefficient on the diagonal.
This namespace holds all the interior-point optimisation classes.