00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #pragma warning(disable: 4786)
00015
00016 #include <cstdlib>
00017 #include <iostream>
00018 #include <vector>
00019 #include <string>
00020
00021
00022
00023 #include "RepositorySOMDataXML.h"
00024 #include "RepositoryMapcodeXML.h"
00025 #include "RepositorySOMDataFile.h"
00026 #include "RepositoryMapcodeFile.h"
00027
00028
00029
00030 #include "Som.h"
00031 #include "SOMDataCadastre.h"
00032 #include "MapcodeCadastre.h"
00033
00034 #include "GraphSegmentation.h"
00035 #include "util.h"
00036 #include "CDbw.h"
00037 #include "DaviesBouldin.h"
00038
00039 #include "BatchFactory.h"
00040 #include "TwoDFactory.h"
00041 #include "OnlineFactory.h"
00042
00043
00044 using std::cout;
00045
00046
00047
00048
00049 static OnlineFactory fact_online("Online");
00050 static BatchFactory fact_batch("Batch");
00051 static TwoDFactory fact_twoD("Two");
00052
00053 std::map<string, int> makeTblEntry_Cluster(SOM* som,int* clusters,int dimL,int dimC);
00054
00055 int main(int argc, char *argv[]) {
00056
00057 try {
00058
00059 clock_t c0 = clock();
00060
00061
00062 ISOMDataRepository *repD;
00063
00064
00065 SOMDataCadastre *cadD;
00066
00067
00068 std::vector<std::string> params;
00069 params.push_back(argv[1]);
00070
00071
00072 repD = new RepositorySOMDataFile();
00073 repD->load(params,0);
00074
00075
00076 cadD = new SOMDataCadastre(*repD);
00077
00078 cout << "Iniciando o SOMCode-1.0 ...\n\n";
00079
00080
00081 SOMData* data = cadD->load( std::vector<std::string>() );
00082
00083
00084
00085
00086 IMapcodeRepository *repM;
00087
00088
00089 MapcodeCadastre *cadM;
00090
00091
00092 repM = new RepositoryMapcodeFile();
00093 repM->load(argv[2]);
00094
00095
00096 cadM = new MapcodeCadastre(*repM);
00097
00098
00099 Mapcode *map = cadM->load(argv[2]);
00100
00101 clock_t c1 = clock();
00102
00103
00104
00105 clock_t c2 = clock();
00106
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
00145 SOM* mysom = new SOM(net,map);
00146
00147
00148 cout << "\nNumero de neuronios = " << mysom->getMapcode()->getMapSize();
00149 cout << "\nDimensao dos vetores = " << data->getDimension();
00150
00158 mysom->InitMapcode();
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
00173 GraphSegmentation *cluster = new GraphSegmentation();
00174
00175
00176 TIntVector clusters = create_intvector(1, mysom->getMapcode()->getMapSize());
00177
00178
00179
00180 clusters = cluster->Segment( mysom, 3 );
00181
00182
00183 cout << "\n\n\nMapa segmentado: \n\n";
00184 printClusters(clusters,mysom->getMapcode()->getDimensions(0),mysom->getMapcode()->getDimensions(1));
00185
00186
00187
00188 CDbw *cdbw = new CDbw(mysom, clusters, cluster->getNumClusters());
00189 cout << "\nCDbw = " << cdbw->Index();
00190
00191
00192
00193 DaviesBouldin *db = new DaviesBouldin(mysom, clusters, cluster->getNumClusters());
00194 cout << "\nDavies Bouldin = " << db->Index(1,2) << "\n";
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217 delete cdbw;
00218 delete data;
00219 delete mysom;
00220
00221 } catch(std::exception& ex) {
00222 cout << ex.what() << std::endl;
00223 }
00224
00225 return EXIT_SUCCESS;
00226
00227 };
00228
00229
00230
00231
00232 std::map<string, int> makeTblEntry_Cluster(SOM* som,int* clusters,int dimL,int dimC){
00233 TLabel label = som->getMapcode()->getLabel();
00234
00235 std::map<string, int> tbl;
00236
00237 for(int i = 0; i < dimL*dimC; i++){
00238 for(int j = 0; j < label[i].size(); j++){
00239 string value = inttostr( clusters[i+1] );
00240 string id = label[i][j];
00241 tbl[ label[i][j] ] = clusters[i+1];
00242 }
00243 }
00244
00245 return tbl;
00246 }