46 #ifndef SHARK_OBJECTIVEFUNCTIONS_BENCHMARKS_POLE_GRUAU_OBJECTIVE_FUNCTION 47 #define SHARK_OBJECTIVEFUNCTIONS_BENCHMARKS_POLE_GRUAU_OBJECTIVE_FUNCTION 83 bool normalize =
true,
84 std::size_t max_pole_evaluations = 1000)
85 : m_maxPoleEvals(max_pole_evaluations),
86 m_normalize(normalize) {
89 std::cerr <<
"Cannot use linear activation function for pole balancing." 94 std::size_t inputs = 3;
103 m_dimensions = (hidden + 1) * (hidden + 1) +
104 inputs * (hidden + 1) + hidden + 1;
107 m_dimensions = (hidden + 1) * (hidden + 1) + inputs * (hidden + 1);
112 mp_struct->setStructure(inputs, hidden, 1, bias, sigmoidType);
113 mp_net =
new PoleRNNet(mp_struct);
117 std::cerr <<
"Gruau pole RNNet: Dimensions do not match, " 134 return "Objective Function for non-Markov double pole with Gruau fitness.";
145 for(std::size_t i = 0; i != m_dimensions; i++) {
146 startingPoint(i) = 0.0;
148 return startingPoint;
165 double init_angle = 0.07;
168 RealMatrix output(1,1);
169 double totalJiggle = 0;
170 std::size_t jiggleSize = 100;
171 double jiggle[jiggleSize];
172 std::size_t eval_count = 0;
175 pole.
init(init_angle);
176 mp_net->resetInternalState();
179 while(!failed && eval_count < m_maxPoleEvals) {
181 RealMatrix newState(1,3);
182 row(newState,0) = state;
183 mp_net->
eval(newState,output);
184 pole.
move(convertToPoleMovement(output(0,0)));
185 jiggle[eval_count % jiggleSize] = pole.
getJiggle();
190 if(eval_count >= jiggleSize){
191 for(std::size_t i = 0; i < jiggleSize;i++){
192 totalJiggle += jiggle[i];
194 totalJiggle = .75 / totalJiggle;
201 std::size_t maxFit = 1.0;
202 double result = maxFit - (0.1 * eval_count / 1000
203 + 0.9 * totalJiggle);
213 std::size_t maxEvals = 100000) {
215 double init_angle = 0.07;
218 RealMatrix output(1,1);
219 RealMatrix inState(1,3);
220 std::size_t eval_count = 0;
223 pole.
init(init_angle);
224 mp_net->resetInternalState();
227 while(!failed && eval_count < maxEvals) {
229 row(inState,0) = state;
230 mp_net->
eval(inState,output);
231 pole.
move(convertToPoleMovement(output(0,0)));
237 return maxEvals - eval_count;
245 std::size_t maxEvals = 1000){
247 double init_angle = 0.07;
250 RealMatrix output(1,1);
252 const double statevals[5] = {0.05, 0.25, 0.5, 0.75, 0.95};
253 std::size_t successes = 0;
255 for (std::size_t s0c = 0; s0c < 5; ++s0c){
256 for (std::size_t s1c = 0; s1c < 5; ++s1c){
257 for (std::size_t s2c = 0; s2c < 5; ++s2c){
258 for (std::size_t s3c = 0; s3c < 5; ++s3c) {
259 std::size_t eval_count = 0;
260 pole.
init(statevals[s0c] * 4.32 - 2.16,
261 statevals[s1c] * 2.70 - 1.35,
262 statevals[s2c] * 0.12566304 - 0.06283152,
263 statevals[s3c] * 0.30019504 - 0.15009752);
264 mp_net->resetInternalState();
267 while(!failed && eval_count < maxEvals) {
269 RealMatrix newState(1,3);
270 row(newState,0) = state;
271 mp_net->
eval(newState,output);
272 pole.
move(convertToPoleMovement(output(0,0)));
277 if(eval_count == maxEvals){
293 boost::shared_ptr<State> createState()
const{
294 throw std::logic_error(
"State not available for PoleRNNet.");
296 void eval(BatchInputType
const & patterns, BatchOutputType &outputs,
298 throw std::logic_error(
"Batch not available for PoleRNNet.");
305 double convertToPoleMovement(
double output)
const{
306 switch(mp_struct->sigmoidType())
311 return (output + 1.) / 2.;
313 return (output + 1.) / 2.;
315 std::cerr <<
"Unsupported activation function for pole balancing." << std::endl;
325 std::size_t m_dimensions;
327 std::size_t m_maxPoleEvals;