Interior-point-optimisation  1.0-1
Interior-pointoptimisationlibrary
PhaseIObjectiveFunctionAndDerivatives.cc
Go to the documentation of this file.
1 /*
2  * $Id: PhaseIObjectiveFunctionAndDerivatives.cc 137 2013-06-29 15:10:31Z jdl3 $
3  * Copyright (C) 2013 John D Lamb
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or (at
8  * your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 
20 #ifdef HAVE_CONFIG_H
21 # include<config.h>
22 #endif
23 
25 
26 using namespace ipo_function::detail;
27 
30  : FunctionBase { 0 == function.getSize() ? 0 : function.getSize() + 1 }
31 {
32  if( size != 0 ){
33  functionGradient = gsl::vector( size );
34  functionGradient.set_all( 1.0 );
35  functionHessian = gsl::matrix { size, size };
36  functionHessian.set_all( 0.0 );
37  }
38 }
39 
40 double
42  size_t const VSIZE { vector.size() };
43  if( 0 == VSIZE ) return 0; // do something sane
44  return vector[VSIZE - 1];
45 }
46 
47 gsl::vector
49  size_t const SIZE { 0 == getSize() ? vector.size() : getSize() };
50  if( 0 == getSize() )
51  if( functionGradient.size() != SIZE ) functionGradient = gsl::vector( SIZE );
52 
53  for( size_t i { 0 }; i < SIZE; ++i )
54  functionGradient[i] = (i + 1 == SIZE) ? 1.0 : 0.0;
55  return functionGradient;
56 }
57 
58 gsl::matrix
60  size_t const SIZE { 0 == getSize() ? vector.size() : getSize() };
61  if( 0 == getSize() ){
62  if( functionHessian.size1() != SIZE or functionHessian.size2() != SIZE ){
63  functionHessian = gsl::matrix( SIZE, SIZE );
64  functionHessian.set_all( 0.0 );
65  }
66  }
67  return functionHessian;
68 }
69 
70 void
72  size_t const SIZE { 0 == getSize() ? vector.size() : getSize() };
73  if( 0 == getSize() ){
74  if( functionGradient.size() != SIZE ) functionGradient = gsl::vector( SIZE );
75  if( functionHessian.size1() != SIZE or functionHessian.size2() != SIZE ){
76  functionHessian = gsl::matrix( SIZE, SIZE );
77  functionHessian.set_all( 0 );
78  }
79  }
80 
81  double const VSIZE = vector.size();
82  functionValue = 0 == VSIZE ? 0 : vector[VSIZE - 1];
83 
84  for( size_t i = 0; i < SIZE; ++i )
85  functionGradient[i] = (i + 1 == SIZE) ? 1 : 0;
86 }
double functionValue
The function value.
gsl::vector functionGradient
The gradient value.
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
gsl::matrix functionHessian
The Hessian value.
void setVector(gsl::vector const &vector)
Set a vector and compute function value, gradient and Hessian efficiently.
double operator()(gsl::vector const &vector)
The function operator: returns the last element of vector.
size_t getSize() const
Get size of vector for function arguments or zero for arbitrary size.
This class computes a function at a vector.
Definition: Function.hpp:38
Base class for Function and DerivativesEstimates.
PhaseIObjectiveFunctionAndDerivatives(Function const &function)
Construct from a function.