|
@@ -1,69 +0,0 @@
|
|
|
-#ifndef HELPERDATACONVERSIONMEX_H
|
|
|
-#define HELPERDATACONVERSIONMEX_H
|
|
|
-
|
|
|
-// STL includes
|
|
|
-#include <math.h>
|
|
|
-#include <matrix.h>
|
|
|
-#include <mex.h>
|
|
|
-
|
|
|
-// NICE-core includes
|
|
|
-#include <core/vector/MatrixT.h>
|
|
|
-#include <core/vector/VectorT.h>
|
|
|
-
|
|
|
-// Interface for conversion between Matlab and C objects
|
|
|
-#include "gp-hik-core/matlab/ConverterMatlabToNICE.h"
|
|
|
-#include "gp-hik-core/matlab/ConverterNICEToMatlab.h"
|
|
|
-
|
|
|
-#include "vislearning/cbaselib/Example.h"
|
|
|
-
|
|
|
-namespace NICE {
|
|
|
-
|
|
|
-namespace MatlabConversion {
|
|
|
-
|
|
|
-/**
|
|
|
- * @brief Create an Examples class from a given full matrix of features and a matrix/vector of labels.
|
|
|
- *
|
|
|
- * The Examples object consists of individual Example objects containing the label and a pointer to the provided raw feature data.
|
|
|
- * Note: No feature data is copied - an Example only contains a pointer to the raw double data.
|
|
|
- * An NICE::Vector is created as an wrapper around this raw double pointer using it, but not copying it.
|
|
|
- * You need to take care to delete these wrapper vectors once you're finished working with the Examples object, otherwise you generate a memory leak.
|
|
|
- *
|
|
|
- * @param p_pArrTrainData double MATLAB matrix containing the features (dimension M) of N samples ( M x N matrix )
|
|
|
- * @param p_pArrTrainLabels double MATLAB matrix containing the labels for N samples (1xN)
|
|
|
- *
|
|
|
- * @param p_ExamplesTrain created Examples class (vector of N Example object with each Example containing a valid vec-ptr to the feature data [uncopied] )
|
|
|
- *
|
|
|
- * @return true for successful Examples creation
|
|
|
- * @author Johannes Ruehle
|
|
|
- */
|
|
|
-bool convertDoubleRawPointersToExamples( const mxArray *p_pArrTrainData, const mxArray *p_pArrTrainLabels, OBJREC::Examples &p_ExamplesTrain )
|
|
|
-{
|
|
|
-
|
|
|
- int iNumFeatureDimension = mxGetM( p_pArrTrainData ); // feature dimensions
|
|
|
-
|
|
|
- NICE::Vector yValuesTrain = convertDoubleVectorToNice( p_pArrTrainLabels );
|
|
|
- NICE::Matrix matDataTrain = convertDoubleMatrixToNice( p_pArrTrainData );
|
|
|
- assert( yValuesTrain.size() == matDataTrain.cols() );
|
|
|
- assert( iNumFeatureDimension == matDataTrain.rows() );
|
|
|
-
|
|
|
- p_ExamplesTrain.reserve( matDataTrain.cols() );
|
|
|
-
|
|
|
- const double *pDataPtr = matDataTrain.getDataPointer();
|
|
|
-
|
|
|
- for (int i = 0; i < (int)matDataTrain.cols(); i++, pDataPtr+= iNumFeatureDimension )
|
|
|
- {
|
|
|
- NICE::Vector *t_pVecTrainData = new NICE::Vector( pDataPtr , (size_t)iNumFeatureDimension);
|
|
|
- OBJREC::Example t_Example;
|
|
|
- t_Example.vec = t_pVecTrainData;
|
|
|
-
|
|
|
- p_ExamplesTrain.push_back( std::pair<int, OBJREC::Example>( (int)yValuesTrain[i], t_Example ) );
|
|
|
- }
|
|
|
-
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-#endif //HELPERDATACONVERSIONMEX_H
|