class MahalanobisDistance
The Mahalanobis distance for real valued features computes the distance between a feature vector and a distribution of features characterized by its mean and covariance.
\[\displaystyle D = \sqrt{ (x_i - \mu)^T \Sigma^{-1} (x_i - \mu) } \]
The Mahalanobis Squared distance does not take the square root:
\[\displaystyle D = (x_i - \mu)^T \Sigma^{-1} (x_i - \mu) \]
If use_mean is set to false (which it is by default) the distance is computed as
\[\displaystyle D = \sqrt{ (x_i - x_i')^T \Sigma^{-1} (x_i - x_i') } \]
i.e., instead of the mean as reference two vector \(x_i\) and \(x_i'\) are compared.
在文件 MahalanobisDistance.h 第 52 行定义.
Public 成员函数 | |
CMahalanobisDistance () | |
CMahalanobisDistance (CDenseFeatures< float64_t > *l, CDenseFeatures< float64_t > *r) | |
virtual | ~CMahalanobisDistance () |
virtual bool | init (CFeatures *l, CFeatures *r) |
virtual void | cleanup () |
virtual EDistanceType | get_distance_type () |
virtual EFeatureType | get_feature_type () |
virtual const char * | get_name () const |
virtual bool | get_disable_sqrt () |
virtual void | set_disable_sqrt (bool state) |
virtual bool | get_use_mean () |
virtual void | set_use_mean (bool state) |
virtual EFeatureClass | get_feature_class () |
virtual float64_t | distance (int32_t idx_a, int32_t idx_b) |
virtual float64_t | distance_upper_bounded (int32_t idx_a, int32_t idx_b, float64_t upper_bound) |
SGMatrix< float64_t > | get_distance_matrix () |
template<class T > | |
SGMatrix< T > | get_distance_matrix () |
int32_t | compute_row_start (int64_t offs, int32_t n, bool symmetric) |
void | load (CFile *loader) |
void | save (CFile *writer) |
CFeatures * | get_lhs () |
CFeatures * | get_rhs () |
CFeatures * | replace_rhs (CFeatures *rhs) |
CFeatures * | replace_lhs (CFeatures *lhs) |
virtual void | remove_lhs_and_rhs () |
virtual void | remove_lhs () |
takes all necessary steps if the lhs is removed from distance matrix 更多... | |
virtual void | remove_rhs () |
takes all necessary steps if the rhs is removed from distance matrix 更多... | |
bool | get_precompute_matrix () |
virtual void | set_precompute_matrix (bool flag) |
virtual int32_t | get_num_vec_lhs () |
virtual int32_t | get_num_vec_rhs () |
virtual bool | has_features () |
bool | lhs_equals_rhs () |
virtual CSGObject * | shallow_copy () const |
virtual CSGObject * | deep_copy () const |
virtual bool | is_generic (EPrimitiveType *generic) const |
template<class T > | |
void | set_generic () |
template<> | |
void | set_generic () |
template<> | |
void | set_generic () |
template<> | |
void | set_generic () |
template<> | |
void | set_generic () |
template<> | |
void | set_generic () |
template<> | |
void | set_generic () |
template<> | |
void | set_generic () |
template<> | |
void | set_generic () |
template<> | |
void | set_generic () |
template<> | |
void | set_generic () |
template<> | |
void | set_generic () |
template<> | |
void | set_generic () |
template<> | |
void | set_generic () |
template<> | |
void | set_generic () |
template<> | |
void | set_generic () |
void | unset_generic () |
virtual void | print_serializable (const char *prefix="") |
virtual bool | save_serializable (CSerializableFile *file, const char *prefix="") |
virtual bool | load_serializable (CSerializableFile *file, const char *prefix="") |
void | set_global_io (SGIO *io) |
SGIO * | get_global_io () |
void | set_global_parallel (Parallel *parallel) |
Parallel * | get_global_parallel () |
void | set_global_version (Version *version) |
Version * | get_global_version () |
SGStringList< char > | get_modelsel_names () |
void | print_modsel_params () |
char * | get_modsel_param_descr (const char *param_name) |
index_t | get_modsel_param_index (const char *param_name) |
void | build_gradient_parameter_dictionary (CMap< TParameter *, CSGObject * > *dict) |
virtual void | update_parameter_hash () |
virtual bool | parameter_hash_changed () |
virtual bool | equals (CSGObject *other, float64_t accuracy=0.0, bool tolerant=false) |
virtual CSGObject * | clone () |
静态 Public 成员函数 | |
template<class T > | |
static void * | get_distance_matrix_helper (void *p) |
Public 属性 | |
SGIO * | io |
Parallel * | parallel |
Version * | version |
Parameter * | m_parameters |
Parameter * | m_model_selection_parameters |
Parameter * | m_gradient_parameters |
uint32_t | m_hash |
Protected 成员函数 | |
virtual float64_t | compute (int32_t idx_a, int32_t idx_b) |
void | do_precompute_matrix () |
matrix precomputation 更多... | |
virtual void | load_serializable_pre () throw (ShogunException) |
virtual void | load_serializable_post () throw (ShogunException) |
virtual void | save_serializable_pre () throw (ShogunException) |
virtual void | save_serializable_post () throw (ShogunException) |
静态 Protected 成员函数 | |
static void * | run_distance_thread (void *p) |
run distance thread 更多... | |
Protected 属性 | |
bool | disable_sqrt |
bool | use_mean |
SGVector< float64_t > | mean |
SGMatrix< float64_t > | icov |
float32_t * | precomputed_matrix |
bool | precompute_matrix |
CFeatures * | lhs |
feature vectors to occur on the left hand side 更多... | |
CFeatures * | rhs |
feature vectors to occur on the right hand side 更多... | |
int32_t | num_lhs |
int32_t | num_rhs |
default constructor
在文件 MahalanobisDistance.cpp 第 24 行定义.
CMahalanobisDistance | ( | CDenseFeatures< float64_t > * | l, |
CDenseFeatures< float64_t > * | r | ||
) |
constructor
l | features of left-hand side |
r | features of right-hand side |
在文件 MahalanobisDistance.cpp 第 29 行定义.
|
virtual |
在文件 MahalanobisDistance.cpp 第 36 行定义.
|
inherited |
Builds a dictionary of all parameters in SGObject as well of those of SGObjects that are parameters of this object. Dictionary maps parameters to the objects that own them.
dict | dictionary of parameters to be built. |
在文件 SGObject.cpp 第 597 行定义.
|
virtual |
|
virtualinherited |
Creates a clone of the current object. This is done via recursively traversing all parameters, which corresponds to a deep copy. Calling equals on the cloned object always returns true although none of the memory of both objects overlaps.
在文件 SGObject.cpp 第 714 行定义.
|
protectedvirtual |
compute Mahalanobis distance between a feature vector of lhs to a feature vector of rhs if use_mean then idx_a is not used and the distance computed is between a feature vector of rhs and the distribution lhs
idx_a | index of the feature vector in lhs |
idx_b | index of the feature vector in rhs |
实现了 CRealDistance.
在文件 MahalanobisDistance.cpp 第 66 行定义.
|
inherited |
compute row start offset for parallel kernel matrix computation
offs | offset |
n | number of columns |
symmetric | whether matrix is symmetric |
在文件 Distance.h 第 144 行定义.
|
virtualinherited |
A deep copy. All the instance variables will also be copied.
在文件 SGObject.cpp 第 198 行定义.
|
virtualinherited |
get distance function for lhs feature vector a and rhs feature vector b
idx_a | feature vector a at idx_a |
idx_b | feature vector b at idx_b |
在文件 Distance.cpp 第 189 行定义.
|
virtualinherited |
get distance function for lhs feature vector a and rhs feature vector b. The computation of the distance stops if the intermediate result is larger than upper_bound. This is useful to use with John Langford's Cover Tree and it is ONLY implemented for Euclidean distance
idx_a | feature vector a at idx_a |
idx_b | feature vector b at idx_b |
upper_bound | value above which the computation halts |
被 CEuclideanDistance 重载.
在文件 Distance.h 第 118 行定义.
|
protectedinherited |
matrix precomputation
在文件 Distance.cpp 第 227 行定义.
Recursively compares the current SGObject to another one. Compares all registered numerical parameters, recursion upon complex (SGObject) parameters. Does not compare pointers!
May be overwritten but please do with care! Should not be necessary in most cases.
other | object to compare with |
accuracy | accuracy to use for comparison (optional) |
tolerant | allows linient check on float equality (within accuracy) |
在文件 SGObject.cpp 第 618 行定义.
|
virtual |
disable application of sqrt on matrix computation the matrix can then also be named norm squared
在文件 MahalanobisDistance.h 第 100 行定义.
|
inherited |
|
staticinherited |
helper for computing the kernel matrix in a parallel way
p | thread parameters |
在文件 Distance.cpp 第 266 行定义.
|
virtual |
get distance type we are
实现了 CRealDistance.
在文件 MahalanobisDistance.h 第 81 行定义.
|
virtualinherited |
get feature class the distance can deal with
实现了 CDistance.
在文件 DenseDistance.h 第 42 行定义.
|
virtual |
get feature type the distance can deal with
重载 CRealDistance .
在文件 MahalanobisDistance.h 第 87 行定义.
|
inherited |
|
inherited |
|
inherited |
|
inherited |
get left-hand side features used in distance matrix
在文件 Distance.h 第 195 行定义.
|
inherited |
在文件 SGObject.cpp 第 498 行定义.
|
inherited |
Returns description of a given parameter string, if it exists. SG_ERROR otherwise
param_name | name of the parameter |
在文件 SGObject.cpp 第 522 行定义.
|
inherited |
Returns index of model selection parameter with provided index
param_name | name of model selection parameter |
在文件 SGObject.cpp 第 535 行定义.
|
virtual |
|
virtualinherited |
get number of vectors of lhs features
被 CCustomDistance 重载.
在文件 Distance.h 第 283 行定义.
|
virtualinherited |
get number of vectors of rhs features
被 CCustomDistance 重载.
在文件 Distance.h 第 292 行定义.
|
inherited |
FIXME: precompute matrix should be dropped, handling should be via customdistance
在文件 Distance.h 第 261 行定义.
|
inherited |
get right-hand side features used in distance matrix
在文件 Distance.h 第 201 行定义.
|
virtual |
whether the distance is computed between the mean and a vector of rhs or between lhs and rhs
在文件 MahalanobisDistance.h 第 114 行定义.
|
virtualinherited |
test whether features have been assigned to lhs and rhs
被 CCustomDistance 重载.
在文件 Distance.h 第 301 行定义.
init distance
l | features of left-hand side |
r | features of right-hand side |
重载 CRealDistance .
在文件 MahalanobisDistance.cpp 第 41 行定义.
|
virtualinherited |
If the SGSerializable is a class template then TRUE will be returned and GENERIC is set to the type of the generic.
generic | set to the type of the generic if returning TRUE |
在文件 SGObject.cpp 第 296 行定义.
|
inherited |
test whether features on lhs and rhs are the same
在文件 Distance.h 第 310 行定义.
|
inherited |
|
virtualinherited |
Load this object from file. If it will fail (returning FALSE) then this object will contain inconsistent data and should not be used!
file | where to load from |
prefix | prefix for members |
在文件 SGObject.cpp 第 369 行定义.
|
protectedvirtualinherited |
Can (optionally) be overridden to post-initialize some member variables which are not PARAMETER::ADD'ed. Make sure that at first the overridden method BASE_CLASS::LOAD_SERIALIZABLE_POST is called.
ShogunException | will be thrown if an error occurs. |
被 CKernel, CWeightedDegreePositionStringKernel, CList, CAlphabet, CLinearHMM, CGaussianKernel, CInverseMultiQuadricKernel, CCircularKernel , 以及 CExponentialKernel 重载.
在文件 SGObject.cpp 第 426 行定义.
|
protectedvirtualinherited |
Can (optionally) be overridden to pre-initialize some member variables which are not PARAMETER::ADD'ed. Make sure that at first the overridden method BASE_CLASS::LOAD_SERIALIZABLE_PRE is called.
ShogunException | will be thrown if an error occurs. |
被 CDynamicArray< T >, CDynamicArray< float64_t >, CDynamicArray< float32_t >, CDynamicArray< int32_t >, CDynamicArray< char >, CDynamicArray< bool > , 以及 CDynamicObjectArray 重载.
在文件 SGObject.cpp 第 421 行定义.
|
virtualinherited |
在文件 SGObject.cpp 第 262 行定义.
|
inherited |
prints all parameter registered for model selection and their type
在文件 SGObject.cpp 第 474 行定义.
|
virtualinherited |
|
virtualinherited |
takes all necessary steps if the lhs is removed from distance matrix
在文件 Distance.cpp 第 130 行定义.
|
virtualinherited |
remove lhs and rhs from distance
在文件 Distance.cpp 第 119 行定义.
|
virtualinherited |
takes all necessary steps if the rhs is removed from distance matrix
takes all necessary steps if the rhs is removed from distance
在文件 Distance.cpp 第 138 行定义.
replace left-hand side features used in distance matrix
make sure to check that your distance can deal with the supplied features (!)
lhs | features of right-hand side |
在文件 Distance.cpp 第 167 行定义.
replace right-hand side features used in distance matrix
make sure to check that your distance can deal with the supplied features (!)
rhs | features of right-hand side |
在文件 Distance.cpp 第 145 行定义.
|
staticprotectedinherited |
run distance thread
|
inherited |
|
virtualinherited |
Save this object to file.
file | where to save the object; will be closed during returning if PREFIX is an empty string. |
prefix | prefix for members |
在文件 SGObject.cpp 第 314 行定义.
|
protectedvirtualinherited |
Can (optionally) be overridden to post-initialize some member variables which are not PARAMETER::ADD'ed. Make sure that at first the overridden method BASE_CLASS::SAVE_SERIALIZABLE_POST is called.
ShogunException | will be thrown if an error occurs. |
被 CKernel 重载.
在文件 SGObject.cpp 第 436 行定义.
|
protectedvirtualinherited |
Can (optionally) be overridden to pre-initialize some member variables which are not PARAMETER::ADD'ed. Make sure that at first the overridden method BASE_CLASS::SAVE_SERIALIZABLE_PRE is called.
ShogunException | will be thrown if an error occurs. |
被 CKernel, CDynamicArray< T >, CDynamicArray< float64_t >, CDynamicArray< float32_t >, CDynamicArray< int32_t >, CDynamicArray< char >, CDynamicArray< bool > , 以及 CDynamicObjectArray 重载.
在文件 SGObject.cpp 第 431 行定义.
|
virtual |
disable application of sqrt on matrix computation the matrix can then also be named norm squared
state | new disable_sqrt |
在文件 MahalanobisDistance.h 第 107 行定义.
|
inherited |
在文件 SGObject.cpp 第 41 行定义.
|
inherited |
在文件 SGObject.cpp 第 46 行定义.
|
inherited |
在文件 SGObject.cpp 第 51 行定义.
|
inherited |
在文件 SGObject.cpp 第 56 行定义.
|
inherited |
在文件 SGObject.cpp 第 61 行定义.
|
inherited |
在文件 SGObject.cpp 第 66 行定义.
|
inherited |
在文件 SGObject.cpp 第 71 行定义.
|
inherited |
在文件 SGObject.cpp 第 76 行定义.
|
inherited |
在文件 SGObject.cpp 第 81 行定义.
|
inherited |
在文件 SGObject.cpp 第 86 行定义.
|
inherited |
在文件 SGObject.cpp 第 91 行定义.
|
inherited |
在文件 SGObject.cpp 第 96 行定义.
|
inherited |
在文件 SGObject.cpp 第 101 行定义.
|
inherited |
在文件 SGObject.cpp 第 106 行定义.
|
inherited |
在文件 SGObject.cpp 第 111 行定义.
|
inherited |
set generic type to T
|
inherited |
|
inherited |
|
inherited |
|
virtualinherited |
FIXME: precompute matrix should be dropped, handling should be via customdistance
flag | if precompute_matrix |
在文件 Distance.h 第 268 行定义.
|
virtual |
whether the distance is computed between the mean and a vector of rhs or between lhs and rhs
state | new use_mean |
在文件 MahalanobisDistance.h 第 121 行定义.
|
virtualinherited |
A shallow copy. All the SGObject instance variables will be simply assigned and SG_REF-ed.
被 CGaussianKernel 重载.
在文件 SGObject.cpp 第 192 行定义.
|
inherited |
unset generic type
this has to be called in classes specializing a template class
在文件 SGObject.cpp 第 303 行定义.
|
virtualinherited |
Updates the hash of current parameter combination
在文件 SGObject.cpp 第 248 行定义.
|
protected |
if application of sqrt on matrix computation is disabled
在文件 MahalanobisDistance.h 第 140 行定义.
inverse of the covariance matrix of lhs feature vectors
在文件 MahalanobisDistance.h 第 148 行定义.
|
inherited |
io
在文件 SGObject.h 第 369 行定义.
|
protectedinherited |
feature vectors to occur on the left hand side
在文件 Distance.h 第 343 行定义.
|
inherited |
parameters wrt which we can compute gradients
在文件 SGObject.h 第 384 行定义.
|
inherited |
Hash of parameter values
在文件 SGObject.h 第 387 行定义.
|
inherited |
model selection parameters
在文件 SGObject.h 第 381 行定义.
|
inherited |
parameters
在文件 SGObject.h 第 378 行定义.
vector mean of the lhs feature vectors
在文件 MahalanobisDistance.h 第 146 行定义.
|
protectedinherited |
number of feature vectors on the left hand side
在文件 Distance.h 第 348 行定义.
|
protectedinherited |
number of feature vectors on the right hand side
在文件 Distance.h 第 350 行定义.
|
inherited |
parallel
在文件 SGObject.h 第 372 行定义.
|
protectedinherited |
FIXME: precompute matrix should be dropped, handling should be via customdistance
在文件 Distance.h 第 340 行定义.
|
protectedinherited |
FIXME: precompute matrix should be dropped, handling should be via customdistance
在文件 Distance.h 第 335 行定义.
|
protectedinherited |
feature vectors to occur on the right hand side
在文件 Distance.h 第 345 行定义.
|
protected |
whether the features lhs and rhs have exactly the same values
在文件 MahalanobisDistance.h 第 143 行定义.
|
inherited |
version
在文件 SGObject.h 第 375 行定义.