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

SubGraph.hh

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*/
00010 /*---------------------------------------------------------------------------*/
00011 #include <iostream>
00012 #include <fstream>
00013 #include <string>  
00014 #include <vector>
00015 
00016 #include <cstdio>
00017 #include <cstdlib>
00018 #include <cmath>
00019 #include <cassert>
00023 class SubGraph 
00024 {
00025   public:
00026   
00027    /***************ATTRIBUTES****************************/      
00028    
00029   // subGraph general attributes:
00031         int nbTimeSamp;
00033         float *tDelay;
00035         int nbDim;
00037         int nbMTClusters;
00038         
00039   //Vertex attributes:
00040   
00041         //Projected MT cluster attributes
00043         vector<float*> *meanMT;
00045         vector<float**> *covMT;
00047         vector<unsigned long int> weightMT;
00048         
00049         //TL associated cluster attributes
00051         vector<int> *orderAddedNode;
00053         vector<float*> *meanTL;
00055         vector<float**> *covTL;
00057         vector<vector<int> > *indexMTinTL;
00059         vector<vector<unsigned long int> > *weightMTinTL;
00061         vector<vector<float> > *divTL_MT;
00062         
00063         
00064   //Edges attributes
00065         
00067         vector<vector<vector<unsigned long int> > > *flowMatrix;
00068         
00070         vector<vector<vector<float> > > *divMatrix;
00071         
00073         vector<vector<vector<float> > > *MIMatrix;
00074         
00075   /***************METHODES****************************/
00077         SubGraph(int nb_dim, int nb_tSamp, float *t_delay){
00078                 
00079                 nbDim=nb_dim;
00080                 nbMTClusters=0;
00081                 nbTimeSamp=nb_tSamp; 
00082                 tDelay=new float[nbTimeSamp-1];
00083                 for (int i=0;i<nbTimeSamp-1;i++){tDelay[i]=t_delay[i];}
00084                 meanMT=new vector<float*>[nbTimeSamp];
00085                 covMT=new vector<float**>[nbTimeSamp];
00086                 //weightMT=new vector<unsigned long int>[nbTimeSamp];
00087                 meanTL=new vector<float*>[nbTimeSamp];
00088                 covTL=new vector<float**>[nbTimeSamp];
00089                 weightMTinTL=new vector<vector<unsigned long int> >[nbTimeSamp];
00090                 indexMTinTL=new vector<vector<int> >[nbTimeSamp];
00091                 divTL_MT=new vector<vector<float> >[nbTimeSamp];
00092                 flowMatrix=new vector<vector<vector<unsigned long int> > >[nbTimeSamp];
00093                 divMatrix=new vector<vector<vector<float> > >[nbTimeSamp];
00094                 MIMatrix=new vector<vector<vector<float> > >[nbTimeSamp];
00095                 orderAddedNode=new vector<int>[nbTimeSamp];
00096                 
00097         }
00099         virtual~SubGraph(){
00100         
00101                 delete [] tDelay;
00102                 for (int t=0;t<nbTimeSamp;t++){
00103                         meanMT[t].clear();
00104                         covMT[t].clear();
00105                         //weightMT[t].clear();
00106                         meanTL[t].clear();
00107                         covTL[t].clear();
00108                         for (int k=0;(unsigned int)k<indexMTinTL[t].size();k++){
00109                                 indexMTinTL[t][k].clear();
00110                                 weightMTinTL[t][k].clear();
00111                                 divTL_MT[t][k].clear();
00112                         }
00113                         indexMTinTL[t].clear();
00114                         weightMTinTL[t].clear();
00115                         divTL_MT[t].clear();
00116                 }
00117                 weightMT.clear();
00118                 delete [] meanTL;
00119                 delete [] covTL;
00120                 delete [] indexMTinTL;
00121                 delete [] weightMTinTL;
00122                 delete [] divTL_MT;
00123                 delete [] meanMT;
00124                 delete [] covMT;
00125                 delete [] orderAddedNode;
00126                 //delete [] weightMT;
00127                 
00128         }
00132         void AddAttMT(float **mean, float ***cov,unsigned long int weight){
00133                 
00134                 //adding the attributes of a projected MT Cluster
00135                 for (int t=0;t<nbTimeSamp;t++){
00136                         float *auxmean=new float[nbDim];
00137                         float **auxcov=new float*[nbDim];
00138                         
00139                         for (int j1=0;j1<nbDim;j1++){
00140                                 auxmean[j1]=mean[t][j1];
00141                                 auxcov[j1]=new float[nbDim];
00142                                 for (int j2=0;j2<nbDim;j2++){
00143                                         auxcov[j1][j2]=cov[t][j1][j2];
00144                                 }
00145                         }
00146                         
00147                         meanMT[t].push_back(auxmean);
00148                         covMT[t].push_back(auxcov);
00149                 }
00150                 
00151                 unsigned long int *auxweight=new unsigned long int[1];
00152                 auxweight[0]=weight;
00153                 weightMT.push_back(auxweight[0]);
00154                 
00155                 nbMTClusters++;
00156                 //deleting MT eigen related  parameters
00157                 for (int i=0;i<nbTimeSamp;i++){orderAddedNode[i].clear();}
00158                 
00159         }
00163         void AddAttTLforMT(int time, int nbClusters, float **mean, float ***cov,unsigned long int *weight, float *div){
00164                 
00165                 int addNewCluster, check,sameClusterIndex=-1;   
00166                 for (int k=0;k<nbClusters;k++){
00167                    //checking if it is a new vertex
00168                    addNewCluster=1;
00169                    check=0;
00170                    for (int l=0;(unsigned int)l<meanTL[time].size();l++){
00171                         check=0;
00172                         for (int j=0;j<nbDim;j++){
00173                                 if (meanTL[time][l][j]==mean[k][j]&&covTL[time][l][j][j]==cov[k][j][j]){
00174                                         check++;
00175                                 }
00176                         }
00177                         if(check==nbDim){
00178                                 addNewCluster=0;sameClusterIndex=l;
00179                         }
00180                    }    
00181                    // adding the new vertex
00182                    if (addNewCluster==1){
00183                         float *auxmean=new float[nbDim];
00184                         float **auxcov=new float*[nbDim];               
00185                         for (int j1=0;j1<nbDim;j1++){
00186                                 auxmean[j1]=mean[k][j1];
00187                                 auxcov[j1]=new float[nbDim];
00188                                 for (int j2=0;j2<nbDim;j2++){
00189                                         auxcov[j1][j2]=cov[k][j1][j2];
00190                                 }
00191                         }
00192                         meanTL[time].push_back(auxmean);
00193                         covTL[time].push_back(auxcov);
00194                         vector<int> auxindexvector;
00195                         int *auxindex=new int[1];
00196                         auxindex[0]=nbMTClusters-1;
00197                         auxindexvector.push_back(auxindex[0]);
00198                         indexMTinTL[time].push_back(auxindexvector);
00199                         vector<unsigned long int> auxweightvector;
00200                         unsigned long int *auxweight=new unsigned long int[1];
00201                         auxweight[0]=weight[k];
00202                         auxweightvector.push_back(auxweight[0]);
00203                         weightMTinTL[time].push_back(auxweightvector);
00204                         vector<float>  auxdivvector;
00205                         float  *auxdiv=new float[1];
00206                         auxdiv[0]=div[k];
00207                         auxdivvector.push_back(auxdiv[0]);
00208                         divTL_MT[time].push_back(auxdivvector);
00209                         
00210                    }
00211                    else{
00212                         //filling the identical vertex with the MT related attributes   
00213                         int *auxindex=new int[1];auxindex[0]=nbMTClusters-1;
00214                         indexMTinTL[time][sameClusterIndex].push_back(auxindex[0]);
00215                         unsigned long int *auxweight=new unsigned long int[1];auxweight[0]=weight[k];
00216                         weightMTinTL[time][sameClusterIndex].push_back(auxweight[0]);
00217                         float  *auxdiv=new float[1];auxdiv[0]=div[k];
00218                         divTL_MT[time][sameClusterIndex].push_back(auxdiv[0]);
00219                    }
00220                 
00221                 }
00222                 
00223                 for (int k=0;k<nbClusters;k++){
00224                    //checking if it is a new vertex
00225                    check=0;
00226                    for (int l=0;(unsigned int)l<meanTL[time].size();l++){
00227                         check=0;
00228                         for (int j=0;j<nbDim;j++){
00229                                 if (meanTL[time][l][j]==mean[k][j]&&covTL[time][l][j][j]==cov[k][j][j]){
00230                                         check++;
00231                                 }
00232                         }
00233                         if(check==nbDim){
00234                                 addNewCluster=0;sameClusterIndex=l;
00235                                 int *order =new int[1];order[0]=l;
00236                                 orderAddedNode[time].push_back(order[0]);
00237                         }
00238                    }
00239                  }
00240                  
00241         }
00245         void AddEdgesAttMT(int time,  int nbClusters1,int nbClusters2,unsigned long int **flow, float **div, float **MI ){
00246         //adding edges (flow, Div & MI) related to the trajectories of a MT between time and time-1
00247                         
00248                 //updating size of adajacent matrices (creating new matrices, copying in it the values of old matrices which are deleted)
00249                 int nbNewNodes1;
00250                 int nbNewNodes2;
00251                 if (flowMatrix[time].size()==0){
00252                   nbNewNodes1=meanTL[time-1].size();
00253                   nbNewNodes2=meanTL[time].size();
00254                 }
00255                 else{
00256                   nbNewNodes1=meanTL[time-1].size()-flowMatrix[time][0].size();
00257                   nbNewNodes2=meanTL[time].size()-flowMatrix[time][0][0].size();
00258                 } 
00259                 if (nbNewNodes1!=0||nbNewNodes2!=0){
00260                     vector<vector<unsigned long int> > *auxauxflowvector=new vector<vector<unsigned long int> >[nbMTClusters];
00261                     vector<vector<float> > *auxauxdivvector=new vector<vector<float> >[nbMTClusters];
00262                     vector<vector<float> > *auxauxMIvector= new vector<vector<float> >[nbMTClusters];
00263                    for (int k=0;k<nbMTClusters;k++){         
00264                      for (int l1=0;(unsigned int)l1<meanTL[time-1].size();l1++){
00265                         vector<unsigned long int> *auxflowvector=new vector<unsigned long int>[1];
00266                         vector<float> *auxdivvector=new vector<float>[1];
00267                         vector<float> *auxMIvector=new vector<float>[1];
00268                         for (int l2=0;(unsigned int)l2<meanTL[time].size();l2++){
00269                                 unsigned long int *auxflow=new unsigned long[1] ;
00270                                 float *auxdiv=new float[1];
00271                                 float *auxMI=new float[1];
00272                                 if (flowMatrix[time].size()!=0){
00273                                   if ((unsigned int)l1<flowMatrix[time][0].size() && (unsigned int)l2<flowMatrix[time][0][0].size() && k!=nbMTClusters-1){
00274                                         auxflow[0]=flowMatrix[time][k][l1][l2];
00275                                         auxdiv[0]=divMatrix[time][k][l1][l2];
00276                                         auxMI[0]=MIMatrix[time][k][l1][l2];     
00277                                   }
00278                                   else{
00279                                         auxflow[0]=0;
00280                                         auxdiv[0]=-1;
00281                                         auxMI[0]=-1;
00282                                   }
00283                                 }
00284                                 else{
00285                                    auxflow[0]=0;
00286                                    auxdiv[0]=-1;
00287                                    auxMI[0]=-1;
00288                                 }
00289                                 auxflowvector[0].push_back(auxflow[0]);
00290                                 auxdivvector[0].push_back(auxdiv[0]);
00291                                 auxMIvector[0].push_back(auxMI[0]);
00292                         }
00293                         auxauxflowvector[k].push_back(auxflowvector[0]);
00294                         auxauxdivvector[k].push_back(auxdivvector[0]);
00295                         auxauxMIvector[k].push_back(auxMIvector[0]);
00296                      }
00297                    }
00298                    flowMatrix[time].clear();
00299                    divMatrix[time].clear();
00300                    MIMatrix[time].clear();
00301                    for (int k=0;k<nbMTClusters;k++){
00302                      flowMatrix[time].push_back(auxauxflowvector[k]);
00303                      divMatrix[time].push_back(auxauxdivvector[k]);
00304                      MIMatrix[time].push_back(auxauxMIvector[k]);
00305                    }
00306                 }
00307                 else{
00308                      vector<vector<unsigned long int> > auxauxflowvector;
00309                      vector<vector<float> > auxauxdivvector;
00310                      vector<vector<float> > auxauxMIvector;
00311                      for (int l1=0;(unsigned int)l1<meanTL[time-1].size();l1++){
00312                          vector<unsigned long int> auxflowvector;
00313                          vector<float> auxdivvector;
00314                          vector<float> auxMIvector;
00315                          for (int l2=0;(unsigned int)l2<meanTL[time].size();l2++){
00316                                 unsigned long int *auxflow=new unsigned long int[1];
00317                                 auxflow[0]=0;
00318                                 auxflowvector.push_back(auxflow[0]);
00319                                 float *auxdiv=new float[1];
00320                                 auxdiv[0]=-1;
00321                                 auxdivvector.push_back(auxdiv[0]);
00322                                 float *auxMI=new float[1];
00323                                 auxMI[0]=-1;
00324                                 auxMIvector.push_back(auxMI[0]);
00325                          }
00326                          auxauxflowvector.push_back(auxflowvector);
00327                          auxauxdivvector.push_back(auxdivvector);
00328                          auxauxMIvector.push_back(auxMIvector);
00329                      }
00330                      flowMatrix[time].push_back(auxauxflowvector);
00331                      divMatrix[time].push_back(auxauxdivvector);
00332                      MIMatrix[time].push_back(auxauxMIvector);
00333                 }
00334                 //adding the new values in the adjacent matrices
00335                 for (int v1=0;v1<nbClusters1;v1++){
00336                         for (int v2=0;v2<nbClusters2;v2++){
00337                                 flowMatrix[time][nbMTClusters-1][orderAddedNode[time-1][v1]][orderAddedNode[time][v2]]=flow[v1][v2];
00338                                 divMatrix[time][nbMTClusters-1][orderAddedNode[time-1][v1]][orderAddedNode[time][v2]]=div[v1][v2];
00339                                 MIMatrix[time][nbMTClusters-1][orderAddedNode[time-1][v1]][orderAddedNode[time][v2]]=MI[v1][v2];
00340                         }
00341                 }
00342                 
00343         
00344         }
00345                 
00346 };

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