-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwolfeLineSearch.c
41 lines (32 loc) · 929 Bytes
/
wolfeLineSearch.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "declarations.h"
#include "constants.h"
void wolfeLineSearch(double* current,double* direction,double* gradient,double* nextGradient, double* next){
double sDotjacU0 = dot(direction,gradient,size);
if(sDotjacU0 < 0){
printf("wolfeLineSearch input direction is not descent\n");
exit(0);
}
double fU0 = myFunction(current);
double fullstep = 1;
int i;
double left = 0, mid = fullstep, right = fullstep;
while(right - left > wolfeTol){
for(i=0; i<size; i++){
next[i] = current[i] - mid * direction[i];
}
myGradient(next,nextGradient);
if(myFunction(next) <= fU0 - c1 * mid * sDotjacU0){
if((fabs(dot(direction,nextGradient,size)) <= c2 * fabs(sDotjacU0)) || mid == fullstep){
return;
}
else{
left = mid;
mid = (mid+right)/2;
}
}
else{
right = mid;
mid = (mid+left)/2;
}
}
}