52 addUsageLine(
"Purpose: Kernel Density Estimator Self-Organizing Map");
53 addUsageLine(
"+KerDenSOM stands for Kernel Probability Density Estimator Self-Organizing Map.");
54 addUsageLine(
"+It maps a set of high dimensional input vectors into a two-dimensional grid. ");
55 addUsageLine(
"+For more information, please see the following [[http://www.ncbi.nlm.nih.gov/pubmed/11472094][reference]].");
57 addUsageLine(
"+The topology of the network can be hexagonal or rectangular (see below). ");
58 addUsageLine(
"+It is advised to design maps with one of its sides larger than the other (e.g. 10x5).");
78 addParamsLine(
" : This file is generated by [[image_vectorize_v3][image_vectorize]]");
79 addParamsLine(
" --oroot <rootname> : rootname_classes.xmd, rootname_images.xmd and rootname_vectors.xmd will be created");
80 addParamsLine(
" : This file mst be read by [[image_vectorize_v3][image_vectorize]]");
81 addParamsLine(
" [--xdim <Hdimension=10>] : Horizontal size of the map");
82 addParamsLine(
" [--ydim <Vdimension=5>] : Vertical size of the map");
83 addParamsLine(
" [--topology <topology=RECT>] : Lattice topology");
84 addParamsLine(
" :+The following picture will help in understanding the differences ");
85 addParamsLine(
" :+between both topologies and the map axis convention:");
87 addParamsLine(
" [--deterministic_annealing <steps=10> <Initial_reg=1000> <Final_reg=100>] : Deterministic annealing");
93 addExampleLine(
"xmipp_image_vectorize -i images.stk -o vectors.xmd");
94 addExampleLine(
"xmipp_classify_kerdensom -i vectors.xmd -o kerdensom.xmd");
106 annSteps =
getIntParam(
"--deterministic_annealing",0);
117 if ((reg0 <= reg1) && (reg0 != 0) && (annSteps > 1))
133 std::cout <<
"Input data file : " << fn_in << std::endl;
134 std::cout <<
"Output rootname : " << fn_root << std::endl;
135 std::cout <<
"Horizontal dimension (Xdim) = " << xdim << std::endl;
136 std::cout <<
"Vertical dimension (Ydim) = " << ydim << std::endl;
137 if (layout ==
"HEXA")
138 std::cout <<
"Hexagonal topology " << std::endl;
140 std::cout <<
"Rectangular topology " << std::endl;
141 std::cout <<
"Initial smoothness factor (reg0) = " << reg0 << std::endl;
142 std::cout <<
"Final smoothness factor (reg1) = " << reg1 << std::endl;
143 std::cout <<
"Deterministic annealing steps = " << annSteps << std::endl;
144 std::cout <<
"Total number of iterations = " << iter << std::endl;
145 std::cout <<
"Stopping criteria (eps) = " << eps << std::endl;
147 std::cout <<
"Normalize input data" << std::endl;
149 std::cout <<
"Do not normalize input data " << std::endl;
155 FileName fnClasses=fn_root+
"_classes.xmd";
161 std::cout << std::endl <<
"Reading input data file " << fn_in <<
"....." << std::endl;
167 std::cout <<
"Normalizing....." << std::endl;
171 auto *myMap =
new FuzzyMap(layout, xdim, ydim, ts);
178 thisSOM->
train(*myMap, ts, fnClasses);
181 double dist = thisSOM->
test(*myMap, ts);
182 std::cout << std::endl <<
"Quantization error : " << dist << std::endl;
185 std::cout <<
"Classifying....." << std::endl;
186 myMap->classify(&ts);
189 std::cout <<
"Calibrating....." << std::endl;
190 myMap->calibrate(ts);
205 for (
unsigned i = 0;
i < myMap->size();
i++)
215 std::cout <<
"Saving neurons assigments ....." << std::endl;
218 std::vector<size_t> objIds;
220 for (
unsigned i = 0;
i < myMap->size();
i++)
223 for (
size_t j = 0;
j < myMap->classifAt(
i).size();
j++)
226 size_t order=myMap->classifAt(
i)[
j];
227 vectorContentIn.
getRow(row,objIds[order]);
239 MDimages.
write((
String)
"images@"+fn_root+
"_images.xmd");
244 std::cout <<
"Denormalizing code vectors....." << std::endl;
247 MetaDataVec vectorHeaderIn, vectorHeaderOut, vectorContentOut;
250 size_t size, vectorSize;
252 size_t idOut=vectorHeaderOut.
addObject();
263 FileName fnVectorsRaw=fn_root+
"_vectors.vec";
264 std::ofstream fhVectorsRaw(fnVectorsRaw.c_str(),std::ios::binary);
267 for (
size_t i = 0;
i < myMap->size();
i++)
272 fhVectorsRaw.write((
char*)&(myMap->theItems[
i][0]),vectorSize*
sizeof(
float));
274 fhVectorsRaw.close();
double getDoubleParam(const char *param, int arg=0)
#define REPORT_ERROR(nerr, ErrormMsg)
void setListener(BaseListener *_listener)
Couldn't write to file.
void setValue(const MDObject &object) override
void read(const FileName &fnIn)
virtual double test(const FuzzyMap &_som, const TS &_examples) const
virtual void train(FuzzyMap &_som, TS &_examples, FileName &_fn_vectors, bool _update=false, double _sigma=0, bool _saveIntermediate=false)=0
void addSeeAlsoLine(const char *seeAlso)
const char * getParam(const char *param, int arg=0)
virtual unsigned & setVerbosity()
Incorrect argument received.
void addExampleLine(const char *example, bool verbatim=true)
int verbose
Verbosity level.
String formatString(const char *format,...)
virtual const std::vector< statsStruct > & getNormalizationInfo() const
bool checkParam(const char *param)
void addUsageLine(const char *line, bool verbatim=false)
int getIntParam(const char *param, int arg=0)
void addParamsLine(const String &line)