Commit 2ad6553c authored by Serrière Guillaume's avatar Serrière Guillaume
Browse files

Plugin: Fix issue with OneVsAll.


Signed-off-by: default avatarSerrière Guillaume <guillaume.serriere@inria.fr>
parent 63cc552d
......@@ -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;
......
......@@ -266,7 +266,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";
}
......@@ -279,8 +279,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}");
......@@ -306,6 +304,8 @@ boolean CBoxAlgorithmClassifierTrainer::process(void)
if(m_ui64PartitionCount>=2)
{
float64 l_f64PartitionAccuracy=0;
float64 l_f64FinalAccuracy=0;
OpenViBEToolkit::Tools::Matrix::clearContent(l_oConfusion);
......@@ -446,8 +446,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(),
......@@ -456,7 +459,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;
this->getLogManager() << LogLevel_Debug << "Recognize " << l_f64PredictedValue << "\n";
if(l_f64PredictedValue==l_f64CorrectValue)
{
l_iSuccessfullTrainerCount++;
......
......@@ -28,12 +28,18 @@ namespace OpenViBEPlugins
public:
CBoxAlgorithmCommonClassifierListener(const OpenViBE::uint32 ui32CustomSettingBase)
:m_ui32CustomSettingBase(ui32CustomSettingBase)
:m_oClassifierClassIdentifier(OV_UndefinedIdentifier),
m_oStrategyClassIdentifier(0x0),//OV_UndefinedIdentifier is already use for the native, We initialize to an unused identifier in the strategy list
m_pClassifier(NULL),
m_pStrategy(NULL),
m_ui32CustomSettingBase(ui32CustomSettingBase),
m_i32StrategyAmountSettings(-1)
{
}
virtual OpenViBE::boolean initialize(void)
{
//Even if everything should have been set in constructor, we still set everything in initialize (in case of)
m_oClassifierClassIdentifier=OV_UndefinedIdentifier;
m_pClassifier=NULL;
......
......@@ -1284,10 +1284,6 @@
<Identifier>(0xc46b3d00, 0x3e0454e1)</Identifier>
<Value>(0x00000000, 0x01a0f0a5)</Value>
</Attribute>
<Attribute>
<Identifier>(0xc67a01dc, 0x28ce06c1)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xc73e83ec, 0xf855c5bc)</Identifier>
<Value>false</Value>
......
......@@ -379,10 +379,6 @@
<Identifier>(0xc46b3d00, 0x3e0454e1)</Identifier>
<Value>(0x00000000, 0x00e9c456)</Value>
</Attribute>
<Attribute>
<Identifier>(0xc67a01dc, 0x28ce06c1)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xce18836a, 0x9c0eb403)</Identifier>
<Value>2</Value>
......
......@@ -161,10 +161,10 @@ boolean CAlgorithmConfusionMatrix::process(void)
std::map<uint64,uint64>::iterator l_itTarget = m_mTargetsTimeLine.begin();
std::map<uint64,uint64>::iterator l_itNextTarget;
boolean l_bFound = false;
for(;l_itTarget != m_mTargetsTimeLine.end() && !l_bFound;l_itTarget++)
for(;l_itTarget != m_mTargetsTimeLine.end() && !l_bFound;++l_itTarget)
{
l_itNextTarget = l_itTarget;
l_itNextTarget++;
++l_itNextTarget;
if( (l_itNextTarget == m_mTargetsTimeLine.end() || l_ui64StimulationFromClassifierDate < l_itNextTarget->first)
&& l_ui64StimulationFromClassifierDate > l_itTarget->first)
{
......
......@@ -19,7 +19,7 @@ namespace
{
CBoxAlgorithmClassifierAccuracyMeasure* l_pClassifierAccuracyMeasure=reinterpret_cast<CBoxAlgorithmClassifierAccuracyMeasure*>(pUserData);
vector<CBoxAlgorithmClassifierAccuracyMeasure::SProgressBar>::iterator l_iter = l_pClassifierAccuracyMeasure->m_vProgressBar.begin();
for(;l_iter!=l_pClassifierAccuracyMeasure->m_vProgressBar.end();l_iter++)
for(;l_iter!=l_pClassifierAccuracyMeasure->m_vProgressBar.end();++l_iter)
{
l_iter->m_ui32Score = 0;
l_iter->m_ui32StimulationCount = 0;
......@@ -212,7 +212,7 @@ boolean CBoxAlgorithmClassifierAccuracyMeasure::process(void)
// if the incoming chunk is in the timeline
if(l_ui64ChunkEndTime <= m_ui64CurrentProcessingTimeLimit)
{
if(m_mTargetsTimeLine.size() != 0)
if(m_mTargetsTimeLine.empty())
{
// we can process it
m_vpClassifierStimulationDecoder[ip-1]->decode(i);
......@@ -240,7 +240,7 @@ boolean CBoxAlgorithmClassifierAccuracyMeasure::process(void)
while(l_itTarget != m_mTargetsTimeLine.end() && l_bContinue)
{
l_itNextTarget = l_itTarget;
l_itNextTarget++;
++l_itNextTarget;
if((l_itNextTarget == m_mTargetsTimeLine.end() || l_ui64StimulationFromClassifierDate < l_itNextTarget->first)
&& l_ui64StimulationFromClassifierDate > l_itTarget->first)
{
......@@ -252,7 +252,7 @@ boolean CBoxAlgorithmClassifierAccuracyMeasure::process(void)
m_vProgressBar[ip-1].m_ui32StimulationCount++;
l_bContinue = false;
}
l_itTarget++;
++l_itTarget;
}
//std::map<uint64,uint64>::iterator l_itTarget = m_mTargetsTimeLine.lower_bound(l_ui64StimulationFromClassifierDate);
......
......@@ -178,7 +178,7 @@ void CROCCurveDraw::redraw()
g_object_unref(l_pText);
if(m_oPointList.size() != 0)
if(m_oPointList.empty())
{
gdk_draw_lines((m_pDrawableArea)->window, GTK_WIDGET(m_pDrawableArea)->style->black_gc, &(m_oPointList[0]), m_oPointList.size());
}
......
......@@ -22,9 +22,9 @@ int main (int argc, char** argv)
string line;
while(getline(file, line))
{
size_t pos;
if(line.find("Final value of Kappa") != string::npos)
{
size_t pos;
cout << "Found kappa line " << line << endl;
pos = line.rfind(" ");
......
......@@ -67,17 +67,17 @@ boolean CAlgorithmClassifier::process(void)
if(this->isInputTriggerActive(OVTK_Algorithm_Classifier_InputTriggerId_Classify))
{
IMatrix* l_pFeatureVector=ip_pFeatureVector;
float64 l_f64Class=0;
IMatrix* l_pClassificationValues=op_pClassificationValues;
IMatrix* l_pProbabilityValues=op_pProbabilityValues;
if(!l_pFeatureVector || !l_pClassificationValues)
if(!l_pFeatureVector || !l_pClassificationValues || !l_pProbabilityValues)
{
this->getLogManager() << LogLevel_ImportantWarning << "Either feature vector matrix is NULL or classification values matrix is NULL\n";
this->getLogManager() << LogLevel_ImportantWarning << "Either feature vector matrix or classification values matrix or probability values matrix is NULL\n";
this->activateOutputTrigger(OVTK_Algorithm_Classifier_OutputTriggerId_Failed, true);
}
else
{
float64 l_f64Class=0;
CFeatureVector l_oFeatureVectorAdapter(*l_pFeatureVector);
CVector l_oClassificationValuesAdapter(*l_pClassificationValues);
CVector l_oProbabilityValuesAdapter(*l_pProbabilityValues);
......
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