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