24 #include <l/l_verbose.h>
54 template<
class F,
class M,
class A>
58 const std::vector<std::pair<double, double> >& bounds,
64 const size_t D = bounds.size();
69 kjb_c::warn_pso(
"The dimensionality of this function is %d; this "
70 "approximation might take a really long time.", D);
73 std::vector<double> bin_widths(D);
74 for(
size_t i = 0;
i <
D;
i++)
76 bin_widths[
i] = (bounds[
i].second - bounds[
i].first)/nbins;
79 std::vector<size_t> indices;
82 while(
next_point(bounds, bin_widths, nbins, indices, x, adapter))
109 template<
class F,
class V>
114 const std::vector<std::pair<double, double> >& bounds,
119 const size_t D = bounds.size();
146 template<
class F,
class M,
class G,
class A>
151 const std::vector<double>& steps,
156 const size_t D = adapter.size(&x);
158 "cannot perform gradient ascent: wrong number of step sizes.");
161 std::vector<double> exg(D);
164 double cur_f = fcn(x);
178 std::multiplies<double>());
186 while(cur_f > prev_f);
188 std::transform(exg.begin(), exg.end(), exg.begin(), std::negate<double>());
206 template<
class F,
class V,
class G>
212 const std::vector<double>& steps,
234 template<
class F,
class M,
class A>
239 const std::vector<double>& steps,
243 double cur_pt = fcn(x);
248 for(
size_t i = 0;
i < adapter.size(&x);
i++)
250 double xi = adapter.get(&x,
i);
253 double right_pt = fcn(x);
257 double left_pt = fcn(x);
260 adapter.set(&x, i, xi);
261 if(cur_pt >= left_pt && cur_pt >= right_pt)
continue;
264 if(left_pt > right_pt)
Int_matrix::Value_type max(const Int_matrix &mat)
Return the maximum value in this matrix.
Definition: l_int_matrix.h:1397
void gradient_ascent(const F &fcn, M &x, const std::vector< double > &steps, const G &grad, const A &adapter)
Maximizes a function using a simple gradient ascent method.
Definition: diff_optim.h:148
void move_param(Model &x, size_t i, double dv, const Adapter &aptr)
Helper function that moves a parameter by an amount.
Definition: diff_util.h:102
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
#define IFT(a, ex, msg)
Definition: l_exception.h:101
bool next_point(const std::vector< std::pair< double, double > > &bounds, const std::vector< double > &widths, size_t nbins, std::vector< size_t > &indices, M &x, const A &adapter)
Gets the next point in a N-dimensional grid.
Definition: diff_util.h:145
void move_params(Model &x, size_t i, size_t j, double dv, double dw, const Adapter &aptr)
Helper function that moves a pair of parameters by an amount.
Definition: diff_util.h:111
x
Definition: APPgetLargeConnectedEdges.m:100
Default adapter for the hessian function.
Definition: diff_util.h:42
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
D
Definition: APPgetLargeConnectedEdges.m:106
Support for error handling exception classes in libKJB.
double grid_maximize(const F &fcn, const std::vector< std::pair< double, double > > &bounds, size_t nbins, const A &adapter, M &mxm)
Maximizes a function by evaluating at all points in a grid.
Definition: diff_optim.h:56
void refine_max(const F &fcn, M &x, const std::vector< double > &steps, const A &adapter)
Refine the maximum of a function.
Definition: diff_optim.h:236
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...