Index: applications/robust/main.cpp
===================================================================
--- applications/robust/main.cpp (revision 1396)
+++ applications/robust/main.cpp (revision 1401)
@@ -27,43 +27,7 @@
 //const int utility_constant = 5;
 
-const int max_model_order = 1;
+const int max_model_order = 2;
 const double apriorno     = 0.01;
-const int max_window_size = 121;
-
-/*
-HDDEDATA CALLBACK DdeCallback(
-	UINT uType,     // Transaction type.
-	UINT uFmt,      // Clipboard data format.
-	HCONV hconv,    // Handle to the conversation.
-	HSZ hsz1,       // Handle to a string.
-	HSZ hsz2,       // Handle to a string.
-	HDDEDATA hdata, // Handle to a global memory object.
-	DWORD dwData1,  // Transaction-specific data.
-	DWORD dwData2)  // Transaction-specific data.
-{
-	return 0;
-}
-
-void DDERequest(DWORD idInst, HCONV hConv, char* szItem)
-{
-	HSZ hszItem = DdeCreateStringHandle(idInst, szItem, 0);
-	HDDEDATA hData = DdeClientTransaction(NULL,0,hConv,hszItem,CF_TEXT, 
-									XTYP_ADVSTART,TIMEOUT_ASYNC , NULL); //TIMEOUT_ASYNC
-	if (hData==NULL)
-	{
-		printf("Request failed: %s\n", szItem);
-	}
-
-	if (hData==0)
-	{
-		printf("Request failed: %s\n", szItem);
-	}
-}
-
-DWORD WINAPI ThrdFunc( LPVOID n )
-{    
-    return 0;
-}
-*/
+const int max_window_size = 30;
 
 class model
@@ -168,10 +132,9 @@
 		vec data_vector;
 		for(set<pair<int,int>>::iterator ar_iterator = ar_components.begin();ar_iterator!=ar_components.end();ar_iterator++)
