mixmod  3.2.0
Mixture models for clustering and classification
 All Classes Namespaces Files Functions Variables Enumerations Friends
Util.h
Go to the documentation of this file.
1 /***************************************************************************
2  SRC/mixmod/Utilities/Util.h description
3  copyright : (C) MIXMOD Team - 2001-2016
4  email : contact@mixmod.org
5  ***************************************************************************/
6 
7 /***************************************************************************
8  This file is part of MIXMOD
9 
10  MIXMOD is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MIXMOD is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with MIXMOD. If not, see <http://www.gnu.org/licenses/>.
22 
23  All informations available on : http://www.mixmod.org
24 ***************************************************************************/
29 #ifndef XEM_UTIL_H
30 #define XEM_UTIL_H
31 
32 #ifndef WANT_STREAM
33 #define WANT_STREAM
34 #endif
35 
36 #ifndef WANT_MATH
37 #define WANT_MATH
38 #endif
39 
41 #include "mixmod/Utilities/exceptions/Exception.h"
42 #include "mixmod/Utilities/exceptions/DCVException.h"
43 #include "mixmod/Utilities/exceptions/DCVonlyInGaussianCaseException.h"
44 #include "mixmod/Utilities/exceptions/InputException.h"
45 #include "mixmod/Utilities/exceptions/NumericException.h"
46 #include "mixmod/Utilities/exceptions/OtherException.h"
47 
48 
49 // Need matrix output routines
50 #include <vector>
51 #include <fstream>
52 #include <string>
53 #include <cstring>
54 #include <ctype.h>
55 #include <stdint.h>
56 #include <memory>
57 #include <limits>
58 #include <sstream>
59 
60 #include <typeinfo>
61 #include <assert.h> //For debugging purpose
62 
63 // Need matrix applications
64 #include "mixmod/Utilities/maths/SelectLibrary.h"
65 
66 namespace XEM {
67 
68 //Macro for throw
69 #define THROW(Exceptionclass,errortype) throw Exceptionclass(__FILE__,__LINE__,errortype)
70 
72 static InputException defaultException = InputException(noError);
73 static Exception & NOERROR = defaultException;
74 
75 class ModelType;
76 class Matrix;
77 class Algo;
78 
79 // Constants definitions
80 
82 const double XEMPI = 3.14159265358979323846; // Number pi
83 
84 // misc
85 const int DEBUG = 0; // >0 for debug information
86  // 0 : no debug
87  // 1 : param debug
88  // 2 : param and fik, tik, zik debug
89 const bool DATA_REDUCE = false; // do not reduce binary data (bug with weights, I don't want to try to fix it.....)
90 const bool VERBOSE = false; // print various execution traces (labels, errors...)
91 
93 const int64_t maxNbSample = 1000000; // Maximum sample size
94 const int64_t maxPbDimension = 10000; // Maximum sample dimension
95 const int64_t minNbIteration = 1; // Minimum number of iterations
96 const int64_t minNbIterationForSEM = 50; // Minimum number of iterations for SEM
97 const int64_t maxNbIteration = 100000; // Maximum number of iterations
98 const int64_t defaultNbIteration = 200; // Default number of iteration
99 const double minEpsilon = 0; // Minimum value of eps
100 const double maxEpsilon = 1; // Maximum value of eps
101 
102 const double defaultEpsilon = 1.0E-3; // Default value of eps
103 const int64_t maxNbNbCluster = 10; // Maximum size of cluster list
104 const int64_t maxNbAlgo = 5; // Maximum number of algorithms
105 const int64_t defaultNbAlgo = 1; // Default number of algorithms
106 const int64_t maxNbStrategy = 10; // Maximum number of strategies
107 const int64_t defaultNbStrategy = 1; // Default number of strategies
108 const int64_t maxNbModel = 100; // Maximum number of models
109 const int64_t defaultNbModel = 1; // Default number of models
110 const int64_t maxNbCriterion = 4; // Maximum number of criteria
111 const int64_t defaultNbCriterion = 1; // Default number of criteria
112 
113 const int64_t minNbTryInStrategy = 1; // min of strategies repeats
114 const int64_t maxNbTryInStrategy = 100; // max of strategies repeats
115 const int64_t defaultNbTryInStrategy = 1; // number of strategies repeats
116 const int64_t nbTryInDefaultClusteringStrategy = 1; // number of strategies repeats
117 
118 const int64_t minNbTryInInit = 1; // min of repeats in init
119 const int64_t maxNbTryInInit = 1000; // max of repeats in init
120 const int64_t defaultNbTryInInit = 10; // number of repeats in init
121 
122 const int64_t minNbIterationInInit = 1; // min number of iterations in init
123 const int64_t maxNbIterationInInit = 1000; // max number of iterations in init
124 const int64_t defaultNbIterationInInit = 5; // default number of iterations in init
125 const int64_t defaultNbIterationInInitForSemMax = 100; // default number of iterations in init
126 
127 const double minEpsilonInInit = 0; // min number of iterations in init
128 const double maxEpsilonInInit = 1; // max number of iterations in init
129 const double defaultEpsilonInInit = 0.001; // default number of iterations in init
130 
131 const int64_t maxNbIterationInCEM_INIT = 100; // Maximum number of iterations of CEM in CEM_INIT
132 
133 const double minOverflow = std::numeric_limits<double>::min(); // Minimum value for overflow
134 const double minUnderflow = std::numeric_limits<double>::min(); // Minimum value for underflow
135 const int64_t nbMaxSelection = 5; // Maximum number of selection
136 const int64_t maxNbOutputFiles = 52; // Maximum number of output Files
137 const int64_t nbTestOutputFiles = 7; // Number of output files to compare in test
138 const double defaultFluryEpsilon = 0.001; // default value for espilon in flury algorthm
139 const int64_t maxFluryIter = 7; // maximum of number of Flury iterations
140 const double minDeterminantValue =
141  std::numeric_limits<double>::min(); // minimum value of determinant of sigma
142 const double maxRelativeDiffValueTest = 1.0E-5; // Maximum difference between 2 value in test
143 const double maxAbsoluteDiffValueTest = 1.0E-8; // Maximum difference between 2 value in test
144 
145 const int64_t defaultDCVnumberOfBlocks = 10; // DCV
146 const int64_t defaultCVnumberOfBlocks = 10; // CV
147 
148 const double minValueForLLandLLOne = 1.e-10; // minimum value for LL - LLone
149 
150 const int64_t int64_t_max = std::numeric_limits<int64_t>::max();
151 
152 const int64_t nbQualitativeGraphics = 2;
153 const int64_t nbQuantitativeGraphics = 3;
154 
155 /*
156 Notes :
157 Enumeration types will be called ...Name
158 Ex : StrategyInitName
159  */
160 
161 enum CVinitBlocks {
162 
163  CV_RANDOM = 0, // initialize the CV blocks by random
164 
165  CV_DIAG = 1 // initialize the CV blocks by assiging
166  /*
167  sample 1 : for w=1 to its weight : sample 1 in block w
168  sample 2 : for w=1 to its weight : sample w1+1 in block w1+w
169 
170  Ex : 1
171  //-----
172  ind weight
173  1 1
174  2 1
175  3 1
176  ...
177  ind 1 -> block1
178  ind 2 -> block2
179  ...
180  ind V -> blockV
181  ind V+1->block1
182  ...
183 
184  Ex 2 :
185  //-----
186  ind weight
187  1 2
188  2 2
189  3 2
190  4 2
191  5 2
192 
193  if V=4:
194  ind 1 -> block1
195  ind 1 -> block2
196  ind 2 -> block3
197  ind 2 -> block4
198  ind 3 -> block1
199  ind 3 -> block2
200  ind 4 -> block3
201  ind 4 -> block4
202  ind 5 -> block1
203  ind 5 -> block2
204 
205  ->> block 1 : ind 1 - 3 - 5
206  block 2 : ind 1 - 3 - 5
207  block 3 : ind 2 - 4
208  block 4 : ind 4 - 5
209  */
210 };
211 const CVinitBlocks defaultCVinitBlocks = CV_RANDOM;
212 
213 enum DCVinitBlocks {
214 
215  DCV_RANDOM = 0, // initialize the DCV blocks by random
216 
217  DCV_DIAG = 1 // initialize the DCV blocks by the same way that CV_DIAG
218  /*
219  Ex : 1
220  //-----
221  ind weight
222  1 1
223  2 1
224  3 1
225  ...
226  ind 1 -> blockTest1
227  ind 2 -> blockTest2
228  ...
229  ind V -> blockTestV
230  ind V+1->blockTest1
231  ...
232 
233  Ex 2 :
234  //-----
235  ind weight
236  1 10
237  2 10
238  3 10
239  4 10
240  5 10
241 
242  if V=4:
243  ind 1 -> blockTest1
244  ind 1 -> blockTest2
245  ind 1 -> blockTest3
246  ind 1 -> blockTest4
247  ind 1 -> blockTest1
248  ind 1 -> blockTest2
249  ind 1 -> blockTest3
250  ind 1 -> blockTest4
251  ind 1 -> blockTest1
252  ind 1 -> blockTest2
253  ind 2 -> blockTest3
254  ind 2 -> blockTest4
255  ind 2 -> blockTest1
256  ind 2 -> blockTest2
257  ind 2 -> blockTest3
258  ind 2 -> blockTest4
259  ind 2 -> blockTest1
260  ind 2 -> blockTest2
261  ind 2 -> blockTest3
262  ind 2 -> blockTest4
263 
264  ->> blockTest 1 : ind 1(x3) - 2(x2) - 3(x3) - 4(x2) - 5(x3) - 6(x2) - 7(x3) - 8(x2) - 9(x3) - 10(x2)
265  blockLearning 1 : ind 1(x7) - 2(x8) - 3(x7) - 4(x8) - 5(x7) - 6(x8) - 7(x7) - 8(x8) - 9(x7) - 10(x8)
266  ...
267  */
268 };
269 const DCVinitBlocks defaultDCVinitBlocks = DCV_RANDOM;
270 
275 
276  RANDOM = 0, // Random centers
277  USER = 1, // Initial parameters specified by user
278  USER_PARTITION = 2, // Partition specified by user
279  SMALL_EM = 3, // EM strategy for initial parameters
280  CEM_INIT = 4, // initialization with CEM
281  SEM_MAX = 5 // initialization with SEM max
282 };
283 const StrategyInitName defaultStrategyInitName = SMALL_EM;
284 const StrategyInitName defaultClusteringStrategyInitName = SMALL_EM;
285 
286 // Type of convergence for each algorithm
287 
292 
293  NO_STOP_NAME = -1, // for MAP or M algo
294  NBITERATION = 0, // Number of iterations specified by user
295  EPSILON = 1, // Stationarity of the xml criterion
296  NBITERATION_EPSILON = 2 // Number of iterations & xml criterion
297 };
298 const AlgoStopName defaultAlgoStopName = NBITERATION_EPSILON;
299 
304 
305  UNKNOWN_CRITERION_NAME = -1, // Unknown criterion
306 
307  BIC = 0, // Bayesian information criterion
308  CV = 1, // Cross validation criterion
309  ICL = 2, // Integrated completed likelihood
310  NEC = 3, // Entropy criterion
311  DCV = 4 // Double Cross validation criterion
312 };
313 const CriterionName defaultCriterionName = BIC;
314 const CriterionName defaultLearnCriterionName = CV;
315 
319 enum AlgoName {
320 
321  UNKNOWN_ALGO_NAME = -1, // Unknown algorithm
322  MAP = 0, // Maximum a posteriori
323  EM = 1, // Expectation maximization
324  CEM = 2, // Classification EM
325  SEM = 3, // Stochastic EM
326  M = 4 // Maximization
327 };
328 const AlgoName defaultAlgoName = EM;
329 const AlgoName defaultClusteringAlgoName = EM;
330 
334 const int64_t nbFormatNumeric = 3;
335 namespace FormatNumeric {
336 
337  enum FormatNumericFile {
338 
339  txt = 0, // Format txt (ascii)
340  hdf5 = 1, // Format hdf5
341  XML = 2 // Format XML
342  };
343  const FormatNumericFile defaultFormatNumericFile = txt;
344 }
345 
349 namespace TypePartition {
350 
351  enum TypePartition {
352 
353  UNKNOWN_PARTITION = 0,
354  label = 1,
355  partition = 2
356  };
357  const TypePartition defaultTypePartition = label;
358 }
359 
361 
362  std::string _fileName;
363  FormatNumeric::FormatNumericFile _format;
364  TypePartition::TypePartition _type;
365 };
366 
367 enum DataType {
368 
369  QualitativeData = 0,
370  QuantitativeData,
371  HeterogeneousData
372 };
373 
374 enum ModelGenre {
375 
376  QualitativeModel = 0,
377  QuantitativeModel,
378  HeterogeneousModel
379 };
380 
381 bool isKeyword(std::string& name);
382 
387 
388  int64_t val; // index of individual
389  double weight;
390 };
391 
393 struct CVBlock {
394 
395  int64_t _nbSample; // number of samples in this CV Block
396  double _weightTotal; // weight Total of this CV Block
397  TWeightedIndividual * _tabWeightedIndividual; // array (size=nbSample) of weighted individual
398 };
399 
403 enum ModelName {
404 
406  // //
407  // Gaussian Models //
408  // //
410 
411  // Unknown model type
412  UNKNOWN_MODEL_NAME = -1,
413 
414  // 28 Gaussian 'Classical' models
415 
416  // Spherical Gaussian model: proportion fixed
417  Gaussian_p_L_I = 0,
418  Gaussian_p_Lk_I ,
419 
420  // Spherical Gaussian model: proportion free
421  Gaussian_pk_L_I ,
422  Gaussian_pk_Lk_I,
423 
424  // Diagonal Gaussian model: proportion fixed
425  Gaussian_p_L_B,
426  Gaussian_p_Lk_B,
427  Gaussian_p_L_Bk,
428  Gaussian_p_Lk_Bk,
429 
430  // Diagonal Gaussian model: proportion free
431  Gaussian_pk_L_B,
432  Gaussian_pk_Lk_B,
433  Gaussian_pk_L_Bk,
434  Gaussian_pk_Lk_Bk,
435 
436  // Ellipsoidal Gaussian model: proportion fixed
437  Gaussian_p_L_C,
438  Gaussian_p_Lk_C,
439  Gaussian_p_L_D_Ak_D,
440  Gaussian_p_Lk_D_Ak_D,
441  Gaussian_p_L_Dk_A_Dk,
442  Gaussian_p_Lk_Dk_A_Dk,
443  Gaussian_p_L_Ck,
444  Gaussian_p_Lk_Ck,
445 
446  // Ellipsoidal Gaussian model: proportion free
447  Gaussian_pk_L_C,
448  Gaussian_pk_Lk_C,
449  Gaussian_pk_L_D_Ak_D,
450  Gaussian_pk_Lk_D_Ak_D,
451  Gaussian_pk_L_Dk_A_Dk,
452  Gaussian_pk_Lk_Dk_A_Dk,
453  Gaussian_pk_L_Ck,
454  Gaussian_pk_Lk_Ck,
455 
456  //----------------//
457  // 16 HD models //
458  //----------------//
459  Gaussian_HD_p_AkjBkQkDk,
460  Gaussian_HD_p_AkBkQkDk,
461  Gaussian_HD_p_AkjBkQkD ,
462  Gaussian_HD_p_AjBkQkD ,
463  Gaussian_HD_p_AkjBQkD ,
464  Gaussian_HD_p_AjBQkD ,
465  Gaussian_HD_p_AkBkQkD ,
466  Gaussian_HD_p_AkBQkD ,
467 
468  Gaussian_HD_pk_AkjBkQkDk,
469  Gaussian_HD_pk_AkBkQkDk ,
470  Gaussian_HD_pk_AkjBkQkD,
471  Gaussian_HD_pk_AjBkQkD,
472  Gaussian_HD_pk_AkjBQkD,
473  Gaussian_HD_pk_AjBQkD ,
474  Gaussian_HD_pk_AkBkQkD,
475  Gaussian_HD_pk_AkBQkD ,
476 
478  // //
479  // 10 Binary Models //
480  // //
482 
483  // proportion fixed
484  Binary_p_E ,
485  Binary_p_Ek,
486  Binary_p_Ej ,
487  Binary_p_Ekj,
488  Binary_p_Ekjh ,
489  // proportion free
490  Binary_pk_E ,
491  Binary_pk_Ek,
492  Binary_pk_Ej ,
493  Binary_pk_Ekj,
494  Binary_pk_Ekjh ,
495 
496  // Heterogeneous model name:proportions free
497  Heterogeneous_pk_E_L_B,
498  Heterogeneous_pk_E_Lk_B,
499  Heterogeneous_pk_E_L_Bk,
500  Heterogeneous_pk_E_Lk_Bk,
501  Heterogeneous_pk_Ek_L_B,
502  Heterogeneous_pk_Ek_Lk_B,
503  Heterogeneous_pk_Ek_L_Bk,
504  Heterogeneous_pk_Ek_Lk_Bk,
505  Heterogeneous_pk_Ej_L_B,
506  Heterogeneous_pk_Ej_Lk_B,
507  Heterogeneous_pk_Ej_L_Bk,
508  Heterogeneous_pk_Ej_Lk_Bk,
509  Heterogeneous_pk_Ekj_L_B,
510  Heterogeneous_pk_Ekj_Lk_B,
511  Heterogeneous_pk_Ekj_L_Bk,
512  Heterogeneous_pk_Ekj_Lk_Bk,
513  Heterogeneous_pk_Ekjh_L_B,
514  Heterogeneous_pk_Ekjh_Lk_B,
515  Heterogeneous_pk_Ekjh_L_Bk,
516  Heterogeneous_pk_Ekjh_Lk_Bk,
517  // Heterogeneous model name:proportions fix
518  Heterogeneous_p_E_L_B,
519  Heterogeneous_p_E_Lk_B,
520  Heterogeneous_p_E_L_Bk,
521  Heterogeneous_p_E_Lk_Bk,
522  Heterogeneous_p_Ek_L_B,
523  Heterogeneous_p_Ek_Lk_B,
524  Heterogeneous_p_Ek_L_Bk,
525  Heterogeneous_p_Ek_Lk_Bk,
526  Heterogeneous_p_Ej_L_B,
527  Heterogeneous_p_Ej_Lk_B,
528  Heterogeneous_p_Ej_L_Bk,
529  Heterogeneous_p_Ej_Lk_Bk,
530  Heterogeneous_p_Ekj_L_B,
531  Heterogeneous_p_Ekj_Lk_B,
532  Heterogeneous_p_Ekj_L_Bk,
533  Heterogeneous_p_Ekj_Lk_Bk,
534  Heterogeneous_p_Ekjh_L_B,
535  Heterogeneous_p_Ekjh_Lk_B,
536  Heterogeneous_p_Ekjh_L_Bk,
537  Heterogeneous_p_Ekjh_Lk_Bk,
538 
539  nbModelName = 54
540 };
541 
542 const ModelName defaultGaussianModelName = Gaussian_pk_Lk_C;
543 const ModelName defaultBinaryModelName = Binary_pk_Ekjh;
544 const ModelName defaultGaussianHDDAModelName = Gaussian_HD_pk_AkjBkQkD;
545 const ModelName defaultHeterogeneousModelName = Heterogeneous_pk_Ekjh_Lk_Bk;
546 
547 // Output mode
548 enum OutputType {
549 
550  BICstandardOutput = 0, // Standard output mode
551  BICnumericStandardOutput, // Numerical standard output
552  BIClabelOutput, // Label output
553  BICparameterOutput, // Parameter output (numerical)
554  BICtikOutput, // Posterior probabilities output
555  BICzikOutput, // Partition output (notation 1/0)
556  BIClikelihoodOutput, // Log-likelihood, entropy & completed log-likelihood output
557  BICnumericLikelihoodOutput,
558  BICErrorOutput = 8, // error code for BIC Criterion for each estimation
559 
560  CVstandardOutput, // CV Standard output mode
561  CVnumericStandardOutput, // CV Numerical standard output
562  CVlabelOutput, // CV Label output
563  CVparameterOutput, // CV Parameter output (numerical)
564  CVtikOutput, // CV Posterior probabilities output
565  CVzikOutput, // CV Partition output (notation 1/0)
566  CVlikelihoodOutput, // CV Log-likelihood, entropy & completed log-likelihood output
567  CVnumericLikelihoodOutput,
568  CVErrorOutput = 17, // error code for CV Criterion for each estimation
569 
570  ICLstandardOutput, // ICL Standard output mode
571  ICLnumericStandardOutput, // ICL Numerical standard output
572  ICLlabelOutput, // ICL Label output
573  ICLparameterOutput, // ICL Parameter output (numerical)
574  ICLtikOutput, // ICL Posterior probabilities output
575  ICLzikOutput, // ICL Partition output (notation 1/0)
576  ICLlikelihoodOutput, // ICL Log-likelihood, entropy & completed log-likelihood output
577  ICLnumericLikelihoodOutput,
578  ICLErrorOutput = 26, // error code for ICL Criterion for each estimation
579 
580  NECstandardOutput, // NEC Standard output mode
581  NECnumericStandardOutput, // NEC Numerical standard output
582  NEClabelOutput, // NEC Label output
583  NECparameterOutput, // NEC Parameter output (numerical)
584  NECtikOutput, // NEC Posterior probabilities output
585  NECzikOutput, // NEC Partition output (notation 1/0)
586  NEClikelihoodOutput, // NEC Log-likelihood, entropy & completed log-likelihood output
587  NECnumericLikelihoodOutput,
588  NECErrorOutput = 35, // error code for NEC Criterion for each estimation
589 
590  DCVstandardOutput, // DCV Standard output mode
591  DCVnumericStandardOutput, // DCV Numerical standard output
592  DCVlabelOutput, // DCV Label output
593  DCVparameterOutput, // DCV Parameter output (numerical)
594  DCVtikOutput, // DCV Posterior probabilities output
595  DCVzikOutput, // DCV Partition output (notation 1/0)
596  DCVlikelihoodOutput, // DCV Log-likelihood, entropy & completed log-likelihood output
597  DCVnumericLikelihoodOutput,
598  DCVErrorOutput = 44, // error code for DCV Criterion for each estimation
599 
600  completeOutput , // Complete output mode
601  numericCompleteOutput, // Numerical complete output
602 
603  CVlabelClassificationOutput, // label of classification CV method
604 
605  errorMixmodOutput, // error code for mixmod execution
606  errorModelOutput, // error code for NEC Criterion for each estimation
607 
608  DCVinfo, // double cross validation information
609  DCVnumericInfo = 51 // numeric double cross validation information (for validation test)
610 };
611 
613 double powAndCheckIfNotNull(double a, double b,
614  const Exception & errorType = NumericException("Defaulter", 0, nullDeterminant) );
615 
617 int64_t Round(double d);
618 
620 void ConvertBigtoLowString(std::string & str);
621 
622 //ModelNameToString
623 std::string ModelNameToString(const ModelName & modelName);
624 
625 //StringToModelName
626 ModelName StringToModelName(const std::string & strModelName);
627 
628 //get Heterogeneous model name
629 ModelName getHeterogeneousModelName(const ModelName binaryName, const ModelName gaussianName);
630 //get binary model name
631 ModelName getBinaryModelNamefromHeterogeneous(const ModelName HeterogeneousName);
632 //get gaussian model name
633 ModelName getGaussianModelNamefromHeterogeneous(const ModelName HeterogeneousName);
634 
635 // edit modelName
636 void edit(const ModelName & modelName);
637 
638 //criterionNameToString
639 std::string CriterionNameToString(const CriterionName & criterionName);
640 
641 //StringtoXEMCriterionName
642 CriterionName StringtoCriterionName(const std::string & str);
643 
644 // edit CriterionName
645 void edit(const CriterionName & criterionName);
646 
647 // AlgoNameToString
648 std::string AlgoNameToString(const AlgoName & typeAlgo);
649 
650 //StringToAlgoName
651 AlgoName StringToAlgoName(const std::string & str);
652 
653 // edit AlgoName
654 void edit(const AlgoName & typeAlgo);
655 
656 //FormatFileToString
657 std::string FormatNumericFileToString(const FormatNumeric::FormatNumericFile & formatNumericFile);
658 
659 //StringToFormatFile
660 FormatNumeric::FormatNumericFile StringToFormatNumericFile(const std::string & strFormatNumericFile);
661 
662 //TypePartitionToString
663 std::string TypePartitionToString(const TypePartition::TypePartition & typePartition);
664 
665 //StringToTypePartition
666 TypePartition::TypePartition StringToTypePartition(const std::string & strTypePartition);
667 
668 //StrategyInitNameToString
669 std::string StrategyInitNameToString(const StrategyInitName & strategyInitName);
670 
671 //StringToStrategyInitName
672 StrategyInitName StringToStrategyInitName(const std::string & str);
673 
674 // edit StrategyInitName
675 void edit(const StrategyInitName & strategyInitName);
676 
677 // AlgoStopNameToString
678 std::string AlgoStopNameToString(const AlgoStopName & algoStopName);
679 
680 // void AlgoStopName
681 void edit(const AlgoStopName & algoStopName);
682 
683 // is modelName has free proportion
684 bool hasFreeProportion(ModelName modelName);
685 
686 // is modelName a diagonal Gaussian Model
687 bool isDiagonal(ModelName modelName);
688 
689 // is modelName a spherical Gaussian Model
690 bool isSpherical(ModelName modelName);
691 
692 // is modelName a general Gaussian Model
693 bool isGeneral(ModelName modelName);
694 
695 // is modelName a EDDA (Classical Gaussian)
696 bool isEDDA(ModelName modelName);
697 
698 // is modelName a HD (or HDk)
699 bool isHD(ModelName modelName);
700 
701 bool isFreeSubDimension(ModelName modelName);
702 
703 bool isBinary(ModelName modelName);
704 bool isHeterogeneous(ModelName modelname);
705 
706 ModelGenre getModelGenre(ModelName modelname);
707 
708 
709 // traitement sur les tableaux
710 //----------------------------
711 
712 // T* copyTab(T * tab, int64_t dim)
713 template<typename T> T * copyTab(T * tab, int64_t dim) {
714  T * res = new T[dim];
715  int64_t i;
716  for (i = 0; i < dim; i++) {
717  res[i] = tab[i];
718  }
719  return res;
720 }
721 
722 // T ** copyTab(T ** tab, int64_t dim1, int64_t dim2)
723 template<typename T> T ** copyTab(T ** tab, int64_t dim1, int64_t dim2) {
724  T ** res = new T*[dim1];
725  int64_t i, j;
726  for (i = 0; i < dim1; i++) {
727  res[i] = new T[dim2];
728  for (j = 0 ; j < dim2; j++)
729  res[i][j] = tab[i][j];
730  }
731  return res;
732 }
733 
734 // void recopyTab(T * source, T * destination,int64_t dim)
735 template<typename T> void recopyTab(T * source, T * destination, int64_t dim) {
736  int64_t i;
737  for (i = 0; i < dim; i++) {
738  destination[i] = source[i];
739  }
740 }
741 
742 inline void recopyTab(int64_t * source, double * destination, int64_t dim) {
743  int64_t i;
744  for (i = 0; i < dim; i++) {
745  destination[i] = source[i];
746  }
747 }
748 
749 inline void recopyTabToVector(double ** source,
750  std::vector<std::vector<double> > & destination, int64_t dim1, int64_t dim2)
751 {
752  destination.resize(dim1);
753  int64_t i, j;
754  for (i = 0; i < dim1; i++) {
755  destination[i].resize(dim2);
756  for (j = 0; j < dim2; j++) {
757  destination[i][j] = source[i][j];
758  }
759  }
760 }
761 
762 inline void recopyTabToVector(int64_t * source, std::vector<int64_t> & destination, int64_t dim1) {
763  destination.resize(dim1);
764  int64_t i;
765  for (i = 0; i < dim1; i++) {
766  destination[i] = source[i];
767  }
768 }
769 
770 inline void recopyVectorToTab(std::vector<std::vector<double> > source, double **& destination) {
771  int64_t dim1 = source.size();
772  int64_t dim2 = source[0].size();
773  destination = new double*[dim1];
774  for (int64_t i = 0; i < dim1; i++) {
775  destination[i] = new double[dim2];
776  for (int64_t k = 0; k < dim2; k++) {
777  destination[i][k] = source[i][k];
778  }
779  }
780 }
781 
782 inline void recopyVectorToTab(std::vector<int64_t> source, int64_t *& destination) {
783  int64_t dim1 = source.size();
784  destination = new int64_t[dim1];
785  for (int64_t i = 0; i < dim1; i++) {
786  destination[i] = source[i];
787  }
788 }
789 
790 // void recopyTab(T ** source, T ** destination, int64_t dim1, int64_t dim2)
791 template<typename T> void recopyTab(T ** source, T ** destination, int64_t dim1, int64_t dim2) {
792  int64_t i, j;
793  for (i = 0; i < dim1; i++) {
794  for (j = 0; j < dim2; j++) {
795  destination[i][j] = source[i][j];
796  }
797  }
798 }
799 
800 void editSimpleTab(double * tab, int64_t n, std::ostream & flux, std::string sep = " ", std::string before = " ");
801 void editSimpleTab(int64_t * tab, int64_t n, std::ostream & flux);
802 
803 template<typename T> void editTab(T ** tab, int64_t dim1, int64_t dim2,
804  std::ostream & flux, std::string sep = " ", std::string before = "")
805 {
806  T ** p_tab = tab;
807  T * p_tab_i;
808  int64_t i, j ;
809  for (i = 0; i < dim1; i++) {
810  p_tab_i = *p_tab;
811  flux << before;
812  for (j = 0; j < dim2; j++) {
813  flux << p_tab_i[j] << sep;
814  }
815  flux << endl;
816  p_tab++;
817  }
818 }
819 
820 //Deleters for unique_ptr
821 template<typename T>
822  struct TabDeleter {
823  TabDeleter(int64_t size) : _size(size){};
824  int64_t _size;
825  void operator()(T** p) {
826  for(int64_t i=0;i<_size;i++){
827  delete[] p[i];
828  };
829  delete[] p;
830 
831  }
832 };
833 
834 template<typename T>
836  IfChangedDeleter(T* initial) : _initial(initial){};
837  T* _initial;
838  void operator()(T* p) {
839  if(p != _initial) delete p;
840  }
841 };
842 
843 
844 
845 // move on a file until *what* is reached
846 void moveUntilReach(std::ifstream & fi, std::string what = "datafile");
847 
848 void readTabFileName(std::ifstream & fi, int64_t nbNbCluster, std::string * tabFileName, std::string & keyWord);
849 
850 void initToZero(double * tab, int64_t n);
851 void initToZero(double * tab, int64_t n);
852 
853 const int64_t SMALL_ENOUGH_TO_USE_SELECTION_SORT = 15;
854 void echange(double * tab, int64_t i1, int64_t i2);
855 void echange(int64_t * tab , int64_t i1, int64_t i2);
856 
857 void selectionSortWithOrder(double * tabRandom, int64_t * tabOrder, int64_t left, int64_t right);
858 
859 int64_t partition(double * tabRandom, int64_t * tabOrder, int64_t left, int64_t right);
860 
861 void quickSortWithOrder(double * tabRandom, int64_t * tabOrder, int64_t left, int64_t right);
862 
863 int64_t generateRandomIndex(bool * tabIndividualCanBeUsedForInitRandom, double * weight, double totalWeight);
864 
865 void inputCriterion(std::ifstream & fi, CriterionName & criterionName);
866 
867 void inputCVinitBlocks(std::ifstream & fi, CVinitBlocks cVinitBlocks);
868 
869 void inputDCVinitBlocks(std::ifstream & fi, DCVinitBlocks dCVinitBlocks);
870 
871 
872 }
873 
874 #endif
ModelName
Enumeration of model name.
Definition: Util.h:403
void ConvertBigtoLowString(std::string &str)
convert big char of a string in low char
Definition: Util.cpp:50
XEMCVBlock.
Definition: Util.h:393
Definition: Util.h:822
Definition: Util.h:835
AlgoName
Enumeration of Algo type.
Definition: Util.h:319
int64_t Round(double d)
return the nearest int64_t
Definition: Util.cpp:42
double powAndCheckIfNotNull(double a, double b, const Exception &errorType)
compute a^b and throw an error if it's equal to zero
Definition: Util.cpp:32
CriterionName
Enumeration of Criterion type.
Definition: Util.h:303
StrategyInitName
Enumeration of differents strategy initialization.
Definition: Util.h:274
const double XEMPI
Define PI.
Definition: Util.h:82
Definition: Util.h:360
Structure for chain list of differents sample.
Definition: Util.h:386
const int64_t maxNbSample
Define number of maximum samples.
Definition: Util.h:93
AlgoStopName
Enumeration of differents type of converge of algorithm (stop rule)
Definition: Util.h:291