Main Page   Compound List   File List   Compound Members   File Members   Related Pages  

SupLearnPara.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*/
00010 /*---------------------------------------------------------------------------*/
00011 
00012 #include <iostream>
00013 #include <string>  
00014 #include <vector>
00015 #include <fstream>
00016 
00017 #include <cstdio>
00018 #include <cstdlib>
00019 #include <cmath>
00020 #include <cassert>
00021 #include <ctime>
00022 
00023 #include "graphCharac+.hh"
00024 
00025 
00026 using namespace std;
00027  
00028 
00029  
00031 void usage(std::string argv0) {
00032     std::cout <<"\nAuthor : Patrick HEAS, Date : 2005\n";
00033     std::cout << "\nusage: " << ">"
00034               << argv0 <<std::endl; 
00035     std::cout << "       Graph_FileName TimeDelays_FileName "<<std::endl; 
00036     std::cout << "\n*****************************************************************************************************************************************\n";
00037   }
00038 
00065 int main(int argc, char *argv [])
00066 {   
00067  
00068         std::string ifn1;
00069         std::string ifn2;
00070         switch (argc-1) { 
00071                 case 2:  ifn2                   = std::string(argv[2]);
00072                 case 1:  ifn1                   = std::string(argv[1]); break;
00073                 case 0:
00074                 default: usage(argv[0]); return -1;
00075         }
00076         if ((argc-1) < 2) { usage(argv[0]); return -1;}
00077         std::cout << "> " << argv[0] << " " << ifn1 << " " << ifn2 << std::endl;
00078              
00079         srand((unsigned)time(NULL));
00080         time_t tdeb, t1,t2;
00081         time(&tdeb);
00082         t1=tdeb;
00083         
00084 /*****************Reading the Graph*****************************************************************/
00085 
00086         GraphManipulator Graphtool;
00087         Graphtool.ReadGraphVersion3((char *)ifn1.c_str(),(char *)ifn2.c_str());
00088         
00089 
00090 /*****************GraphMatching with the Parametric Similarty Model**********************************/  
00091         std::cout<<"GraphMatching with the Parametric Similarty Model..."<<endl;        
00092         
00093         int nb_samples=2;int minSample=0;int maxSample=1;float seuilDiv=5; // part of the graph to search in 
00094         int firstSample1=0;int kMT1a=0;int kMT1b=-1; // spatio-temporal location
00095         float weightMTinTLDiff=1;float TL1TL2Div=1;float flowDiff=1;float divDiff=1;float MIDiff=1;float divMTaMTbCost=1;float timeDiff=1;// a priori
00096         string userAPriori="n";string userParaSearch="n"; //search parameters
00097         bool meanCalcul=true;int aux=1;
00098         int nbMiniBranches=30;
00099         int RefSGTime=0;int RefSGkMT1a=0;int RefSGkMT1b=0;
00100         
00101 
00102         //User defining a time window,a part of interest in the graph, and the complexity of the graph. 
00103         cout<<"number of samples of the time-window?"<<endl;
00104         cin >> nb_samples;      
00105         cout<<"Minimum sample time of the graph for searching other sub-graphs?"<<endl;cin >> minSample;minSample--;    
00106         cout<<"Maximum sample time of the graph for searching other sub-graphs?"<<endl;cin >> maxSample;maxSample--;
00107         cout<<"Divergence treshold?"<<endl;
00108         cin >> seuilDiv;
00109         //Spatio-temporal location of sub-graph of interest                     
00110         cout<<"First sample of the sub-graph of interest?"<<endl;
00111         cin >> firstSample1; firstSample1--;RefSGTime=  firstSample1;                                           
00112         cout<<"Index of the MT Class of interest?"<<endl;
00113         cin >> kMT1a;kMT1a--;RefSGkMT1a=kMT1a   ;               
00114         cout<<"If you want to consider 2 MT Class per sub-graph, enter the index of the 2nd MT class, otherwise respond -1"<<endl;
00115         cin >> kMT1b;if (kMT1b!=-1){ kMT1b--;}  RefSGkMT1b=kMT1b;
00116         //User fixing the a priori parameters of the parametric model similiarity  (OPTIONAL)
00117         cout<<"Do you want to fix  a priori parameter for the similarity model ('y'/'n')?"<<endl;cin >> userAPriori;
00118         if (userAPriori=="y"){
00119                 cout<<"a priori parameter weighting the population of each node?"<<endl;
00120                 cin >> weightMTinTLDiff;                                
00121                 cout<<"a priori parameter weighting the nodes' distribution?"<<endl;
00122                 cin >> TL1TL2Div;                                       
00123                 cout<<"a priori parameter weighting the flow of pixels exchanged between nodes?"<<endl;
00124                 cin >> flowDiff;                                        
00125                 cout<<"a priori parameter weighting the change in time of the nodes' distribution?"<<endl;
00126                 cin >> divDiff;                                         
00127                 cout<<"a priori parameter weighting the intra-node change in time?"<<endl;
00128                 cin >> MIDiff;                                                  
00129                 cout<<"a priori parameter weighting the interaction of the 2 MT classes (only if 2 MT class are considered)?"<<endl;
00130                 cin >> divMTaMTbCost;                                   
00131                 cout<<"a priori parameter weighting the time lattice on which the sub-graph is defined?"<<endl;
00132                 cin >> timeDiff;
00133         }
00134         //User fixing parameters for the search (OPTIONAL)      
00135         cout<<"Do you want to fix some specific parameters for the search ('y'/'n')?"<<endl;cin >> userParaSearch;
00136         if (userParaSearch=="y"){
00137                 //cout<<"mean calculation / Kullback-Leibler divergence calculation  (1=mean/0=divergence)?"<<endl;
00138                 cin >> aux;if (aux==0){meanCalcul=false;}               
00139                 cout<<"number of branches considered in the search tree?"<<endl;cin >> nbMiniBranches;
00140         }       
00141                 
00142         
00143 
00144         
00145         
00146         //Finding the most likely MT class associations for the matching when 2MT classes are considered
00147         if (kMT1b!=-1){
00148                 Graphtool.InitGraphforMatch(nb_samples,firstSample1,seuilDiv,kMT1a,-1);
00149                 Graphtool.CreateMatchCostObject();
00150                 Graphtool.FixWeights(weightMTinTLDiff,TL1TL2Div,flowDiff,divDiff,MIDiff,divMTaMTbCost,timeDiff,meanCalcul);
00151                 Graphtool.Match(1,minSample,maxSample,2);
00152                 Graphtool.SaveSortedList(1,0);
00153                 Graphtool.InitGraphforMatch(nb_samples,firstSample1,seuilDiv,kMT1b,-1);
00154                 Graphtool.CreateMatchCostObject();
00155                 Graphtool.FixWeights(weightMTinTLDiff,TL1TL2Div,flowDiff,divDiff,MIDiff,divMTaMTbCost,timeDiff,meanCalcul);
00156                 Graphtool.Match(1,minSample,maxSample,2);
00157                 Graphtool.SaveSortedList(0,1);
00158                 
00159         }
00160         
00161         //Matching 
00162         Graphtool.InitGraphforMatch(nb_samples,firstSample1,seuilDiv,kMT1a,kMT1b);
00163         Graphtool.CreateMatchCostObject();
00164         Graphtool.FixWeights(weightMTinTLDiff,TL1TL2Div,flowDiff,divDiff,MIDiff,divMTaMTbCost,timeDiff,meanCalcul);
00165         Graphtool.Match(1,minSample,maxSample,nbMiniBranches);
00166         
00167 /*****************learning Parameter Matching***********************************************************************/   
00168                 
00169         int interestkMT2a;
00170         int interestkMT2b;
00171         int interestfirstSample2;
00172         int negkMT2a=-1;
00173         int negkMT2b=-1;
00174         int negfirstSample2=-1;
00175         bool negLearn=false;
00176         int again=1;
00177         int posOrNeg=1;
00178         int newSub=1;
00179         int erase=0;
00180         int iteration=0;
00181         bool scale=true;
00182         float factorReducList;
00183         Graphtool.InitParaLearn(1,0);
00184         while (newSub==1){      
00185 
00186                 //Negative semantic matching 
00187                 //      (with negative semantic ref graph as the most unlikely graph of the positive semantic matching) 
00188                 Graphtool.SaveSortedList(1,1);
00189                 if (negkMT2a==-1){Graphtool.InitGraphforMatchNeg(nb_samples,seuilDiv,kMT1b);}
00190                 else{Graphtool.InitGraphforMatch(nb_samples,negfirstSample2,seuilDiv,negkMT2a,negkMT2b);}
00191                 Graphtool.CreateMatchCostObject();
00192                 if (!negLearn){
00193                         Graphtool.FixWeights(weightMTinTLDiff,TL1TL2Div,flowDiff,divDiff,MIDiff,divMTaMTbCost,timeDiff,meanCalcul);
00194                 }
00195                 else{Graphtool.FixLearnedWeights(-1,meanCalcul,1);}
00196                 Graphtool.Match(-1,minSample,maxSample,nbMiniBranches);
00197                 
00198 
00199                 //negative semantic learning init               
00200                 if (iteration==0){Graphtool.InitParaLearn(0,1);}
00201                 else{Graphtool.ScaleParaLearnForSG(0,1,scale);}
00202                 
00203                 //init positive learning with new positive semantic ref graph
00204                 if (iteration!=0){Graphtool.ScaleParaLearnForSG(1,0,scale);}
00205                 
00206                 //learning with positive semantic ref graph (only first iteration)
00207                 if (iteration==0){Graphtool.LearnRefGraph(1);}
00208                 else{Graphtool.Learn(1,interestkMT2a,interestkMT2b,interestfirstSample2);}
00209                 //learning with negative semantic ref graph
00210                 if (negkMT2a!=-1){Graphtool.Learn(-1,negkMT2a,negkMT2b,negfirstSample2);negLearn=true;}
00211                                 
00212                 //Creating stochastique links & writing output
00213                 Graphtool.PrintProbaLink();
00214                 Graphtool.WriteAPostList();
00215                 
00216                 while (again==1){
00217                 
00218                         
00219                         cout<<"LOCATION OF SUB-GRAPH OF INTEREST (1) OR OF NON-INTEREST (-1)?"<<endl;cin >> posOrNeg;
00220                         cout<<"First sample of the sub-graph of interest or non-interest?"<<endl;cin >> interestfirstSample2;interestfirstSample2--;
00221                         cout<<"Index of the MT Class of interest or non-interest?"<<endl;cin >> interestkMT2a;interestkMT2a--;
00222                         if (kMT1b!=-1){cout<<"Index of the other MT Class of interest or non-interest?"<<endl;cin >> interestkMT2b;interestkMT2b--;}
00223                         Graphtool.Learn(posOrNeg,interestkMT2a,interestkMT2b,interestfirstSample2);
00224                         Graphtool.PrintProbaLink();
00225                         Graphtool.WriteAPostList();
00226                         
00227                         if (kMT1b==-1){
00228                                 cout<<"Actual maximum a posteriori subgraph: (time sample="<<Graphtool.firstSample2Sorted[0]+1<<", Index MT class="<<Graphtool.kMT2aSorted[0]+1<<"), ";
00229                                 cout<<"do you want to keep the actual reference subgraph: (time sample="<<RefSGTime+1<<", Index MT class="<<RefSGkMT1a+1<<")? (yes='1'/no='0')"<<endl;
00230                         }
00231                         else{
00232                                 cout<<"Actual maximum a posteriori subgraph: (time sample="<<Graphtool.firstSample2Sorted[0]+1<<", Index MT class1="<<Graphtool.kMT2aSorted[0]+1<<", Index MT class2="<<Graphtool.kMT2bSorted[0]+1<<") ";
00233                                 cout<<"do you want to keep the actual reference subgraph: (time sample="<<RefSGTime+1<<", Index MT class1="<<RefSGkMT1a+1<<", Index MT class2="<<RefSGkMT1b+1<<")? (yes='1'/no='0')"<<endl;
00234                         }
00235                         cin >> again;
00236                         if (again==1){cout<<"Erase learning memory (pos='1',neg='-1',both='2'/no='0')?"<<endl;cin >> erase;}
00237                         else{cout<<"Erase learning memory (pos='1',neg='-1'/no='0')?"<<endl;cin >> erase;}
00238                         if (erase!=0){Graphtool.EraseMemLearn(erase);}
00239                                 
00240                 }
00241 
00242                 again=1;
00243                 Graphtool.SaveSortedList(1,1);
00244                 cout<<"CONTINUE LEARNING WITH NEW REFERENCE SUB-GRAPH ...."<<endl;
00245                 cout<<"First sample of the sub-graph of interest?"<<endl;cin >> interestfirstSample2;
00246                 interestfirstSample2--;RefSGTime=interestfirstSample2;
00247                 cout<<"Index of the MT Class of interest?"<<endl;cin >> interestkMT2a;interestkMT2a--;RefSGkMT1a=interestkMT2a;
00248                 if (kMT1b!=-1){cout<<"Index of the other MT Class of interest?"<<endl;cin >> interestkMT2b;interestkMT2b--;RefSGkMT1b=interestkMT2b;}
00249                 else{interestkMT2b=-1;}
00250                 cout<<"Factor to reduce Sub-Graph list ?"<<endl;
00251                 cin >> factorReducList;scale=(factorReducList==1);
00252                 cout<<"Do you want to fix some specific parameters for the search ('y'/'n')?"<<endl;cin >> userParaSearch;
00253         if (userParaSearch=="y"){
00254                         cout<<"mean calculation / Kullback-Leibler divergence calculation  (1=mean/0=divergence)?"<<endl;
00255                         cout<<"nunmber of branches considered in the search tree?"<<endl;cin >> nbMiniBranches;
00256                         cin >> aux;if (aux==0){meanCalcul=false;}else{meanCalcul=true;} 
00257                 }       
00258                 
00259                 //Positive semantic matching
00260                 Graphtool.InitGraphforMatch(nb_samples,interestfirstSample2,seuilDiv,interestkMT2a,interestkMT2b);
00261                 Graphtool.CreateMatchCostObject();
00262                 Graphtool.FixLearnedWeights(1,meanCalcul,factorReducList);
00263                 Graphtool.Match(1,minSample,maxSample,nbMiniBranches);
00264 
00265                 
00266                 
00267                 iteration++;
00268         }
00269         
00270                 
00271         
00272 /*****************OutPutSaving***********************************************************************/          
00273 /****************************************************************************************************/
00274         
00275         time(&t2);
00276         cout<< "Learning time duration : "<<t2-t1<<" seconds."<<endl;
00277         return 0;
00278 }

Generated on Thu Feb 17 11:03:19 2005 for Interactive Learning of Sub-Graphs Semantics by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002