g++ [flags ...] file ... -l /isip/tools/lib/$ISIP_BINARY/lib_algo.a
#include <NonLinearOptimization.h>
NonLinearOptimization();
NonLinearOptimization(const NonLinearOptimization& arg);
static boolean levenbergMarquardt(VectorDouble& params, double& chi_square,
const VectorDouble& x, const VectorDouble& y,
const VectorDouble& stddev,
LEV_MARQ_FUNC_DOUBLE func,
double convergence=DEF_LEVMARQ_CONVERGE);
static boolean levenbergMarquardt(VectorFloat& params, float& chi_square,
const VectorFloat& x, const VectorFloat& y,
const VectorFloat& stddev,
LEV_MARQ_FUNC_FLOAT func,
float convergence=DEF_LEVMARQ_CONVERGE);
quick start:
description:VectorFloat v_fl(L"1, 2, 3"); float chi_sq_fl = 0; VectorFloat x_fl(L" 0, 1, 1"); VectorFloat stddev_fl(L"1, 1, 1"); VectorFloat y_fl; NonlinearOptimization::levenbergMarquardt(v_fl, chi_sq_fl, x_fl, y_fl, stddev_fl, NonlinearOptimization::diagnoseSigmoidFl);
static const String CLASS_NAME = L"NonLinearOptimization";
static const String DEF_PARAM = L"";
static const float LEVMARQ_INIT_LAMBDA = 0.001;
static const float DEF_LEVMARQ_CONVERGE = 0.1;error codes:
static const long ERR = (long)35200;
static const long ERR_LEV_MARQ = (long)35201;
typedef boolean (*LEV_MARQ_FUNC_FLOAT)(float&, VectorFloat&, const float, const VectorFloat&);
typedef boolean (*LEV_MARQ_FUNC_DOUBLE)(double&, VectorDouble&, const double, const VectorDouble&);
static Integral::DEBUG debug_level_d;
static MemoryManager mgr_d;
static const String& name();
static boolean diagnose(Integral::DEBUG debug_level);
boolean setDebug(Integral::DEBUG debug_level);
boolean debug(const unichar* message) const;
~NonLinearOptimization();
NonLinearOptimization();
NonLinearOptimization(const NonLinearOptimization& arg);
boolean assign(const NonLinearOptimization& arg)
NonLinearOptimization& operator= (const NonLinearOptimization& arg);
long sofSize() const;
boolean read(Sof& sof, long tag, const String& name = CLASS_NAME);
boolean write(Sof& sof, long tag, const String& name = CLASS_NAME) const;
boolean readData(Sof& sof, const String& pname = DEF_PARAM,long size = SofParser::FULL_OBJECT, boolean param = true, boolean nested = false);
boolean writeData(Sof& sof, const String& pname = DEF_PARAM) const;
boolean eq(const NonLinearOptimization& arg) const;
static void* operator new(size_t size);
static void* operator new[](size_t size);
static void operator delete(void* ptr);
static void operator delete[](void* ptr);
static boolean setGrowSize(long grow_size);
boolean clear(Integral::CMODE ctype = Integral::DEF_CMODE);
static boolean levenbergMarquardt(VectorFloat& params, float& chi_square, const VectorFloat& x, const VectorFloat& y, const VectorFloat& stddev, LEV_MARQ_FUNC_FLOAT func, float convergence=DEF_LEVMARQ_CONVERGE);
static boolean levenbergMarquardt(VectorDouble& params, double& chi_square, const VectorDouble& x, const VectorDouble& y, const VectorDouble& stddev, LEV_MARQ_FUNC_DOUBLE func, double convergence=DEF_LEVMARQ_CONVERGE);
template <class TMatrix, class TVector, class TIntegral> static boolean levMarqTemplate(TVector& params, TIntegral& chi_square, const TVector& x, const TVector& y, const TVector& stddev, boolean (*)(TIntegral&, TVector&, const TIntegral, const TVector&), TIntegral convergence);
template <class TMatrix, class TVector, class TIntegral> static boolean levMarqChiSquare(TIntegral& chi_square, TMatrix& alpha, TVector& beta, const TVector& x, const TVector& y, const TVector& inv_variance, const TVector& params, boolean (*)(TIntegral&, TVector&, const TIntegral, const TVector&));
template <class TMatrix, class TVector, class TIntegral> static boolean scaleDiagonal(TMatrix& mat, const TIntegral& scale);
static boolean diagnoseSigmoidFl(float& y, VectorFloat& derivatives, const float x, const VectorFloat& params);
static boolean diagnoseSigmoidDoub(double& y, VectorDouble& derivatives, const double x, const VectorDouble& params);
#include <NonLinearOptimization.h>
#include <Console.h>
int main() {
// declare the measured data
//
VectorFloat params_fl;
VectorFloat x_fl;
VectorFloat y_fl;
VectorFloat stddev_fl;
VectorFloat final_params_fl;
// open the test file
//
String test_file(L"diagnose.sof");
Sof test_sof;
test_sof.open(test_file);
// read in the test data
//
String x_tag(L"x");
String y_tag(L"y");
String stddev_tag(L"stddev");
String init_params_tag(L"initial_params");
String final_params_tag(L"final_params");
params_fl.read(test_sof, 0, init_params_tag);
x_fl.read(test_sof, 0, x_tag);
y_fl.read(test_sof, 0, y_tag);
stddev_fl.read(test_sof, 0, stddev_tag);
final_params_fl.read(test_sof, 0, final_params_tag);
test_sof.close();
// test levenbergMarquardt
//
float chi_sq_fl = 0;
NonlinearOptimization::levenbergMarquardt(params_fl, chi_sq_fl, x_fl,
y_fl, stddev_fl,
NonlinearOptimization::diagnoseSigmoidFl);
// verify that results match
//
if (!final_params_fl.almostEqual(params_fl)) {
params_fl.debug(L"actual params");
final_params_fl.debug(L"expected params");
Console::put(L"Error in levenbergMarquardt method");
}
// exit gracefully
//
Integral::exit();
}