예제 #1
0
int main(int argc, char **argv)
{
    std::vector<Demonstration> demos;
    Demonstration demo =  Demonstration(4,200,0);
    std::vector<std::string> vars,vars2;
    vars.push_back("t");
    vars.push_back("x");
    vars.push_back("y");
    vars.push_back("z");

    demo.getDatapoints().loadFromFile("../../data/data_txyz.txt");

    demo.getDatapoints().setVarNames(vars);


    cout << endl << "Data is: " << demo.getDatapoints().getData() << endl;
    cout << endl << "nbVar is: " << demo.getDatapoints().getNumVARS() << endl;
    cout << endl << "nbDatapoints is: " << demo.getDatapoints().getNumPOINTS() << endl;

    getchar();
    demos.push_back(demo);

    GMM_Model *gmm;
    gmm = new GMM_Model(demos, 3);
    gmm->setVARSNames(vars);


    cout << "\n EM rounds = " << gmm->EM_learn();

    cout << "\n MU = " << endl << gmm->getCOMPONENTS().at(0).getMU();
    cout << "\n MU = " << endl << gmm->getCOMPONENTS().at(1).getMU();
    cout << "\n MU = " << endl << gmm->getCOMPONENTS().at(2).getMU();

    cout << "\n SIGMA = " << endl << gmm->getCOMPONENTS().at(0).getSIGMA();
    cout << "\n SIGMA = " << endl << gmm->getCOMPONENTS().at(1).getSIGMA();
    cout << "\n SIGMA = " << endl << gmm->getCOMPONENTS().at(2).getSIGMA();



    Datapoints *Repros;
        Repros = new Datapoints(1,200);


        vars2.push_back("t");

        Repros->setVarNames(vars2);


        mat data = demo.getDatapoints().getData().submat(0,0,0,199);
        Repros->setData(data);
        GMR* reg = new GMR(gmm);
        reg->regression(Repros);


        cout << "\n SIGMA = "  << reg->getCOMPONENTS().at(199).getSIGMA();
        cout << "\n MU = "  << reg->getCOMPONENTS().at(199).getMU();

  return 0;
}
예제 #2
0
int main(int argc, char **argv)
{
	std::vector<Demonstration> demos;
	Demonstration demo =  Demonstration(nbVar,nbData);
	std::vector<std::string> vars;
	vars.push_back("t");
	vars.push_back("x");
	vars.push_back("y");
	vars.push_back("z");

	demo.getDatapoints().loadFromFile("../../data/data_txyz.txt");
	demo.getDatapoints().setVarNames(vars);

	cout << endl << "Data is: " << demo.getDatapoints().getData() << endl;
	cout << endl << "nbVar is: " << demo.getDatapoints().getNumVARS() << endl;
	cout << endl << "nbDatapoints is: " << demo.getDatapoints().getNumPOINTS() << endl;
	cout << "\nPress enter to continue..." << endl; getchar();

	demos.push_back(demo);

	GMM_Model *gmm;
	gmm = new GMM_Model(demos,nbStates);
	gmm->setVARSNames(vars);

	cout << "\n Number of EM iterations: " << gmm->EM_learn();
	for (int i=0;i<nbStates;i++){
		cout << "\n Mu_" << i << " = \n" << gmm->getMU(i);
		cout << "\n Sigma_" << i << " = \n" << gmm->getSIGMA(i);
	}
	//Save GMM in files GMM_priors.txt, GMM_mu.txt, GMM_sigma.txt and GMM_vars.txt
	gmm->saveInFiles();
	cout << "\nPress enter to continue..." << endl; getchar();

	//Loading the GMM model from files...  
	GMM_Model *gmm2 = new GMM_Model("GMM_priors.txt", "GMM_mu.txt", "GMM_sigma.txt", "GMM_vars.txt");

	for (int i=0;i<nbStates;i++)
		gmm2->setMU(i, gmm2->getMU(i)*10.0);
	for (int i=0;i<nbStates;i++)
		cout << "\n Mu_" << i << " = \n" << gmm2->getMU(i);
	return 0;
}