PICCANTE  0.4
The hottest HDR imaging library!
nelder_mead_opt_test_function.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_COMPUTER_VISION_NELDER_MEAD_OPT_TEST_FUNCTION_HPP
19 #define PIC_COMPUTER_VISION_NELDER_MEAD_OPT_TEST_FUNCTION_HPP
20 
21 #include <random>
22 
23 #include "../util/nelder_mead_opt_base.hpp"
24 
25 namespace pic {
26 
28 {
29 public:
30 
31  float a, b;
32 
34  {
35  this->a = a;
36  this->b = b;
37  }
38 
39  float function(float *x, unsigned int n)
40  {
41  if(n != 2) {
42  return FLT_MAX;
43  }
44 
45  float a_x = (a - x[0]);
46  float y_x2 = x[1] - x[0] * x[0];
47 
48  return a_x * a_x + b * y_x2 *y_x2;
49  }
50 
51  static void test()
52  {
53  NelderMeadOptTestFunction test(1.0f, 100.0f);
54 
55  std::mt19937 rnd(1);
56  float start[2];
57  for(int i = 0; i < 1000; i++) {
58 
59  start[0] = float(rnd() % 1000) * 0.003f;
60  start[1] = float(rnd() % 1000) * 0.002f;
61 
62  float *sol = test.run(start, 2, 1e-12f, 10000);
63  printf("x: %f y: %f f: %f\n", sol[0], sol[1], test.function(sol, 2));
64  }
65  }
66 };
67 
68 }
69 
70 #endif // PIC_COMPUTER_VISION_NELDER_MEAD_OPT_TEST_FUNCTION_HPP
static void test()
Definition: nelder_mead_opt_test_function.hpp:51
float b
Definition: nelder_mead_opt_test_function.hpp:31
Definition: nelder_mead_opt_test_function.hpp:27
float a
Definition: nelder_mead_opt_test_function.hpp:31
NelderMeadOptTestFunction(float a, float b)
Definition: nelder_mead_opt_test_function.hpp:33
The NelderMeadOptBase class.
Definition: nelder_mead_opt_base.hpp:31
Definition: bilateral_separation.hpp:25