Commit fdc56aee authored by Jussi Lindgren's avatar Jussi Lindgren

Plugins: Improved error handling for missing classifiers

- Also some code cleanup
parent 31cbfc7f
......@@ -16,77 +16,110 @@ CAlgorithmProxy::CAlgorithmProxy(const IKernelContext& rKernelContext, CAlgorith
CIdentifier CAlgorithmProxy::getNextInputParameterIdentifier(
const CIdentifier& rPreviousInputParameterIdentifier) const
{
if(!m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
if(!m_bIsInitialized)
{
getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
}
return m_rAlgorithm.getNextInputParameterIdentifier(rPreviousInputParameterIdentifier);
}
CString CAlgorithmProxy::getInputParameterName(
const CIdentifier& rInputParameterIdentifier) const
{
if(!m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
if(!m_bIsInitialized)
{
getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
}
return m_rAlgorithm.getInputParameterName(rInputParameterIdentifier);
}
IParameter* CAlgorithmProxy::getInputParameter(
const CIdentifier& rInputParameterIdentifier)
{
if(!m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
if(!m_bIsInitialized)
{
getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
}
return m_rAlgorithm.getInputParameter(rInputParameterIdentifier);
}
CIdentifier CAlgorithmProxy::getNextOutputParameterIdentifier(
const CIdentifier& rPreviousOutputParameterIdentifier) const
{
if(!m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
if(!m_bIsInitialized)
{
getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
}
return m_rAlgorithm.getNextOutputParameterIdentifier(rPreviousOutputParameterIdentifier);
}
CString CAlgorithmProxy::getOutputParameterName(
const CIdentifier& rOutputParameterIdentifier) const
{
if(!m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
if(!m_bIsInitialized)
{
getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
}
return m_rAlgorithm.getOutputParameterName(rOutputParameterIdentifier);
}
IParameter* CAlgorithmProxy::getOutputParameter(
const CIdentifier& rOutputParameterIdentifier)
{
if(!m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
if(!m_bIsInitialized)
{
getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
}
return m_rAlgorithm.getOutputParameter(rOutputParameterIdentifier);
}
CIdentifier CAlgorithmProxy::getNextOutputTriggerIdentifier(
const CIdentifier& rPreviousOutputTriggerIdentifier) const
{
if(!m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
if(!m_bIsInitialized)
{
getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
}
return m_rAlgorithm.getNextOutputTriggerIdentifier(rPreviousOutputTriggerIdentifier);
}
CString CAlgorithmProxy::getOutputTriggerName(
const CIdentifier& rOutputTriggerIdentifier) const
{
if(!m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
if(!m_bIsInitialized)
{
getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
}
return m_rAlgorithm.getOutputTriggerName(rOutputTriggerIdentifier);
}
boolean CAlgorithmProxy::isOutputTriggerActive(
const CIdentifier& rOutputTriggerIdentifier) const
{
if(!m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Calling state accessor on uninitialized algorithm\n";
if(!m_bIsInitialized)
{
getLogManager() << LogLevel_ImportantWarning << "Calling state accessor on uninitialized algorithm\n";
}
return m_rAlgorithm.isOutputTriggerActive(rOutputTriggerIdentifier);
}
CIdentifier CAlgorithmProxy::getNextInputTriggerIdentifier(
const CIdentifier& rPreviousInputTriggerIdentifier) const
{
if(!m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
if(!m_bIsInitialized)
{
getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
}
return m_rAlgorithm.getNextInputTriggerIdentifier(rPreviousInputTriggerIdentifier);
}
CString CAlgorithmProxy::getInputTriggerName(
const CIdentifier& rInputTriggerIdentifier) const
{
if(!m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
if(!m_bIsInitialized)
{
getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
}
return m_rAlgorithm.getInputTriggerName(rInputTriggerIdentifier);
}
......@@ -94,13 +127,19 @@ boolean CAlgorithmProxy::activateInputTrigger(
const CIdentifier& rInputTriggerIdentifier,
const boolean bTriggerState)
{
if(!m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Calling state accessor on uninitialized algorithm\n";
if(!m_bIsInitialized)
{
getLogManager() << LogLevel_ImportantWarning << "Calling state accessor on uninitialized algorithm\n";
}
return m_rAlgorithm.activateInputTrigger(rInputTriggerIdentifier, bTriggerState);
}
boolean CAlgorithmProxy::initialize(void)
{
if(m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Can not initialize already initialized algorithm\n";
if(m_bIsInitialized)
{
getLogManager() << LogLevel_ImportantWarning << "Can not initialize already initialized algorithm\n";
}
m_bIsInitialized=m_rAlgorithm.initialize();
......@@ -109,27 +148,39 @@ boolean CAlgorithmProxy::initialize(void)
boolean CAlgorithmProxy::uninitialize(void)
{
if(!m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Can not uninitialize uninitialized algorithm\n";
if(!m_bIsInitialized)
{
getLogManager() << LogLevel_ImportantWarning << "Can not uninitialize uninitialized algorithm\n";
}
return (m_bIsInitialized && m_rAlgorithm.uninitialize());
}
boolean CAlgorithmProxy::process(void)
{
if(!m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
if(!m_bIsInitialized)
{
getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
}
return m_rAlgorithm.process();
}
boolean CAlgorithmProxy::process(
const CIdentifier& rTriggerIdentifier)
{
if(!m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
if(!m_bIsInitialized)
{
getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
}
return m_rAlgorithm.process(rTriggerIdentifier);
}
boolean CAlgorithmProxy::isAlgorithmDerivedFrom(const CIdentifier& rClassIdentifier)
{
if(!m_bIsInitialized) getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
if(!m_bIsInitialized)
{
getLogManager() << LogLevel_ImportantWarning << "Calling accessor on uninitialized algorithm\n";
}
return m_rAlgorithm.isAlgorithmDerivedFrom(rClassIdentifier);
}
......@@ -27,7 +27,7 @@ namespace OpenViBE
* \param rAlgorithmClassIdentifier [out] : the class identifier of
* the newly created algorithm
* \return \e true in case of success.
* \return \e false in case of error.
* \return \e OV_UndefinedIdentifier in case of error.
*/
virtual OpenViBE::CIdentifier createAlgorithm(
const OpenViBE::CIdentifier& rAlgorithmClassIdentifier)=0;
......
......@@ -225,9 +225,15 @@ boolean CAlgorithmClassifierOneVsAll::classify(const IFeatureVector& rFeatureVec
return true;
}
void CAlgorithmClassifierOneVsAll::addNewClassifierAtBack(void)
boolean CAlgorithmClassifierOneVsAll::addNewClassifierAtBack(void)
{
IAlgorithmProxy* l_pSubClassifier = &this->getAlgorithmManager().getAlgorithm(this->getAlgorithmManager().createAlgorithm(this->m_oSubClassifierAlgorithmIdentifier));
const CIdentifier l_oSubClassifierAlgorithm = this->getAlgorithmManager().createAlgorithm(this->m_oSubClassifierAlgorithmIdentifier);
if(l_oSubClassifierAlgorithm == OV_UndefinedIdentifier)
{
this->getLogManager() << LogLevel_Error << "Unable to instantiate classifier for class " << this->m_oSubClassifierAlgorithmIdentifier << "\n. Is the classifier still available in OpenViBE?";
return false;
}
IAlgorithmProxy* l_pSubClassifier = &this->getAlgorithmManager().getAlgorithm(l_oSubClassifierAlgorithm);
l_pSubClassifier->initialize();
//Set a references to the extra parameters input of the pairing strategy
......@@ -235,6 +241,8 @@ void CAlgorithmClassifierOneVsAll::addNewClassifierAtBack(void)
ip_pExtraParameters.setReferenceTarget(this->getInputParameter(OVTK_Algorithm_Classifier_InputParameterId_ExtraParameter));
this->m_oSubClassifierList.push_back(l_pSubClassifier);
return true;
}
void CAlgorithmClassifierOneVsAll::removeClassifierAtBack(void)
......@@ -253,7 +261,10 @@ boolean CAlgorithmClassifierOneVsAll::designArchitecture(const OpenViBE::CIdenti
}
for(size_t i = 0 ; i < rClassAmount ; ++i)
{
this->addNewClassifierAtBack();
if(!this->addNewClassifierAtBack())
{
return false;
}
}
return true;
}
......@@ -336,7 +347,10 @@ boolean CAlgorithmClassifierOneVsAll::loadConfiguration(XML::IXMLNode *pConfigur
}
else
{
this->addNewClassifierAtBack();
if(!this->addNewClassifierAtBack())
{
return false;
}
}
}
......
......@@ -36,7 +36,7 @@ namespace OpenViBEPlugins
private:
XML::IXMLNode* getClassifierConfiguration(OpenViBE::Kernel::IAlgorithmProxy* classifier);
void addNewClassifierAtBack(void);
OpenViBE::boolean addNewClassifierAtBack(void);
void removeClassifierAtBack(void);
OpenViBE::boolean setSubClassifierIdentifier(const OpenViBE::CIdentifier &rId);
OpenViBE::uint32 getClassAmount(void) const;
......
......@@ -278,7 +278,13 @@ boolean CAlgorithmClassifierOneVsOne::designArchitecture(const OpenViBE::CIdenti
{
for(size_t l_iSecondClass = l_iFirstClass+1 ; l_iSecondClass <= rClassAmount ; ++l_iSecondClass)
{
IAlgorithmProxy* l_pSubClassifier = &this->getAlgorithmManager().getAlgorithm(this->getAlgorithmManager().createAlgorithm(this->m_oSubClassifierAlgorithmIdentifier));
const CIdentifier l_oSubClassifierAlgorithm = this->getAlgorithmManager().createAlgorithm(this->m_oSubClassifierAlgorithmIdentifier);
if(l_oSubClassifierAlgorithm == OV_UndefinedIdentifier)
{
this->getLogManager() << LogLevel_Error << "Unable to instantiate classifier for class " << this->m_oSubClassifierAlgorithmIdentifier << "\n. Is the classifier still available in OpenViBE?";
return false;
}
IAlgorithmProxy* l_pSubClassifier = &this->getAlgorithmManager().getAlgorithm(l_oSubClassifierAlgorithm);
l_pSubClassifier->initialize();
//Set a references to the extra parameters input of the pairing strategy
......
......@@ -30,7 +30,7 @@ void dumpMatrix(OpenViBE::Kernel::ILogManager &rMgr, const CMatrix& mat, const C
for(uint32 i=0;i<mat.getDimensionSize(0);i++) {
rMgr << LogLevel_Info << "Row " << i << ": ";
for(uint32 j=0;j<mat.getDimensionSize(1);j++) {
rMgr << mat.getBuffer()[i*mat.getDimensionSize(0)+j] << " ";
rMgr << mat.getBuffer()[i*mat.getDimensionSize(1)+j] << " ";
}
rMgr << "\n";
}
......
......@@ -119,17 +119,30 @@ boolean CBoxAlgorithmClassifierProcessor::initialize(void)
}
m_pFeaturesDecoder=&this->getAlgorithmManager().getAlgorithm(this->getAlgorithmManager().createAlgorithm(OVP_GD_ClassId_Algorithm_FeatureVectorStreamDecoder));
m_pLabelsEncoder=&this->getAlgorithmManager().getAlgorithm(this->getAlgorithmManager().createAlgorithm(OVP_GD_ClassId_Algorithm_StimulationStreamEncoder));
m_pClassificationStateEncoder=&this->getAlgorithmManager().getAlgorithm(this->getAlgorithmManager().createAlgorithm(OVP_GD_ClassId_Algorithm_StreamedMatrixStreamEncoder));
m_pClassifier=&this->getAlgorithmManager().getAlgorithm(this->getAlgorithmManager().createAlgorithm(l_oAlgorithmClassIdentifier));
m_pProbabilityValues=&this->getAlgorithmManager().getAlgorithm(this->getAlgorithmManager().createAlgorithm(OVP_GD_ClassId_Algorithm_StreamedMatrixStreamEncoder));
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();
m_pProbabilityValues->initialize();
const CIdentifier l_oClassifierAlgorithmIdentifier = this->getAlgorithmManager().createAlgorithm(l_oAlgorithmClassIdentifier);
if(l_oClassifierAlgorithmIdentifier == OV_UndefinedIdentifier)
{
this->getLogManager() << LogLevel_Error << "Error instantiating classifier class with id "
<< l_oAlgorithmClassIdentifier
<< ". If you've loaded an old scenario or configuration file(s), make sure that the classifiers specified in it are still available.\n";
return false;
}
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();
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));
......
......@@ -71,7 +71,16 @@ boolean CBoxAlgorithmClassifierTrainer::initialize(void)
if(l_oStrategyClassIdentifier==OV_UndefinedIdentifier)
{
//That means that we want to use a classical algorithm so just let's create it
m_pClassifier=&this->getAlgorithmManager().getAlgorithm(this->getAlgorithmManager().createAlgorithm(l_oClassifierAlgorithmClassIdentifier));
const CIdentifier l_oClassifierAlgorithmIdentifier = this->getAlgorithmManager().createAlgorithm(l_oClassifierAlgorithmClassIdentifier);
if(l_oClassifierAlgorithmIdentifier == OV_UndefinedIdentifier)
{
this->getLogManager() << LogLevel_Error << "Error instantiating classifier class with id "
<< l_oClassifierAlgorithmClassIdentifier
<< ". If you've loaded an old scenario or configuration file(s), make sure that the classifiers specified in it are still available.\n";
return false;
}
m_pClassifier=&this->getAlgorithmManager().getAlgorithm(l_oClassifierAlgorithmIdentifier);
m_pClassifier->initialize();
}
else
......
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