Index: applications/trading_models/trading_models_main.cpp
===================================================================
--- applications/trading_models/trading_models_main.cpp (revision 1338)
+++ applications/trading_models/trading_models_main.cpp (revision 1347)
@@ -8,8 +8,11 @@
 
 //<<<<<<< .mine
+#include "robustlib.h"
 #include "trading_models_lib.h"
 #include <iostream> 
 #include "estim/arx.h"
+
 //=======
+//#include "application/robust/robustlib.h"  ma tu byt aj daka cesta k tomu suboru?
 #include "trading_models_lib.h"
 #include "estim/arx.h"
@@ -23,45 +26,24 @@
 using namespace bdm;
 
-/*
-string cislo(string s)   // tato procedura spracova tie cisla z toho textoveho suboru tak aby sa odstranilo to e-001 a boli v spravnom 
-						//formate. Lebo predtym to vyhadyovalo divne cisla, nevedel som ci je to zato, ze bayes si  stym neporadi, ale yjavne nepomohlo
-{
-	int b=s.find('e');
-	string t=s.substr(0,b);
-	string poz=s.substr(b+1,s.size());
-
-	istringstream g(poz);
-	int pozc;
-	g>>pozc;
-	istringstream k(t);
-	double csl;
-	k>>csl;
-	if (pozc<0) //pozc moze byt niekedy aj kladne
+double sumastlpec(int k,vector<vec> pole,vector<vec> pravd) {  
+	double r=0;
+	for (int i=0;i < pole.size();i++)
 	{
-		for(int i=1;i<=-pozc;i++)
-		csl/=10;
-	} else
-	{ 
-		for(int j=1;j<=pozc;j++)
-		csl*=10;
+		r+=pole[i][k+4]*pravd[i][k];
+		//r=r+exp(pole[i][k+4]-m[k+4]+pravd[i][k]);  
 	}
+	//cout <<"r"<< log(r);
+ 	return r; //log
+		}
+
+int main () {
 	
-	ostringstream o;
-	o<<csl;
-	return o.str();
-} */
-
-double sumastlpec(int k,vector<vec> pole,vector<vec> pravd) {  //robi sumu k-teho stlpca, pouzivam na konci pri ratani pravdepodobnosti
-	double r=0;
-	for (int i=0;i<pole.size();i++)
-	{
-		r+=pole[i][k]*pravd[i][k];
-	}
-	return r;
-		}
-
-int main () {
+	char* outfile_strings[18] = {"prsti_BO_.txt", "prsti_PA_.txt", "prsti_PL_.txt", "prsti_AD_.txt", "prsti_BP_.txt", "prsti_C__.txt", "prsti_CC_.txt", "prsti_CD_.txt", "prsti_CL_.txt", "prsti_CT_.txt", "prsti_CU_.txt", "prsti_ED_.txt", "prsti_FC2.txt", "prsti_FV2.txt", "prsti_GC_.txt", "prsti_HG_.txt", "prsti_HO_.txt", "prsti_HU_.txt"};
+	char* file_strings[18] = {"c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\BO_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\PA_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\PL_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\AD_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\BP_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\C__.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\CC_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\CD_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\CL_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\CT_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\CU_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\ED_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\FC2.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\FV2.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\GC_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\HG_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\HO_.txt", "c:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-MATHEMATIKA\\HU_.txt"};
+	//for (int a=0;a<18;a++)
+	//{
+	int a=3;
 	vector<vector<string>> ADdata;     //nacitavanie dat do pola ADdata -funguje spravne
-		ifstream myfile("C:\\AD_dataupravene.txt");
+		ifstream myfile(file_strings[a]);				//"C:\\Users\\Peto\\Desktop\\PROG-BAK\\DATA-Mathematika\\CL_.txt");
 		if (myfile.is_open())
 		{
@@ -82,5 +64,22 @@
 		}
 		myfile.close();  //konec nacitavania dat
-
+		/*		//to malo byt rpevedenie str na double, aspon mysslim
+		std::istringstream stme,stmd;	//je to dake chybne, aj cisla z toho ADdata cita/zapisuje trochu ine
+		double d,e;
+		vector<vec> data_rozdiel;
+		for (int b=0;b<ADdata.size();b++)
+		{
+			vec pom;
+			stmd.str(ADdata[b][0]);
+			stmd >>d;
+			for (int c=1;c<ADdata[b].size();c++)
+			{	
+				stme.str(ADdata[b][c]);
+				stme >>e;
+				cout<<e<<' '<<d ;
+				pom.ins(pom.size(),e-d);
+				cout<<pom;
+			}
+		}*/
 		vector<vec> norm; //do norm zapisujeme normalizacne faktory
 		for (int h=1;h<=2;h++) //cyklus ktory ovplzvnuje konstantu h=1- model s konstantou, h=2, bez konstanty
@@ -94,5 +93,5 @@
 			while (g<=4)  //cyklus co meni rozmery matice V
 			{
-				mat V0 = 0.0001 * eye ( g ); // aj tato matica ma vplyv na normalizacny faktor, nemoze byt aj preto taky velky, ako inak by sa dala zvolit?
+				mat V0 = 0.0001*eye ( g ); // aj tato matica ma vplyv na normalizacny faktor, nemoze byt aj preto taky velky, ako inak by sa dala zvolit?
 				
 				int p=0;
@@ -107,4 +106,5 @@
 						{
 							ARX Ar;
+							RARX RAr(g+h-3,0,b);
 							Ar.set_statistics ( 1, V0 ); //nu is default (set to have finite moments)
 							Ar.set_constant ( b );
@@ -116,13 +116,17 @@
 								vec predikce;
 								predikce.ins(0,ADdata[3][k+2]);			//predpovede nacitavame a zadavame do Bayes zvlast
-								condition.ins(0,ADdata[i][k+1]);					
-								condition.ins(0,ADdata[j][k+p]);//zmena i -> j aby to bralo regresory z roznych riadkov, ak p=1 bereme data z toho isteho casu
-								
-								cout << "Pred:" << predikce << ", ";
-								cout << "Cond:" << condition << endl;
-								
+								condition.ins(0,ADdata[i][k+1]);				
+								condition.ins(1,ADdata[j][k+p]);//zalezi na poradi v conditions? Teraz su na zaciatku starsie data
+								//cout<<condition;
+								RAr.bayes(condition.right(g+h-3));
 								Ar.bayes(predikce,condition.right(g+h-3));	//z condition berem len urcity pocet prvkov, bud 0, 1,alebo 2, lebo nepotrebujem vzdy vsetky (AR(1) model)					
 								pomocka.ins(pomocka.size(),Ar.posterior().lognc()); //nie je tu exponenciala! -aby to bolo mensie
-							}  					
+							}  
+							//cout<<pomocka;
+							pomocka.ins(0,j+1);
+							pomocka.ins(0,i+1);
+							pomocka.ins(0,g);
+							pomocka.ins(0,h);
+							RAr.posterior->log_nc;
 							norm.push_back(pomocka);  
 							if ((g==3 && h==2) || (g==4))  //tento cyklus sa bude opakovat, len ak mame maticu V0 roymeru 4x4, to je AR(2) model s konst, alebo podobne len g=3, h=2, teda AR(2)bez kons
@@ -154,136 +158,60 @@
 			}
 		}
