Commit 0a38e128 authored by Serrière Guillaume's avatar Serrière Guillaume

Processor box set correctly the header of its outputs.

Signed-off-by: default avatarSerrière Guillaume <guillaume.serriere@inria.fr>
parent 4081e4fa
......@@ -70,9 +70,28 @@ void CAlgorithmClassifierLDA::dumpMatrix(OpenViBE::Kernel::ILogManager &rMgr, co
}
}
#else
void CAlgorithmClassifierLDA::dumpMatrix(OpenViBE::Kernel::ILogManager& /* rMgr */, const MatrixXdRowMajor& /*mat*/, const CString& /*desc*/) { };
void CAlgorithmClassifierLDA::dumpMatrix(OpenViBE::Kernel::ILogManager& /* rMgr */, const MatrixXdRowMajor& /*mat*/, const CString& /*desc*/) { }
#endif
uint32 CAlgorithmClassifierLDA::getOutputProbabilityVectorLength()
{
if(m_bv1Classification){
return 1;
} else{
return m_vDiscriminantFunctions.size();
}
}
uint32 CAlgorithmClassifierLDA::getOutputDistanceVectorLength()
{
if(m_bv1Classification){
return 1;
} else{
return m_vDiscriminantFunctions.size();
}
}
boolean CAlgorithmClassifierLDA::initialize(void)
{
m_bv1Classification = false;
......@@ -348,7 +367,7 @@ boolean CAlgorithmClassifierLDA::classify(const IFeatureVector& rFeatureVector,
// with aj = (Weight for class j).transpose() * x + (Bias for class j)
//Exponential can lead to nan results, so we reduce the computation and instead compute
// p(Ck | x) = 1 / sum[j](exp(aj) - exp(ak))
// p(Ck | x) = 1 / sum[j](exp(aj - ak))
//All ak are given by computation helper
for(size_t i = 0 ; i < l_ui32ClassCount ; ++i)
......@@ -436,6 +455,7 @@ boolean CAlgorithmClassifierLDA::loadConfiguration(XML::IXMLNode *pConfiguration
}
m_vLabelList.clear();
m_vDiscriminantFunctions.clear();
XML::IXMLNode* l_pTempNode;
......@@ -481,6 +501,7 @@ boolean CAlgorithmClassifierLDA::loadConfiguration(XML::IXMLNode *pConfiguration
m_vDiscriminantFunctions.push_back(CAlgorithmLDADiscriminantFunction());
m_vDiscriminantFunctions[i].loadConfiguration(l_pConfigsNode->getChild(i));
}
}
return true;
}
......
#ifndef __OpenViBEPlugins_Algorithm_ClassifierLDA_H__
#define __OpenViBEPlugins_Algorithm_ClassifierLDA_H__
#if defined TARGET_HAS_ThirdPartyEIGEN
#include "../ovp_defines.h"
#include "ovpCAlgorithmLDADiscriminantFunction.h"
#include <openvibe/ov_all.h>
#include <toolkit/ovtk_all.h>
#if defined TARGET_HAS_ThirdPartyEIGEN
#include <xml/IXMLNode.h>
#include <stack>
......@@ -49,6 +49,9 @@ namespace OpenViBEPlugins
virtual XML::IXMLNode* saveConfiguration(void);
virtual OpenViBE::boolean loadConfiguration(XML::IXMLNode *pConfigurationNode);
virtual OpenViBE::uint32 getOutputProbabilityVectorLength();
virtual OpenViBE::uint32 getOutputDistanceVectorLength();
_IsDerivedFromClass_Final_(CAlgorithmClassifier, OVP_ClassId_Algorithm_ClassifierLDA);
protected:
......
#if defined TARGET_HAS_ThirdPartyEIGEN
#include "ovpCAlgorithmClassifierMLP.h"
#include <map>
......@@ -544,3 +546,14 @@ void CAlgorithmClassifierMLP::loadData(XML::IXMLNode *pNode, float64 &f64Value)
std::stringstream l_sData(pNode->getPCData());
l_sData >> f64Value;
}
uint32 CAlgorithmClassifierMLP::getOutputProbabilityVectorLength()
{
return m_oLabelList.size();
}
uint32 CAlgorithmClassifierMLP::getOutputDistanceVectorLength()
{
return m_oLabelList.size();
}
#endif
#ifndef __OpenViBEPlugins_Algorithm_ClassifierMLP_H__
#define __OpenViBEPlugins_Algorithm_ClassifierMLP_H__
#if defined TARGET_HAS_ThirdPartyEIGEN
#include "../ovp_defines.h"
#include <openvibe/ov_all.h>
#include <toolkit/ovtk_all.h>
......@@ -41,6 +43,9 @@ namespace OpenViBEPlugins
virtual XML::IXMLNode* saveConfiguration(void);
virtual OpenViBE::boolean loadConfiguration(XML::IXMLNode *pConfigurationNode);
virtual OpenViBE::uint32 getOutputProbabilityVectorLength();
virtual OpenViBE::uint32 getOutputDistanceVectorLength();
_IsDerivedFromClass_Final_(CAlgorithmClassifier, OVP_ClassId_Algorithm_ClassifierMLP)
protected:
......@@ -104,6 +109,7 @@ namespace OpenViBEPlugins
};
}
}
#endif // TARGET_HAS_ThirdPartyEIGEN
#endif // __OpenViBEPlugins_Algorithm_ClassifierMLP_H__
......
......@@ -76,3 +76,13 @@ boolean CAlgorithmClassifierNULL::loadConfiguration(XML::IXMLNode *pConfiguratio
{
return true;
}
uint32 CAlgorithmClassifierNULL::getOutputProbabilityVectorLength()
{
return 1;
}
uint32 CAlgorithmClassifierNULL::getOutputDistanceVectorLength()
{
return 1;
}
......@@ -35,9 +35,14 @@ namespace OpenViBEPlugins
virtual XML::IXMLNode* saveConfiguration(void);
virtual OpenViBE::boolean loadConfiguration(XML::IXMLNode *pConfigurationNode);
virtual OpenViBE::uint32 getOutputProbabilityVectorLength();
virtual OpenViBE::uint32 getOutputDistanceVectorLength();
_IsDerivedFromClass_Final_(CAlgorithmClassifier, OVP_ClassId_Algorithm_ClassifierNULL);
protected:
};
class CAlgorithmClassifierNULLDesc : public OpenViBEToolkit::CAlgorithmClassifierDesc
......
......@@ -341,6 +341,18 @@ boolean CAlgorithmClassifierOneVsAll::loadConfiguration(XML::IXMLNode *pConfigur
return loadSubClassifierConfiguration(pConfigurationNode->getChildByName(c_sSubClassifiersNodeName));
}
uint32 CAlgorithmClassifierOneVsAll::getOutputProbabilityVectorLength()
{
TParameterHandler < IMatrix* > op_pProbabilityValues(m_oSubClassifierList[0]->getOutputParameter(OVTK_Algorithm_Classifier_OutputParameterId_ProbabilityValues));
return op_pProbabilityValues->getDimensionSize(0);
}
uint32 CAlgorithmClassifierOneVsAll::getOutputDistanceVectorLength()
{
TParameterHandler < IMatrix* > op_pDistanceValues(m_oSubClassifierList[0]->getOutputParameter(OVTK_Algorithm_Classifier_OutputParameterId_ClassificationValues));
return op_pDistanceValues->getDimensionSize(0);
}
boolean CAlgorithmClassifierOneVsAll::loadSubClassifierConfiguration(XML::IXMLNode *pSubClassifiersNode)
{
for( size_t i = 0; i < pSubClassifiersNode->getChildCount() ; ++i)
......
......@@ -32,8 +32,14 @@ namespace OpenViBEPlugins
virtual XML::IXMLNode* saveConfiguration(void);
virtual OpenViBE::boolean loadConfiguration(XML::IXMLNode *pConfigurationNode);
virtual OpenViBE::uint32 getOutputProbabilityVectorLength();
virtual OpenViBE::uint32 getOutputDistanceVectorLength();
_IsDerivedFromClass_Final_(OpenViBEToolkit::CAlgorithmPairingStrategy, OVP_ClassId_Algorithm_ClassifierOneVsAll)
protected:
private:
XML::IXMLNode* getClassifierConfiguration(OpenViBE::Kernel::IAlgorithmProxy* classifier);
OpenViBE::boolean addNewClassifierAtBack(void);
......
......@@ -459,6 +459,16 @@ boolean CAlgorithmClassifierOneVsOne::loadConfiguration(XML::IXMLNode *pConfigur
return loadSubClassifierConfiguration(pConfigurationNode->getChildByName(c_sSubClassifiersNodeName));
}
uint32 CAlgorithmClassifierOneVsOne::getOutputProbabilityVectorLength()
{
return this->getClassCount();
}
uint32 CAlgorithmClassifierOneVsOne::getOutputDistanceVectorLength()
{
return 0;
}
boolean CAlgorithmClassifierOneVsOne::loadSubClassifierConfiguration(XML::IXMLNode *pSubClassifiersNode)
{
for(size_t i = 0; i < pSubClassifiersNode->getChildCount() ; ++i)
......
......@@ -56,8 +56,14 @@ namespace OpenViBEPlugins
virtual XML::IXMLNode* saveConfiguration(void);
virtual OpenViBE::boolean loadConfiguration(XML::IXMLNode *pConfigurationNode);
virtual OpenViBE::uint32 getOutputProbabilityVectorLength();
virtual OpenViBE::uint32 getOutputDistanceVectorLength();
_IsDerivedFromClass_Final_(OpenViBEToolkit::CAlgorithmPairingStrategy, OVP_ClassId_Algorithm_ClassifierOneVsOne)
protected:
private:
std::vector<SSubClassifierDescriptor> m_oSubClassifierDescriptorList;
fClassifierComparison m_fAlgorithmComparison;
......
......@@ -893,3 +893,13 @@ CString CAlgorithmClassifierSVM::problemToString(svm_problem *pProb)
return CString(l_sProb.str().c_str());
}
uint32 CAlgorithmClassifierSVM::getOutputProbabilityVectorLength()
{
return 1;
}
uint32 CAlgorithmClassifierSVM::getOutputDistanceVectorLength()
{
return 0;
}
......@@ -60,9 +60,13 @@ namespace OpenViBEPlugins
virtual OpenViBE::CString modelToString();
virtual OpenViBE::CString problemToString(svm_problem *pProb);
virtual OpenViBE::uint32 getOutputProbabilityVectorLength();
virtual OpenViBE::uint32 getOutputDistanceVectorLength();
_IsDerivedFromClass_Final_(CAlgorithmClassifier, OVP_ClassId_Algorithm_ClassifierSVM);
protected:
std::vector <OpenViBE::float64> m_vClass;
struct svm_parameter m_oParam;
......
......@@ -53,6 +53,9 @@ namespace OpenViBEToolkit
virtual XML::IXMLNode* saveConfiguration(void)=0;
virtual OpenViBE::boolean loadConfiguration(XML::IXMLNode * pConfigurationRoot)=0;
virtual OpenViBE::uint32 getOutputProbabilityVectorLength(void) =0;
virtual OpenViBE::uint32 getOutputDistanceVectorLength(void) =0;
_IsDerivedFromClass_(OpenViBEToolkit::TAlgorithm < OpenViBE::Plugins::IAlgorithm >, OVTK_ClassId_Algorithm_Classifier);
protected:
......@@ -67,6 +70,7 @@ namespace OpenViBEToolkit
private:
OpenViBE::CString& getParameterValue(const OpenViBE::CIdentifier& rParameterIdentifier);
void setMatrixOutputDimension(OpenViBE::Kernel::TParameterHandler < OpenViBE::IMatrix* > &rMatrix, OpenViBE::uint32 ui32Length);
OpenViBE::Kernel::IAlgorithmProxy *m_pAlgorithmProxy;
void* m_pExtraParameter;
......
......@@ -46,6 +46,9 @@ namespace OpenViBEToolkit
virtual OpenViBE::boolean loadConfiguration(XML::IXMLNode* pConfiguratioNode)=0;
_IsDerivedFromClass_(CAlgorithmClassifier, OVTK_ClassId_Algorithm_PairingStrategy)
virtual OpenViBE::uint32 getOutputProbabilityVectorLength(void) =0;
virtual OpenViBE::uint32 getOutputDistanceVectorLength(void) =0;
protected:
// std::vector <OpenViBE::float64> m_fClasses;
......
......@@ -135,6 +135,9 @@ boolean CAlgorithmClassifier::process(void)
if(this->loadConfiguration(l_pNode))
{
this->activateOutputTrigger(OVTK_Algorithm_Classifier_OutputTriggerId_Success, true);
//Now we need to parametrize the two output Matrix for values
setMatrixOutputDimension(op_pProbabilityValues, this->getOutputProbabilityVectorLength());
setMatrixOutputDimension(op_pClassificationValues, this->getOutputDistanceVectorLength());
}
else
{
......@@ -173,6 +176,12 @@ CString& CAlgorithmClassifier::getParameterValue(const CIdentifier &rParameterId
return (*static_cast<std::map<CString, CString>* >(m_pExtraParameter))[l_pParameterName];
}
void CAlgorithmClassifier::setMatrixOutputDimension(TParameterHandler<IMatrix*> &rMatrix, uint32 ui32Length)
{
rMatrix->setDimensionCount(1);
rMatrix->setDimensionSize(0, ui32Length);
}
int64 CAlgorithmClassifier::getInt64Parameter(const CIdentifier &rParameterIdentifier)
{
TParameterHandler < int64 > ip_i64Temp(getInputParameter(rParameterIdentifier));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment