Added script front-end for primer-design code
[htsworkflow.git] / htswanalysis / MACS / lib / gsl / gsl-1.11 / multimin / test_funcs.c
1 /* multimin/test_funcs.c
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
20 #include <config.h>
21 #include <gsl/gsl_multimin.h>
22
23 #include "test_funcs.h"
24
25 gsl_multimin_function_fdf rosenbrock =
26 {&rosenbrock_f,
27  &rosenbrock_df,
28  &rosenbrock_fdf,
29  2, 0};
30
31 gsl_multimin_function rosenbrock_fmin =
32 {&rosenbrock_f,
33  2, 0};
34
35 void rosenbrock_initpt (gsl_vector * x)
36 {
37   gsl_vector_set (x, 0, -1.2);
38   gsl_vector_set (x, 1, 1.0);
39 }
40
41 double rosenbrock_f (const gsl_vector * x, void *params)
42 {
43   double u = gsl_vector_get(x,0);
44   double v = gsl_vector_get(x,1);
45   double a = u - 1;
46   double b = u * u - v;
47   fcount++;
48   return a * a + 10 * b * b;
49 }
50
51 void rosenbrock_df (const gsl_vector * x, void *params, gsl_vector * df)
52 {
53   double u = gsl_vector_get(x,0);
54   double v = gsl_vector_get(x,1);
55   double b = u * u - v;
56   gcount++;
57   gsl_vector_set(df,0,2 * (u - 1) + 40 * u * b);
58   gsl_vector_set(df,1,-20 * b);  
59 }
60
61 void rosenbrock_fdf (const gsl_vector * x, void *params, double * f,
62                      gsl_vector * df) 
63 {
64   double u = gsl_vector_get(x,0);
65   double v = gsl_vector_get(x,1);
66   double a = u - 1;
67   double b = u * u - v;
68   gcount++;
69   *f = a * a + 10 * b * b;
70   gsl_vector_set(df,0,2 * (u - 1) + 40 * u * b);
71   gsl_vector_set(df,1,-20 * b);  
72 }
73
74 gsl_multimin_function_fdf roth =
75 {&roth_f,
76  &roth_df,
77  &roth_fdf,
78  2, 0};
79
80 gsl_multimin_function roth_fmin =
81 {&roth_f,
82  2, 0};
83
84 void roth_initpt (gsl_vector * x)
85 {
86   gsl_vector_set (x, 0, 4.5);
87   gsl_vector_set (x, 1, 3.5);
88 }
89
90 double roth_f (const gsl_vector * x, void *params)
91 {
92   double u = gsl_vector_get(x,0);
93   double v = gsl_vector_get(x,1);
94   double a = -13.0 + u + ((5.0 - v)*v - 2.0)*v;
95   double b = -29.0 + u + ((v + 1.0)*v - 14.0)*v;
96   fcount++;
97   return a * a + b * b;
98 }
99
100 void roth_df (const gsl_vector * x, void *params, gsl_vector * df)
101 {
102   double u = gsl_vector_get(x,0);
103   double v = gsl_vector_get(x,1);
104   double a = -13.0 + u + ((5.0 - v)*v - 2.0)*v;
105   double b = -29.0 + u + ((v + 1.0)*v - 14.0)*v;
106   double c = -2 + v * (10 - 3 * v);
107   double d = -14 + v * (2 + 3 * v);
108   gcount++;
109   gsl_vector_set(df,0,2 * a + 2 * b);
110   gsl_vector_set(df,1,2 * a * c + 2 * b * d);
111 }
112
113 void roth_fdf (const gsl_vector * x, void *params, double * f,
114                gsl_vector * df) 
115 {
116   *f = roth_f (x,params);
117   roth_df(x,params,df);
118 }
119
120 gsl_multimin_function_fdf wood =
121 {&wood_f,
122  &wood_df,
123  &wood_fdf,
124  4, 0};
125
126 gsl_multimin_function wood_fmin =
127 {&wood_f,
128  4, 0};
129
130 void
131 wood_initpt (gsl_vector * x)
132 {
133   gsl_vector_set (x, 0, -3.0);
134   gsl_vector_set (x, 1, -1.0);
135   gsl_vector_set (x, 2, -3.0);
136   gsl_vector_set (x, 3, -1.0);
137 }
138
139 double wood_f (const gsl_vector * x, void *params)
140 {
141   double u1 = gsl_vector_get(x,0);
142   double u2 = gsl_vector_get(x,1);
143   double u3 = gsl_vector_get(x,2);
144   double u4 = gsl_vector_get(x,3);
145
146   double t1 = u1 * u1 - u2;
147   double t2 = u3 * u3 - u4;
148   fcount++;
149   return 100 * t1 * t1 + (1 - u1) * (1 - u1)
150     + 90 * t2 * t2 + (1 - u3) * (1 - u3)
151     + 10.1 * ( (1 - u2) * (1 - u2) + (1 - u4) * (1 - u4) )
152     + 19.8 * (1 - u2) * (1 - u4);
153 }
154
155 void wood_df (const gsl_vector * x, void *params, gsl_vector * df)
156 {
157   double u1 = gsl_vector_get(x,0);
158   double u2 = gsl_vector_get(x,1);
159   double u3 = gsl_vector_get(x,2);
160   double u4 = gsl_vector_get(x,3);
161
162   double t1 = u1 * u1 - u2;
163   double t2 = u3 * u3 - u4;
164   gcount++;
165   gsl_vector_set(df,0, 400 * u1 * t1 - 2 * (1 - u1) );
166   gsl_vector_set(df,1, -200 * t1 - 20.2 * (1 - u2) - 19.8 * (1 - u4) );
167   gsl_vector_set(df,2, 360 * u3 * t2 - 2 * (1 - u3) );
168   gsl_vector_set(df,3, -180 * t2 - 20.2 * (1 - u4) - 19.8 * (1 - u2) );
169   
170 }
171
172 void wood_fdf (const gsl_vector * x, void *params, double * f, gsl_vector * df)
173 {
174   wood_df(x,params,df);
175   *f=wood_f(x,params);
176 }
177
178
179 gsl_multimin_function_fdf Nrosenbrock =
180 {&rosenbrock_f,
181  &Nrosenbrock_df,
182  &Nrosenbrock_fdf,
183  2, 0};
184
185 void Nrosenbrock_df (const gsl_vector * x, void *params, gsl_vector * df)
186 {
187   gsl_multimin_function F ;
188   F.f = rosenbrock_f;
189   F.params = params;
190   F.n = x->size;
191   gsl_multimin_diff (&F, x, df);
192 }
193
194 void Nrosenbrock_fdf (const gsl_vector * x, void *params, double * f,
195                      gsl_vector * df) 
196 {
197   *f = rosenbrock_f (x, params);
198   Nrosenbrock_df (x, params, df);
199 }
200
201 gsl_multimin_function_fdf Nroth =
202 {&roth_f,
203  &Nroth_df,
204  &Nroth_fdf,
205  2, 0};
206
207 void Nroth_df (const gsl_vector * x, void *params, gsl_vector * df)
208 {
209   gsl_multimin_function F ;
210   F.f = roth_f;
211   F.params = params;
212   F.n = x->size;
213   gsl_multimin_diff (&F, x, df);
214 }
215
216 void Nroth_fdf (const gsl_vector * x, void *params, double * f,
217                      gsl_vector * df) 
218 {
219   *f = roth_f (x, params);
220   Nroth_df (x, params, df);
221 }
222
223
224 gsl_multimin_function_fdf Nwood =
225 {&wood_f,
226  &Nwood_df,
227  &Nwood_fdf,
228  4, 0};
229
230 void Nwood_df (const gsl_vector * x, void *params, gsl_vector * df)
231 {
232   gsl_multimin_function F ;
233   F.f = wood_f;
234   F.params = params;
235   F.n = x->size;
236   gsl_multimin_diff (&F, x, df);
237 }
238
239 void Nwood_fdf (const gsl_vector * x, void *params, double * f,
240                      gsl_vector * df) 
241 {
242   *f = wood_f (x, params);
243   Nwood_df (x, params, df);
244 }