-
-		/*  //tu je to povodne
-		mat V0 = 0.0001 * eye ( 2 );  //pre pripad samotnej konstanty
-		ARX Ar;
-		Ar.set_statistics ( 1, V0 ); //nu is default (set to have finite moments)
-		Ar.set_constant ( true );
-		Ar.validate();			// forgetting is default: 1.0
-		vector<double> pom1;
-		for(int k = 0;k<140;k++) //prechadyame "po riadkoch" 
-			{
-				vec predikce;
-				vec cond;
-				cond.ins(0,ADdata[3][3]);
-				predikce.ins(0,ADdata[3][k+2]);			//predpovede nacitavame a zadavame do Bayes zvlast
-				Ar.bayes(predikce,cond.right(0));					
-				pom1.push_back(exp(Ar.posterior().lognc()));
-			}  
-		norm.push_back(pom1);  
-		
-		for (int a=2;a<=3;a++)  //AR(1) bez a potom s konstantou
-		{
-			bool b=false;			//b pouzivame pri set_constant
-			if(a==3)
-				b=true;
-			mat V0 = 0.0001 * eye ( a );  //pre pripad samotnej konstanty
-			
-			for (int p=0;p < ADdata.size();p++)
-			{
-				ARX Ar;
-				Ar.set_statistics ( 1, V0 ); //nu is default (set to have finite moments)
-				Ar.set_constant ( b );
-				Ar.validate();			// forgetting is default: 1.0
-				vector<double> pom1;
-				for(int k = 0;k<140;k++) //prechadyame "po riadkoch" 
-				{
-					vec predikce;
-					vec condition;
-					condition.ins(0,ADdata[p][k]);
-					predikce.ins(0,ADdata[3][k+1]);			//predpovede nacitavame a zadavame do Bayes zvlast
-					Ar.bayes(predikce,condition);					
-					pom1.push_back(exp(Ar.posterior().lognc()));
-				}  
-				norm.push_back(pom1);  //normalizacne faktory pre urcitu kombinaciu regresorov(teda po kazdom riadku) ulozi do pola norm
-			}
-		}
-		
-		
-		for (int g=3;g<=4;g++)  //tento cyklus je az do konca, raz to robime s konstantou, raz bez.
-		{
-			bool b;			//b pouzivame pri set_constant
-			if(g==3)
-				b=false;   
-			else
-				b=true;
-			mat V0 = 0.0001 * eye ( g );
-			for(int i = 0;i < ADdata.size();i++) //po pocet riadkov, co bz malo byt 6
-			{
-				for(int j = i+1; j<ADdata.size();j++)
-				{
-					ARX Ar;
-					Ar.set_statistics ( 1, V0 ); //nu is default (set to have finite moments)
-					Ar.set_constant ( b );
-					Ar.validate();
-							// forgetting is default: 1.0
-					vector<double> pomocka;
-					for(int k = 0;k<140;k++) //prechadyame "po riadkoch" 
-					{
-						vec condition;	
-						vec predikce;
-						predikce.ins(0,ADdata[3][k+1]);			//predpovede nacitavame a zadavame do Bayes zvlast
-						condition.ins(0,ADdata[i][k]);						
-						condition.ins(0,ADdata[j][k]);//zmena i -> j qby to bralo regresory z roznych riadkov			
-						Ar.bayes(predikce,condition);					
-						pomocka.push_back(exp(Ar.posterior().lognc()));
-					}  					
-					norm.push_back(pomocka);  
-				}
-			}		
-			for(int i = 0;i < ADdata.size();i++) //po pocet riadkov, co bz malo byt 6
-			{
-				for(int j = 0; j<ADdata.size();j++)
-				{
-					ARX Ar;
-					Ar.set_statistics ( 1, V0 ); //nu is default (set to have finite moments)
-					Ar.set_constant ( b );
-					Ar.validate();
-							// forgetting is default: 1.0
-					vector<double> pomocka;
-					for(int k = 0;k<140;k++) //prechadyame "po riadkoch" 
-					{
-						vec condition;	
-						vec predikce;
-						predikce.ins(0,ADdata[3][k+2]);			//predpovede nacitavame a zadavame do Bayes zvlast
-						condition.ins(0,ADdata[i][k]); 
-						
-						condition.ins(0,ADdata[j][k+1]);//zmena i -> j qby to bralo regresory z roznych riadkov			
-						Ar.bayes(predikce,condition);					
-						pomocka.push_back(Ar.posterior().lognc());
-					}  
-					
-					norm.push_back(pomocka);  
-				}
-			}
-		}*/
-			vector<vec> prsti; //hypotez je 85
+		//pocitanie maxima y kaydeho stlpcu norm
+		vector<double> max;
+		for (int i=4;i<345;i++)
+		{
+			double pom=norm[0][i];
+			for (int j=1;j<norm.size();j++)
+			{
+				if (pom<norm[j][i])
+				{
+					pom=norm[j][i];
+				}			
+			}
+			max.push_back(pom);
+		}
+		//nove pole namiesto norm, kde bude odcitane max a bude v spravnej forme, teda aj s exponencialov
+		vector<vec> nfaktor;
+		for (int j=1;j<norm.size();j++)
+		{
+			for (int i=1;j<norm[j].size();j++)
+			{
+				nfaktor[j][i]=exp(norm[j][i+4]-max[i]);			
+			}
+		}
+
+
+			vector<vec> prsti; 
 			int m,n,p;
