source: cpp/frams/model/similarity/measure-greedy.h @ 1044

Last change on this file since 1044 was 1044, checked in by oriona, 4 years ago

Similarity measures code refactored. Distribution-based similarity measure added.

File size: 4.2 KB
Line 
1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
4
5#ifndef _GREEDY_MEASURE_H
6#define _GREEDY_MEASURE_H
7
8#include "measure-mds-based.h"
9#include "frams/genetics/geno.h"
10#include "frams/model/model.h"
11#include "simil-match.h"
12#include "measure-greedy.h"
13
14#define TDN_SIZE 5
15
16
17enum TDNELEMS2
18{
19        ORG_IND = 0,
20        DEG = 1,
21        NEUR_CONNS = 2,
22        NEUROS = 3,
23        FUZ_DEG = 4
24};
25
26class SimilMeasureGreedy : public SimilMeasureMDSBased
27{
28public:
29        SimilMeasureGreedy();
30        ~SimilMeasureGreedy(){};
31
32        static int compareDegrees(const void *pElem1, const void *pElem2);
33        static int compareFuzzyDegrees(const void *pElem1, const void *pElem2);
34        static int compareConnsNo(const void *pElem1, const void *pElem2);
35        static int getNOFactors();
36        int setParams(std::vector<double> params);
37        /// Interface to local parameters
38        Param localpar;
39        /// Table of weights for weighted distance function.
40        /// Weights are for factors in the following order:
41        /// [0]: m_iDV (difference in the number of vertices)
42        /// [1]: m_iDD (difference in degrees over matching)
43        /// [2]: m_iDN (difference in neurons over matching)
44        /// [3]: m_dDG (difference in geometry over matching)
45        /// @sa EvaluateDistance
46        double m_adFactors[4];
47
48        //Controls the depth of fuzzy neighbourhood
49        int fuzzyDepth;
50        bool isFuzzy;
51
52protected:
53        double distanceForTransformation();
54        double distanceWithoutAlignment();
55        void prepareData();
56        void beforeTransformation();
57        void computeMatching();
58        void copyMatching();
59        void cleanData();
60
61        int sortPartInfoTables();
62        int countPartNeurons();
63        int countPartDegrees();
64        int countPartsDistance();
65
66        void countFuzzyNeighb();
67        void sortFuzzyNeighb();
68        void getNeighbIndexes(int mod, int partInd, std::vector<int> &indexes);
69        void fuzzyOrder();
70        int createPartInfoTables();
71       
72        void _PrintArray(int *array, int base, int size);
73        void _PrintArrayDouble(double *array, int base, int size);
74        void _PrintDegrees(int i);
75        void _PrintNeighbourhood(int i);
76        void _PrintFuzzyNeighbourhood(int i);
77        void _PrintSeamnessTable(std::vector<int> *pVector, int iCount);
78        void _PrintPartsMatching();
79        void saveIntermediateFiles();
80
81        /// Number of parts of two creatures (index the same as for m_Mod).
82        int m_aiPartCount[2];
83
84        /// Difference between number of parts in organisms
85        int m_iDV;
86
87        /// Sum of absolute values of differences between matched part degrees
88        int m_iDD;
89
90        /// Sum of absolute values of differences between matched part
91        /// in neurons number.
92        int m_iDN;
93        //2 matrices of neighbourhood of parts - one for each genotype
94
95        /// Sum of Euclidean distances between matched parts
96        /// Unmatched Parts have the distance measured to (0,0,0) (the middle of
97        /// an organism)
98        double m_dDG;
99
100        /// Object that holds the matching of Parts.
101        SimilMatching *m_pMatching;
102        /// Object that holds temporary matching of Parts.
103        SimilMatching *tempMatching;
104
105        /// Type of 4 ints - describing one Part of the creature in
106        /// its sorted table of degrees
107        /// TDN[0] - original index of creature's Part (that is "i" from GetPart(i))
108        /// TDN[1] - degree (number of adjacent joints) of one Part
109        /// TDN[2] - number of NeuroConnections and Neurons belonging to one Part
110        /// TDN[3] - number of Neurons of the Part
111        /// TDN[4] - fuzzy degree
112        typedef int TDN[5];
113
114        /** 2 arrays holding information about compared organisms (one for each
115        creature) of degree and neuro info for Parts.
116        Index corresponds to the one in m_Mod
117        m_aDegrees[i][j] is a TDN of the j-th Part of the i-th creature in m_Mod
118        */
119        TDN *m_aDegrees[2];
120
121        //std::pair<TDN, double> *m_aDegrees[2];
122        /// Holds information on all on-joint neurons. Only TDN[3] and TDN[4]
123        /// are important (original index and degree are not important).
124        TDN m_aOnJoint[2];
125
126        /// Holds information on all neurons that are not placed neither on
127        /// a joint nor on a part. Only TDN[3] and TDN[4]
128        /// are important (original index and degree are not important).
129        TDN m_aAnywhere[2];
130
131        //array of parts neighbourhood
132        int **m_Neighbours[2];
133        //array of "fuzzy neigbourhood" for each of organisms. Dimensions: parts_num x fuzzyDepth
134        float **m_fuzzyNeighb[2];
135
136        /// Number of weights in the function which evaluates distance.
137        static const int iNOFactors;
138};
139
140#endif /* GREEDY_MEASURE_H */
141
Note: See TracBrowser for help on using the repository browser.