ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/NLModel1.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/NLModel1.cpp (file contents):
Revision 996 by tim, Wed Jan 28 22:44:44 2004 UTC vs.
Revision 1023 by tim, Wed Feb 4 22:26:00 2004 UTC

# Line 1 | Line 1
1   #include "NLModel.hpp"
2 + #include "Utility.hpp"
3 +
4 +
5 +
6   //calculate hessian using finite difference
7   SymMatrix NLModel1::FiniteHessian(vector<double>& x, vector<double>& h){
8  
# Line 9 | Line 13 | SymMatrix NLModel1::FiniteHessian(vector<double>& x, v
13    
14   #ifdef IS_MPI
15    vector<double> gplusAll;
16 <  vector<double> currentGradAll;
16 >  vector<double> tempGradAll;
17  
18 <  currentGradAll = getAllGrad();
18 >  tempGradAll = getAllGrad();
19   #endif
20  
21    tempX = x;
# Line 25 | Line 29 | SymMatrix NLModel1::FiniteHessian(vector<double>& x, v
29  
30      gplus = calcGrad(tempX);
31  
32 <    hessian.Cloume(i) = (gplus - currentGrad) / hi;  
32 >    //hessian.Colume(i) = (gplus - currentGrad) / hi;  
33  
34      //restore tempX to its original value
35      tempX[i] -= hi;
# Line 54 | Line 58 | SymMatrix NLModel1::FiniteHessian(vector<double>& x, v
58  
59      }
60  
61 <    hessian.Cloume(i) = (gplusAll - currentGradAll) / hi;  
61 >    hessian.Cloume(i) = (gplusAll - tempGradAll) / hi;  
62   #endif
63  
64    }
# Line 63 | Line 67 | SymMatrix NLModel1::FiniteHessian(vector<double>& x, v
67    
68   }
69  
70 < double ConcreteNLMode1::calcF(){
70 > //----------------------------------------------------------------------------//
71 > ConcreteNLModel1::ConcreteNLModel1(int dim, ObjFunctor1* func ,  ConstraintList* cons)
72 >                         : NLModel1(dim, cons){
73 >  objfunc = func;
74 > }
75 > double ConcreteNLModel1::calcF(){
76 >  
77 >  currentF = (*objfunc)(currentX, currentGrad);
78 >  numOfFunEval ++;
79  
80 +  return currentF;
81   }
82  
83 < double ConcreteNLMode1::calcF(const vector<double>& x){
83 > double ConcreteNLModel1::calcF(vector<double>& x){
84  
85 +  vector<double> tempGrad(x.size());
86 +  
87 +  double tempF;
88 +
89 +  tempF = (*objfunc)(x, tempGrad);
90 +  numOfFunEval ++;
91 +  
92 +  return tempF;  
93   }
94  
95 < vector<double> ConcreteNLMode1::calcGrad(){
95 > vector<double> ConcreteNLModel1::calcGrad(){
96 >  
97 >  currentF = (*objfunc)(currentX, currentGrad);
98  
99 +  return currentGrad;
100 +
101   }
102  
103 < vector<double> ConcreteNLMode1::calcGrad(vector<double>& x){
103 > vector<double> ConcreteNLModel1::calcGrad(vector<double>& x){
104 >  vector<double> tempGrad(x.size());
105  
106 +  double tempF;
107 +  
108 +  tempF = (*objfunc)(x, tempGrad);
109 +
110 +  return tempGrad;
111   }
112  
82 SymMatrix ConcreteNLMode1::calcHessian(){
113  
114 + SymMatrix ConcreteNLModel1::calcHessian(){
115 +  calcGrad(currentX);
116 +  
117 +  return FiniteHessian(currentX, currentX);
118   }
119  
120 < SymMatrix ConcreteNLMode1::calcHessian(vector<double>& x){
121 <
120 > SymMatrix ConcreteNLModel1::calcHessian(vector<double>& x){
121 >  return FiniteHessian(x, x);
122   }
123 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines