void setup() { stream.setLabelsForAllDimensions({"x", "y", "z"}); useInputStream(stream); DTW dtw(false, true, null_rej); dtw.enableTrimTrainingData(true, 0.1, 75); pipeline.setClassifier(dtw); pipeline.addPostProcessingModule(ClassLabelTimeoutFilter(timeout)); usePipeline(pipeline); registerTuneable( null_rej, 0.1, 5.0, "Variability", "How different from the training data a new gesture can be and " "still be considered the same gesture. The higher the number, the " "more different it can be.", [](double new_null_rej) { pipeline.getClassifier()->setNullRejectionCoeff(new_null_rej); pipeline.getClassifier()->recomputeNullRejectionThresholds(); }); registerTuneable( timeout, 1, 3000, "Timeout", "How long (in milliseconds) to wait after recognizing a " "gesture before recognizing another one.", [](double new_timeout) { ClassLabelTimeoutFilter* filter = dynamic_cast<ClassLabelTimeoutFilter*>( pipeline.getPostProcessingModule(0)); assert(filter != nullptr); filter->setTimeoutDuration(new_timeout); }); }
int main() { char a[] = "university"; char b[] = "unverstiy"; int distance1 = dtw(sizeof(a) - 1, sizeof(b) - 1, a, b); cout << distance1 << endl; int distance2 = btu_dtw(sizeof(a) - 1, sizeof(b) - 1, a, b); cout << distance2 << endl; getchar(); return 0; }
double dtw_model::calcObjective(const vector<tsample>& samples) { double obj = 0; foreach (i, samples) { double cscore = dtw(samples[i].first.first, samples[i].first.second); if (cscore == float_inf) continue; bool positive = samples[i].second; if (positive) obj += cscore; // obj += (positive) ? cscore : (-_intra_inter_weight * cscore); }
FLOAT BlockAStar::getRealCost(point current,int currentIdx) { FLOAT cost; int BS_rows = min(blockSize, size[0]-current.first*blockSize); int BS_cols = min(blockSize, size[1]-current.second*blockSize); //point move = current-prev; if (currentIdx == -1){ //calculate current block cost = dtw(current.first*blockSize,current.second*blockSize,BS_rows,BS_cols,current); } else{ //update current block cost = dtw_update(current.first*blockSize,current.second*blockSize,BS_rows,BS_cols,current,gScore[currentIdx]); } return cost; }
int main() { //init the price table int p[11] = { 0,1,5,8,9,10,17,17,20,24,30 }; /*for (int i = 0; i < 11; i++) { cout << p[i] << ","; }*/ cout << memoized_dp_fib(10) << endl; cout << fib(10) << endl; cout << bt_dp_fib(10); char a[] = "university"; char b[] = "unverstiy"; int distance1 = dtw(sizeof(a) - 1, sizeof(b) - 1, a, b); cout << distance1 << endl; int distance2 = btu_dtw(sizeof(a) - 1, sizeof(b) - 1, a, b); cout << distance2 << endl; getchar(); return 0; }
void SeqModel::reSegment(WaveFeatureOP & input, int templateIdx) { dtw( input, FULL_PATH ); // printf("%p\n", this); std::vector< int > path; collectBestPath( path, input.size() ); if(path.size() <= 0) { Warn("Don't try to train a empty file!"); return ; } int pathIdx; int preState = path[0]; int stateID; int startI = 0; KMeanState *state; for(pathIdx = 1; pathIdx < path.size(); pathIdx ++) { stateID = path[pathIdx]; // Log("%d->%d : %d ", preState, stateID, pathIdx); if(stateID != preState) { // no support soft yet.. state = (KMeanState *)(states[preState].hmmState); // Log("State %d: %d->%d\n", preState, startI, pathIdx - 1); state->edgePoints[templateIdx] = std::make_pair(startI, pathIdx - 1); preState = stateID; startI = pathIdx; } } state = (KMeanState *)(states[preState].hmmState); // Log("State %d: %d->%d\n", preState, startI, input.size()- 1); state->edgePoints[templateIdx] = std::make_pair(startI, input.size() - 1); // printf("xxoo %d\n", ((KMeanState *)(states[15].hmmState))->points.size()); }
void setup() { useInputStream(iStream); useOutputStream(oStream); calibrator.setCalibrateFunction(processAccelerometerData); calibrator.addCalibrateProcess("Resting", "Rest accelerometer on flat surface.", restingDataCollected); useCalibrator(calibrator); DTW dtw(false, true, null_rej); pipeline.setClassifier(dtw); usePipeline(pipeline); registerTuneable(null_rej, 0.1, 5.0, "Variability", "How different from the training data a new gesture can be and " "still be considered the same gesture. The higher the number, the " "more different it can be.", updateVariability); useTrainingSampleChecker(checkTrainingSample); }
float euclidean_distance(const coord_t *a, const coord_t *b){ float total = 0; switch(DIST_ID){ case 1: for(int i=0;i<BAND_NUM;i++) total += (a->data[i]-b->data[i])*(a->data[i]-b->data[i]); return sqrt(total); break; case 2: float mat1[BAND_NUM + 1][BAND_NUM + 1]; total = dtw(a, b, mat1, 1); return total; break; case 3: float mat2[BAND_NUM][BAND_NUM]; total = frechet(a, b, mat2); return total; break; default: break; } return total; }
Results *Recognizer::recognize(Character *ch, unsigned int n_results) { unsigned int group_id, i, size, n_chars, char_id, n_group_chars; unsigned int n_vectors, n_strokes; float *cursor = strokedata; float *input; n_vectors = ch->get_n_vectors(); n_strokes = ch->get_n_strokes(); input = ch->get_points(); #if 0 assert_aligned16((char *) input); #endif for (group_id=0, n_chars=0, char_id=0; group_id < n_groups; group_id++) { /* Only compare the input with templates which have +- window_size the same number of strokes as the input */ if (n_strokes > window_size) { if (groups[group_id].n_strokes > (n_strokes + window_size)) break; if (groups[group_id].n_strokes < (n_strokes - window_size)) { char_id += groups[group_id].n_chars; continue; } } cursor = (float *) (data + groups[group_id].offset); #ifdef __SSE__ float *ref1, *ref2, *ref3, *ref4; unsigned int size1, size2, size3, size4; wg_v4sf dtwres4; /* Process 4 reference characters at a time */ for (i=0; i < (groups[group_id].n_chars / 4); i++) { distm[n_chars].unicode = characters[char_id].unicode; ref1 = cursor; size1 = characters[char_id].n_vectors; ref2 = ref1 + characters[char_id].n_vectors * VEC_DIM_MAX; char_id++; distm[n_chars+1].unicode = characters[char_id].unicode; size2 = characters[char_id].n_vectors; ref3 = ref2 + characters[char_id].n_vectors * VEC_DIM_MAX; char_id++; distm[n_chars+2].unicode = characters[char_id].unicode; size3 = characters[char_id].n_vectors; ref4 = ref3 + characters[char_id].n_vectors * VEC_DIM_MAX; char_id++; distm[n_chars+3].unicode = characters[char_id].unicode; size4 = characters[char_id].n_vectors; cursor = ref4 + characters[char_id].n_vectors * VEC_DIM_MAX; char_id++; dtwres4 = dtw4(input, n_vectors, ref1, size1, ref2, size2, ref3, size3, ref4, size4); distm[n_chars++].dist = dtwres4.s[0]; distm[n_chars++].dist = dtwres4.s[1]; distm[n_chars++].dist = dtwres4.s[2]; distm[n_chars++].dist = dtwres4.s[3]; } /* Process the remaining of references */ n_group_chars = (groups[group_id].n_chars % 4); #else /* SSE not available, we need to process references sequentially */ n_group_chars = groups[group_id].n_chars; #endif for (i=0; i < n_group_chars; i++) { distm[n_chars].unicode = characters[char_id].unicode; distm[n_chars].dist = dtw(input, n_vectors, cursor, characters[char_id].n_vectors); cursor += characters[char_id].n_vectors * VEC_DIM_MAX; char_id++; n_chars++; } } /* sort the results with glibc's quicksort */ qsort ((void *) distm, (size_t) n_chars, sizeof (CharDist), (int (*) (const void *, const void*)) char_dist_cmp); size = MIN(n_chars, n_results); Results *results = new Results(size); for(i=0; i < size; i++) results->add(i, distm[i].unicode, distm[i].dist); return results; }
void SeqModel::recognition(WaveFeatureOP & input, std::vector<std::string> & res, SEQ_DTW_PATH_TYPE path_type) { // path_type = FULL_PATH; dtw( input, path_type ); collectRes(res, path_type, input.size()); }
void modCalcEquinox::processLines( QTextStream &istream ) { // we open the output file // QTextStream istream(&fIn); QString outputFileName; outputFileName = OutputLineEditBatch->text(); QFile fOut( outputFileName ); fOut.open(IO_WriteOnly); QTextStream ostream(&fOut); QString line; QString space = " "; int yearB; int i = 0; long double jdsp = 0., jdsu = 0., jdau = 0., jdwin = 0., jdsp1 = 0.; KStarsData *kd = (KStarsData*) parent()->parent()->parent(); KSSun *Sun = new KSSun(kd); while ( ! istream.eof() ) { line = istream.readLine(); line.stripWhiteSpace(); //Go through the line, looking for parameters QStringList fields = QStringList::split( " ", line ); i = 0; // Read year and write in ostream if corresponds if(yearCheckBatch->isChecked() ) { yearB = fields[i].toInt(); i++; } else yearB = yearEditBatch->text().toInt(); if ( allRadioBatch->isChecked() ) ostream << yearB << space; else if(yearCheckBatch->isChecked() ) ostream << yearB << space; jdsp = Sun->springEquinox(yearB); jdsu = Sun->summerSolstice(yearB); jdau = Sun->autumnEquinox(yearB); jdwin = Sun->winterSolstice(yearB); jdsp1 = Sun->springEquinox(yearB+1); KStarsDateTime dts( jdsp ); KStarsDateTime dtu( jdsu ); KStarsDateTime dta( jdau ); KStarsDateTime dtw( jdwin ); ostream << dts.toString(Qt::ISODate) << space << (float)(jdsu - jdsp) << space << dtu.toString(Qt::ISODate) << space << (float)(jdau - jdsu) << space << dta.toString(Qt::ISODate) << space << (float)(jdwin - jdau) << space << dtw.toString(Qt::ISODate) << space << (float)(jdsp1 - jdwin) << endl; } fOut.close(); }