ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/NLModel1.cpp
Revision: 1015
Committed: Tue Feb 3 22:54:52 2004 UTC (20 years, 5 months ago) by tim
File size: 2061 byte(s)
Log Message:
NLModel0, NLModel1 pass uit test

File Contents

# Content
1 #include "NLModel.hpp"
2 //calculate hessian using finite difference
3 SymMatrix NLModel1::FiniteHessian(vector<double>& x, vector<double>& h){
4
5 SymMatrix hessian(ndim);
6 vector<double> gplus;
7 vector<double> tempX;
8 double hi;
9
10 #ifdef IS_MPI
11 vector<double> gplusAll;
12 vector<double> tempGradAll;
13
14 tempGradAll = getAllGrad();
15 #endif
16
17 tempX = x;
18
19 for(int i = 0; i < ndim; i++){
20
21 #ifndef IS_MPI
22 hi = copysign(h[i], tempX[i]);
23
24 tempX[i] += hi;
25
26 gplus = calcGrad(tempX);
27
28 //hessian.Colume(i) = (gplus - currentGrad) / hi;
29
30 //restore tempX to its original value
31 tempX[i] -= hi;
32 #else
33 if(procMappingArray[i] == myRank){
34
35 hi = copysign(h[i], tempX[i]);
36 tempX[i] += hi;
37
38 }
39
40 gplus = calcGrad(tempX);
41
42 gplusAll.clear();
43
44 //very inefficient, need to change
45 for(int j = 0; j , numOfProc; j++){
46 brocastVector(gplus, j);
47 gplusAll.insert(gplus);
48 }
49
50 if(procMappingArray[i] == myRank){
51
52 hi = copysign(h[i], tempX[i]);
53 tempX[i] += hi;
54
55 }
56
57 hessian.Cloume(i) = (gplusAll - tempGradAll) / hi;
58 #endif
59
60 }
61
62 return hessian;
63
64 }
65
66 double ConcreteNLMode1::calcF(){
67
68 currentF = (*objfunc)(currentX, currentGrad);
69 numOfFunEval ++;
70
71 return currentF;
72 }
73
74 double ConcreteNLMode1::calcF(vector<double>& x){
75
76 vector<double> tempGrad(x.size());
77
78 double tempF;
79
80 tempF = (*objfunc)(x, tempGrad);
81 numOfFunEval ++;
82
83 return tempF;
84 }
85
86 vector<double> ConcreteNLMode1::calcGrad(){
87
88 currentF = (*objfunc)(currentX, currentGrad);
89
90 return currentGrad;
91
92 }
93
94 vector<double> ConcreteNLMode1::calcGrad(vector<double>& x){
95 vector<double> tempGrad(x.size());
96
97 double tempF;
98
99 tempF = (*objfunc)(x, tempGrad);
100
101 return tempGrad;
102 }
103
104 /*
105 SymMatrix ConcreteNLMode1::calcHessian(){
106 calcGrad(currentX);
107 return FiniteHessian(currentX);
108 }
109
110 SymMatrix ConcreteNLMode1::calcHessian(vector<double>& x){
111 return FiniteHessian(x);
112 }
113 */

Properties

Name Value
svn:executable *