-		{  //ar?iterator ide len od 1 pod 2, alebo niekedy len 1
+		{  
 			data_vector.ins(data_vector.size(),(*data_matrix).get(ar_iterator->first,time-ar_iterator->second));
-// do data vector vlozi pre dany typ regresoru prislusne cisla z data_matrix. Ale ako? preco time-ar_iterator->second?
 		}
 		if(my_rarx!=NULL)
-		{	//pre robust priradi az tu do data_vector aj predikciu
+		{	
 			data_vector.ins(0,(*data_matrix).get(predicted_channel,time));
 			my_rarx->bayes(data_vector);
@@ -179,5 +142,5 @@
 		else
 		{
-			vec pred_vec;//tu sa predikcia zadava zvlast
+			vec pred_vec;
 			pred_vec.ins(0,(*data_matrix).get(predicted_channel,time));
 			my_arx->bayes(pred_vec,data_vector);
@@ -245,10 +208,10 @@
 		set<set<pair<int,int>>> created_model_types;		
 
-		if(max_order == 1)//ukoncovacia vetva
+		if(max_order == 1)
 		{			
-			for(int channel = 0;channel<number_of_channels;channel++)//pre AR 1 model vytvori kombinace kanalov v prvom kroku poyadu
+			for(int channel = 0;channel<number_of_channels;channel++)
 			{
 				set<pair<int,int>> returned_type;
-				returned_type.insert(pair<int,int>(channel,1));  //??
+				returned_type.insert(pair<int,int>(channel,1));  
 				created_model_types.insert(returned_type);
 			}
@@ -258,5 +221,5 @@
 		else
 		{
-			created_model_types = possible_models_recurse(max_order-1,number_of_channels);//tu uz mame ulozene kombinace o jeden krok dozadu  //rekuryivne volanie
+			created_model_types = possible_models_recurse(max_order-1,number_of_channels);
 			set<set<pair<int,int>>> returned_types;
 			
@@ -269,8 +232,8 @@
 					{
 						set<pair<int,int>> returned_type;
-						pair<int,int> new_pair = pair<int,int>(channel,order);//??
-						if(find((*model_ref).begin(),(*model_ref).end(),new_pair)==(*model_ref).end()) //??
+						pair<int,int> new_pair = pair<int,int>(channel,order);
+						if(find((*model_ref).begin(),(*model_ref).end(),new_pair)==(*model_ref).end()) 
 						{
-							returned_type.insert((*model_ref).begin(),(*model_ref).end()); //co vlozi na zaciatok retuned_type?
+							returned_type.insert((*model_ref).begin(),(*model_ref).end()); 
 							returned_type.insert(new_pair);
 							
@@ -294,14 +257,7 @@
 int main ( int argc, char* argv[] ) 
 {
-	
-	// EXPERIMENT: A moving window estimation and prediction of RARX is tested on data generated from 
-    // y_t=0.95*y_(t-1)+0.05*y_(t-2)+0.2*e_t, where e_t is normally, student(4) and cauchy distributed. It
-    // can be compared to the classical setup.
-	
-	itpp::Laplace_RNG LapRNG = Laplace_RNG();	
-
 	vector<vector<string>> strings;
 
-	char* file_string =  "C:\\results\\cauchy"; // "C:\\dataADClosePercDiff"; //  
+	char* file_string =  "C:\\results\\normalM"; // "C:\\dataADClosePercDiff"; //  
 
 	char dfstring[80];
@@ -318,7 +274,6 @@
 		{			
 			vec data_vector;
-			while(line.find(',') != string::npos) //zmenil som ciarku za medzeru
-			{
-				//line.erase(0,1); // toto som sem pridal
+			while(line.find(',') != string::npos) 
+			{				
 				int loc2 = line.find('\n');
 				int loc  = line.find(',');
@@ -336,367 +291,73 @@
 		cout << "Can't open data file!" << endl;
 	}
-	
-	//konec nacitavania dat
-	set<set<pair<int,int>>> model_types = model::possible_models_recurse(max_model_order,data_matrix.rows()); //volanie funkce kde robi kombinace modelov
-												//to priradime do model_types, data_matrix.row urcuje pocet kanalov dat
+
+	set<pair<int,int>> model_type;
+	model_type.insert(pair<int,int>(0,1));
+	model_type.insert(pair<int,int>(0,2));
+
 	vector<model*> models;
-	for(set<set<pair<int,int>>>::iterator model_type = model_types.begin();model_type!=model_types.end();model_type++)
-	{// prechadza rozne typy kanalov, a poctu regresorov
-		for(int window_size = max_window_size-1;window_size < max_window_size;window_size++)
-		{
-			//models.push_back(new model((*model_type),true,true,window_size,0,&data_matrix));   // to su len konstruktory, len inicializujeme rozne typy
-			//models.push_back(new model((*model_type),false,true,window_size,0,&data_matrix));
-			models.push_back(new model((*model_type),true,false,window_size,0,&data_matrix));
-			models.push_back(new model((*model_type),false,false,window_size,0,&data_matrix));		
-		}
-
-		//set<pair<int,int>> empty_list;
-		//models.push_back(new model(empty_list,false,true,100,0,&data_matrix));
-	}
-	
-	mat result_lognc;
-	// mat result_preds;
 
 	ofstream myfilew;
-	//char fstring[80];					
-	//strcpy(fstring,file_string);
-	//strcat(fstring,"lognc.txt");
-	//strcat(fstring,"preds.txt");	
-
-	for(int time = max_model_order;time<data_matrix.cols();time++) //time<data_matrix.cols() 
-	{ 	
-		if(time==max_window_size)
-		{
-			exit(1);
-		}
 		
-		//pocet stlpcov data_matrix je pocet casovych krokov
-		vec cur_res_lognc;
-		// vec preds;
-		vector<string> nazvy;
-		for(vector<model*>::iterator model_ref = models.begin();model_ref!=models.end();model_ref++)
-		{//posuvam s apo models, co je pole modelov urobene o cyklus vyssie. Teda som v case time a robim to tam pre vsetky typy modelov, kombinace regresorov
-			(*model_ref)->data_update(time); //pozret sa preco je toto tu nutne
-
-			cout << "Updated." << endl;
-			//if (time = max_model_order) nazvy.push_back(models.model_ref]);// ako by som mohol dostat nazov modelu?
-
-			if((*model_ref)->my_rarx!=NULL)	//vklada normalizacni faktor do cur_res_lognc
-			{
-				cout << "Maxlik vertex:" << (*model_ref)->my_rarx->posterior->minimal_vertex->get_coordinates() << endl;
-				cur_res_lognc.ins(cur_res_lognc.size(),(*model_ref)->my_rarx->posterior->_ll());				
-			}
-			else
-			{
-				cur_res_lognc.ins(cur_res_lognc.size(),(*model_ref)->my_arx->_ll());
-			}
-			
-			if(time == max_window_size-1)
-			{
-				//***********************
-				int sample_size = 100000;
-				//***********************
-				
-				pair<vec,mat> samples;
-				if((*model_ref)->my_arx!=NULL)
+
+	while(data_matrix.rows()!=0)
+	{
+		for(int i=0;i<models.size();i++)
+		{
+			delete models[i];
+		}
+		
+		models.clear();
+		models.push_back(new model(model_type,true,false,max_window_size,0,&data_matrix));
+		models.push_back(new model(model_type,false,false,max_window_size,0,&data_matrix));
+
+		for(int time = max_model_order;time<max_window_size;time++) //time<data_matrix.cols() 
+		{		
+			vec cur_res_lognc;
+		
+			vector<string> nazvy;
+			for(vector<model*>::iterator model_ref = models.begin();model_ref!=models.end();model_ref++)
+			{
+				(*model_ref)->data_update(time);
+
+				cout << "Updated:" << time << endl;	
+
+				if(time == max_window_size-1)
 				{
-					mat samp_mat = (*model_ref)->my_arx->posterior().sample_mat(sample_size);
-					samples = pair<vec,mat>(ones(samp_mat.cols()),samp_mat);
+					char fstring[80];					
+					strcpy(fstring,file_string);
+					strcat(fstring,"ml");					
+					strcat(fstring,(*model_ref)->name);
+					strcat(fstring,".txt");
+
+					vec coords;
+					if((*model_ref)->my_arx!=NULL)
+					{
+						coords = (*model_ref)->my_arx->posterior().est_theta();
+					}
+					else
+					{
+						coords = (*model_ref)->my_rarx->posterior->minimal_vertex->get_coordinates();						
+					}
+
+					myfilew.open(fstring,ios::app);
+
+					for(int i=0;i<coords.size();i++)
+					{
+						myfilew << coords.get(i) << ",";
+					}
+					myfilew << endl;
+
+					myfilew.close();				
 				}
-				else
-				{
-					samples = (*model_ref)->my_rarx->posterior->sample(sample_size,true);					
-				}
-
-				char fstring[80];					
-				strcpy(fstring,file_string);
-				strcat(fstring,(*model_ref)->name);
-				strcat(fstring,".txt");
-				
-				//cout << samples.first << endl;
-				
-				myfilew.open(fstring,ios::app);
-				
-				/*
-				for(int i = 0;i<samples.first.size();i++)
-				{
-					myfilew << samples.first.get(i) << ",";
-				}
-				myfilew << endl;
-				*/
-
-				for(int j = 0;j<samples.second.rows()+1;j++)
-				{			
-					for(int i = 0;i<samples.second.cols();i++)
-					{
-						if(j!=samples.second.rows())
-						{
-							myfilew << samples.second.get(j,i) << ",";
-						}
-						/*
-						else
-						{
-							myfilew << "0,";
-						}
-						*/
-					}				
-					myfilew << endl;
-				}
-
-				cout << "*************************************" << endl;
-
-				myfilew.close();				
-			}
-			
-			/* // PREDICTIONS
-			pair<vec,vec> predictions = (*model_ref)->predict(500,time,&LapRNG);
-
-			cout << predictions.first << endl << predictions.second << endl;
-
-			double avg_prediction = (predictions.first*predictions.second)/(predictions.first*ones(predictions.first.size()));
-
-			(*model_ref)->predictions.ins((*model_ref)->predictions.size(),avg_prediction);
-					
-			myfilew.open(fstring,ios::app);
-			myfilew << avg_prediction << ","; 
-			myfilew.close();
-			*/
-
-			//preds.ins(0,data_matrix.get(0,time+1));
-		}
-
-		
-		/* // REAL PRICE
-		myfilew.open(fstring,ios::app);
-		myfilew << data_matrix.get(0,time+1) << endl;
-		myfilew.close();
-		*/
-
-		result_lognc.ins_col(result_lognc.cols(),cur_res_lognc);
-		// result_preds.ins_col(result_preds.cols(),preds);
-
-		// cout << "Updated." << endl;	
-							
-		/*
-		myfilew.open(fstring,ios::app);
-		
-		// myfile << my_rarx->posterior->minimal_vertex->get_coordinates()[0];
-		
-		if(time == max_model_order)
-		{ 
-			for(int i = 0;i<cur_res_lognc.size();i++)
-			{
-				for(set<pair<int,int>>::iterator ar_ref = models[i]->ar_components.begin();ar_ref != models[i]->ar_components.end();ar_ref++)
-				{
-					myfilew << (*ar_ref).second << (*ar_ref).first;							
-				}
-
-				myfilew << ".";
-
-				if(models[i]->my_arx == NULL)
-				{
-					myfilew << "1";
-				}
-				else
-				{
-					myfilew << "0";
-				}
-					
-				if(models[i]->has_constant)
-				{
-					myfilew << "1";
-				}
-				else
-				{
-					myfilew << "0";
-				}
-
-				myfilew << ",";
-			}
-
-			myfilew << endl;
-		}
-		
-		
-		// for(int i = 0;i<cur_res_lognc.size();i++)
-		// {
-		// 	   myfilew << cur_res_lognc[i] << ' ';//zmenil som ciarku ze medzeru
-		// }
-		
-
-		myfilew << endl;				
-		
-		myfilew.close();
-		*/
-		
-}
-	
-
-
-	// EXPERIMENT: One step ahead price prediction. Comparison of classical and robust model using optimal trading
-    //             with maximization of logarithm of one-step ahead wealth.
-
-	
-		
-		/*
-		cout << "One experiment finished." << endl;
-
-		ofstream myfile;
-		myfile.open("c:\\robust_ar1.txt",ios::app);
-		myfile << endl;
-		myfile.close();
-
-		myfile.open("c:\\robust_ar2.txt",ios::app);
-		myfile << endl;
-		myfile.close();*/
-	
-
-	//emlig* emlig1 = new emlig(emlig_size);
-
-	//emlig1->step_me(0);
-	//emlig* emlig2 = new emlig(emlig_size);
-	
-	/*
-	emlig1->set_correction_factors(4);
-
-	for(int j = 0;j<emlig1->correction_factors.size();j++)
-	{
-		for(set<my_ivec>::iterator vec_ref = emlig1->correction_factors[j].begin();vec_ref!=emlig1->correction_factors[j].end();vec_ref++)
-		{
-			cout << j << "    ";
-			
-			for(int i=0;i<(*vec_ref).size();i++)
-			{
-				cout << (*vec_ref)[i];
-			}
-
-			cout << endl;
-		}
-	}*/
-	
-	/*
-    vec condition5 = "1.0 1.0 1.01";//"-0.3 1.7 1.5";
-
-	emlig1->add_condition(condition5);
-	//emlig1->step_me(0);
-
-
-	vec condition1a = "-1.0 1.02 0.5";
-	//vec condition1b = "1.0 1.0 1.01";
-	emlig1->add_condition(condition1a);
-	//emlig2->add_condition(condition1b);
-
-	vec condition2a = "-0.3 1.7 1.5";
-	//vec condition2b = "-1.0 1.0 1.0";
-	emlig1->add_condition(condition2a);
-	//emlig2->add_condition(condition2b);
-
-	vec condition3a = "0.5 -1.01 1.0";
-	//vec condition3b = "0.5 -1.01 1.0";
-
-	emlig1->add_condition(condition3a);
-	//emlig2->add_condition(condition3b);	
-
-	vec condition4a = "-0.5 -1.0 1.0";
-	//vec condition4b = "-0.5 -1.0 1.0";	
-
-	emlig1->add_condition(condition4a);
-	//cout << "************************************************" << endl;
-	//emlig2->add_condition(condition4b);
-	//cout << "************************************************" << endl;
-	
-	//cout << emlig1->minimal_vertex->get_coordinates();
-	
-	//emlig1->remove_condition(condition3a);
-	//emlig1->step_me(0);
-	//emlig1->remove_condition(condition2a);
-	//emlig1->remove_condition(condition1a);
-	//emlig1->remove_condition(condition5);
-	
-
-	//emlig1->step_me(0);
-	//emlig2->step_me(0);
-	
-
-	// DA SE POUZIT PRO VYPIS DO SOUBORU
-	// emlig1->step_me(0);
-
-	//emlig1->remove_condition(condition1);
-	
-	
-
-	
-	
-	/*
-	for(int i = 0;i<100;i++)
-	{
-		cout << endl << "Step:" << i << endl;		
-
-		double condition[emlig_size+1];		
-
-		for(int k = 0;k<=emlig_size;k++)
-		{
-			condition[k] = (rand()-RAND_MAX/2)/1000.0;		
-		}
-			
-
-		vec* condition_vec = new vec(condition,emlig_size+1);
-		emlig1->add_condition(*condition_vec);
-
-		/*
-		for(polyhedron* toprow_ref = emlig1->statistic.rows[emlig_size]; toprow_ref != emlig1->statistic.end_poly; toprow_ref = toprow_ref->next_poly)
-		{
-			cout << ((toprow*)toprow_ref)->probability << endl;
-		}
-		*/
-		/*
-		cout << emlig1->statistic_rowsize(emlig_size) << endl << endl;
-	
-		/*
-		if(i-emlig1->number_of_parameters >= 0)
-		{
-			pause(30);
-		}
-		*/
-
-		// emlig1->step_me(i);
-		
-		/*
-		vector<int> sizevector;
-		for(int s = 0;s<=emlig1->number_of_parameters;s++)
-		{
-			sizevector.push_back(emlig1->statistic_rowsize(s));
-		}
-		*/
-	//}
-    
-
-
-	
-	/*
-	emlig1->step_me(1);
-
-	vec condition = "2.0 0.0 1.0";	
-
-	emlig1->add_condition(condition);
-
-	vector<int> sizevector;
-	for(int s = 0;s<=emlig1->number_of_parameters;s++)
-	{
-		sizevector.push_back(emlig1->statistic_rowsize(s));
-	}
-
-	emlig1->step_me(2);
-
-	condition = "2.0 1.0 0.0";
-
-	emlig1->add_condition(condition);
-
-	sizevector.clear();
-	for(int s = 0;s<=emlig1->number_of_parameters;s++)
-	{
-		sizevector.push_back(emlig1->statistic_rowsize(s));
-	}
-	*/
+			}
+		}
+
+		data_matrix.del_row(0);
+	}
+	
+
+
+	
 
 	return 0;
