| 1 |
|
#include "NLModel.hpp" |
| 2 |
|
#include <math.h> |
| 3 |
< |
|
| 3 |
> |
#include "Utility.hpp" |
| 4 |
|
/** |
| 5 |
|
* calculate gradient using backward finite difference |
| 6 |
|
* df(Xk)/dXi = (f(Xk) - f(Xk - h*ei)) /h |
| 89 |
|
tempX[i] += hi; |
| 90 |
|
} |
| 91 |
|
|
| 92 |
< |
fminus = calcF(tempX); |
| 92 |
> |
fplus = calcF(tempX); |
| 93 |
|
|
| 94 |
|
if(procMappingArray[i] == myRank){ |
| 95 |
< |
partialGrad[i] = (fx - fminus) / hi; |
| 95 |
> |
partialGrad[i] = (fplus - fx) / hi; |
| 96 |
|
|
| 97 |
|
//restore tempX to its original value |
| 98 |
|
tempX[i] -= hi; |
| 154 |
|
tempX[i] -= 2*hi; |
| 155 |
|
} |
| 156 |
|
|
| 157 |
< |
fminus = (*objfunc)(tempX); |
| 157 |
> |
fminus = calcF(tempX); |
| 158 |
|
|
| 159 |
|
if(procMappingArray[i] == myRank){ |
| 160 |
|
partialGrad[i] = (fx - fminus) / (2*hi); |