// Created on 2008-07-10 // Test for what's happen when the extrapolated motion patterns are recognized by mimesis // also for RSJ conf. 2008 int test_extra_recognition(void) { tl_message ("start"); JHMM *hmm1 = NULL, *hmm2 = NULL, *hmm3 = NULL, *synthesis_hmm = NULL; Behavior *beh = NULL; JHMM *hmm_vec[3]; double weight[3]; int i; hmm1 = new JHMM; hmm2 = new JHMM; hmm3 = new JHMM; hmm1->Load("./.tmp/punch/punch.hmm"); hmm2->Load("./.tmp/squat/squat.hmm"); hmm3->Load("./.tmp/kick/kick.hmm"); hmm_vec[0] = hmm1; hmm_vec[1] = hmm2; hmm_vec[2] = hmm3; WorkSpace *work = NULL; work = new WorkSpace(); if (script_file[0]==0) { print_usage(); exit(0); } work->LoadMotionDB (script_file); work->SetHTKUnitsFromMotionDB (); work->BeforeRecognize(); work->DistanceLoad ("../../script/symbol_data/tmp_distance_vector"); work->SpaceLoad ("../../script/symbol_data/tmp_dim.spc"); vector<double> tmp_dis, new_dis, hellinger, tmp_cord; vector<double> likelihood; tl_message ("# of motion db is : %d\n", work->GetNumOfMotionDB() ); cout << "c_1, c_2, "; for (i=0; i<(int)(work->GetNumOfMotionDB()); i++) cout << "old_KLdistance[" << i << "] ,"; for (i=0; i<(int)(work->GetNumOfMotionDB()); i++) cout << "new_KLdivergence[" << i << "] ,"; for (i=0; i<(int)(work->GetNumOfMotionDB()); i++) cout << "Hellinger Distance[" << i << "] ,"; for (i=0; i<(int)(work->GetPsymbolSpace()->GetDimension() ); i++) cout << "x[" << i << "] , "; cout << endl; for (int i=-10; i<20; i++) { synthesis_hmm = new JHMM; weight[0] = i * 0.1; weight[1] = 1 - weight[0]; synthesis_hmm->InterpolationAny (hmm_vec, weight, 2); beh = synthesis_hmm->GenerateBehavior(100, 30); work->CalcHellingerDistanceOfOnlineBehavior(beh, hellinger); tl_message ("step hoge %d.0", i); for (int j=0; j<(int)(hellinger.size()); j++) cout << hellinger[j] << " , "; cout << endl; tl_message ("step hoge %d.1", i); work->CalcLikelihoodVector (beh, likelihood); tl_message ("step hoge %d.2", i); work->CalcDistanceOfInputBehavior (beh, tmp_dis); tl_message ("step hoge %d.3", i); work->CalcDistanceOfOnlineBehavior(beh, new_dis); tl_message ("step hoge %d.4", i); work->GetPsymbolSpace()->CoordinateFromDistanceData(tmp_dis, tmp_cord); tl_message ("step hoge %d.5", i); cout << weight[0] << " , " << weight[1] << " , "; for (int j=0; j<(int)(tmp_dis.size()); j++) cout << tmp_dis[j] << " , "; for (int j=0; j<(int)(new_dis.size()); j++) cout << new_dis[j] << " , "; for (int j=0; j<(int)(hellinger.size()); j++) cout << hellinger[j] << " , "; for (int j=0; j<(int)(tmp_cord.size()); j++) cout << tmp_cord[j] << " , "; cout << endl; delete synthesis_hmm; } delete beh; delete hmm1; delete hmm2; delete hmm3; delete synthesis_hmm; return TRUE; }
int main(int argc, char **argv) { srand (getpid()); Common_SetDebug (TRUE); get_args(argc, argv); JHMM *synthesis_hmm = NULL, *hmm[10]; Behavior *beh = NULL; tl_message ("Loading hmm factor for synthesis"); hmm[0] = new JHMM; hmm[1] = new JHMM; hmm[2] = new JHMM; hmm[0]->Load("./.tmp/squat/squat.hmm"); hmm[1]->Load("./.tmp/kick/kick.hmm"); hmm[2]->Load("./.tmp/punch/punch.hmm"); WorkSpace *work = NULL; work = new WorkSpace(); work->LoadMotionDB ("../../script/learning_scriptfile_2"); //work->LoadHTKUnits ("../../script/htkunit_scriptfile_2"); work->SetHTKUnitsFromMotionDB (); work->SetLabelFromHTKUnit(); work->BeforeRecognize(); //work->DisVectorLoad("../../script/symbol_data/tmp_distance_vector"); work->SpaceLoad ("../../script/symbol_data/tmp_dim.spc"); cerr << "num of htk_units = " << work->NumOfHTKUnits() << endl; #if 0 work->CalcKLDivergenceMatrix(); work->SpaceFileOut ("./tmp_space_output.txt"); tl_message ("KL distance from 0 to 1 (by new algo.) = %g", work->GetNthHTKUnit(0)->CalcKLDistance ( work->GetNthHTKUnit(1) ) ); tl_message ("KL distance from 1 to 0 (by new algo.) = %g", work->GetNthHTKUnit(1)->CalcKLDistance ( work->GetNthHTKUnit(0) ) ); tl_message ("KL distance from 0 to 2 (by new algo.) = %g", work->GetNthHTKUnit(0)->CalcKLDistance ( work->GetNthHTKUnit(2) ) ); tl_message ("KL distance from 2 to 0 (by new algo.) = %g", work->GetNthHTKUnit(2)->CalcKLDistance ( work->GetNthHTKUnit(0) ) ); tl_message ("KL distance from 1 to 2 (by new algo.) = %g", work->GetNthHTKUnit(1)->CalcKLDistance ( work->GetNthHTKUnit(2) ) ); tl_message ("KL distance from 2 to 1 (by new algo.) = %g", work->GetNthHTKUnit(2)->CalcKLDistance ( work->GetNthHTKUnit(1) ) ); #else work->CalcHellingerMatrix(); work->SpaceFileOut ("./tmp_space_output.txt"); tl_message ("Hellinger Distance from 0 to 1 = %g", work->GetNthHTKUnit(0)->CalcHellingerDistance ( *(work->GetNthHTKUnit(1)) ) ); tl_message ("Hellinger Distance from 1 to 0 = %g", work->GetNthHTKUnit(1)->CalcHellingerDistance ( *(work->GetNthHTKUnit(0)) ) ); tl_message ("Hellinger Distance from 0 to 2 = %g", work->GetNthHTKUnit(0)->CalcHellingerDistance ( *(work->GetNthHTKUnit(2)) ) ); //tl_message ("Hellinger Distance from 2 to 0 = %g", work->GetNthHTKUnit(2)->CalcHellingerDistance ( work->GetNthHTKUnit(0) ) ); tl_message ("Hellinger Distance from 1 to 2 = %g", work->GetNthHTKUnit(1)->CalcHellingerDistance ( *(work->GetNthHTKUnit(2)) ) ); //tl_message ("Hellinger Distance from 2 to 1 = %g", work->GetNthHTKUnit(2)->CalcHellingerDistance ( work->GetNthHTKUnit(1) ) ); #endif vector<double> tmp_dis, tmp_cord; tl_message ("Now generate a general synthesised HMM"); ofstream fout("./result.dat"); fout << "weight[0], weight[1], pseudo_distance to [0], pseudo_distance to [1], position_1, position_2" << endl; for (int i=-20; i<=20; i++) { synthesis_hmm = new JHMM; weight[0] = 0.1 * i; weight[1] = 1.0 - 0.1 * i; synthesis_hmm->InterpolationAny (hmm, weight, 2); beh = synthesis_hmm->GenerateBehavior(100, 30); delete synthesis_hmm; work->CalcDistanceOfInputBehavior(beh, tmp_dis); work->GetPsymbolSpace()->CoordinateFromDistanceData(tmp_dis, tmp_cord); fout << weight[0] << "," << weight[1] << ","; for (int i=0; i<(int)(tmp_dis.size()); i++) fout << tmp_dis[i] << ","; for (int i=0; i<(int)(tmp_cord.size()); i++) fout << tmp_cord[i] << ","; fout << endl; cerr << "size of distance vector = " << tmp_dis.size() << ", and size of coordinate = " << tmp_cord.size() << endl; } delete beh; for (int i=0; i<3; i++) delete hmm[i]; return TRUE; return TRUE; }