Jafar
|
Module jmath defines some common mathematical tools, among them vector and matrix manipulation, random number generation,...
uBlas library from the boost project (http://www.boost.org) implements the Basic Linear Algebra System specification in a efficient way (it uses templates and operator expressions). It defines different vectors and matrix types (dense, symmetric, sparse, banded).
Links of interest concerning uBlas:
jblas.hpp is the standard jafar header to use ublas in your own modules. It defines some standard vector and matrix types in the jafar::blas
namespace (shortcut jblas). If any type of vector or matrix is needed but is not redefined in jblas.hpp, we recommend to define it rather than using directly the boost uBlas type.
The module filter is a good example of how to use linear algebra in jafar.
Like many other C++ libraries, uBlas is implemented in templates, so this is the user who controls the compilation of uBlas (in Jafar, you edit the User.make
of your module). uBlas can use exceptions to report errors, we recommand you use this feature, it is enabled with -DBOOST_UBLAS_USE_EXCEPTIONS
. For optimal performance you may also define -DNDEBUG
to suppress a lot of internal checks (it is more than ten times faster !). If you use uBlas in your module, your User.make
should contain:
CPPFLAGS += $(BOOST_CPPFLAGS) -DBOOST_UBLAS_USE_EXCEPTIONS CPPFLAGS += -DNDEBUG
This module wraps some basic functions to manipulate vector and matrix from boost ublas library in tcl. All the types defined in jblas.hpp are available.
The constructors defined in the ublas vector and matrix class are not well suited to be used from tcl (available with new_vec
, new_mat
,...). Others functions are defined which are called create_vec
, create_mat
,... the function setValue can init the value of the container from a string. Also some print
functions are defined. These extra template functions are defined in jmathTcl.hpp.
If your module manipulate data types defined in jblas.hpp, you may want to manipulate these types inside a tcl shell. As is, you get a reasonable interface to manipulate them using function wrapped in the jmath module.
If you want to use the OO notation on data returned by functions from your module, you need to add the following to your module.i:
%import "jmath/jblas.i"
For example, module filter uses this hint.
Please, do not reinvent the wheel ! Many good, efficient, well documented and free libraries exist. Moreover bindings are provided for uBlas to other well known algebra libraries such that LAPACK or ATLAS. These bindings add powerfull algebra routines to uBlas. Currently they are not part of the official boost release but can be found on the boost-sandbox cvs.
The use of Numerical Recipes code is not recommended since it is not published under a free licence. However, the books can help a lot, they are freely available at http://www.library.cornell.edu/nr .
Here is a few example of a correspondance of functions between matlab and jafar:
#include <boost/numeric/bindings/lapack/gesvd.hpp> using namespace boost::numeric::bindings; jblas::vec s(3); jblas::mat_column_major M; jblas::mat_column_major U(3, 3); jblas::mat_column_major VT(3, 3); int ierr = lapack::gesvd(M,s,U,VT);
Note that you can use gesdd to do the singular value decomposition using the divide and conquer method.
00001 # $Id$ # 00002 00003 # 00004 #/** Demo of jblas vector. \file demoJblas.tcl \ingroup jmath */ 00005 # 00006 00007 00008 package require jmath 00009 00010 set v [jmath::new_vec 10] 00011 jmath::setValue $v "(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)" 00012 00013 jmath::print $v 00014 00015 for {set i 0} {$i < [$v size]} {incr i} { 00016 $v set $i [expr "2*[$v get $i]"] 00017 } 00018 00019 jmath::print $v 00020
The interface of the module is generated from the following files:
try
{ } catch
block for this module. Classes | |
class | jafar::jmath::GaussianVector |
A simple gaussian vector represented by its mean and covariance. More... | |
class | jafar::jmath::WeightedGaussianVector |
A weighted gaussian vector, add a weight to a GaussianVector. More... | |
class | jafar::jmath::JmathException |
Base class for all exceptions defined in the module jmath. More... | |
class | jafar::jmath::LapackException |
This exception is thrown when a lapack routine fails. More... | |
struct | joptimization::methods::GaussNewton< _TFunction_, _TType_ > |
Use this class as a template parameter for the gaussNewton function if you want to use the Gauss-Newton method which uses only the jacobian. More... | |
struct | joptimization::methods::Newton< _TFunction_, _TType_ > |
Use this class as a template parameter for the gaussNewton function if you want to use the Newton method which uses the Hessian. More... | |
class | jafar::jmath::MATLAB |
Class for serializing boost arrays into Matlab format. More... | |
class | jafar::jmath::UniformDistribution |
Uniform distribution generator using the Boost random library. More... | |
class | jafar::jmath::MultiDimUniformDistribution |
Multi dimensionnal uniform distribution generator using the Boost random library. More... | |
class | jafar::jmath::NormalDistribution |
Normal distribution generator using the Boost random library. More... | |
class | jafar::jmath::MultiDimNormalDistribution |
Multi dimensionnal normal distribution generator using the Boost random library. More... | |
class | jafar::jmath::RANSAC< NUMTYPE > |
An implementation of the RANSAC algorithm for robust fitting of models to data. More... | |
class | jafar::jmath::matrix_file< T > |
Class matrix_file loads/saves data into/from a matrix from/to a file. More... | |
class | jafar::jmath::vector_file< T > |
Class vector_file loads/saves data into/from a vector from/to a file. More... | |
Namespaces | |
namespace | jblas |
shortcut for ublas namespace | |
namespace | joptimization |
shortcut for ublas namespace | |
namespace | joptimization::algorithms |
This namespace contains function to call some of the classical optimization algorithm for estimating the parameter p and minimizing sum( f_i(p)2 ). | |
namespace | jafar::jmath::ublasExtra |
This namespace contains some extra tools for ublas vector and matrix. | |
Files | |
file | indirectArray.hpp |
| |
file | ixaxpy.hpp |
| |
file | jann.hpp |
This is the standard header defined in jafar to bind the flann library. | |
file | jblas.hpp |
This is the standard header defined in jafar to use the boost uBlas library. | |
file | joptimization.hpp |
This is the standard header defined in jafar to use non linear optimaztion methods Code spoofed from Cyrille Berger (cberger@cberger.net) | |
Typedefs | |
typedef _TType_ | joptimization::methods::GaussNewton< _TFunction_, _TType_ >::Type |
typedef _TFunction_ | joptimization::methods::GaussNewton< _TFunction_, _TType_ >::Function |
typedef _TType_ | joptimization::methods::Newton< _TFunction_, _TType_ >::Type |
typedef _TFunction_ | joptimization::methods::Newton< _TFunction_, _TType_ >::Function |
Functions | |
static void | joptimization::methods::GaussNewton< _TFunction_, _TType_ >::computeM (const ublas::matrix< _TType_ > &jacobian, const _TFunction_ *f, ublas::vector< _TType_ > ¶meters, ublas::vector< _TType_ > &values, ublas::matrix< _TType_ > &M) |
static void | joptimization::methods::Newton< _TFunction_, _TType_ >::computeM (const ublas::matrix< _TType_ > &jacobian, const _TFunction_ *f, ublas::vector< _TType_ > ¶meters, ublas::vector< _TType_ > &values, ublas::matrix< _TType_ > &M) |
template<class _TFunction_ , typename _TType_ > | |
_TType_ | joptimization::algorithms::gradientDescent (_TFunction_ *f, ublas::vector< _TType_ > ¶meters, int iter, _TType_ epsilon, _TType_ gamma) |
Perform an optimization following Gauss Newton algorithm. | |
template<class _TMethod_ > | |
_TMethod_::Type | joptimization::algorithms::gaussNewton (typename _TMethod_::Function *f, ublas::vector< typename _TMethod_::Type > ¶meters, int iter, typename _TMethod_::Type epsilon) |
Perform an optimization following Gauss Newton algorithm. | |
template<class _TFunction_ , typename _TType_ > | |
_TType_ | joptimization::algorithms::levenbergMarquardt (_TFunction_ *f, ublas::vector< _TType_ > ¶meters, int iter, _TType_ epsilon, _TType_ lambda0, _TType_ nu) |
Perform an optimization following Levenberg Marquardt algorithm. | |
template<typename _TType_ > | |
double | optimization::details::computeRemain (const ublas::vector< _TType_ > &values) |
template<typename _TType_ > | |
ublas::vector< double > | optimization::details::solve (const ublas::matrix< _TType_ > &M, const ublas::matrix< _TType_ > &jacobian, const ublas::vector< _TType_ > &values, int p_count) |
_TMethod_::Type joptimization::algorithms::gaussNewton | ( | typename _TMethod_::Function * | f, |
ublas::vector< typename _TMethod_::Type > & | parameters, | ||
int | iter, | ||
typename _TMethod_::Type | epsilon | ||
) |
Perform an optimization following Gauss Newton algorithm.
f | functions |
parameters | intial guess of the parameters value |
iter | maximal number of iterations |
epsilon | if the remain is below epsilon the function return |
_TType_ joptimization::algorithms::gradientDescent | ( | _TFunction_ * | f, |
ublas::vector< _TType_ > & | parameters, | ||
int | iter, | ||
_TType_ | epsilon, | ||
_TType_ | gamma | ||
) |
Perform an optimization following Gauss Newton algorithm.
f | functions |
parameters | intial guess of the parameters value |
iter | maximal number of iterations |
epsilon | if the remain is below epsilon the function return |
gamma | the coeficient apply to the derivative |
_TType_ joptimization::algorithms::levenbergMarquardt | ( | _TFunction_ * | f, |
ublas::vector< _TType_ > & | parameters, | ||
int | iter, | ||
_TType_ | epsilon, | ||
_TType_ | lambda0, | ||
_TType_ | nu | ||
) |
Perform an optimization following Levenberg Marquardt algorithm.
f | functions |
parameters | intial guess of the parameters value |
iter | maximal number of iterations |
epsilon | if the remain is below epsilon the function return |
lambda0 | the intial value of the damping parameter |
nu | adjustment coefficient of the damping parameter |
Generated on Wed Oct 15 2014 00:37:30 for Jafar by doxygen 1.7.6.1 |