本文整理汇总了C++中TimeSeriesClassificationData::save方法的典型用法代码示例。如果您正苦于以下问题:C++ TimeSeriesClassificationData::save方法的具体用法?C++ TimeSeriesClassificationData::save怎么用?C++ TimeSeriesClassificationData::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimeSeriesClassificationData
的用法示例。
在下文中一共展示了TimeSeriesClassificationData::save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
vector<string> gestures(0,"");
GetFilesInDirectory(gestures, "rawdata");
CreateDirectory("processed", NULL);
sort(gestures.begin(), gestures.end());
data = vector<vector<vector<double > > >(gestures.size(), vector<vector<double > >(0,vector<double>(0,0)));
for(size_t i = 0; i < gestures.size(); i++) {
ifstream fin(gestures[i]);
int n; fin >> n;
// cerr << gestures[i] << endl;
// cerr << n << endl;
data[i] = vector<vector<double> >(n, vector<double>(NUMPARAM, 0));
for(int j = 0; j < n; j++) {
for(int k = 0; k < NUMPARAM; k++) {
fin >> data[i][j][k];
}
}
fin.close();
}
//Create a new instance of the TimeSeriesClassificationDataStream
TimeSeriesClassificationData trainingData;
// ax, ay, az
trainingData.setNumDimensions(3);
trainingData.setDatasetName("processed\\GestureTrainingData.txt");
ofstream labelfile("processed\\GestureTrainingDataLabels.txt");
UINT currLabel = 1;
Random random;
map<string, int> gesturenames;
for(size_t overall = 0; overall < gestures.size(); overall++) {
string nam = gestures[overall].substr(8,gestures[overall].find_first_of('_')-8);
if(gesturenames.count(nam)) currLabel = gesturenames[nam];
else {
currLabel = gesturenames.size()+1;
gesturenames[nam] = currLabel;
labelfile << currLabel << " " << nam << endl;
}
MatrixDouble trainingSample;
VectorDouble currVec( trainingData.getNumDimensions() );
for(size_t k = 1; k < data[overall].size(); k++) {
for(UINT j=0; j<currVec.size(); j++){
currVec[j] = data[overall][k][j];
}
trainingSample.push_back(currVec);
}
trainingData.addSample(currLabel, trainingSample);
}
for(size_t i = 0; i < gestures.size(); i++) {
MatrixDouble trainingSample;
VectorDouble currVec(trainingData.getNumDimensions());
for(UINT j = 0; j < currVec.size(); j++) {
currVec[j] = random.getRandomNumberUniform(-1.0, 1.0);
}
for(size_t k = 0; k < 100; k++) {
trainingSample.push_back(currVec);
}
trainingData.addSample(0, trainingSample);
}
//After recording your training data you can then save it to a file
if( !trainingData.save( "processed\\TrainingData.grt" ) ){
cout << "ERROR: Failed to save dataset to file!\n";
return EXIT_FAILURE;
}
//This can then be loaded later
if( !trainingData.load( "processed\\TrainingData.grt" ) ){
cout << "ERROR: 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;
}
DTW dtw;
if( !dtw.train( trainingData ) ){
cerr << "Failed to train classifier!\n";
//.........这里部分代码省略.........