Image Component Library (ICL)
Classes | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
icl::math::LLM Class Reference

Local Linear Map implementation (LLM) More...

#include <LLM.h>

Inheritance diagram for icl::math::LLM:
icl::utils::Configurable

Classes

struct  Kernel
 Internally used Kernel structure. More...
 

Public Member Functions

 LLM (unsigned int inputDim, unsigned int outputDim)
 Creates a new llm with given input and output dimensions. More...
 
 LLM (unsigned int inputDim, unsigned int outputDim, unsigned int numCenters, const std::vector< utils::Range< icl32f > > &ranges, const std::vector< float > &var=std::vector< float >(1, 1))
 
void init (unsigned int numCenters, const std::vector< utils::Range< icl32f > > &ranges, const std::vector< float > &var=std::vector< float >(1, 1))
 initializes the LLM prototypes with given kernel count More...
 
void init (const std::vector< float * > &centers, const std::vector< float > &var=std::vector< float >(1, 1))
 initializes the LLM prototypes with given set of kernels More...
 
const float * apply (const float *x)
 applies the LLM and returns current NET output vector More...
 
void train (const float *x, const float *y, int trainflags=TRAIN_ALL)
 applies an update step to the net with given net input x and destination output y More...
 
void trainCenters (const float *x)
 trains the input weights w_in More...
 
void trainSigmas (const float *x)
 trains the input variances sigma More...
 
void trainOutputs (const float *x, const float *y)
 trains the output weights w_out More...
 
void trainMatrices (const float *x, const float *y)
 trains the output slope matrices A More...
 
const float * getErrorVec (const float *x, const float *y)
 returns the current error vector with respect to a given destination value y More...
 
void setEpsilonIn (float val)
 sets up learning rate for input weights to a new value (about 0..1) More...
 
void setEpsilonOut (float val)
 sets up learning rate for output weights to a new value (about 0..1) More...
 
void setEpsilonA (float val)
 sets up learning rate for slope matrices to a new value (about 0..1) More...
 
void setEpsilonSigma (float val)
 sets up learning rate for sigmas to a new value (about 0..1) More...
 
void showKernels () const
 Shows all current kernels to std::out. More...
 
unsigned int numKernels () const
 returns the current internal kernel count More...
 
const Kerneloperator[] (unsigned int i) const
 returns a specifice kernel at given index (const) More...
 
Kerneloperator[] (unsigned int i)
 returns a specifice kernel (unconst version) More...
 
bool isSoftMaxUsed () const
 returns whether the softmax function for calculation for g_i[x] is used More...
 
void setSoftMaxEnabled (bool enabled)
 sets whether the softmax function for calculation for g_i[x] is used More...
 
- Public Member Functions inherited from icl::utils::Configurable
virtual ~Configurable ()
 virtual destructor More...
 
 Configurable (const Configurable &other)
 Copy constructor. More...
 
Configurableoperator= (const Configurable &other)
 Assignment operator. More...
 
void setConfigurableID (const std::string &ID)
 sets the ID of this configurable More...
 
const std::string & getConfigurableID () const
 returns the configurables static ID More...
 
bool isOrderedFlagSet () const
 returns whether the ordered flag is set More...
 
void deactivateProperty (const std::string &pattern)
 adds an additional deativation pattern More...
 
void deleteDeactivationPattern (const std::string &pattern)
 removed a formerly added deactivation pattern More...
 
std::vector< std::string > getPropertyListWithoutDeactivated () const
 this returns a filtered list of properties (using all filters added by deactivateProperty) More...
 
virtual void adaptProperty (const std::string &name, const std::string &newType, const std::string &newInfo, const std::string &newToolTip)
 this function can be used to adapt a specific property afterwards More...
 
void registerCallback (const Callback &cb)
 add a callback for changed properties More...
 
void removedCallback (const Callback &cb)
 removes a callback that was registered before More...
 
