00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <GradientProjectionSearchDirection.h>
00035 #include <SearchDirection.h>
00036 #include <StepSizeRule.h>
00037 #include <ProbabilityTransformation.h>
00038 #include <GFunEvaluator.h>
00039 #include <RootFinding.h>
00040 #include <Vector.h>
00041 #include <Matrix.h>
00042
00043
00044 GradientProjectionSearchDirection::GradientProjectionSearchDirection(
00045 StepSizeRule *passedStepSizeRule,
00046 ProbabilityTransformation *passedProbabilityTransformation,
00047 GFunEvaluator *passedGFunEvaluator,
00048 RootFinding *passedRootFindingAlgorithm)
00049 :SearchDirection()
00050 {
00051 theStepSizeRule = passedStepSizeRule;
00052 theProbabilityTransformation = passedProbabilityTransformation;
00053 theGFunEvaluator = passedGFunEvaluator;
00054 theRootFindingAlgorithm = passedRootFindingAlgorithm;
00055 }
00056
00057 GradientProjectionSearchDirection::~GradientProjectionSearchDirection()
00058 {
00059 }
00060
00061
00062
00063
00064 Vector
00065 GradientProjectionSearchDirection::getSearchDirection()
00066 {
00067 return searchDirection;
00068 }
00069
00070
00071
00072 int
00073 GradientProjectionSearchDirection::computeSearchDirection(int stepNumber,
00074 Vector u,
00075 double passed_g,
00076 Vector gradG)
00077 {
00078
00079
00080
00081 int i,j;
00082 Vector u_new;
00083 double initialStepSize;
00084 Vector Direction;
00085
00086
00087
00088 int nrv = u.Size();
00089
00090
00091
00092 Matrix I(nrv,nrv);
00093 for (i=0; i<nrv; i++) {
00094 for (j=0; j<nrv; j++) {
00095 if (i==j) {
00096 I(i,j) = 1.0;
00097 }
00098 else {
00099 I(i,j) = 0.0;
00100 }
00101 }
00102 }
00103
00104
00105
00106 Matrix dGdG(nrv,nrv);
00107 for (i=0; i<nrv; i++) {
00108 for (j=0; j<nrv; j++) {
00109 dGdG(i,j) = gradG(i)*gradG(j);
00110 }
00111 }
00112
00113
00114 initialStepSize = theStepSizeRule->getInitialStepSize();
00115
00116
00117
00118
00119 if (stepNumber != 1) {
00120
00121
00122 Vector direction = (-1)* (I - (1.0/(gradG^gradG))*dGdG ) * u;
00123
00124
00125 u_new = u + initialStepSize*direction;
00126
00127
00128 Direction = gradG;
00129 }
00130
00131
00132 else {
00133
00134 u_new = u;
00135
00136
00137 Vector alpha = gradG * ( (-1) / gradG.Norm() );
00138
00139
00140 double alpha_times_u = alpha ^ u ;
00141 Vector direction = alpha * ( passed_g / gradG.Norm() + alpha_times_u ) - u;
00142
00143
00144 Direction = (-1)*direction;
00145 }
00146
00147
00148
00149 double tangent = gradG.Norm();
00150 Vector u_newest = theRootFindingAlgorithm->findLimitStateSurface(2,passed_g, Direction, u_new);
00151
00152
00153
00154
00155 searchDirection = (1.0/initialStepSize)*(u_newest-u);
00156
00157 return 0;
00158
00159 }
00160
00161
00162
00163