本文整理汇总了C++中TimeSeriesClassificationData::loadDatasetFromFile方法的典型用法代码示例。如果您正苦于以下问题:C++ TimeSeriesClassificationData::loadDatasetFromFile方法的具体用法?C++ TimeSeriesClassificationData::loadDatasetFromFile怎么用?C++ TimeSeriesClassificationData::loadDatasetFromFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimeSeriesClassificationData
的用法示例。
在下文中一共展示了TimeSeriesClassificationData::loadDatasetFromFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (int argc, const char * argv[])
{
TimeSeriesClassificationData trainingData; //This will store our training data
GestureRecognitionPipeline pipeline; //This is a wrapper for our classifier and any pre/post processing modules
string dirPath = "/home/vlad/AndroidStudioProjects/DataCapture/dataSetGenerator/build";
if (!trainingData.loadDatasetFromFile(dirPath + "/acc-training-set-segmented.data")) {
printf("Cannot open training set\n");
return 0;
}
printf("Successfully opened training data set ...\n");
HMM hmm;
hmm.setHMMType( HMM_CONTINUOUS );
hmm.setDownsampleFactor( 5 );
hmm.setAutoEstimateSigma( true );
hmm.setSigma( 20.0 );
hmm.setModelType( HMM_LEFTRIGHT );
hmm.setDelta( 1 );
// LowPassFilter lpf(0.1, 1, 3);
// pipeline.setPreProcessingModule(lpf);
pipeline.setClassifier( hmm );
pipeline.train(trainingData, 20);
//You can then get then get the accuracy of how well the pipeline performed during the k-fold cross validation testing
double accuracy = pipeline.getCrossValidationAccuracy();
printf("Accuracy: %f\n", accuracy);
}
示例2: main
int main(int argc, const char * argv[]){
//Load the training data
TimeSeriesClassificationData trainingData;
if( !trainingData.loadDatasetFromFile("HMMTrainingData.grt") ){
cout << "ERROR: Failed to load training data!\n";
return false;
}
//Remove 20% of the training data to use as test data
TimeSeriesClassificationData testData = trainingData.partition( 80 );
//The input to the HMM must be a quantized discrete value
//We therefore use a KMeansQuantizer to covert the N-dimensional continuous data into 1-dimensional discrete data
const UINT NUM_SYMBOLS = 10;
KMeansQuantizer quantizer( NUM_SYMBOLS );
//Train the quantizer using the training data
if( !quantizer.train( trainingData ) ){
cout << "ERROR: Failed to train quantizer!\n";
return false;
}
//Quantize the training data
TimeSeriesClassificationData quantizedTrainingData( 1 );
for(UINT i=0; i<trainingData.getNumSamples(); i++){
UINT classLabel = trainingData[i].getClassLabel();
MatrixDouble quantizedSample;
for(UINT j=0; j<trainingData[i].getLength(); j++){
quantizer.quantize( trainingData[i].getData().getRowVector(j) );
quantizedSample.push_back( quantizer.getFeatureVector() );
}
if( !quantizedTrainingData.addSample(classLabel, quantizedSample) ){
cout << "ERROR: Failed to quantize training data!\n";
return false;
}
}
//Create a new HMM instance
HMM hmm;
//Set the number of states in each model
hmm.setNumStates( 4 );
//Set the number of symbols in each model, this must match the number of symbols in the quantizer
hmm.setNumSymbols( NUM_SYMBOLS );
//Set the HMM model type to LEFTRIGHT with a delta of 1
hmm.setModelType( HiddenMarkovModel::LEFTRIGHT );
hmm.setDelta( 1 );
//Set the training parameters
hmm.setMinImprovement( 1.0e-5 );
hmm.setMaxNumIterations( 100 );
hmm.setNumRandomTrainingIterations( 20 );
//Train the HMM model
if( !hmm.train( quantizedTrainingData ) ){
cout << "ERROR: Failed to train the HMM model!\n";
return false;
}
//Save the HMM model to a file
if( !hmm.save( "HMMModel.grt" ) ){
cout << "ERROR: Failed to save the model to a file!\n";
return false;
}
//Load the HMM model from a file
if( !hmm.load( "HMMModel.grt" ) ){
cout << "ERROR: Failed to load the model from a file!\n";
return false;
}
//Quantize the test data
TimeSeriesClassificationData quantizedTestData( 1 );
for(UINT i=0; i<testData.getNumSamples(); i++){
UINT classLabel = testData[i].getClassLabel();
MatrixDouble quantizedSample;
for(UINT j=0; j<testData[i].getLength(); j++){
quantizer.quantize( testData[i].getData().getRowVector(j) );
quantizedSample.push_back( quantizer.getFeatureVector() );
}
if( !quantizedTestData.addSample(classLabel, quantizedSample) ){
cout << "ERROR: Failed to quantize training data!\n";
return false;
}
}
//.........这里部分代码省略.........
示例3: main
int main (int argc, const char * argv[])
{
//Create a new instance of the TimeSeriesClassificationData
TimeSeriesClassificationData trainingData;
//Set the dimensionality of the data (you need to do this before you can add any samples)
trainingData.setNumDimensions( 3 );
//You can also give the dataset a name (the name should have no spaces)
trainingData.setDatasetName("DummyData");
//You can also add some info text about the data
trainingData.setInfoText("This data contains some dummy timeseries data");
//Here you would record a time series, when you have finished recording the time series then add the training sample to the training data
UINT gestureLabel = 1;
MatrixDouble trainingSample;
//For now we will just add 10 x 20 random walk data timeseries
Random random;
for(UINT k=0; k<10; k++){//For the number of classes
gestureLabel = k+1;
//Get the init random walk position for this gesture
VectorDouble startPos( trainingData.getNumDimensions() );
for(UINT j=0; j<startPos.size(); j++){
startPos[j] = random.getRandomNumberUniform(-1.0,1.0);
}
//Generate the 20 time series
for(UINT x=0; x<20; x++){
//Clear any previous timeseries
trainingSample.clear();
//Generate the random walk
UINT randomWalkLength = random.getRandomNumberInt(90, 110);
VectorDouble sample = startPos;
for(UINT i=0; i<randomWalkLength; i++){
for(UINT j=0; j<startPos.size(); j++){
sample[j] += random.getRandomNumberUniform(-0.1,0.1);
}
//Add the sample to the training sample
trainingSample.push_back( sample );
}
//Add the training sample to the dataset
trainingData.addSample( gestureLabel, trainingSample );
}
}
//After recording your training data you can then save it to a file
if( !trainingData.saveDatasetToFile( "TrainingData.txt" ) ){
cout << "Failed to save dataset to file!\n";
return EXIT_FAILURE;
}
//This can then be loaded later
if( !trainingData.loadDatasetFromFile( "TrainingData.txt" ) ){
cout << "Failed to load dataset from file!\n";
return EXIT_FAILURE;
}
//This is how you can get some stats from the training data
string datasetName = trainingData.getDatasetName();
string infoText = trainingData.getInfoText();
UINT numSamples = trainingData.getNumSamples();
UINT numDimensions = trainingData.getNumDimensions();
UINT numClasses = trainingData.getNumClasses();
cout << "Dataset Name: " << datasetName << endl;
cout << "InfoText: " << infoText << endl;
cout << "NumberOfSamples: " << numSamples << endl;
cout << "NumberOfDimensions: " << numDimensions << endl;
cout << "NumberOfClasses: " << numClasses << endl;
//You can also get the minimum and maximum ranges of the data
vector< MinMax > ranges = trainingData.getRanges();
cout << "The ranges of the dataset are: \n";
for(UINT j=0; j<ranges.size(); j++){
cout << "Dimension: " << j << " Min: " << ranges[j].minValue << " Max: " << ranges[j].maxValue << endl;
}
//If you want to partition the dataset into a training dataset and a test dataset then you can use the partition function
//A value of 80 means that 80% of the original data will remain in the training dataset and 20% will be returned as the test dataset
TimeSeriesClassificationData testData = trainingData.partition( 80 );
//If you have multiple datasets that you want to merge together then use the merge function
if( !trainingData.merge( testData ) ){
cout << "Failed to merge datasets!\n";
return EXIT_FAILURE;
}
//If you want to run K-Fold cross validation using the dataset then you should first spilt the dataset into K-Folds
//A value of 10 splits the dataset into 10 folds and the true parameter signals that stratified sampling should be used
if( !trainingData.spiltDataIntoKFolds( 10, true ) ){
cout << "Failed to spiltDataIntoKFolds!\n";
//.........这里部分代码省略.........