-			for(p=0;p<115;p++) //inicializuem apriorne pravdepodobnosti
+			for(p=0;p<115;p++) 
 			{
 				vec k;
-				k.ins(0,1/115.);
+				k.ins(0,1/115.);	//log
 				prsti.push_back(k);
 			}
 			// v ramci riadku v poli norm su hodnoty pre jednu hypotezu v roznych casoch, pocitanie pravdepodobnosti z norm. faktorov
-			for (m=0;m<norm[1].size();m++) 
+			for (m=0;m<norm[1].size()-4;m++) 
 			{	double k=sumastlpec(m,norm,prsti);
 				for(n=0;n < norm.size();n++)
 				{
-					prsti[n].ins(prsti[n].size(),norm[n][m]*prsti[n][m]/k);				
+					prsti[n].ins(prsti[n].size(),norm[n][m+4]*prsti[n][m]/k);
+					//prsti[n].ins(prsti[n].size(),norm[n][m+4]+prsti[n][m]-k);				
 				}
 			}		
-			ofstream file;	//zapis pravdepodobnosti do suboru
-			file.open("prsti_hypot.txt");
+			ofstream file;	
+			
+			file.open(outfile_strings[a]);			//"prsti_hypot.txt",ios::app);
 			for(int i=0;i < prsti.size();i++)
 			{
+				file << norm[i][0] <<" "<<norm[i][1]<<" "<<norm[i][2]<<" "<<norm[i][3]<<" ";
 				for(int j=0;j < prsti[i].size();j++)
 				{
 					if(j!=prsti[i].size()-1)
 					{
-						file << prsti[i][j]<<" ";
+						file << prsti[i][j]<<" "; //exp
 					}else
 					{
-						file<<prsti[i][j]<<endl;
+						file<<prsti[i][j]<<endl; //exp
 					}					
 				}
@@ -291,5 +219,5 @@
 			file<<endl;
 			file.close();
-		
+	//}	
 	}
 
