LArSoft
v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
|
SupportVectorMachine class. More...
#include "LArSupportVectorMachine.h"
Classes | |
class | FeatureInfo |
FeatureInfo class. More... | |
class | SupportVectorInfo |
SupportVectorInfo class. More... | |
Public Types | |
enum | KernelType { USER_DEFINED = 0, LINEAR = 1, QUADRATIC = 2, CUBIC = 3, GAUSSIAN_RBF = 4 } |
KernelType enum. More... | |
typedef std::function< double(const LArMvaHelper::MvaFeatureVector &, const LArMvaHelper::MvaFeatureVector &, const double)> | KernelFunction |
Public Member Functions | |
SupportVectorMachine () | |
Default constructor. More... | |
pandora::StatusCode | Initialize (const std::string ¶meterLocation, const std::string &svmName) |
Initialize the svm using a serialized model. More... | |
bool | Classify (const LArMvaHelper::MvaFeatureVector &features) const |
Make a classification for a set of input features, based on the trained model. More... | |
double | CalculateClassificationScore (const LArMvaHelper::MvaFeatureVector &features) const |
Calculate the classification score for a set of input features, based on the trained model. More... | |
double | CalculateProbability (const LArMvaHelper::MvaFeatureVector &features) const |
Calculate the classification probability for a set of input features, based on the trained model. More... | |
bool | IsInitialized () const |
Query whether this svm is initialized. More... | |
unsigned int | GetNFeatures () const |
Get the number of features. More... | |
void | SetKernelFunction (KernelFunction kernelFunction) |
Set the kernel function to use. More... | |
Private Types | |
typedef std::vector< SupportVectorInfo > | SVInfoList |
typedef std::vector< FeatureInfo > | FeatureInfoVector |
typedef std::map< KernelType, KernelFunction > | KernelMap |
Private Member Functions | |
void | ReadXmlFile (const std::string &svmFileName, const std::string &svmName) |
Read the svm parameters from an xml file. More... | |
pandora::StatusCode | ReadComponent (pandora::TiXmlElement *pCurrentXmlElement) |
Read the component at the current xml element. More... | |
pandora::StatusCode | ReadMachine (const pandora::TiXmlHandle ¤tHandle) |
Read the machine component at the current xml handle. More... | |
pandora::StatusCode | ReadFeatures (const pandora::TiXmlHandle ¤tHandle) |
Read the feature component at the current xml handle. More... | |
pandora::StatusCode | ReadSupportVector (const pandora::TiXmlHandle ¤tHandle) |
Read the support vector component at the current xml handle. More... | |
double | CalculateClassificationScoreImpl (const LArMvaHelper::MvaFeatureVector &features) const |
Implementation method for calculating the classification score using the trained model. More... | |
Static Private Member Functions | |
static double | QuadraticKernel (const LArMvaHelper::MvaFeatureVector &supportVector, const LArMvaHelper::MvaFeatureVector &features, const double scaleFactor=1.) |
An inhomogeneous quadratic kernel. More... | |
static double | CubicKernel (const LArMvaHelper::MvaFeatureVector &supportVector, const LArMvaHelper::MvaFeatureVector &features, const double scaleFactor=1.) |
An inhomogeneous cubic kernel. More... | |
static double | LinearKernel (const LArMvaHelper::MvaFeatureVector &supportVector, const LArMvaHelper::MvaFeatureVector &features, const double scaleFactor=1.) |
A linear kernel. More... | |
static double | GaussianRbfKernel (const LArMvaHelper::MvaFeatureVector &supportVector, const LArMvaHelper::MvaFeatureVector &features, const double scaleFactor=1.) |
A gaussian RBF kernel. More... | |
Private Attributes | |
bool | m_isInitialized |
Whether this svm has been initialized. More... | |
bool | m_enableProbability |
Whether to enable probability calculations. More... | |
double | m_probAParameter |
The first-order score coefficient for mapping to a probability using the logistic function. More... | |
double | m_probBParameter |
The score offset parameter for mapping to a probability using the logistic function. More... | |
bool | m_standardizeFeatures |
Whether to standardize the features. More... | |
unsigned int | m_nFeatures |
The number of features. More... | |
double | m_bias |
The bias term. More... | |
double | m_scaleFactor |
The kernel scale factor. More... | |
SVInfoList | m_svInfoList |
The list of SupportVectorInfo objects. More... | |
FeatureInfoVector | m_featureInfoList |
The list of FeatureInfo objects. More... | |
KernelType | m_kernelType |
The kernel type. More... | |
KernelFunction | m_kernelFunction |
The kernel function. More... | |
KernelMap | m_kernelMap |
Map from the kernel types to the kernel functions. More... | |
SupportVectorMachine class.
Definition at line 30 of file LArSupportVectorMachine.h.
|
private |
Definition at line 162 of file LArSupportVectorMachine.h.
typedef std::function<double(const LArMvaHelper::MvaFeatureVector &, const LArMvaHelper::MvaFeatureVector &, const double)> lar_content::SupportVectorMachine::KernelFunction |
Definition at line 33 of file LArSupportVectorMachine.h.
|
private |
Definition at line 164 of file LArSupportVectorMachine.h.
|
private |
Definition at line 161 of file LArSupportVectorMachine.h.
KernelType enum.
Enumerator | |
---|---|
USER_DEFINED | |
LINEAR | |
QUADRATIC | |
CUBIC | |
GAUSSIAN_RBF |
Definition at line 38 of file LArSupportVectorMachine.h.
lar_content::SupportVectorMachine::SupportVectorMachine | ( | ) |
Default constructor.
Definition at line 18 of file LArSupportVectorMachine.cc.
References CUBIC, CubicKernel(), GAUSSIAN_RBF, GaussianRbfKernel(), LINEAR, LinearKernel(), QUADRATIC, and QuadraticKernel().
|
inlinevirtual |
Calculate the classification score for a set of input features, based on the trained model.
features | the input features |
Implements lar_content::MvaInterface.
Definition at line 295 of file LArSupportVectorMachine.h.
References CalculateClassificationScoreImpl().
|
private |
Implementation method for calculating the classification score using the trained model.
features | the vector of features |
Definition at line 250 of file LArSupportVectorMachine.cc.
References m_bias, m_featureInfoList, m_isInitialized, m_kernelFunction, m_nFeatures, m_scaleFactor, m_standardizeFeatures, and m_svInfoList.
Referenced by CalculateClassificationScore(), CalculateProbability(), and Classify().
|
inlinevirtual |
Calculate the classification probability for a set of input features, based on the trained model.
features | the input features |
Implements lar_content::MvaInterface.
Definition at line 302 of file LArSupportVectorMachine.h.
References CalculateClassificationScoreImpl(), m_enableProbability, m_probAParameter, and m_probBParameter.
|
inlinevirtual |
Make a classification for a set of input features, based on the trained model.
features | the input features |
Implements lar_content::MvaInterface.
Definition at line 288 of file LArSupportVectorMachine.h.
References CalculateClassificationScoreImpl().
|
inlinestaticprivate |
An inhomogeneous cubic kernel.
supportVector | the support vector |
features | the features |
scale | factor the scale factor |
Definition at line 373 of file LArSupportVectorMachine.h.
Referenced by SupportVectorMachine().
|
inlinestaticprivate |
A gaussian RBF kernel.
supportVector | the support vector |
features | the features |
scale | factor the scale factor |
Definition at line 390 of file LArSupportVectorMachine.h.
Referenced by SupportVectorMachine().
|
inline |
Get the number of features.
Definition at line 326 of file LArSupportVectorMachine.h.
References m_nFeatures.
StatusCode lar_content::SupportVectorMachine::Initialize | ( | const std::string & | parameterLocation, |
const std::string & | svmName | ||
) |
Initialize the svm using a serialized model.
parameterLocation | the location of the model |
svmName | the name of the model |
Definition at line 35 of file LArSupportVectorMachine.cc.
References m_featureInfoList, m_isInitialized, m_nFeatures, m_scaleFactor, m_standardizeFeatures, m_svInfoList, and ReadXmlFile().
|
inline |
Query whether this svm is initialized.
Definition at line 319 of file LArSupportVectorMachine.h.
References m_isInitialized.
|
inlinestaticprivate |
A linear kernel.
supportVector | the support vector |
features | the features |
scale | factor the scale factor |
Definition at line 340 of file LArSupportVectorMachine.h.
Referenced by SupportVectorMachine().
|
inlinestaticprivate |
An inhomogeneous quadratic kernel.
supportVector | the support vector |
features | the features |
scale | factor the scale factor |
Definition at line 356 of file LArSupportVectorMachine.h.
Referenced by SupportVectorMachine().
|
private |
Read the component at the current xml element.
pCurrentXmlElement | address of the current xml element |
Definition at line 143 of file LArSupportVectorMachine.cc.
References ReadFeatures(), ReadMachine(), and ReadSupportVector().
Referenced by ReadXmlFile().
|
private |
Read the feature component at the current xml handle.
currentHandle | the current xml handle |
Definition at line 204 of file LArSupportVectorMachine.cc.
References m_featureInfoList.
Referenced by ReadComponent().
|
private |
Read the machine component at the current xml handle.
currentHandle | the current xml handle |
Definition at line 165 of file LArSupportVectorMachine.cc.
References m_bias, m_enableProbability, m_kernelFunction, m_kernelMap, m_kernelType, m_probAParameter, m_probBParameter, m_scaleFactor, and USER_DEFINED.
Referenced by ReadComponent().
|
private |
Read the support vector component at the current xml handle.
currentHandle | the current xml handle |
Definition at line 232 of file LArSupportVectorMachine.cc.
References m_svInfoList, value, and util::values().
Referenced by ReadComponent().
|
private |
Read the svm parameters from an xml file.
svmFileName | the sml file name |
svmName | the name of the svm |
Definition at line 83 of file LArSupportVectorMachine.cc.
References ReadComponent().
Referenced by Initialize().
|
inline |
Set the kernel function to use.
kernelFunction | the kernel function |
Definition at line 333 of file LArSupportVectorMachine.h.
References m_kernelFunction.
|
private |
The bias term.
Definition at line 174 of file LArSupportVectorMachine.h.
Referenced by CalculateClassificationScoreImpl(), and ReadMachine().
|
private |
Whether to enable probability calculations.
Definition at line 168 of file LArSupportVectorMachine.h.
Referenced by CalculateProbability(), and ReadMachine().
|
private |
The list of FeatureInfo objects.
Definition at line 178 of file LArSupportVectorMachine.h.
Referenced by CalculateClassificationScoreImpl(), Initialize(), and ReadFeatures().
|
private |
Whether this svm has been initialized.
Definition at line 166 of file LArSupportVectorMachine.h.
Referenced by CalculateClassificationScoreImpl(), Initialize(), and IsInitialized().
|
private |
The kernel function.
Definition at line 181 of file LArSupportVectorMachine.h.
Referenced by CalculateClassificationScoreImpl(), ReadMachine(), and SetKernelFunction().
|
private |
Map from the kernel types to the kernel functions.
Definition at line 182 of file LArSupportVectorMachine.h.
Referenced by ReadMachine().
|
private |
The kernel type.
Definition at line 180 of file LArSupportVectorMachine.h.
Referenced by ReadMachine().
|
private |
The number of features.
Definition at line 173 of file LArSupportVectorMachine.h.
Referenced by CalculateClassificationScoreImpl(), GetNFeatures(), and Initialize().
|
private |
The first-order score coefficient for mapping to a probability using the logistic function.
Definition at line 169 of file LArSupportVectorMachine.h.
Referenced by CalculateProbability(), and ReadMachine().
|
private |
The score offset parameter for mapping to a probability using the logistic function.
Definition at line 170 of file LArSupportVectorMachine.h.
Referenced by CalculateProbability(), and ReadMachine().
|
private |
The kernel scale factor.
Definition at line 175 of file LArSupportVectorMachine.h.
Referenced by CalculateClassificationScoreImpl(), Initialize(), and ReadMachine().
|
private |
Whether to standardize the features.
Definition at line 172 of file LArSupportVectorMachine.h.
Referenced by CalculateClassificationScoreImpl(), and Initialize().
|
private |
The list of SupportVectorInfo objects.
Definition at line 177 of file LArSupportVectorMachine.h.
Referenced by CalculateClassificationScoreImpl(), Initialize(), and ReadSupportVector().