void syncChangesTo (Configurable *others, int num=1)
 this can be used to let this instance also apply property changes to others More...
 
virtual void setPropertyValue (const std::string &propertyName, const Any &value)
 sets a property value More...
 
virtual std::vector< std::string > getPropertyList () const
 returns a list of All properties, that can be set using setProperty More...
 
virtual bool supportsProperty (const std::string &propertyName) const
 base implementation for property check (seaches in the property list) More...
 
virtual void saveProperties (const std::string &filename, const std::vector< std::string > &propertiesToSkip=EMPTY_VEC) const
 writes all available properties into a file More...
 
virtual void loadProperties (const std::string &filename, const std::vector< std::string > &propertiesToSkip=EMPTY_VEC)
 reads a camera config file from disc More...
 
virtual std::string getPropertyType (const std::string &propertyName) const
 get type of property More...
 
virtual std::string getPropertyInfo (const std::string &propertyName) const
 get information of a properties valid values More...
 
virtual Any getPropertyValue (const std::string &propertyName) const
 returns the current value of a property or a parameter More...
 
virtual std::string getPropertyToolTip (const std::string &propertyName) const
 returns the tooltip description for a given property More...
 
virtual int getPropertyVolatileness (const std::string &propertyName) const
 Returns whether this property may be changed internally. More...
 

Static Public Attributes

static const int TRAIN_CENTERS = 1
 
static const int TRAIN_SIGMAS = 2
 
static const int TRAIN_OUTPUTS = 4
 
static const int TRAIN_MATRICES = 8
 
static const int TRAIN_ALL = TRAIN_CENTERS | TRAIN_SIGMAS | TRAIN_OUTPUTS | TRAIN_MATRICES
 
- Static Public Attributes inherited from icl::utils::Configurable
static const std::vector< std::string > EMPTY_VEC
 used as shortcut – just an empty vector of std::strings More...
 

Private Member Functions

void init_private (unsigned int inputDim, unsigned int outputDim)
 
const float * updateGs (const float *x)
 possible usefull utility function (internally used) More...
 
void trainCentersIntern (const float *x, const float *g)
 internal training function for the input weights/prototypes More...
 
void trainSigmasIntern (const float *x, const float *g)
 interal training function for the sigmas More...
 
void trainOutputsIntern (const float *x, const float *y, const float *g, const float *dy, bool useDeltaWin)
 internal training function for the output weights More...
 
void trainMatricesIntern (const float *x, const float *y, const float *g, const float *dy)
 internal training function for the slope matrices A More...
 
const float * applyIntern (const float *x, const float *g)
 internal apply function More...
 
const float * getErrorVecIntern (const float *y, const float *ynet)
 internal function to return the current error vector More...
 

Private Attributes

unsigned int m_inputDim
 input dimension More...
 
unsigned int m_outputDim
 output dimension More...
 
std::vector< Kernelm_kernels
 internal storage for the kernels More...
 
std::vector< float > m_outBuf
 internal output value buffer More...
 
std::vector< float > m_gBuf
 internal buffer for the g_i[x] More...
 
std::vector< float > m_errorBuf
 internal buffer for the current error vector More...
 

Additional Inherited Members

- Public Types inherited from icl::utils::Configurable
typedef Function< void, const Property & > Callback
 Function type for changed properties. More...
 
- Static Public Member Functions inherited from icl::utils::Configurable
static std::string create_default_ID (const std::string &prefix)
 this function can be used in subclasses to create a default ID More...
 
static Configurableget (const std::string &id)
 returns configurable by given ID More...
 
static void register_configurable_type (const std::string &classname, Function< Configurable * > creator)
 registers a configurable type More...
 
static std::vector< std::string > get_registered_configurables ()
 returns a list of all registered configurable classnames More...
 
static Configurablecreate_configurable (const std::string &classname)
 creates a configurable by given name More...
 
