gsl_multimin.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /* multimin/gsl_multimin.h
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000 Fabrice Rossi
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. /* Modified by Tuomo Keskitalo to include fminimizer and
  20. Nelder Mead related lines */
  21. #ifndef __GSL_MULTIMIN_H__
  22. #define __GSL_MULTIMIN_H__
  23. #include <stdlib.h>
  24. #include "gsl_types.h"
  25. #include "gsl_math.h"
  26. #include "gsl_vector.h"
  27. #include "gsl_matrix.h"
  28. #include "gsl_min.h"
  29. #undef __BEGIN_DECLS
  30. #undef __END_DECLS
  31. #ifdef __cplusplus
  32. # define __BEGIN_DECLS extern "C" {
  33. # define __END_DECLS }
  34. #else
  35. # define __BEGIN_DECLS /* empty */
  36. # define __END_DECLS /* empty */
  37. #endif
  38. __BEGIN_DECLS
  39. /* Definition of an arbitrary real-valued function with gsl_vector input and */
  40. /* parameters */
  41. struct gsl_multimin_function_struct
  42. {
  43. double (* f) (const gsl_vector * x, void * params);
  44. size_t n;
  45. void * params;
  46. };
  47. typedef struct gsl_multimin_function_struct gsl_multimin_function;
  48. #define GSL_MULTIMIN_FN_EVAL(F,x) (*((F)->f))(x,(F)->params)
  49. /* Definition of an arbitrary differentiable real-valued function */
  50. /* with gsl_vector input and parameters */
  51. struct gsl_multimin_function_fdf_struct
  52. {
  53. double (* f) (const gsl_vector * x, void * params);
  54. void (* df) (const gsl_vector * x, void * params,gsl_vector * df);
  55. void (* fdf) (const gsl_vector * x, void * params,double *f,gsl_vector * df);
  56. size_t n;
  57. void * params;
  58. };
  59. typedef struct gsl_multimin_function_fdf_struct gsl_multimin_function_fdf;
  60. #define GSL_MULTIMIN_FN_EVAL_F(F,x) (*((F)->f))(x,(F)->params)
  61. #define GSL_MULTIMIN_FN_EVAL_DF(F,x,g) (*((F)->df))(x,(F)->params,(g))
  62. #define GSL_MULTIMIN_FN_EVAL_F_DF(F,x,y,g) (*((F)->fdf))(x,(F)->params,(y),(g))
  63. int gsl_multimin_diff (const gsl_multimin_function * f,
  64. const gsl_vector * x, gsl_vector * g);
  65. /* minimization of non-differentiable functions */
  66. typedef struct
  67. {
  68. const char *name;
  69. size_t size;
  70. int (*alloc) (void *state, size_t n);
  71. int (*set) (void *state, gsl_multimin_function * f,
  72. const gsl_vector * x,
  73. double * size,
  74. const gsl_vector * step_size);
  75. int (*iterate) (void *state, gsl_multimin_function * f,
  76. gsl_vector * x,
  77. double * size,
  78. double * fval);
  79. void (*free) (void *state);
  80. }
  81. gsl_multimin_fminimizer_type;
  82. typedef struct
  83. {
  84. /* multi dimensional part */
  85. const gsl_multimin_fminimizer_type *type;
  86. gsl_multimin_function *f;
  87. double fval;
  88. gsl_vector * x;
  89. double size;
  90. void *state;
  91. }
  92. gsl_multimin_fminimizer;
  93. gsl_multimin_fminimizer *
  94. gsl_multimin_fminimizer_alloc(const gsl_multimin_fminimizer_type *T,
  95. size_t n);
  96. int
  97. gsl_multimin_fminimizer_set (gsl_multimin_fminimizer * s,
  98. gsl_multimin_function * f,
  99. const gsl_vector * x,
  100. const gsl_vector * step_size);
  101. void
  102. gsl_multimin_fminimizer_free(gsl_multimin_fminimizer *s);
  103. const char *
  104. gsl_multimin_fminimizer_name (const gsl_multimin_fminimizer * s);
  105. int
  106. gsl_multimin_fminimizer_iterate(gsl_multimin_fminimizer *s);
  107. gsl_vector *
  108. gsl_multimin_fminimizer_x (const gsl_multimin_fminimizer * s);
  109. double
  110. gsl_multimin_fminimizer_minimum (const gsl_multimin_fminimizer * s);
  111. double
  112. gsl_multimin_fminimizer_size (const gsl_multimin_fminimizer * s);
  113. /* Convergence test functions */
  114. int
  115. gsl_multimin_test_gradient(const gsl_vector * g,double epsabs);
  116. int
  117. gsl_multimin_test_size(const double size ,double epsabs);
  118. /* minimisation of differentiable functions */
  119. typedef struct
  120. {
  121. const char *name;
  122. size_t size;
  123. int (*alloc) (void *state, size_t n);
  124. int (*set) (void *state, gsl_multimin_function_fdf * fdf,
  125. const gsl_vector * x, double * f,
  126. gsl_vector * gradient, double step_size, double tol);
  127. int (*iterate) (void *state,gsl_multimin_function_fdf * fdf,
  128. gsl_vector * x, double * f,
  129. gsl_vector * gradient, gsl_vector * dx);
  130. int (*restart) (void *state);
  131. void (*free) (void *state);
  132. }
  133. gsl_multimin_fdfminimizer_type;
  134. typedef struct
  135. {
  136. /* multi dimensional part */
  137. const gsl_multimin_fdfminimizer_type *type;
  138. gsl_multimin_function_fdf *fdf;
  139. double f;
  140. gsl_vector * x;
  141. gsl_vector * gradient;
  142. gsl_vector * dx;
  143. void *state;
  144. }
  145. gsl_multimin_fdfminimizer;
  146. gsl_multimin_fdfminimizer *
  147. gsl_multimin_fdfminimizer_alloc(const gsl_multimin_fdfminimizer_type *T,
  148. size_t n);
  149. int
  150. gsl_multimin_fdfminimizer_set (gsl_multimin_fdfminimizer * s,
  151. gsl_multimin_function_fdf *fdf,
  152. const gsl_vector * x,
  153. double step_size, double tol);
  154. void
  155. gsl_multimin_fdfminimizer_free(gsl_multimin_fdfminimizer *s);
  156. const char *
  157. gsl_multimin_fdfminimizer_name (const gsl_multimin_fdfminimizer * s);
  158. int
  159. gsl_multimin_fdfminimizer_iterate(gsl_multimin_fdfminimizer *s);
  160. int
  161. gsl_multimin_fdfminimizer_restart(gsl_multimin_fdfminimizer *s);
  162. gsl_vector *
  163. gsl_multimin_fdfminimizer_x (gsl_multimin_fdfminimizer * s);
  164. gsl_vector *
  165. gsl_multimin_fdfminimizer_dx (gsl_multimin_fdfminimizer * s);
  166. gsl_vector *
  167. gsl_multimin_fdfminimizer_gradient (gsl_multimin_fdfminimizer * s);
  168. double
  169. gsl_multimin_fdfminimizer_minimum (gsl_multimin_fdfminimizer * s);
  170. GSL_VAR const gsl_multimin_fdfminimizer_type *gsl_multimin_fdfminimizer_steepest_descent;
  171. GSL_VAR const gsl_multimin_fdfminimizer_type *gsl_multimin_fdfminimizer_conjugate_pr;
  172. GSL_VAR const gsl_multimin_fdfminimizer_type *gsl_multimin_fdfminimizer_conjugate_fr;
  173. GSL_VAR const gsl_multimin_fdfminimizer_type *gsl_multimin_fdfminimizer_vector_bfgs;
  174. GSL_VAR const gsl_multimin_fdfminimizer_type *gsl_multimin_fdfminimizer_vector_bfgs2;
  175. GSL_VAR const gsl_multimin_fminimizer_type *gsl_multimin_fminimizer_nmsimplex;
  176. __END_DECLS
  177. #endif /* __GSL_MULTIMIN_H__ */