00001 00012 #ifdef _MSC_VER 00013 #include "msdevstudio/MSconfig.h" 00014 #endif 00015 00016 #include "StatedFCN.h" 00017 00018 #include "functions/FunctionBase.h" 00019 00020 using std::string; 00021 using std::vector; 00022 00023 StatedFCN:: 00024 StatedFCN ( ) 00025 : m_function ( 0 ), 00026 m_has_errors ( false ) 00027 { 00028 } 00029 00030 StatedFCN:: 00031 StatedFCN ( const StatedFCN & fcn ) 00032 : m_fixed_flags ( fcn.m_fixed_flags ), 00033 m_function ( fcn.m_function ), 00034 m_has_errors ( fcn.m_has_errors ) 00035 { 00036 } 00037 00038 StatedFCN:: 00039 StatedFCN ( FunctionBase * function ) 00040 : FCNBase (), 00041 m_has_errors ( false ) 00042 { 00043 setFunction ( function ); 00044 } 00045 00046 bool 00047 StatedFCN:: 00048 hasFunction () const 00049 { 00050 return m_function != 0; 00051 } 00052 00053 void 00054 StatedFCN:: 00055 setFunction ( FunctionBase * function ) 00056 { 00057 m_function = function; 00058 unsigned int size = m_function -> size(); 00059 m_fixed_flags.resize ( size ); 00060 00061 for ( unsigned int i = 0; i < size; i++ ) { 00062 m_fixed_flags [i] = 0; 00063 } 00064 } 00065 00066 const vector < string > & 00067 StatedFCN:: 00068 getParmNames () const 00069 { 00070 return m_function -> parmNames (); 00071 } 00072 00073 const vector < double > & 00074 StatedFCN:: 00075 getParameters ( ) const 00076 { 00077 return m_function -> getParameters ( ); 00078 } 00079 00080 void 00081 StatedFCN:: 00082 setParameters ( const std::vector < double > & parms ) 00083 { 00084 m_function -> setParameters ( parms ); 00085 } 00086 00087 void 00088 StatedFCN:: 00089 fillFreeParameters ( std::vector < double > & free_parms ) const 00090 { 00091 free_parms.clear(); 00092 const vector < double > & parms = m_function -> getParameters (); 00093 unsigned int size = parms.size (); 00094 for ( unsigned int i = 0; i < size; i++ ) { 00095 if ( m_fixed_flags[ i ] == 0 ) { 00096 free_parms.push_back ( parms[ i ] ); 00097 } 00098 } 00099 } 00100 00101 unsigned int 00102 StatedFCN:: 00103 getNumberFreeParms () const 00104 { 00105 unsigned int number = 0; 00106 unsigned int size = m_fixed_flags.size (); 00107 for ( unsigned int i = 0; i < size; i++ ) { 00108 if ( m_fixed_flags[i] == 0 ) number++; 00109 } 00110 00111 return number; 00112 } 00113 00114 const vector < int > & 00115 StatedFCN:: 00116 getFixedFlags () const 00117 { 00118 // return m_function -> fixedFlags (); 00119 return m_fixed_flags; 00120 } 00121 00122 void 00123 StatedFCN:: 00124 setFixedFlags ( const std::vector < int > & flags ) 00125 { 00126 m_fixed_flags = flags; 00127 } 00128 00129 void 00130 StatedFCN:: 00131 setFreeParameters ( const std::vector < double > & free_parms ) 00132 { 00133 vector < double > parms = m_function -> getParameters (); 00134 unsigned int size = parms.size (); 00135 unsigned int j = 0; 00136 00137 for ( unsigned int i = 0; i < size; i++ ) { 00138 if ( m_fixed_flags [i] == 0 ) { 00139 parms[i] = free_parms[j]; 00140 j++; 00141 } 00142 } 00143 00144 m_function -> setParameters ( parms ); 00145 } 00146 00147 void 00148 StatedFCN:: 00149 fillFreeDerivatives ( std::vector < double > & derives, double x ) 00150 { 00151 derives.clear(); 00152 const vector < double > & parms = m_function -> getParameters (); 00153 unsigned int size = parms.size(); 00154 00155 for ( unsigned int i = 0; i < size; i++ ) { 00156 if ( m_fixed_flags [i] == 0 ) { 00157 double value = m_function -> derivByParm ( i, x ); 00158 derives.push_back ( value ); 00159 } 00160 } 00161 } 00162 00163 double 00164 StatedFCN:: 00165 operator () ( const std::vector < double > & parms ) const 00166 { 00167 m_function -> setParameters ( parms ); 00168 00169 return objectiveValue (); 00170 }