- Protected Member Functions inherited from icl::utils::Configurable
void addProperty (const std::string &name, const std::string &type, const std::string &info, const Any &value=Any(), const int volatileness=0, const std::string &tooltip=std::string())
 This can be used by derived classes to store supported properties in the internal list. More...
 
void addChildConfigurable (Configurable *configurable, const std::string &childPrefix="")
 This adds another configurable as child. More...
 
void removeChildConfigurable (Configurable *configurable)
 removes the given child configurable More...
 
Propertyprop (const std::string &propertyName)
 this CAN be used e.g. to store a property value in internal property-list More...
 
const Propertyprop (const std::string &propertyName) const
 this CAN be used e.g. to store a property value in internal property-list More...
 
 Configurable (const std::string &ID="", bool ordered=true)
 create this configurable with given ID More...
 
void call_callbacks (const std::string &propertyName, const Configurable *caller) const
 calls all registered callbacks More...
 
- Protected Attributes inherited from icl::utils::Configurable
std::vector< Callbackcallbacks
 internally managed list of callbacks More...
 

Detailed Description

Local Linear Map implementation (LLM)

The LLM-network (Local Linear Maps) is a very powerful regression network that uses a superposition of linearily weighted gaussians as regression model:

Net Function y=f(x)

\[ \vec{y}^{net}(x) = \sum\limits_{i=1}^N ( \vec{w}_i^{out}+A_i ( \vec{x}-\vec{w}_i^{in} ) ) \cdot g_i(\vec{x}) \]

where each kernel i is defined by a kernel function $g_i(\vec{x})$ that is weighted linearily using $ ( \vec{w}_i^{out}+A_i ( \vec{x}-\vec{w}_i^{in} ) ) $. $\vec{w}_i^{in}$ is the location in the input space, where kernel i is centered, and $\vec{w}_i^{out}$ resp. $A_i$ are parameters of a linear weighting function.

Kernel functions

Here, normalized Gaussians are always used a kernel functions:

\[ g_i(\vec{x}) = \frac{\exp(-\frac{\|\vec{x}-\vec{w}_i^{in}\|^2}{2\sigma_i^2})} {\sum\limits_{j=1}^N \exp(-\frac{\|\vec{x}-\vec{w}_j^{in}\|^2}{2\sigma_j^2})} \]

Training of input weights and variances(unsuperwised)

The kernel centers (also refered as data prototypes) $\vec{w}_i^{in}$ can be initialized randomly e.g. using a uniform distribution in input data space or by a set of given prototypes. The prototypes can be adapted while the network training process using means of vector quantisation (e.g. KMeans) externally or by using the following internally implemented update rule:

\[ \Delta \vec{w}_i^{in} = \epsilon_{in} \cdot ( \vec{x} - \vec{w}_i^{in} ) \cdot g_i(\vec{x}) \]

and

\[ \Delta \sigma^2 = \epsilon_{\sigma} \cdot ( \vec{x} - \vec{w}_i^{in} )^2 - \sigma^2 \cdot g_i(\vec{x}) \]

Note: For some initial tries, it turned out, that updating the kernel radii is rather unstable.

Training of output weights and matrices (superwised)

Training rules for output weights $\vec{w}_i^{out}$ and matrices $A_i$ are obtained by simple gradient descent approach (given input tuple $(\vec{x}^{\alpha},\vec{y}^{\alpha})$):

\[ \Delta \vec{w}_i^{out} = \epsilon_{out} \cdot g_i(\vec{x}^{\alpha}) \cdot (\vec{y}^{\alpha} - \vec{y}^{net}(\vec{x}^{\alpha}) ) + A_i \Delta \vec{w}_i^{in} \]

and

\[ \Delta A_i = \epsilon_A \cdot g_i(\vec{x}^{\alpha}) \cdot (\vec{y}^{\alpha} - \vec{y}^{net}(\vec{x}^{\alpha}) ) \cdot \frac{(\vec{x}^{\alpha} - \vec{w}_i^{in} )^{\tau}}{\|\vec{x}^{\alpha} - \vec{w}_i^{in}\|^2} \]

