Commit ac340625 authored by Jussi Lindgren's avatar Jussi Lindgren
Browse files

Merge branch 'wip-gserrier-final' of git+ssh://scm.gforge.inria.fr//gitroot/openvibe/openvibe

parents b50e47b8 560a8952
......@@ -1278,6 +1278,7 @@ boolean CInterfacedScenario::pickInterfacedObject(int x, int y, int iSizeX, int
return l_bRes;
}
//Fixme: this attribute is part of the saving process. That should not be the case.
#define OV_ClassId_Selected OpenViBE::CIdentifier(0xC67A01DC, 0x28CE06C1)
void CInterfacedScenario::undoCB(boolean bManageModifiedStatusFlag)
......
......@@ -35,7 +35,7 @@ OpenViBE::int32 OpenViBEPlugins::Classification::LDAClassificationCompare(OpenVi
const OpenViBE::float64 l_f64MaxSecond = *(std::max_element(l_pClassificationValueBuffer, l_pClassificationValueBuffer+rSecondClassificationValue.getBufferElementCount()));
//Then we just compared them
if(!ov_float_equal(l_f64MaxFirst, l_f64MaxSecond))
if(ov_float_equal(l_f64MaxFirst, l_f64MaxSecond))
{
return 0;
}
......@@ -229,6 +229,9 @@ boolean CAlgorithmClassifierLDA::train(const IFeatureVectorSet& rFeatureVectorSe
// Compute cov
if(!m_pCovarianceAlgorithm->process()) {
this->getLogManager() << LogLevel_Error << "Global covariance computation failed\n";
//Free memory before leaving
delete[] l_oPerClassMeans;
return false;
}
......@@ -339,7 +342,7 @@ boolean CAlgorithmClassifierLDA::classify(const IFeatureVector& rFeatureVector,
}
else
{
if(m_vDiscriminantFunctions.size() == 0)
if(m_vDiscriminantFunctions.empty())
{
this->getLogManager() << LogLevel_Error << "LDA discriminant function list is empty\n";
return false;
......@@ -393,8 +396,8 @@ boolean CAlgorithmClassifierLDA::classify(const IFeatureVector& rFeatureVector,
}
rf64Class = m_vLabelList[l_ui32ClassIndex];
delete l_pValueArray;
delete l_pProbabilityValue;
delete[] l_pValueArray;
delete[] l_pProbabilityValue;
}
return true;
}
......
......@@ -43,7 +43,7 @@ OpenViBE::int32 OpenViBEPlugins::Classification::MLPClassificationCompare(OpenVi
OpenViBE::float64 l_f64MaxSecond = *(std::max_element(l_pClassificationValueBuffer, l_pClassificationValueBuffer+rSecondClassificationValue.getBufferElementCount()));
//Then we just compared them
if(!ov_float_equal(l_f64MaxFirst, l_f64MaxSecond))
if(ov_float_equal(l_f64MaxFirst, l_f64MaxSecond))
{
return 0;
}
......
......@@ -148,7 +148,7 @@ boolean CAlgorithmClassifierOneVsAll::classify(const IFeatureVector& rFeatureVec
{
l_oClassificationVector.push_back(CClassifierOutput(static_cast<float64>(op_f64ClassificationStateClass), static_cast<IMatrix*>(op_pClassificationValues)));
}
//this->getLogManager() << LogLevel_Info << l_iClassifierCounter << " " << (float64)op_f64ClassificationStateClass << " " << (*op_pClassificationValues)[0] << "\n";
this->getLogManager() << LogLevel_Debug << l_iClassifierCounter << " " << (float64)op_f64ClassificationStateClass << " " << (*op_pProbabilityValues)[0] << " " << (*op_pProbabilityValues)[1] << "\n";
}
//Now, we determine the best classification
......@@ -167,7 +167,7 @@ boolean CAlgorithmClassifierOneVsAll::classify(const IFeatureVector& rFeatureVec
}
else
{
if((*m_fAlgorithmComparison)((*l_oBest.second), *(l_pTemp.second)) < 0)
if((*m_fAlgorithmComparison)((*l_oBest.second), *(l_pTemp.second)) > 0)
{
l_oBest = l_pTemp;
rf64Class = l_iClassificationCount+1;
......@@ -179,6 +179,7 @@ boolean CAlgorithmClassifierOneVsAll::classify(const IFeatureVector& rFeatureVec
//If no one recognize the class, let's take the more relevant
if(rf64Class == -1)
{
this->getLogManager() << LogLevel_Debug << "Unable to find a class in first instance\n";
for(uint32 l_iClassificationCount = 0; l_iClassificationCount < l_oClassificationVector.size() ; ++l_iClassificationCount)
{
CClassifierOutput& l_pTemp = l_oClassificationVector[l_iClassificationCount];
......@@ -190,7 +191,7 @@ boolean CAlgorithmClassifierOneVsAll::classify(const IFeatureVector& rFeatureVec
else
{
//We take the one that is the least like the second class
if((*m_fAlgorithmComparison)((*l_oBest.second), *(l_pTemp.second)) > 0)
if((*m_fAlgorithmComparison)((*l_oBest.second), *(l_pTemp.second)) < 0)
{
l_oBest = l_pTemp;
rf64Class = l_iClassificationCount+1;
......
......@@ -36,7 +36,7 @@ extern const char* const c_sClassifierRoot;
OpenViBE::int32 OpenViBEPlugins::Classification::SVMClassificationCompare(OpenViBE::IMatrix& rFirstClassificationValue, OpenViBE::IMatrix& rSecondClassificationValue)
{
if(ov_float_equal(rFirstClassificationValue[0], ::fabs(rSecondClassificationValue[0])))
if(ov_float_equal(::fabs(rFirstClassificationValue[0]), ::fabs(rSecondClassificationValue[0])))
return 0;
else if(::fabs(rFirstClassificationValue[0]) > ::fabs(rSecondClassificationValue[0]))
return -1;
......
#include "ovpCBoxAlgorithmClassifierProcessor.h"
#include <fstream>
#include <iostream>
#include <sstream>
#include <xml/IXMLHandler.h>
......@@ -17,12 +15,15 @@ using namespace std;
boolean CBoxAlgorithmClassifierProcessor::initialize(void)
{
m_pFeaturesDecoder = NULL;
m_pLabelsEncoder = NULL;
m_pClassificationStateEncoder = NULL;
m_pProbabilityValues=NULL;
m_pClassifier = NULL;
m_oFeatureVectorDecoder.initialize(*this, 0);
m_oLabelsEncoder.initialize(*this, 0);
m_oHyperplanValuesEncoder.initialize(*this, 1);
m_oProbabilitiesValuesEncoder.initialize(*this, 2);
IBox& l_rStaticBoxContext=this->getStaticBoxContext();
//First of all, let's get the XML file for configuration
......@@ -125,15 +126,6 @@ boolean CBoxAlgorithmClassifierProcessor::initialize(void)
this->getLogManager() << LogLevel_Warning << "The configuration file had no node " << c_sStimulationsNodeName << ". Trouble may appear later.\n";
}
m_pFeaturesDecoder=&this->getAlgorithmManager().getAlgorithm(this->getAlgorithmManager().createAlgorithm(OVP_GD_ClassId_Algorithm_FeatureVectorStreamDecoder));
m_pFeaturesDecoder->initialize();
m_pLabelsEncoder=&this->getAlgorithmManager().getAlgorithm(this->getAlgorithmManager().createAlgorithm(OVP_GD_ClassId_Algorithm_StimulationStreamEncoder));
m_pLabelsEncoder->initialize();
m_pClassificationStateEncoder=&this->getAlgorithmManager().getAlgorithm(this->getAlgorithmManager().createAlgorithm(OVP_GD_ClassId_Algorithm_StreamedMatrixStreamEncoder));
m_pClassificationStateEncoder->initialize();
const CIdentifier l_oClassifierAlgorithmIdentifier = this->getAlgorithmManager().createAlgorithm(l_oAlgorithmClassIdentifier);
if(l_oClassifierAlgorithmIdentifier == OV_UndefinedIdentifier)
{
......@@ -145,14 +137,11 @@ boolean CBoxAlgorithmClassifierProcessor::initialize(void)
m_pClassifier=&this->getAlgorithmManager().getAlgorithm(l_oClassifierAlgorithmIdentifier);
m_pClassifier->initialize();
m_pProbabilityValues=&this->getAlgorithmManager().getAlgorithm(this->getAlgorithmManager().createAlgorithm(OVP_GD_ClassId_Algorithm_StreamedMatrixStreamEncoder));
m_pProbabilityValues->initialize();
TParameterHandler < IMatrix* > ip_pClassifierStimulationSet(m_pClassifier->getInputParameter(OVTK_Algorithm_Classifier_InputParameterId_FeatureVector));
ip_pClassifierStimulationSet.setReferenceTarget(m_oFeatureVectorDecoder.getOutputMatrix());
m_pClassifier->getInputParameter(OVTK_Algorithm_Classifier_InputParameterId_FeatureVector)->setReferenceTarget(m_pFeaturesDecoder->getOutputParameter(OVP_GD_Algorithm_FeatureVectorStreamDecoder_OutputParameterId_Matrix));
m_pClassificationStateEncoder->getInputParameter(OVP_GD_Algorithm_StreamedMatrixStreamEncoder_InputParameterId_Matrix)->setReferenceTarget(m_pClassifier->getOutputParameter(OVTK_Algorithm_Classifier_OutputParameterId_ClassificationValues));
m_pProbabilityValues->getInputParameter(OVP_GD_Algorithm_StreamedMatrixStreamEncoder_InputParameterId_Matrix)->setReferenceTarget(m_pClassifier->getOutputParameter(OVTK_Algorithm_Classifier_OutputParameterId_ProbabilityValues));
m_oHyperplanValuesEncoder.getInputMatrix().setReferenceTarget(m_pClassifier->getOutputParameter(OVTK_Algorithm_Classifier_OutputParameterId_ClassificationValues));
m_oProbabilitiesValuesEncoder.getInputMatrix().setReferenceTarget(m_pClassifier->getOutputParameter(OVTK_Algorithm_Classifier_OutputParameterId_ProbabilityValues));
TParameterHandler < XML::IXMLNode* > ip_pClassificationConfiguration(m_pClassifier->getInputParameter(OVTK_Algorithm_Classifier_InputParameterId_Configuration));
ip_pClassificationConfiguration = l_pRootNode->getChildByName(c_sClassifierRoot)->getChild(0);
......@@ -164,12 +153,16 @@ boolean CBoxAlgorithmClassifierProcessor::initialize(void)
l_pRootNode->release();
l_pHandler->release();
m_bOutputHeaderSent=false;
return true;
}
boolean CBoxAlgorithmClassifierProcessor::uninitialize(void)
{
m_oFeatureVectorDecoder.uninitialize();
m_oLabelsEncoder.uninitialize();
m_oHyperplanValuesEncoder.uninitialize();
m_oProbabilitiesValuesEncoder.uninitialize();
if(m_pClassifier)
{
m_pClassifier->uninitialize();
......@@ -177,34 +170,6 @@ boolean CBoxAlgorithmClassifierProcessor::uninitialize(void)
m_pClassifier = NULL;
}
if(m_pClassificationStateEncoder)
{
m_pClassificationStateEncoder->uninitialize();
this->getAlgorithmManager().releaseAlgorithm(*m_pClassificationStateEncoder);
m_pClassificationStateEncoder = NULL;
}
if(m_pProbabilityValues)
{
m_pProbabilityValues->uninitialize();
this->getAlgorithmManager().releaseAlgorithm(*m_pProbabilityValues);
m_pProbabilityValues = NULL;
}
if(m_pLabelsEncoder)
{
m_pLabelsEncoder->uninitialize();
this->getAlgorithmManager().releaseAlgorithm(*m_pLabelsEncoder);
m_pLabelsEncoder = NULL;
}
if(m_pFeaturesDecoder)
{
m_pFeaturesDecoder->uninitialize();
this->getAlgorithmManager().releaseAlgorithm(*m_pFeaturesDecoder);
m_pFeaturesDecoder = NULL;
}
return true;
}
......@@ -224,58 +189,45 @@ boolean CBoxAlgorithmClassifierProcessor::process(void)
uint64 l_ui64StartTime=l_rDynamicBoxContext.getInputChunkStartTime(0, i);
uint64 l_ui64EndTime=l_rDynamicBoxContext.getInputChunkEndTime(0, i);
TParameterHandler < const IMemoryBuffer* > ip_pFeatureVectorMemoryBuffer(m_pFeaturesDecoder->getInputParameter(OVP_GD_Algorithm_FeatureVectorStreamDecoder_InputParameterId_MemoryBufferToDecode));
TParameterHandler < IMemoryBuffer* > op_pLabelsMemoryBuffer(m_pLabelsEncoder->getOutputParameter(OVP_GD_Algorithm_StimulationStreamEncoder_OutputParameterId_EncodedMemoryBuffer));
TParameterHandler < IMemoryBuffer* > op_pClassificationStateMemoryBuffer(m_pClassificationStateEncoder->getOutputParameter(OVP_GD_Algorithm_StreamedMatrixStreamEncoder_OutputParameterId_EncodedMemoryBuffer));
TParameterHandler < IMemoryBuffer* > op_pProbabilityValues(m_pProbabilityValues->getOutputParameter(OVP_GD_Algorithm_StreamedMatrixStreamEncoder_OutputParameterId_EncodedMemoryBuffer));
TParameterHandler < IStimulationSet* > ip_pLabelsStimulationSet(m_pLabelsEncoder->getInputParameter(OVP_GD_Algorithm_StimulationStreamEncoder_InputParameterId_StimulationSet));
TParameterHandler < IStimulationSet* > &ip_pLabelsStimulationSet = m_oLabelsEncoder.getInputStimulationSet();
TParameterHandler < float64 > op_f64ClassificationStateClass(m_pClassifier->getOutputParameter(OVTK_Algorithm_Classifier_OutputParameterId_Class));
ip_pFeatureVectorMemoryBuffer=l_rDynamicBoxContext.getInputChunk(0, i);
op_pLabelsMemoryBuffer=l_rDynamicBoxContext.getOutputChunk(0);
op_pClassificationStateMemoryBuffer=l_rDynamicBoxContext.getOutputChunk(1);
op_pProbabilityValues = l_rDynamicBoxContext.getOutputChunk(2);
m_oFeatureVectorDecoder.decode(i);
m_pFeaturesDecoder->process();
if(m_pFeaturesDecoder->isOutputTriggerActive(OVP_GD_Algorithm_FeatureVectorStreamDecoder_OutputTriggerId_ReceivedHeader))
if(m_oFeatureVectorDecoder.isHeaderReceived())
{
m_bOutputHeaderSent=false;
m_oLabelsEncoder.encodeHeader();
m_oHyperplanValuesEncoder.encodeHeader();
m_oProbabilitiesValuesEncoder.encodeHeader();
l_rDynamicBoxContext.markOutputAsReadyToSend(0, l_ui64StartTime, l_ui64EndTime);
l_rDynamicBoxContext.markOutputAsReadyToSend(1, l_ui64StartTime, l_ui64EndTime);
l_rDynamicBoxContext.markOutputAsReadyToSend(2, l_ui64StartTime, l_ui64EndTime);
}
if(m_pFeaturesDecoder->isOutputTriggerActive(OVP_GD_Algorithm_FeatureVectorStreamDecoder_OutputTriggerId_ReceivedBuffer))
if(m_oFeatureVectorDecoder.isBufferReceived())
{
if(m_pClassifier->process(OVTK_Algorithm_Classifier_InputTriggerId_Classify))
{
if (m_pClassifier->isOutputTriggerActive(OVTK_Algorithm_Classifier_OutputTriggerId_Success))
{
//this->getLogManager() << LogLevel_Warning << "---Classification successful---\n";
if(!m_bOutputHeaderSent)
{
m_pLabelsEncoder->process(OVP_GD_Algorithm_StimulationStreamEncoder_InputTriggerId_EncodeHeader);
m_pClassificationStateEncoder->process(OVP_GD_Algorithm_StreamedMatrixStreamEncoder_InputTriggerId_EncodeHeader);
m_pProbabilityValues->process(OVP_GD_Algorithm_StreamedMatrixStreamEncoder_InputTriggerId_EncodeHeader);
l_rDynamicBoxContext.markOutputAsReadyToSend(0, l_ui64StartTime, l_ui64StartTime);
l_rDynamicBoxContext.markOutputAsReadyToSend(1, l_ui64StartTime, l_ui64StartTime);
l_rDynamicBoxContext.markOutputAsReadyToSend(2, l_ui64StartTime, l_ui64StartTime);
m_bOutputHeaderSent=true;
}
ip_pLabelsStimulationSet->setStimulationCount(1);
ip_pLabelsStimulationSet->setStimulationIdentifier(0, m_vStimulation[op_f64ClassificationStateClass]);
ip_pLabelsStimulationSet->setStimulationDate(0, l_ui64EndTime);
ip_pLabelsStimulationSet->setStimulationDuration(0, 0);
m_pLabelsEncoder->process(OVP_GD_Algorithm_StimulationStreamEncoder_InputTriggerId_EncodeBuffer);
m_pClassificationStateEncoder->process(OVP_GD_Algorithm_StreamedMatrixStreamEncoder_InputTriggerId_EncodeBuffer);
m_pProbabilityValues->process(OVP_GD_Algorithm_StreamedMatrixStreamEncoder_InputTriggerId_EncodeBuffer);
m_oLabelsEncoder.encodeBuffer();
m_oHyperplanValuesEncoder.encodeBuffer();
m_oProbabilitiesValuesEncoder.encodeBuffer();
l_rDynamicBoxContext.markOutputAsReadyToSend(0, l_ui64StartTime, l_ui64EndTime);
l_rDynamicBoxContext.markOutputAsReadyToSend(1, l_ui64StartTime, l_ui64EndTime);
l_rDynamicBoxContext.markOutputAsReadyToSend(2, l_ui64StartTime, l_ui64EndTime);
}
else
{
// this->getLogManager() << LogLevel_Error << "Classification failed (success trigger not active).\n";
// return false;
this->getLogManager() << LogLevel_Error << "Classification failed (success trigger not active).\n";
return false;
}
}
else
......@@ -284,11 +236,12 @@ boolean CBoxAlgorithmClassifierProcessor::process(void)
return false;
}
}
if(m_pFeaturesDecoder->isOutputTriggerActive(OVP_GD_Algorithm_FeatureVectorStreamDecoder_OutputTriggerId_ReceivedEnd))
if(m_oFeatureVectorDecoder.isEndReceived())
{
m_pLabelsEncoder->process(OVP_GD_Algorithm_StimulationStreamEncoder_InputTriggerId_EncodeEnd);
m_pClassificationStateEncoder->process(OVP_GD_Algorithm_StreamedMatrixStreamEncoder_InputTriggerId_EncodeEnd);
m_pProbabilityValues->process(OVP_GD_Algorithm_StreamedMatrixStreamEncoder_InputTriggerId_EncodeEnd);
m_oLabelsEncoder.encodeEnd();
m_oHyperplanValuesEncoder.encodeEnd();
m_oProbabilitiesValuesEncoder.encodeEnd();
l_rDynamicBoxContext.markOutputAsReadyToSend(0, l_ui64StartTime, l_ui64EndTime);
l_rDynamicBoxContext.markOutputAsReadyToSend(1, l_ui64StartTime, l_ui64EndTime);
l_rDynamicBoxContext.markOutputAsReadyToSend(2, l_ui64StartTime, l_ui64EndTime);
......
......@@ -29,14 +29,15 @@ namespace OpenViBEPlugins
private:
OpenViBE::Kernel::IAlgorithmProxy* m_pFeaturesDecoder;
OpenViBE::Kernel::IAlgorithmProxy* m_pLabelsEncoder;
OpenViBE::Kernel::IAlgorithmProxy* m_pClassificationStateEncoder;
OpenViBE::Kernel::IAlgorithmProxy* m_pProbabilityValues;
OpenViBEToolkit::TFeatureVectorDecoder < CBoxAlgorithmClassifierProcessor > m_oFeatureVectorDecoder;
OpenViBEToolkit::TStimulationEncoder < CBoxAlgorithmClassifierProcessor > m_oLabelsEncoder;
OpenViBEToolkit::TStreamedMatrixEncoder < CBoxAlgorithmClassifierProcessor > m_oHyperplanValuesEncoder;
OpenViBEToolkit::TStreamedMatrixEncoder < CBoxAlgorithmClassifierProcessor > m_oProbabilitiesValuesEncoder;
OpenViBE::Kernel::IAlgorithmProxy* m_pClassifier;
std::map < OpenViBE::float64, OpenViBE::uint64 > m_vStimulation;
OpenViBE::boolean m_bOutputHeaderSent;
};
class CBoxAlgorithmClassifierProcessorDesc : virtual public OpenViBE::Plugins::IBoxAlgorithmDesc
......
......@@ -3,7 +3,6 @@
#include <system/ovCMemory.h>
#include <system/ovCMath.h>
#include <fstream>
#include <sstream>
#include <cmath>
#include <algorithm>
......@@ -40,8 +39,9 @@ using namespace std;
boolean CBoxAlgorithmClassifierTrainer::initialize(void)
{
m_pClassifier = NULL;
m_pStimulationsDecoder = NULL;
m_pStimulationsEncoder = NULL;
m_oLabelsDecoder.initialize(*this, 0);
m_oStimulationsEncoder.initialize(*this, 0);
IBox& l_rStaticBoxContext=this->getStaticBoxContext();
//As we add some parameter in the middle of "static" parameters, we cannot rely on settings index.
......@@ -104,20 +104,14 @@ boolean CBoxAlgorithmClassifierTrainer::initialize(void)
for(uint32 i=1; i<l_rStaticBoxContext.getInputCount(); i++)
{
m_vFeatureVectorsDecoder[i-1]=&this->getAlgorithmManager().getAlgorithm(this->getAlgorithmManager().createAlgorithm(OVP_GD_ClassId_Algorithm_FeatureVectorStreamDecoder));
m_vFeatureVectorsDecoder[i-1]->initialize();
m_vFeatureVectorsDecoder.push_back(new OpenViBEToolkit::TFeatureVectorDecoder<CBoxAlgorithmClassifierTrainer>());
m_vFeatureVectorsDecoder[i-1]->initialize(*this, i);
}
m_pStimulationsDecoder=&this->getAlgorithmManager().getAlgorithm(this->getAlgorithmManager().createAlgorithm(OVP_GD_ClassId_Algorithm_StimulationStreamDecoder));
m_pStimulationsDecoder->initialize();
//We link the parameters to the extra parameters input parameter to transmit them
TParameterHandler < map<CString , CString> * > ip_pExtraParameter(m_pClassifier->getInputParameter(OVTK_Algorithm_Classifier_InputParameterId_ExtraParameter));
ip_pExtraParameter = m_pParameter;
m_pStimulationsEncoder=&this->getAlgorithmManager().getAlgorithm(this->getAlgorithmManager().createAlgorithm(OVP_GD_ClassId_Algorithm_StimulationStreamEncoder));
m_pStimulationsEncoder->initialize();
m_vFeatureCount.clear();
//If we have to deal with a pairing strategy we have to pass argument
......@@ -145,29 +139,19 @@ boolean CBoxAlgorithmClassifierTrainer::initialize(void)
boolean CBoxAlgorithmClassifierTrainer::uninitialize(void)
{
m_oLabelsDecoder.uninitialize();
m_oStimulationsEncoder.uninitialize();
// IBox& l_rStaticBoxContext=this->getStaticBoxContext();
// IBoxIO& l_rDynamicBoxContext=this->getDynamicBoxContext();
if(m_pClassifier)
{
m_pClassifier->uninitialize();
this->getAlgorithmManager().releaseAlgorithm(*m_pClassifier);
}
if(m_pStimulationsDecoder)
{
m_pStimulationsDecoder->uninitialize();
this->getAlgorithmManager().releaseAlgorithm(*m_pStimulationsDecoder);
}
if(m_pStimulationsEncoder)
{
m_pStimulationsEncoder->uninitialize();
this->getAlgorithmManager().releaseAlgorithm(*m_pStimulationsEncoder);
}
for(uint32 i=0; i<m_vFeatureVectorsDecoder.size(); i++)
{
m_vFeatureVectorsDecoder[i]->uninitialize();
this->getAlgorithmManager().releaseAlgorithm(*m_vFeatureVectorsDecoder[i]);
delete m_vFeatureVectorsDecoder[i];
}
m_vFeatureVectorsDecoder.clear();
......@@ -193,7 +177,6 @@ boolean CBoxAlgorithmClassifierTrainer::uninitialize(void)
boolean CBoxAlgorithmClassifierTrainer::processInput(uint32 ui32InputIndex)
{
getBoxAlgorithmContext()->markAlgorithmAsReadyToProcess();
return true;
}
......@@ -208,33 +191,18 @@ boolean CBoxAlgorithmClassifierTrainer::process(void)
// Parses stimulations
for(i=0; i<l_rDynamicBoxContext.getInputChunkCount(0); i++)
{
TParameterHandler < const IMemoryBuffer* > ip_pMemoryBuffer(m_pStimulationsDecoder->getInputParameter(OVP_GD_Algorithm_StimulationStreamDecoder_InputParameterId_MemoryBufferToDecode));
TParameterHandler < const IStimulationSet* > op_pStimulationSet(m_pStimulationsDecoder->getOutputParameter(OVP_GD_Algorithm_StimulationStreamDecoder_OutputParameterId_StimulationSet));
ip_pMemoryBuffer=l_rDynamicBoxContext.getInputChunk(0, i);
TParameterHandler < IStimulationSet* > ip_pStimulationSet(m_pStimulationsEncoder->getInputParameter(OVP_GD_Algorithm_StimulationStreamEncoder_InputParameterId_StimulationSet));
TParameterHandler < IMemoryBuffer* > op_pEncodedMemoryBuffer(m_pStimulationsEncoder->getOutputParameter(OVP_GD_Algorithm_StimulationStreamEncoder_OutputParameterId_EncodedMemoryBuffer));
TParameterHandler < IStimulationSet* > op_pStimulationSet = m_oLabelsDecoder.getOutputStimulationSet();
TParameterHandler < IStimulationSet* > ip_pStimulationSet = m_oStimulationsEncoder.getInputStimulationSet();
CStimulationSet l_oStimulationSet;
ip_pStimulationSet=&l_oStimulationSet;
m_oLabelsDecoder.decode(i);
if(l_rStaticBoxContext.getOutputCount()>=1)
{
op_pEncodedMemoryBuffer=l_rDynamicBoxContext.getOutputChunk(0);
}
else
if(m_oLabelsDecoder.isHeaderReceived())
{
op_pEncodedMemoryBuffer->setSize(0, true);
}
m_pStimulationsDecoder->process();
m_oStimulationsEncoder.encodeHeader();
if(m_pStimulationsDecoder->isOutputTriggerActive(OVP_GD_Algorithm_StimulationStreamDecoder_OutputTriggerId_ReceivedHeader))
{
m_pStimulationsEncoder->process(OVP_GD_Algorithm_StimulationStreamEncoder_InputTriggerId_EncodeHeader);
l_rDynamicBoxContext.markOutputAsReadyToSend(0, l_rDynamicBoxContext.getInputChunkStartTime(0, i), l_rDynamicBoxContext.getInputChunkEndTime(0, i));
}
if(m_pStimulationsDecoder->isOutputTriggerActive(OVP_GD_Algorithm_StimulationStreamDecoder_OutputTriggerId_ReceivedBuffer))
if(m_oLabelsDecoder.isBufferReceived())
{
for(uint64 j=0; j<op_pStimulationSet->getStimulationCount(); j++)
{
......@@ -244,22 +212,22 @@ boolean CBoxAlgorithmClassifierTrainer::process(void)
this->getLogManager() << LogLevel_Trace << "Raising train-completed Flag.\n";
uint64 l_ui32TrainCompletedStimulation = this->getTypeManager().getEnumerationEntryValueFromName(OV_TypeId_Stimulation,"OVTK_StimulationId_TrainCompleted");
l_oStimulationSet.appendStimulation(l_ui32TrainCompletedStimulation, op_pStimulationSet->getStimulationDate(j), 0);
ip_pStimulationSet->appendStimulation(l_ui32TrainCompletedStimulation, op_pStimulationSet->getStimulationDate(j), 0);
}
}
m_pStimulationsEncoder->process(OVP_GD_Algorithm_StimulationStreamEncoder_InputTriggerId_EncodeBuffer);
m_oStimulationsEncoder.encodeBuffer();
l_rDynamicBoxContext.markOutputAsReadyToSend(0, l_rDynamicBoxContext.getInputChunkStartTime(0, i), l_rDynamicBoxContext.getInputChunkEndTime(0, i));
}
if(m_pStimulationsDecoder->isOutputTriggerActive(OVP_GD_Algorithm_StimulationStreamDecoder_OutputTriggerId_ReceivedEnd))
if(m_oLabelsDecoder.isEndReceived())
{
m_pStimulationsEncoder->process(OVP_GD_Algorithm_StimulationStreamEncoder_InputTriggerId_EncodeEnd);
}
m_oStimulationsEncoder.encodeEnd();
if(l_rStaticBoxContext.getOutputCount()>=1)
{
l_rDynamicBoxContext.markOutputAsReadyToSend(0, l_rDynamicBoxContext.getInputChunkStartTime(0, i), l_rDynamicBoxContext.getInputChunkEndTime(0, i));
}
l_rDynamicBoxContext.markInputAsDeprecated(0, i);
//l_rDynamicBoxContext.markInputAsDeprecated(0, i);
}
// Parses feature vectors
......@@ -267,28 +235,25 @@ boolean CBoxAlgorithmClassifierTrainer::process(void)
{
for(j=0; j<l_rDynamicBoxContext.getInputChunkCount(i); j++)
{
TParameterHandler < const IMemoryBuffer* > ip_pFeatureVectorMemoryBuffer(m_vFeatureVectorsDecoder[i-1]->getInputParameter(OVP_GD_Algorithm_FeatureVectorStreamDecoder_InputParameterId_MemoryBufferToDecode));
TParameterHandler < const IMatrix* > op_pFeatureVectorMatrix(m_vFeatureVectorsDecoder[i-1]->getOutputParameter(OVP_GD_Algorithm_FeatureVectorStreamDecoder_OutputParameterId_Matrix));
ip_pFeatureVectorMemoryBuffer=l_rDynamicBoxContext.getInputChunk(i, j);
m_vFeatureVectorsDecoder[i-1]->process();
if(m_vFeatureVectorsDecoder[i-1]->isOutputTriggerActive(OVP_GD_Algorithm_FeatureVectorStreamDecoder_OutputTriggerId_ReceivedHeader))
TParameterHandler < IMatrix* > op_pFeatureVectorMatrix = m_vFeatureVectorsDecoder[i-1]->getOutputMatrix();
m_vFeatureVectorsDecoder[i-1]->decode(j);
if(m_vFeatureVectorsDecoder[i-1]->isHeaderReceived())
{
}
if(m_vFeatureVectorsDecoder[i-1]->isOutputTriggerActive(OVP_GD_Algorithm_FeatureVectorStreamDecoder_OutputTriggerId_ReceivedBuffer))
if(m_vFeatureVectorsDecoder[i-1]->isBufferReceived())
{
CBoxAlgorithmClassifierTrainer::SFeatureVector l_oFeatureVector;
l_oFeatureVector.m_pFeatureVectorMatrix=new CMatrix();
l_oFeatureVector.m_ui64StartTime=l_rDynamicBoxContext.getInputChunkStartTime(i, j);
l_oFeatureVector.m_ui64EndTime=l_rDynamicBoxContext.getInputChunkEndTime(i, j);
l_oFeatureVector.m_ui32InputIndex=i;
OpenViBEToolkit::Tools::Matrix::copy(*l_oFeatureVector.m_pFeatureVectorMatrix, *op_pFeatureVectorMatrix);
m_vFeatureVector.push_back(l_oFeatureVector);
m_vFeatureCount[i]++;
}
if(m_vFeatureVectorsDecoder[i-1]->isOutputTriggerActive(OVP_GD_Algorithm_FeatureVectorStreamDecoder_OutputTriggerId_ReceivedEnd))
if(m_vFeatureVectorsDecoder[i-1]->isEndReceived())
{
}
l_rDynamicBoxContext.markInputAsDeprecated(i, j);
//l_rDynamicBoxContext.markInputAsDeprecated(i, j);
}
}
......@@ -300,7 +265,7 @@ boolean CBoxAlgorithmClassifierTrainer::process(void)
this->getLogManager() << LogLevel_Error << "Fewer examples (" << (uint32)m_vFeatureVector.size() << ") than the specified partition count (" << m_ui64PartitionCount << ").\n";
return false;
}
if(m_vFeatureVector.size()==0)
if(m_vFeatureVector.empty())
{
this->getLogManager() << LogLevel_Warning << "Received train stimulation but no training examples received\n";
}
......@@ -313,8 +278,6 @@ boolean CBoxAlgorithmClassifierTrainer::process(void)
this->getLogManager() << LogLevel_Trace << "For information, we have " << m_vFeatureCount[i] << " feature vector(s) for input " << i << "\n";
}
float64 l_f64PartitionAccuracy=0;
float64 l_f64FinalAccuracy=0;
vector<float64> l_vPartitionAccuracies((unsigned int)m_ui64PartitionCount);
boolean l_bRandomizeVectorOrder = (&(this->getConfigurationManager()))->expandAsBoolean("${Plugin_Classification_RandomizeKFoldTestData}");
......@@ -340,6 +303,8 @@ boolean CBoxAlgorithmClassifierTrainer::process(void)
if(m_ui64PartitionCount>=2)
{
float64 l_f64PartitionAccuracy=0;
float64 l_f64FinalAccuracy=0;
OpenViBEToolkit::Tools::Matrix::clearContent(l_oConfusion);
......@@ -480,8 +445,11 @@ float64 CBoxAlgorithmClassifierTrainer::getAccuracy(const size_t uiStartIndex, c
{
const size_t k = m_vFeatureVectorIndex[j];
float64* l_pFeatureVectorBuffer=ip_pFeatureVector->getBuffer();
const float64 l_f64CorrectValue=(float64)m_vFeatureVector[k].m_ui32InputIndex;
this->getLogManager() << LogLevel_Debug << "Try to recognize " << l_f64CorrectValue << "\n";
System::Memory::copy(
l_pFeatureVectorBuffer,
m_vFeatureVector[k].m_pFeatureVectorMatrix->getBuffer(),
......@@ -490,7 +458,7 @@ float64 CBoxAlgorithmClassifierTrainer::getAccuracy(const size_t uiStartIndex, c
m_pClassifier->process(OVTK_Algorithm_Classifier_InputTriggerId_Classify);
const float64 l_f64PredictedValue = op_f64ClassificationStateClass;
//std::cout << "Try to recognize " << l_f64CorrectValue << " and get " << l_f64PredictedValue << std::endl;