00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #pragma warning(disable: 4786)
00016
00017 #include <cstdlib>
00018 #include <iostream>
00019 #include <vector>
00020 #include <string>
00021
00022
00023
00024
00025 #include "RepositorySOMDataXML.h"
00026 #include "RepositoryMapcodeXML.h"
00027 #include "RepositorySOMDataFile.h"
00028 #include "RepositoryMapcodeFile.h"
00029
00030
00031
00032 #include "Som.h"
00033 #include "SOMDataCadastre.h"
00034 #include "MapcodeCadastre.h"
00035
00036 #include "GraphSegmentation.h"
00037 #include "util.h"
00038 #include "CDbw.h"
00039 #include "DaviesBouldin.h"
00040
00041 #include "BatchFactory.h"
00042 #include "TwoDFactory.h"
00043 #include "OnlineFactory.h"
00044
00045
00046 using std::cout;
00047
00048
00049
00050
00051 static OnlineFactory fact_online("Online");
00052 static BatchFactory fact_batch("Batch");
00053 static TwoDFactory fact_twoD("Two");
00054
00055 std::map<string, int> makeTblEntry_Cluster(SOM* som,int* clusters,int dimL,int dimC);
00056
00057 int main(int argc, char *argv[]) {
00058
00059 try {
00060
00061 clock_t c0 = clock();
00062
00063
00064 ISOMDataRepository *repD;
00065
00066
00067 SOMDataCadastre *cadD;
00068
00069
00070 std::vector<std::string> params;
00071 params.push_back(argv[1]);
00072
00073
00074 repD = new RepositorySOMDataFile();
00075 repD->load(params,0);
00076
00077
00078 cadD = new SOMDataCadastre(*repD);
00079
00080 cout << "Starting SOMCode-1.0 ...\n\n";
00081
00082
00083 SOMData* data = cadD->load( std::vector<std::string>() );
00084
00085
00086
00087 IMapcodeRepository *repM;
00088
00089
00090 MapcodeCadastre *cadM;
00091
00092
00093 repM = new RepositoryMapcodeFile();
00094 repM->load(argv[2]);
00095
00096
00097 cadM = new MapcodeCadastre(*repM);
00098
00099
00100 Mapcode *map = cadM->load(argv[2]);
00101
00102 clock_t c1 = clock();
00103
00104
00105
00106 clock_t c2 = clock();
00107
00108
00109
00110
00111
00112 NetParams* net = new NetParams();
00113
00114
00129 net->setData(data);
00130 net->setNumIterations( 2000 );
00131
00132 net->setInitType(10);
00133
00134
00135
00136
00137 net->setInitLearningRate( 0.5 );
00138 net->setInitNeighbor( 15 );
00139 net->setLearningType( BATCH );
00140 net->setLearnType( "Batch" );
00141 net->setMapcode(map);
00142
00143
00144 SOM* mysom = new SOM(net,map);
00145
00146
00147 cout << "\nNumber of neurons = " << mysom->getMapcode()->getMapSize();
00148 cout << "\nDimension of vectors = " << data->getDimension();
00149
00150
00151
00152
00153
00154
00155
00156
00157 mysom->InitMapcode();
00158
00159
00160
00161
00162 mysom->getLearningAlgorithm()->MakeBMU(data,map);
00163
00164
00165
00166
00167 mysom->Labeling();
00168
00169 clock_t c3 = clock();
00170
00171
00172 GraphSegmentation *cluster = new GraphSegmentation();
00173
00174
00175 TIntVector clusters = create_intvector(1, mysom->getMapcode()->getMapSize());
00176
00177
00178
00179 clusters = cluster->Segment( mysom, 3 );
00180
00181
00182 cout << "\n\n\nSegmented map: \n\n";
00183 printClusters(clusters,mysom->getMapcode()->getDimensions(0),mysom->getMapcode()->getDimensions(1));
00184
00185
00186 CDbw *cdbw = new CDbw(mysom, clusters, cluster->getNumClusters());
00187 cout << "\nCDbw = " << cdbw->Index();
00188
00189
00190
00191 DaviesBouldin *db = new DaviesBouldin(mysom, clusters, cluster->getNumClusters());
00192 cout << "\nDavies Bouldin = " << db->Index(1,2) << "\n";
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 delete cdbw;
00214 delete data;
00215 delete mysom;
00216
00217 } catch(std::exception& ex) {
00218 cout << ex.what() << std::endl;
00219 }
00220
00221 return EXIT_SUCCESS;
00222
00223 };
00224
00225
00226
00227
00228 std::map<string, int> makeTblEntry_Cluster(SOM* som,int* clusters,int dimL,int dimC){
00229 TLabel label = som->getMapcode()->getLabel();
00230
00231 std::map<string, int> tbl;
00232
00233 for(int i = 0; i < dimL*dimC; i++){
00234 for(int j = 0; j < label[i].size(); j++){
00235 string value = inttostr( clusters[i+1] );
00236 string id = label[i][j];
00237 tbl[ label[i][j] ] = clusters[i+1];
00238 }
00239 }
00240
00241 return tbl;
00242 }