Hacks

TODO

Constructor & Destructor Documentation

◆ LLM() [1/2]

icl::math::LLM::LLM ( unsigned int  inputDim,
unsigned int  outputDim 
)

Creates a new llm with given input and output dimensions.

◆ LLM() [2/2]

icl::math::LLM::LLM ( unsigned int  inputDim,
unsigned int  outputDim,
unsigned int  numCenters,
const std::vector< utils::Range< icl32f > > &  ranges,
const std::vector< float > &  var = std::vector< float >(1, 1) 
)

Member Function Documentation

◆ apply()

const float* icl::math::LLM::apply ( const float *  x)

applies the LLM and returns current NET output vector

the ownership of the returnd float * is not passed to the caller. The output remains valid until apply is called with another x-value

◆ applyIntern()

const float* icl::math::LLM::applyIntern ( const float *  x,
const float *  g 
)
private

internal apply function

◆ getErrorVec()

const float* icl::math::LLM::getErrorVec ( const float *  x,
const float *  y 
)

returns the current error vector with respect to a given destination value y

◆ getErrorVecIntern()

const float* icl::math::LLM::getErrorVecIntern ( const float *  y,
const float *  ynet 
)
private

internal function to return the current error vector

◆ init() [1/2]

void icl::math::LLM::init ( unsigned int  numCenters,
const std::vector< utils::Range< icl32f > > &  ranges,
const std::vector< float > &  var = std::vector< float >(1, 1) 
)

initializes the LLM prototypes with given kernel count

Internally creates numCenters kernels for this LLM. Each kernel is initialized as follows:

  • input weight w_in: created with respect to ranges (w_in[i] becomes a value drawn from a uniform distibution of range ranges[i])
  • output weight w_out: initialized to 0-vector
  • Slope Matrix A: initialized to 0-matrix
  • variance sigma: initialized to given variance vector var

(internally this init function calls the other init function)

Parameters
numCentersnew prototype count
rangesranges for uniform distributed prototypes (ranges.size must be equal to the input dimension of the LLM)
varvariance for the new created Gaussians (var.size must be equal to the input dimension of the LLM)

◆ init() [2/2]

void icl::math::LLM::init ( const std::vector< float * > &  centers,
const std::vector< float > &  var = std::vector< float >(1, 1) 
)

initializes the LLM prototypes with given set of kernels

Internall all centers.size() vectors are used to create that many prototypes. The given vectors are deeply copied and not released internally. Initialization is performend as described in the above function.

◆ init_private()

void icl::math::LLM::init_private ( unsigned int  inputDim,
unsigned int  outputDim 
)
private

◆ isSoftMaxUsed()

bool icl::math::LLM::isSoftMaxUsed ( ) const
inline

returns whether the softmax function for calculation for g_i[x] is used

◆ numKernels()

unsigned int icl::math::LLM::numKernels ( ) const
inline

returns the current internal kernel count

◆ operator[]() [1/2]

const Kernel& icl::math::LLM::operator[] ( unsigned int  i) const
inline

returns a specifice kernel at given index (const)

◆ operator[]() [2/2]

Kernel& icl::math::LLM::operator[] ( unsigned int  i)
inline

returns a specifice kernel (unconst version)

please note: it is not safe to change the obtained Kernel's value by hand unless you really know what you are doing. For setting the kernel weights manually, it is strongly recommended to use the Kernel::set-method, which does only allow to change the weight values

◆ setEpsilonA()

void icl::math::LLM::setEpsilonA ( float  val)
inline

sets up learning rate for slope matrices to a new value (about 0..1)

◆ setEpsilonIn()

void icl::math::LLM::setEpsilonIn ( float  val)
inline

sets up learning rate for input weights to a new value (about 0..1)

◆ setEpsilonOut()

void icl::math::LLM::setEpsilonOut ( float  val)
inline

sets up learning rate for output weights to a new value (about 0..1)

