00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #pragma warning(disable: 4786)
00027
00028 #include <cstdlib>
00029 #include <iostream>
00030 #include <vector>
00031 #include <string>
00032
00033
00034
00035
00036 #include "RepositorySOMDataXML.h"
00037 #include "RepositoryMapcodeXML.h"
00038 #include "RepositorySOMDataFile.h"
00039 #include "RepositoryMapcodeFile.h"
00040
00041
00042
00043 #include "Som.h"
00044 #include "SOMDataCadastre.h"
00045 #include "MapcodeCadastre.h"
00046
00047 #include "GraphSegmentation.h"
00048 #include "CDbw.h"
00049 #include "DaviesBouldin.h"
00050
00051 #include "BatchFactory.h"
00052 #include "TwoDFactory.h"
00053 #include "OnlineFactory.h"
00054
00055
00056 using std::cout;
00057
00058
00059
00060
00061 static OnlineFactory fact_online("Online");
00062 static BatchFactory fact_batch("Batch");
00063 static TwoDFactory fact_twoD("Two");
00064
00065
00066
00067 int main(int argc, char *argv[]) {
00068
00069 try {
00070
00071
00072 clock_t c0 = clock();
00073
00074
00075 ISOMDataRepository *repD;
00076
00077
00078 SOMDataCadastre *cadD;
00079
00080
00081 std::vector<std::string> params;
00082 params.push_back(argv[1]);
00083
00084
00085 repD = new RepositorySOMDataFile();
00086 repD->load(params,0);
00087
00088
00089 cadD = new SOMDataCadastre(*repD);
00090
00091 cout << "Iniciando o SOMCode-1.0 ...\n\n";
00092
00093
00094 SOMData* data = cadD->load( std::vector<std::string>() );
00095
00096 clock_t c1 = clock();
00097
00098
00099 clock_t c2 = clock();
00100
00109 int dimL, dimC, numIte;
00110 dimL = strtoint(argv[3]);
00111 dimC = strtoint(argv[4]);
00112 numIte = strtoint(argv[5]);
00113
00114
00115
00116 NetParams* net = new NetParams();
00117
00118
00119 Mapcode* map = new Mapcode();
00120
00121
00135 net->setData(data);
00136 net->setNumIterations( numIte );
00137 net->setInitType( LINEAR );
00138 net->setInitLearningRate( 0.5 );
00139 net->setInitNeighbor( 15 );
00140
00141 if ( strcmp(argv[2],"online") == 0 ){
00142 net->setLearningType( ONLINE );
00143 net->setLearnType( "Online" );
00144 }
00145
00146 if ( strcmp(argv[2],"batch") == 0 ) {
00147 net->setLearningType( BATCH );
00148 net->setLearnType( "Batch" );
00149 }
00150
00151 net->setMapcode(map);
00152
00153
00164 net->getMapcode()->setNumVar( data->getDimension() );
00165 net->getMapcode()->setDimensions( 0, dimL );
00166 net->getMapcode()->setDimensions( 1, dimC );
00167 net->getMapcode()->setLattice( "hexa" );
00168 net->getMapcode()->setNeighborType( "gaussian" );
00169 net->getMapcode()->setTopolParamsText( Default_DimensionType );
00170 net->getMapcode()->setDimension(2);
00171
00172
00173
00174 SOM* mysom = new SOM(*net);
00175
00176
00185 mysom->InitMapcode();
00186 mysom->Learning();
00187 mysom->Quality();
00188 mysom->Labeling();
00189
00190 clock_t c3 = clock();
00191
00192
00193
00194 cout << "Erro de quantizacao = " << mysom->getQuantizationError() << std::endl;
00195 cout << "Erro topologico = " << mysom->getTopologicalError() << std::endl;
00196 cout << "Tempo decorrido para carregar os dados = " << (float) (c1 - c0)/CLOCKS_PER_SEC << std::endl;
00197 cout << "Tempo decorrido para processar os dados = " << (float) (c3 - c2)/CLOCKS_PER_SEC << std::endl;
00198
00199
00200
00201
00202 RepositoryMapcodeFile repMapcode;
00203 repMapcode.save(mysom->getMapcode(),argv[6]);
00204
00205
00206
00207
00208 delete data;
00209 delete mysom;
00210
00211 } catch(std::exception& ex) {
00212 cout << ex.what() << std::endl;
00213 }
00214
00215 return EXIT_SUCCESS;
00216
00217 };
00218