Changeset 1044
- Timestamp:
- 12/10/20 22:33:22 (4 years ago)
- Location:
- cpp
- Files:
-
- 14 added
- 5 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/Makefile-SDK-files
r1035 r1044 2 2 3 3 # ALL_DIRS is later expanded by the shell, no spaces/newlines allowed, or it breaks 4 ALL_DIRS={common,PrintFloat,frams,frams/canvas,frams/config,common/loggers,frams/genetics,frams/genetics/f0,frams/genetics/f1,frams/genetics/f2,frams/genetics/f3,frams/genetics/f4,frams/genetics/f5,frams/genetics/f6,frams/genetics/f7,frams/genetics/f8,frams/genetics/f9,frams/genetics/fn,frams/genetics/fF,frams/genetics/fT,frams/genetics/fB,frams/genetics/fH,frams/genetics/fL,frams/genetics/fS,frams/model,frams/neuro,frams/neuro/impl,frams/param,frams/test,frams/util,frams/vm/classes,common/virtfile,frams/_demos,frams/model/geometry,frams/_demos/geometry,frams/model/similarity,frams/model/similarity/hungarian,frams/model/similarity/SVD }4 ALL_DIRS={common,PrintFloat,frams,frams/canvas,frams/config,common/loggers,frams/genetics,frams/genetics/f0,frams/genetics/f1,frams/genetics/f2,frams/genetics/f3,frams/genetics/f4,frams/genetics/f5,frams/genetics/f6,frams/genetics/f7,frams/genetics/f8,frams/genetics/f9,frams/genetics/fn,frams/genetics/fF,frams/genetics/fT,frams/genetics/fB,frams/genetics/fH,frams/genetics/fL,frams/genetics/fS,frams/model,frams/neuro,frams/neuro/impl,frams/param,frams/test,frams/util,frams/vm/classes,common/virtfile,frams/_demos,frams/model/geometry,frams/_demos/geometry,frams/model/similarity,frams/model/similarity/hungarian,frams/model/similarity/SVD,frams/model/similarity/EMD} 5 5 6 6 GEOMETRY_OBJS=frams/model/geometry/meshbuilder.o frams/model/geometry/modelgeometryinfo.o frams/model/geometry/geometryutils.o … … 37 37 NEURO_OBJS=frams/neuro/neuroimpl.o frams/neuro/neurofactory.o frams/neuro/impl/neuroimpl-simple.o frams/neuro/impl/neuroimpl-channels.o frams/neuro/impl/neuroimpl-fuzzy.o frams/neuro/impl/neuroimpl-fuzzy-f0.o 38 38 39 SIMILARITY_OBJS=frams/ model/similarity/hungarian/hungarian.o frams/model/similarity/SVD/lapack.o frams/model/similarity/SVD/matrix_tools.o frams/model/similarity/simil_match.o frams/model/similarity/simil_model.o39 SIMILARITY_OBJS=frams/_demos/geometry/geometrytestutils.o frams/model/similarity/measure-greedy.o frams/model/similarity/measure-hungarian.o frams/model/similarity/measure-distribution.o frams/model/similarity/measure-mds-based.o frams/model/similarity/simil-measure.o frams/model/similarity/hungarian/hungarian.o frams/model/similarity/SVD/lapack.o frams/model/similarity/SVD/matrix_tools.o frams/model/similarity/simil-match.o 40 40 41 41 NN_LAYOUT_OBJS=frams/canvas/nn_layout_model.o frams/canvas/nn_simple_layout.o frams/canvas/nn_smart_layout.o … … 96 96 SIMIL_TEST_OBJS=frams/_demos/simil_test.o $(SIMILARITY_OBJS) frams/_demos/genotypeloader.o frams/_demos/genotypemini.o frams/param/multiparamload.o common/virtfile/stdiofile.o $(STDOUT_LOGGER_OBJS) $(SDK_OBJS) $(GENOCONV_AND_GENMAN_SDK_OBJS) 97 97 98 SIMIL_UNITTESTS_OBJS=frams/_demos/simil_unittests.o frams/model/similarity/simil _match.o98 SIMIL_UNITTESTS_OBJS=frams/_demos/simil_unittests.o frams/model/similarity/simil-match.o 99 99 100 100 PARAMTREE_STDIN_TEST_OBJS=frams/_demos/paramtree_stdin_test.o frams/_demos/paramtree_print.o $(STDOUT_LOGGER_OBJS) common/virtfile/stdiofile.o $(SDK_OBJS) frams/param/paramtree.o 101 101 102 PARAMTREE_PARAMLIST_TEST_OBJS=$(sort frams/_demos/paramtree_paramlist_test.o frams/_demos/paramtree_print.o $(STDOUT_LOGGER_OBJS) common/virtfile/stdiofile.o $(SDK_OBJS) $(GENOCONV_AND_GENMAN_SDK_OBJS) frams/neuro/neuroimpl.o frams/neuro/neurofactory.o frams/neuro/impl/neuroimpl-simple.o frams/neuro/impl/neuroimpl-channels.o frams/neuro/impl/neuroimpl-fuzzy.o frams/neuro/impl/neuroimpl-fuzzy-f0.o $(GENOTYPE_LOADER_OBJS) $(GEOMETRY_OBJS) frams/model/geometry/modelgeoclass.o frams/model/modelobj.o frams/param/paramtree.o)102 PARAMTREE_PARAMLIST_TEST_OBJS=$(sort frams/_demos/paramtree_paramlist_test.o frams/_demos/paramtree_print.o $(STDOUT_LOGGER_OBJS) common/virtfile/stdiofile.o $(SDK_OBJS) $(GENOCONV_AND_GENMAN_SDK_OBJS) frams/neuro/neuroimpl.o frams/neuro/neurofactory.o frams/neuro/impl/neuroimpl-simple.o frams/neuro/impl/neuroimpl-channels.o frams/neuro/impl/neuroimpl-fuzzy.o frams/neuro/impl/neuroimpl-fuzzy-f0.o $(GENOTYPE_LOADER_OBJS) $(GEOMETRY_OBJS) $(SIMILARITY_OBJS) frams/model/geometry/modelgeoclass.o frams/model/modelobj.o frams/param/paramtree.o) 103 103 104 104 MUTABLEPARAM_TEST_OBJS=frams/_demos/mutableparam_test.o $(STDOUT_LOGGER_OBJS) common/virtfile/stdiofile.o $(SDK_OBJS) frams/param/mutableparam.o frams/param/mutparamlist.o frams/param/paramtrans.o -
cpp/frams/_demos/paramtree_paramlist_test.cpp
r795 r1044 11 11 #include <frams/model/geometry/modelgeoclass.h> 12 12 #include <frams/model/modelobj.h> 13 #include <frams/model/similarity/measure-distribution.h> 14 #include <frams/model/similarity/measure-greedy.h> 15 #include <frams/model/similarity/measure-hungarian.h> 13 16 #include "genotypeloader.h" 14 17 #include "paramtree_print.h" … … 27 30 NeuroNetConfig nn_config(&neurofac); 28 31 ModelGeometry modelgeo; 32 SimilMeasureDistribution simil_measure_distr; 33 SimilMeasureGreedy simil_measure_greedy; 34 SimilMeasureHungarian simil_measure_hungarian; 29 35 30 36 MutableParamList combined; … … 39 45 combined += &nn_config.par; 40 46 combined += &modelgeo.par; 47 combined += &simil_measure_distr.localpar; 48 combined += &simil_measure_greedy.localpar; 49 combined += &simil_measure_hungarian.localpar; 41 50 42 51 ParamTree tree(&combined); -
cpp/frams/_demos/simil_test.cpp
r1005 r1044 5 5 6 6 #include <vector> 7 #include <string> 7 8 #include "common/loggers/loggertostdout.h" 8 9 #include "frams/_demos/genotypeloader.h" 9 10 #include "frams/genetics/preconfigured.h" 10 11 #include "common/virtfile/stdiofile.h" 11 #include "frams/model/similarity/simil_model.h" 12 13 12 #include "frams/model/similarity/measure-distribution.h" 13 #include "frams/model/similarity/measure-greedy.h" 14 #include "frams/model/similarity/measure-hungarian.h" 15 16 using namespace std; 17 18 int add_double_param(std::vector<string> *args, int pos, std::vector<double> *params, std::vector<string> *params_names) 19 { 20 for (unsigned int i = 0; i < params_names->size(); i++) 21 { 22 try 23 { 24 params->push_back(std::stod(args->at(pos))); 25 pos++; 26 } 27 catch (const std::invalid_argument&) 28 { 29 printf("%s should be a number\n", params_names->at(i).c_str()); 30 return -1; 31 } 32 catch (const std::out_of_range&) 33 { 34 printf("%s should be inside double range\n", params_names->at(i).c_str()); 35 return -1; 36 } 37 } 38 return 0; 39 } 14 40 15 41 /** Computes a matrix of distances between all genotypes in the specified … … 18 44 int main(int argc, char *argv[]) 19 45 { 20 LoggerToStdout messages_to_stdout(LoggerBase::Enable); 21 int iCurrParam = 0; // index of the currently processed parameter 22 char *szCurrParam = NULL; 23 ModelSimil M; // similarity computing object 24 bool bPrintNames = false; // specifies if names of genotypes are to be printed 25 int nResult = 0; // a temporary result 26 27 if (argc < 8) 28 { 29 printf("Too few parameters!\n"); 30 printf("Command line: [-names] <genotypesFile> <measure> <w_dP> <w_dDEG> <w_dNEU> <w_dGEO> <fixZaxis?>\n\n"); 31 32 printf("Parameters:\n"); 33 printf(" <genotypesFile> name of a file with genotypes\n"); 34 printf(" <measure> similarity measure\n"); 35 printf(" <w_dP> weight of the difference in the number of parts\n"); 36 printf(" <w_dDEG> weight of the difference in degrees of matched parts\n"); 37 printf(" <w_dNEU> weight of the difference in neurons of matched parts\n"); 38 printf(" <w_dGEO> weight of the distance of matched parts\n"); 39 printf(" <fixZaxis?> should the 'z' (vertical) coordinate be fixed during the alignment? (0 or 1)\n\n"); 40 41 printf("Switches:\n"); 42 printf(" -names specifies that the number and names of genotypes are to be printed to output\n"); 43 printf(" before the distance matrix; by default the number and names are not printed\n\n"); 44 45 printf("Outputs a symmetric distance matrix in the format:\n"); 46 printf(" <row_1> (columns in a row are separated by TABs)\n"); 47 printf(" ...\n"); 48 printf(" <row_n>\n"); 49 50 return -1; 51 } 52 53 // prepare output parameters from .gen file 54 vector<Geno *> pvGenos; 55 vector<char *> pvNames; 56 57 // check if there is a switch 58 iCurrParam = 1; 59 szCurrParam = argv[iCurrParam]; 60 if (strcmp(szCurrParam, "-names") == 0) 61 { 62 // switch "-names" was given; print names also 63 bPrintNames = true; 64 // pass to the next parameter 65 iCurrParam++; 66 } 67 68 // check the parameters 69 // get <genotypesFile> name from command line 70 char *szFileName = argv[iCurrParam]; 71 72 // initially set measure components' weights to invalid values (negative) 73 for (int i = 0; i < M.GetNOFactors(); i++) 74 { 75 M.m_adFactors[i] = -1.0; 76 } 77 78 iCurrParam++; 79 szCurrParam = argv[iCurrParam]; 80 int measure_type = -1; 81 nResult = sscanf(szCurrParam, "%d", &measure_type); 82 if (nResult != 1) 83 { 84 printf("Measure type should be a number!\n"); 85 return -1; 86 } 87 88 if (measure_type != 0 && measure_type != 1) 89 { 90 printf("Measure type should be 0 (flexible criteria order and optimal matching) or 1 (vertex degree order and greedy matching)!\n"); 91 return -1; 92 } 93 94 M.matching_method = measure_type; 95 96 const char *params[] = { "<w_dP>", "<w_dDEG>", "<w_dNEU>", "<w_dGEO>" }; 97 for (int i = 0; i < M.GetNOFactors(); i++) 98 { 99 iCurrParam++; 100 szCurrParam = argv[iCurrParam]; 101 nResult = sscanf(szCurrParam, "%lf", &M.m_adFactors[i]); 102 if (nResult != 1) 103 { 104 // <w_dX> is not a number -- error 105 printf("%s", params[i]); 106 printf(" should be a number\n"); 107 return -1; 108 } 109 else 110 { 111 // <w_dX> is a number; check if nonnegative 112 if (M.m_adFactors[i] < 0.0) 113 { 114 printf("%s", params[i]); 115 printf(" should be a nonnegative number\n"); 116 return -1; 117 } 118 } 119 } 120 121 iCurrParam++; 122 szCurrParam = argv[iCurrParam]; 123 nResult = sscanf(szCurrParam, "%d", &M.fixedZaxis); 124 if (nResult != 1) 125 { 126 // <isZFixed> is not a number -- error 127 printf("<isZFixed> should be a number\n"); 128 return -1; 129 } 130 else if (M.fixedZaxis != 0 && M.fixedZaxis != 1) 131 { 132 printf("<isZFixed>=%d. <isZFixed> should be equal to 0 or 1\n", M.fixedZaxis); 133 return -1; 134 } 135 136 // read the input file 137 // prepare loading of genotypes from a .gen file 138 // create some basic genotype converters 139 PreconfiguredGenetics genetics; 140 StdioFileSystem_autoselect stdiofilesys; 141 142 long count = 0, totalsize = 0; 143 GenotypeMiniLoader loader(szFileName); 144 GenotypeMini *loaded; 145 while (loaded = loader.loadNextGenotype()) 146 { 147 // while a valid genotype was loaded 148 count++; 149 totalsize += loaded->genotype.length(); 150 // create a Geno object based on the MiniGenotype 151 Geno *pNextGenotype = new Geno(loaded->genotype); 152 if ((pNextGenotype != NULL) && (pNextGenotype->isValid())) 153 { 154 pvGenos.push_back(pNextGenotype); 155 char *szNewName = new char[loaded->name.length() + 1]; 156 strcpy(szNewName, loaded->name.c_str()); 157 pvNames.push_back(szNewName); 158 } 159 else 160 { 161 printf("Genotype %2li is not valid\n", count); 162 if (pNextGenotype != NULL) delete pNextGenotype; 163 } 164 } 165 if (loader.getStatus() == GenotypeMiniLoader::OnError) 166 { 167 printf("Error: %s", loader.getError().c_str()); 168 } 169 170 double dSimilarity = 0.0; 171 double **aaSimil = NULL; // array of similarities 172 173 // create an empty array of similarities 174 aaSimil = new double*[pvGenos.size()]; 175 for (unsigned int k = 0; k < pvGenos.size(); k++) 176 { 177 aaSimil[k] = new double[pvGenos.size()]; 178 for (unsigned int l = 0; l < pvGenos.size(); l++) 179 aaSimil[k][l] = 0.0; 180 } 181 182 // compute and store similarities 183 for (unsigned int i = 0; i < pvGenos.size(); i++) 184 { 185 for (unsigned int j = 0; j < pvGenos.size(); j++) 186 { 187 dSimilarity = M.EvaluateDistance(pvGenos.operator[](i), pvGenos.operator[](j)); 188 aaSimil[i][j] = dSimilarity; 189 } 190 } 191 192 if (bPrintNames) 193 { 194 // if the "-names" switch was given, print the number of genotypes and their names 195 printf("%li\n", pvGenos.size()); 196 for (unsigned int iGen = 0; iGen < pvNames.size(); iGen++) 197 { 198 printf("%s\n", pvNames.at(iGen)); 199 } 200 } 201 202 // print out the matrix of similarities 203 for (unsigned int i = 0; i < pvGenos.size(); i++) 204 { 205 for (unsigned int j = 0; j < pvGenos.size(); j++) 206 { 207 printf("%.2lf\t", aaSimil[i][j]); 208 } 209 printf("\n"); 210 } 211 212 // delete vectors and arrays 213 for (unsigned int i = 0; i < pvGenos.size(); i++) 214 { 215 delete pvGenos.operator[](i); 216 delete[] pvNames.operator[](i); 217 delete[] aaSimil[i]; 218 } 219 220 delete[] aaSimil; 221 222 return 0; 46 typedef double *pDouble; 47 LoggerToStdout messages_to_stdout(LoggerBase::Enable); 48 SimilMeasure *simil_measure = nullptr; 49 if (argc < 5) 50 { 51 printf("Too few parameters!\n"); 52 printf("Command line: [-names] <genotypesFile> <measure (greedy/hungarian)> <w_dP> <w_dDEG> <w_dNEU> <w_dGEO> <fixZaxis?>\n\n"); 53 printf("Command line: [-names] <genotypesFile> <measure (distribution)> <desc> <simil> <dens> <bins> <samp_num>\n\n"); 54 printf("Parameters:\n"); 55 printf(" <genotypesFile> name of a file with genotypes\n"); 56 printf(" <measure> similarity measure name (greedy/hungarian/distribution)\n"); 57 printf("\n"); 58 printf("Parameters of greedy and hungarian measures:\n"); 59 printf(" <w_dP> weight of the difference in the number of parts\n"); 60 printf(" <w_dDEG> weight of the difference in degrees of matched parts\n"); 61 printf(" <w_dNEU> weight of the difference in neurons of matched parts\n"); 62 printf(" <w_dGEO> weight of the distance of matched parts\n"); 63 printf(" <fixZaxis?> should the 'z' (vertical) coordinate be fixed during the alignment? (0 or 1)\n\n"); 64 printf("Parameters of distribution measure:\n"); 65 printf(" <dens> sampling density\n"); 66 printf(" <bins> number of histogram bins\n"); 67 printf(" <samp_num> number of samples taken\n\n"); 68 69 printf("Switches:\n"); 70 printf(" -names specifies that the number and names of genotypes are to be printed to output\n"); 71 printf(" before the distance matrix; by default the number and names are not printed\n\n"); 72 73 printf("Outputs a symmetric distance matrix in the format:\n"); 74 printf(" <row_1> (columns in a row are separated by TABs)\n"); 75 printf(" ...\n"); 76 printf(" <row_n>\n"); 77 78 return -1; 79 } 80 81 std::vector<string> args; 82 for (int i = 1; i < argc; i++) 83 args.push_back(std::string(argv[i])); 84 85 bool print_names = false; 86 87 int pos = 1; 88 if (args.at(0).compare("-names")==0) 89 { 90 print_names = true; 91 pos = 2; 92 } 93 94 string measure_name = args.at(pos); 95 pos++; 96 std::vector<double> params; 97 98 if (measure_name.compare("greedy")==0 || measure_name.compare("hungarian")==0) 99 { 100 std::vector<string> params_names{ "<w_dP>", "<w_dDEG>", "<w_dNEU>", "<w_dGEO>", "<fixZaxis?>" }; 101 102 if (add_double_param(&args, pos, ¶ms, ¶ms_names) == -1) 103 return -1; 104 105 if (measure_name.compare("greedy")==0) 106 simil_measure = new SimilMeasureGreedy(); 107 else 108 simil_measure = new SimilMeasureHungarian(); 109 } 110 111 112 else if (measure_name.compare("distribution")==0) 113 { 114 std::vector<string> params_names{ "<dens>", "<bins>", "<samp_num>" }; 115 116 if (add_double_param(&args, pos, ¶ms, ¶ms_names)==-1) 117 return -1; 118 119 simil_measure = new SimilMeasureDistribution(); 120 } 121 122 else 123 { 124 printf("Measure type should be greedy (flexible criteria order and optimal matching), hungarian (vertex degree order and greedy matching) or distribution!\n"); 125 return -1; 126 } 127 128 simil_measure->setParams(params); 129 130 // read the input file 131 // prepare loading of genotypes from a .gen file 132 // create some basic genotype converters 133 PreconfiguredGenetics genetics; 134 StdioFileSystem_autoselect stdiofilesys; 135 136 // prepare output parameters from .gen file 137 vector<Geno *> pvGenos; 138 vector<char *> pvNames; 139 140 long count = 0, totalsize = 0; 141 GenotypeMiniLoader loader(args.at(0).c_str()); 142 GenotypeMini *loaded; 143 while (loaded = loader.loadNextGenotype()) 144 { 145 // while a valid genotype was loaded 146 count++; 147 totalsize += loaded->genotype.length(); 148 // create a Geno object based on the MiniGenotype 149 Geno *pNextGenotype = new Geno(loaded->genotype); 150 if ((pNextGenotype != NULL) && (pNextGenotype->isValid())) 151 { 152 pvGenos.push_back(pNextGenotype); 153 char *szNewName = new char[loaded->name.length() + 1]; 154 strcpy(szNewName, loaded->name.c_str()); 155 pvNames.push_back(szNewName); 156 } 157 else 158 { 159 printf("Genotype %2li is not valid\n", count); 160 if (pNextGenotype != NULL) delete pNextGenotype; 161 } 162 } 163 if (loader.getStatus() == GenotypeMiniLoader::OnError) 164 { 165 printf("Error: %s", loader.getError().c_str()); 166 } 167 168 double dSimilarity = 0.0; 169 double **aaSimil = NULL; // array of similarities 170 171 // create the empty array of similarities 172 aaSimil = new pDouble[pvGenos.size()]; 173 for (unsigned int k = 0; k < pvGenos.size(); k++) 174 { 175 aaSimil[k] = new double[pvGenos.size()]; 176 for (unsigned int l = 0; l < pvGenos.size(); l++) 177 aaSimil[k][l] = 0.0; 178 } 179 180 181 182 // compute and remember similarities 183 for (unsigned int i = 0; i < pvGenos.size(); i++) 184 { 185 for (unsigned int j = 0; j < pvGenos.size(); j++) 186 { 187 dSimilarity = simil_measure->evaluateDistance(pvGenos.operator[](i), pvGenos.operator[](j)); 188 aaSimil[i][j] = dSimilarity; 189 } 190 } 191 192 if (print_names) 193 { 194 // if "-names" switch was given, print the number of genotypes and their names 195 printf("%li\n", pvGenos.size()); 196 for (unsigned int iGen = 0; iGen < pvNames.size(); iGen++) 197 { 198 printf("%s\n", pvNames.at(iGen)); 199 } 200 } 201 202 // print out the matrix of similarities 203 for (unsigned int i = 0; i < pvGenos.size(); i++) 204 { 205 for (unsigned int j = 0; j < pvGenos.size(); j++) 206 { 207 printf("%.2lf\t", aaSimil[i][j]); 208 } 209 printf("\n"); 210 } 211 212 // delete vectors and arrays 213 for (unsigned int i = 0; i < pvGenos.size(); i++) 214 { 215 delete pvGenos.operator[](i); 216 delete[] pvNames.operator[](i); 217 delete[] aaSimil[i]; 218 } 219 220 delete[] aaSimil; 221 delete simil_measure; 222 223 return 0; 223 224 } -
cpp/frams/_demos/simil_unittests.cpp
r351 r1044 3 3 // See LICENSE.txt for details. 4 4 5 #include "frams/model/similarity/simil _match.h"5 #include "frams/model/similarity/simil-match.h" 6 6 7 7 /** Runs unit tests of classes used in computation of similarity. … … 42 42 for (i = 0; i < nSize1; i++) 43 43 { 44 assert(match1. IsMatched(j, i) == false);44 assert(match1.isMatched(j, i) == false); 45 45 } 46 46 } 47 47 48 48 // test if all are unmatched - new method 49 assert(match1. IsEmpty() == true);49 assert(match1.isEmpty() == true); 50 50 51 51 // check assymetric matching … … 55 55 for (i = 0; i < nSize1; i++) 56 56 { 57 assert(match2. IsMatched(0, i) == false);57 assert(match2.isMatched(0, i) == false); 58 58 } 59 59 // check if all elements are unmatched yet in object 1 60 60 for (i = 0; i < nSize2; i++) 61 61 { 62 assert(match2. IsMatched(1, i) == false);62 assert(match2.isMatched(1, i) == false); 63 63 } 64 64 65 65 // test if all are unmatched - new method 66 assert(match2. IsEmpty() == true);66 assert(match2.isEmpty() == true); 67 67 68 68 return 0; … … 89 89 90 90 // check size of both objects 91 assert(pMatching-> GetObjectSize(0) == i);92 assert(pMatching-> GetObjectSize(1) == j);91 assert(pMatching->getObjectSize(0) == i); 92 assert(pMatching->getObjectSize(1) == j); 93 93 94 94 // delete disused object … … 114 114 SimilMatching Source(iSize, iSize); 115 115 // check if it is empty 116 assert(Source. IsEmpty() == true);116 assert(Source.isEmpty() == true); 117 117 // check sizes of objects 118 assert(Source. GetObjectSize(0) == iSize);119 assert(Source. GetObjectSize(1) == iSize);118 assert(Source.getObjectSize(0) == iSize); 119 assert(Source.getObjectSize(1) == iSize); 120 120 // create a copy of this matching 121 121 SimilMatching Dest(Source); 122 122 // check the copy: 123 123 // - sizes of matched object 124 assert(Dest. GetObjectSize(0) == Source.GetObjectSize(0));125 assert(Dest. GetObjectSize(1) == Source.GetObjectSize(1));124 assert(Dest.getObjectSize(0) == Source.getObjectSize(0)); 125 assert(Dest.getObjectSize(1) == Source.getObjectSize(1)); 126 126 // - the copy should be empty, too 127 assert(Dest. IsEmpty() == true);127 assert(Dest.isEmpty() == true); 128 128 // make it empty once again 129 Dest. Empty();129 Dest.empty(); 130 130 // and check once more 131 assert(Dest. IsEmpty() == true);131 assert(Dest.isEmpty() == true); 132 132 } 133 133 … … 136 136 SimilMatching Source(iSize, iSize); 137 137 // check if it is empty 138 assert(Source. IsEmpty() == true);138 assert(Source.isEmpty() == true); 139 139 // check sizes of objects 140 assert(Source. GetObjectSize(0) == iSize);141 assert(Source. GetObjectSize(1) == iSize);140 assert(Source.getObjectSize(0) == iSize); 141 assert(Source.getObjectSize(1) == iSize); 142 142 // match objects (iObj, iObj) 143 143 for (iObj = 0; iObj < iSize; iObj++) 144 144 { 145 Source. Match(0, iObj, 1, iObj);145 Source.match(0, iObj, 1, iObj); 146 146 } 147 147 // check if the matching is full 148 assert(Source. IsFull() == true);148 assert(Source.isFull() == true); 149 149 // now create a copy of the matching 150 150 SimilMatching Dest(Source); 151 151 // check the copy 152 152 // - sizes of matched object 153 assert(Dest. GetObjectSize(0) == Source.GetObjectSize(0));154 assert(Dest. GetObjectSize(1) == Source.GetObjectSize(1));153 assert(Dest.getObjectSize(0) == Source.getObjectSize(0)); 154 assert(Dest.getObjectSize(1) == Source.getObjectSize(1)); 155 155 // - the copy should be full, too 156 assert(Dest. IsFull() == true);156 assert(Dest.isFull() == true); 157 157 // - the copy should have exactly the same assignments in matching 158 158 for (iObj = 0; iObj < iSize; iObj++) … … 160 160 // all object should be matched! 161 161 // check both directions: 0 -> 1 162 assert(Dest. IsMatched(0, iObj) == true);163 assert(iObj == Dest. GetMatchedIndex(0, iObj));162 assert(Dest.isMatched(0, iObj) == true); 163 assert(iObj == Dest.getMatchedIndex(0, iObj)); 164 164 // and: 1 -> 0 165 assert(Dest. IsMatched(1, iObj) == true);166 assert(iObj == Dest. GetMatchedIndex(1, iObj));165 assert(Dest.isMatched(1, iObj) == true); 166 assert(iObj == Dest.getMatchedIndex(1, iObj)); 167 167 } 168 168 // make it empty 169 Dest. Empty();169 Dest.empty(); 170 170 // and check once more 171 assert(Dest. IsEmpty() == true);171 assert(Dest.isEmpty() == true); 172 172 } 173 173 … … 176 176 SimilMatching Source(iSize, iSize); 177 177 // check if it is empty 178 assert(Source. IsEmpty() == true);178 assert(Source.isEmpty() == true); 179 179 // check sizes of objects 180 assert(Source. GetObjectSize(0) == iSize);181 assert(Source. GetObjectSize(1) == iSize);180 assert(Source.getObjectSize(0) == iSize); 181 assert(Source.getObjectSize(1) == iSize); 182 182 // match objects (iObj, N - iObj - 1) 183 183 for (iObj = 0; iObj < iSize; iObj++) 184 184 { 185 Source. Match(0, iObj, 1, iSize - iObj - 1);185 Source.match(0, iObj, 1, iSize - iObj - 1); 186 186 } 187 187 // check if the matching is full 188 assert(Source. IsFull() == true);188 assert(Source.isFull() == true); 189 189 // now create a copy of the matching 190 190 SimilMatching Dest(Source); 191 191 // check the copy 192 192 // - sizes of matched object 193 assert(Dest. GetObjectSize(0) == Source.GetObjectSize(0));194 assert(Dest. GetObjectSize(1) == Source.GetObjectSize(1));193 assert(Dest.getObjectSize(0) == Source.getObjectSize(0)); 194 assert(Dest.getObjectSize(1) == Source.getObjectSize(1)); 195 195 // - the copy should be full, too 196 assert(Dest. IsFull() == true);196 assert(Dest.isFull() == true); 197 197 // - the copy should have exactly the same assignments in matching 198 198 for (iObj = 0; iObj < iSize; iObj++) … … 200 200 // all object should be matched! 201 201 // check both directions: 0 -> 1 202 assert(Dest. IsMatched(0, iObj) == true);203 assert((iSize - iObj - 1) == Dest. GetMatchedIndex(0, iObj));202 assert(Dest.isMatched(0, iObj) == true); 203 assert((iSize - iObj - 1) == Dest.getMatchedIndex(0, iObj)); 204 204 // and: 1 -> 0 205 assert(Dest. IsMatched(1, iObj) == true);206 assert((iSize - iObj - 1) == Dest. GetMatchedIndex(1, iObj));205 assert(Dest.isMatched(1, iObj) == true); 206 assert((iSize - iObj - 1) == Dest.getMatchedIndex(1, iObj)); 207 207 } 208 208 // make it empty 209 Dest. Empty();209 Dest.empty(); 210 210 // and check once more 211 assert(Dest. IsEmpty() == true);211 assert(Dest.isEmpty() == true); 212 212 } 213 213 … … 216 216 SimilMatching Source(iSize, 2 * iSize); 217 217 // check if it is empty 218 assert(Source. IsEmpty() == true);218 assert(Source.isEmpty() == true); 219 219 // check sizes of objects 220 assert(Source. GetObjectSize(0) == iSize);221 assert(Source. GetObjectSize(1) == 2 * iSize);220 assert(Source.getObjectSize(0) == iSize); 221 assert(Source.getObjectSize(1) == 2 * iSize); 222 222 // match objects (iObj, 2 * iObj) 223 223 for (iObj = 0; iObj < iSize; iObj++) 224 224 { 225 Source. Match(0, iObj, 1, 2 * iObj);225 Source.match(0, iObj, 1, 2 * iObj); 226 226 } 227 227 // check if the matching is full (should be, as the smaller set is completely matched 228 assert(Source. IsFull() == true);228 assert(Source.isFull() == true); 229 229 // now create a copy of the matching 230 230 SimilMatching Dest(Source); 231 231 // check the copy 232 232 // - sizes of matched object 233 assert(Dest. GetObjectSize(0) == Source.GetObjectSize(0));234 assert(Dest. GetObjectSize(1) == Source.GetObjectSize(1));233 assert(Dest.getObjectSize(0) == Source.getObjectSize(0)); 234 assert(Dest.getObjectSize(1) == Source.getObjectSize(1)); 235 235 // - the copy should be full, too 236 assert(Dest. IsFull() == true);236 assert(Dest.isFull() == true); 237 237 // - the copy should have exactly the same assignments in matching 238 238 for (iObj = 0; iObj < iSize; iObj++) … … 240 240 // check both directions: 0 -> 1 241 241 // (all matched, (iObj, 2 * iObj)) 242 assert(Dest. IsMatched(0, iObj) == true);243 assert((2 * iObj) == Dest. GetMatchedIndex(0, iObj));242 assert(Dest.isMatched(0, iObj) == true); 243 assert((2 * iObj) == Dest.getMatchedIndex(0, iObj)); 244 244 // and direction; 1 -> 0 245 245 // (only even are matched, ( 2 * iObj, iObj)) 246 246 // for 2 * iObj (which are even): matched 247 assert(Dest. IsMatched(1, 2 * iObj) == true);248 assert(iObj == Dest. GetMatchedIndex(1, 2 * iObj));247 assert(Dest.isMatched(1, 2 * iObj) == true); 248 assert(iObj == Dest.getMatchedIndex(1, 2 * iObj)); 249 249 // for 2 * iObj + 1 (which are odd): unmatched 250 assert(Dest. IsMatched(1, 2 * iObj + 1) == false);250 assert(Dest.isMatched(1, 2 * iObj + 1) == false); 251 251 } 252 252 // make it empty 253 Dest. Empty();253 Dest.empty(); 254 254 // and check once more 255 assert(Dest. IsEmpty() == true);255 assert(Dest.isEmpty() == true); 256 256 } 257 257 … … 273 273 274 274 // matching is empty 275 assert(match1. IsEmpty() == true);275 assert(match1.isEmpty() == true); 276 276 277 277 // create matching - (i,i) … … 280 280 281 281 // matching is not full 282 assert(match1. IsFull() == false);282 assert(match1.isFull() == false); 283 283 284 284 // these are not matched yet 285 assert(match1. IsMatched(0, i) == false);286 assert(match1. IsMatched(1, i) == false);285 assert(match1.isMatched(0, i) == false); 286 assert(match1.isMatched(1, i) == false); 287 287 288 288 // now - match! 289 match1. Match(0, i, 1, i);289 match1.match(0, i, 1, i); 290 290 291 291 // matching is not empty 292 assert(match1. IsEmpty() == false);292 assert(match1.isEmpty() == false); 293 293 294 294 // now they are matched 295 assert(match1. IsMatched(0, i) == true);296 assert(match1. IsMatched(1, i) == true);295 assert(match1.isMatched(0, i) == true); 296 assert(match1.isMatched(1, i) == true); 297 297 298 298 // check the matched index for object 0 and 1 299 assert(match1. GetMatchedIndex(0, i) == i);300 assert(match1. GetMatchedIndex(1, i) == i);299 assert(match1.getMatchedIndex(0, i) == i); 300 assert(match1.getMatchedIndex(1, i) == i); 301 301 } 302 302 303 303 // now matching have to be full 304 assert(match1. IsFull() == true);304 assert(match1.isFull() == true); 305 305 306 306 // check some symmetric matching … … 308 308 309 309 // matching is empty 310 assert(match2. IsEmpty() == true);310 assert(match2.isEmpty() == true); 311 311 312 312 // create matching - (i, nSize1 - 1 - i) … … 315 315 316 316 // matching is not full 317 assert(match2. IsFull() == false);317 assert(match2.isFull() == false); 318 318 319 319 // these are not matched yet 320 assert(match2. IsMatched(0, i) == false);321 assert(match2. IsMatched(1, nSize1 - 1 - i) == false);320 assert(match2.isMatched(0, i) == false); 321 assert(match2.isMatched(1, nSize1 - 1 - i) == false); 322 322 323 323 // now - match (but use the opposite syntax)! 324 match2. Match(1, nSize1 - 1 - i, 0, i);324 match2.match(1, nSize1 - 1 - i, 0, i); 325 325 326 326 // matching is not empty 327 assert(match2. IsEmpty() == false);327 assert(match2.isEmpty() == false); 328 328 329 329 // now they are matched 330 assert(match2. IsMatched(0, i) == true);331 assert(match2. IsMatched(1, nSize1 - 1 - i) == true);330 assert(match2.isMatched(0, i) == true); 331 assert(match2.isMatched(1, nSize1 - 1 - i) == true); 332 332 333 333 // check the matched index for object 0 and 1 334 assert(match2. GetMatchedIndex(0, i) == (nSize1 - 1 - i));335 assert(match2. GetMatchedIndex(1, nSize1 - 1 - i) == i);334 assert(match2.getMatchedIndex(0, i) == (nSize1 - 1 - i)); 335 assert(match2.getMatchedIndex(1, nSize1 - 1 - i) == i); 336 336 } 337 337 338 338 // now matching have to be full 339 assert(match2. IsFull() == true);339 assert(match2.isFull() == true); 340 340 341 341 // check some asymmnetic matching, too … … 343 343 344 344 // matching is empty 345 assert(match3. IsEmpty() == true);345 assert(match3.isEmpty() == true); 346 346 347 347 // create matching - (i, 2 * i) … … 350 350 351 351 // matching is not full 352 assert(match3. IsFull() == false);352 assert(match3.isFull() == false); 353 353 354 354 // these are not matched yet 355 assert(match3. IsMatched(0, i) == false);356 assert(match3. IsMatched(1, 2 * i) == false);355 assert(match3.isMatched(0, i) == false); 356 assert(match3.isMatched(1, 2 * i) == false); 357 357 358 358 // now - match (but use the opposite syntax)! 359 match3. Match(1, 2 * i, 0, i);359 match3.match(1, 2 * i, 0, i); 360 360 361 361 // matching is not empty 362 assert(match3. IsEmpty() == false);362 assert(match3.isEmpty() == false); 363 363 364 364 // now they are matched 365 assert(match3. IsMatched(0, i) == true);366 assert(match3. IsMatched(1, 2 * i) == true);365 assert(match3.isMatched(0, i) == true); 366 assert(match3.isMatched(1, 2 * i) == true); 367 367 368 368 // but the odd elements of object 1 are not matched 369 assert(match3. IsMatched(1, 2 * i + 1) == false);369 assert(match3.isMatched(1, 2 * i + 1) == false); 370 370 371 371 // check the matched index for object 0 and 1 372 assert(match3. GetMatchedIndex(0, i) == 2 * i);373 assert(match3. GetMatchedIndex(1, 2 * i) == i);372 assert(match3.getMatchedIndex(0, i) == 2 * i); 373 assert(match3.getMatchedIndex(1, 2 * i) == i); 374 374 } 375 375 376 376 // now matching have to be full (because the smallest object has all elements matched). 377 assert(match3. IsFull() == true);377 assert(match3.isFull() == true); 378 378 379 379 return 0; -
cpp/frams/model/similarity/simil-match.cpp
r1043 r1044 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 19Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 5 5 #include <assert.h> 6 6 #include <stdio.h> 7 #include "simil _match.h"7 #include "simil-match.h" 8 8 9 9 /** Creates an empty matching for two objects of specified size. … … 63 63 @return Size of the object (in elements). 64 64 */ 65 int SimilMatching:: GetObjectSize(int Obj)65 int SimilMatching::getObjectSize(int Obj) 66 66 { 67 67 // check parameter … … 81 81 82 82 */ 83 void SimilMatching:: Match(int Obj0, int Index0, int Obj1, int Index1)83 void SimilMatching::match(int Obj0, int Index0, int Obj1, int Index1) 84 84 { 85 85 // check parameters of object 0 … … 103 103 @return true if the given element is matched, false otherwise. 104 104 */ 105 bool SimilMatching:: IsMatched(int Obj, int Index)105 bool SimilMatching::isMatched(int Obj, int Index) 106 106 { 107 107 // check parameters … … 128 128 (check IsMatched() before using GetMatchedIndex()). 129 129 */ 130 int SimilMatching:: GetMatchedIndex(int Obj, int Index)130 int SimilMatching::getMatchedIndex(int Obj, int Index) 131 131 { 132 132 // check parameters … … 142 142 @return true if matching is full, false otherwise. 143 143 */ 144 bool SimilMatching:: IsFull()144 bool SimilMatching::isFull() 145 145 { 146 146 // assume that the matching is full … … 177 177 @return true if matching is empty, otherwise - false. 178 178 */ 179 bool SimilMatching:: IsEmpty()179 bool SimilMatching::isEmpty() 180 180 { 181 181 // result - assume that matching is empty … … 201 201 /** Makes the matching completely empty. After a call to this method IsEmpty() should return true. 202 202 */ 203 void SimilMatching:: Empty()203 void SimilMatching::empty() 204 204 { 205 205 for (int iObj = 0; iObj < 2; iObj++) // a counter of objects … … 215 215 216 216 // the exit condition 217 assert( IsEmpty() == true);217 assert(isEmpty() == true); 218 218 } 219 219 220 220 /** Prints the current state of the matching 221 221 */ 222 void SimilMatching:: PrintMatching()222 void SimilMatching::printMatching() 223 223 { 224 224 int nBigger; … … 249 249 for (unsigned int i = 0; i < m_apvMatched[nObj]->size(); i++) 250 250 { 251 if ( IsMatched(nObj, i))251 if (isMatched(nObj, i)) 252 252 { 253 253 // if the element is matched - print the index 254 printf("%2d ", GetMatchedIndex(nObj, i));254 printf("%2d ", getMatchedIndex(nObj, i)); 255 255 } 256 256 else -
cpp/frams/model/similarity/simil-match.h
r1043 r1044 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 19Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 26 26 SimilMatching(const SimilMatching &Source); 27 27 ~SimilMatching(); 28 int GetObjectSize(int Obj);29 void Match(int Obj0, int Index0, int Obj1, int Index1);30 bool IsMatched(int Obj, int Index);31 int GetMatchedIndex(int Obj, int index);32 bool IsFull();33 bool IsEmpty();34 void Empty();35 void PrintMatching();28 int getObjectSize(int Obj); 29 void match(int Obj0, int Index0, int Obj1, int Index1); 30 bool isMatched(int Obj, int Index); 31 int getMatchedIndex(int Obj, int index); 32 bool isFull(); 33 bool isEmpty(); 34 void empty(); 35 void printMatching(); 36 36 }; 37 37 -
cpp/tests/similarity-tests.txt
r984 r1044 11 11 TESTNAME:parts weight 12 12 arg:similarity.gen 13 arg: 013 arg:hungarian 14 14 arg:1 15 15 arg:0 … … 22 22 TESTNAME:degrees weight 23 23 arg:similarity.gen 24 arg: 024 arg:hungarian 25 25 arg:0 26 26 arg:1 … … 33 33 TESTNAME:neurons weight 34 34 arg:similarity.gen 35 arg: 035 arg:hungarian 36 36 arg:0 37 37 arg:0 … … 44 44 TESTNAME:distances weight greedy 45 45 arg:similarity.gen 46 arg: 146 arg:greedy 47 47 arg:0 48 48 arg:0 … … 55 55 TESTNAME:all weights greedy 56 56 arg:similarity.gen 57 arg: 157 arg:greedy 58 58 arg:1 59 59 arg:1 … … 66 66 TESTNAME:all weights fixed z greedy 67 67 arg:similarity.gen 68 arg: 168 arg:greedy 69 69 arg:1 70 70 arg:1 … … 77 77 TESTNAME:distances weight hungarian 78 78 arg:similarity.gen 79 arg: 079 arg:hungarian 80 80 arg:0 81 81 arg:0 … … 88 88 TESTNAME:all weights hungarian 89 89 arg:similarity.gen 90 arg: 090 arg:hungarian 91 91 arg:1 92 92 arg:1 … … 99 99 TESTNAME:all weights fixed z hungarian 100 100 arg:similarity.gen 101 arg: 0101 arg:hungarian 102 102 arg:1 103 103 arg:1 … … 107 107 out:*INSERTPLATFORMDEPENDENTFILE*:similarity_goals/all_weights_fixed_z_hungarian 108 108 RUNTEST 109 110 TESTNAME:distribution 111 arg:similarity.gen 112 arg:distribution 113 arg:5 114 arg:128 115 arg:100000 116 out:*INSERTPLATFORMDEPENDENTFILE*:similarity_goals/distribution 117 RUNTEST
Note: See TracChangeset
for help on using the changeset viewer.