◆ setEpsilonSigma()

void icl::math::LLM::setEpsilonSigma ( float  val)
inline

sets up learning rate for sigmas to a new value (about 0..1)

Note Update of the sigmas does not run very good!

◆ setSoftMaxEnabled()

void icl::math::LLM::setSoftMaxEnabled ( bool  enabled)
inline

sets whether the softmax function for calculation for g_i[x] is used

◆ showKernels()

void icl::math::LLM::showKernels ( ) const

Shows all current kernels to std::out.

◆ train()

void icl::math::LLM::train ( const float *  x,
const float *  y,
int  trainflags = TRAIN_ALL 
)

applies an update step to the net with given net input x and destination output y

The trainingflags parameter can be used to specify special parameter updates, a list of training targets can be creates using bit-or: e.g.: TRAIN_CENTERS|TRAIN_SIGMAS

◆ trainCenters()

void icl::math::LLM::trainCenters ( const float *  x)

trains the input weights w_in

◆ trainCentersIntern()

void icl::math::LLM::trainCentersIntern ( const float *  x,
const float *  g 
)
private

internal training function for the input weights/prototypes

◆ trainMatrices()

void icl::math::LLM::trainMatrices ( const float *  x,
const float *  y 
)

trains the output slope matrices A

◆ trainMatricesIntern()

void icl::math::LLM::trainMatricesIntern ( const float *  x,
const float *  y,
const float *  g,
const float *  dy 
)
private

internal training function for the slope matrices A

◆ trainOutputs()

void icl::math::LLM::trainOutputs ( const float *  x,
const float *  y 
)

trains the output weights w_out

◆ trainOutputsIntern()

void icl::math::LLM::trainOutputsIntern ( const float *  x,
const float *  y,
const float *  g,
const float *  dy,
bool  useDeltaWin 
)
private

internal training function for the output weights

◆ trainSigmas()

void icl::math::LLM::trainSigmas ( const float *  x)

trains the input variances sigma

◆ trainSigmasIntern()

void icl::math::LLM::trainSigmasIntern ( const float *  x,
const float *  g 
)
private

interal training function for the sigmas

◆ updateGs()

const float* icl::math::LLM::updateGs ( const float *  x)
private

possible usefull utility function (internally used)

updates an internal variable vector containing provisional results for all g_i[x]. This internally speeds up performance (please dont call this function!, propably it can be made private)

Member Data Documentation

◆ m_errorBuf

std::vector<float> icl::math::LLM::m_errorBuf
private

internal buffer for the current error vector

◆ m_gBuf

std::vector<float> icl::math::LLM::m_gBuf
private

internal buffer for the g_i[x]

◆ m_inputDim

unsigned int icl::math::LLM::m_inputDim
private

input dimension

◆ m_kernels

std::vector<Kernel> icl::math::LLM::m_kernels
private

internal storage for the kernels

◆ m_outBuf

std::vector<float> icl::math::LLM::m_outBuf
private

internal output value buffer

◆ m_outputDim

unsigned int icl::math::LLM::m_outputDim
private

output dimension

◆ TRAIN_ALL

const int icl::math::LLM::TRAIN_ALL = TRAIN_CENTERS | TRAIN_SIGMAS | TRAIN_OUTPUTS | TRAIN_MATRICES
static

training flag for updating all

◆ TRAIN_CENTERS

const int icl::math::LLM::TRAIN_CENTERS = 1
static

training flag for updating input weights/prototype vectors

◆ TRAIN_MATRICES

const int icl::math::LLM::TRAIN_MATRICES = 8
static

training flag for updating output matrices

◆ TRAIN_OUTPUTS

const int icl::math::LLM::TRAIN_OUTPUTS = 4
static

training flag for updating output weights

◆ TRAIN_SIGMAS

const int icl::math::LLM::TRAIN_SIGMAS = 2
static

training flag for updating input sigmas


The documentation for this class was generated from the following file: