source: cpp/frams/model/similarity/simil_model.h @ 601

Last change on this file since 601 was 601, checked in by oriona, 8 years ago

Possibility of fixing z axis during the alignment added.

  • Property svn:eol-style set to native
File size: 5.8 KB
Line 
1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
4
5
6#ifndef _SIMIL_MODEL_H_
7#define _SIMIL_MODEL_H_
8
9#include "frams/genetics/geno.h"
10#include "frams/model/model.h"
11#include "frams/util/3d.h"
12#include "simil_match.h"
13
14#define TDN_SIZE 5
15
16enum TDNELEMS
17{
18    ORIG_IND = 0,
19    DEGREE = 1,
20    NEURO_CONNS = 2,
21    NEURONS = 3,
22    FUZZ_DEG = 4
23};
24
25/** This class defines similarity measure for Framsticks organisms.
26 * Authors:
27 * Marek Kubiak (concept, implementation)
28 * Maciej Komosinski (concept, Framsticks interface)
29 * Agnieszka Mensfelt (refactoring)
30 */
31class ModelSimil
32{
33public:
34    ModelSimil();
35    virtual ~ModelSimil();
36    double EvaluateDistance(const Geno *G0, const Geno *G1);
37
38    static int CompareDegrees(const void *pElem1, const void *pElem2);
39    static int CompareConnsNo(const void *pElem1, const void *pElem2);
40    static int GetNOFactors();
41#define STATRICKCLASS ModelSimil
42    PARAMPROCDEF(p_evaldistance);
43#undef STATRICKCLASS
44
45protected:
46    void _PrintSeamnessTable(std::vector<int> *pVector, int iCount);
47    //matching function
48    int MatchPartsGeometry();
49    void ComputeMatching();
50    void _PrintPartsMatching();
51    void SaveIntermediateFiles();
52
53    static int CheckPartsIdentity(Part *P1, Part *P2);
54    int SortPartInfoTables();
55    int CountPartNeurons();
56    bool ComputePartsPositionsBySVD();
57    int GetPartPositions();
58    int CountPartDegrees();
59
60    int SortPartInfoFuzzy();
61    void CountFuzzyNeighb();
62    void SortFuzzyNeighb();
63    void GetNeighbIndexes(int mod, int partInd, std::vector<int> &indexes);
64    void CheckFuzzyIdentity();
65
66    int CreatePartInfoTables();
67    void _PrintDegrees(int i);
68    void _PrintArray(int *array, int base, int size);
69    void _PrintNeighbourhood(int i);
70    void _PrintArrayDouble(double *array, int base, int size);
71    int CountPartsDistance();
72
73
74public:
75    /// Table of weights for weighted distance function.
76    /// Weights are for factors in the following order:
77    /// [0]: m_iDV (difference in the number of vertices)
78    /// [1]: m_iDD (difference in degrees over matching)
79    /// [2]: m_iDN (difference in neurons over matching)
80    /// [3]: m_dDG (difference in geometry over matching)
81    /// @sa EvaluateDistance
82    double m_adFactors[4];
83
84    //Controls the depth of fuzzy neighbourhood
85    int fuzzyDepth;
86    int isFuzzy;
87    //for Zfixed = 1 z coordinates are not taken into account during PCA alignment
88    int zFixed;
89
90    /// Interface to local parameters
91    Param localpar;
92
93protected:
94
95    /// Between these genotypes distance is evaluated.
96    const Geno *m_Gen[2];
97
98    /// These models will be created to get the information about creatures
99    /// from their genotypes.
100    Model *m_Mod[2];
101
102    /// Index (0 or 1) of the smaler creature (in the meaning of parts).
103    /// Index of the bigger one is (1-m_iSmaller).
104    int m_iSmaller;
105
106    /// Number of parts of two creatures (index the same as for m_Mod).
107    int m_aiPartCount[2];
108
109    /// Difference between number of parts in organisms
110    int m_iDV;
111
112    /// Sum of absolute values of differences between matched part degrees
113    int m_iDD;
114
115    /// Sum of absolute values of differences between matched part
116    /// in neurons number.
117    int m_iDN;
118    //2 matrices of neighbourhood of parts - one for each genotype
119
120    /// Sum of Euclidean distances between matched parts
121    /// Unmatched Parts have the distance measured to (0,0,0) (the middle of
122    /// an organism)
123    double m_dDG;
124
125    /// Object that holds the matching of Parts.
126    // It is not clear now whether the matching function is
127    // created for orginal indices of Parts, or for sorted Parts
128    // Most probably it is for sorted Parts.
129    SimilMatching *m_pMatching;
130
131    /// Type of 4 ints - describing one Part of the creature in
132    /// its sorted table of degrees
133    /// TDN[0] - original index of creature's Part (that is "i" from GetPart(i))
134    /// TDN[1] - degree (number of adjacent joints) of one Part
135    /// TDN[2] - number of NeuroConnections and Neurons belonging to one Part
136    /// TDN[3] - number of Neurons of the Part
137    /// TDN[4] - fuzzy degree
138    typedef int TDN[5];
139
140    /** 2 arrays holding information about compared organisms (one for each
141    creature) of degree and neuro info for Parts.
142    Index corresponds to the one in m_Mod
143    m_aDegrees[i][j] is a TDN of the j-th Part of the i-th creature in m_Mod
144     */
145    TDN *m_aDegrees[2];
146
147    //std::pair<TDN, double> *m_aDegrees[2];
148    /// Holds information on all on-joint neurons. Only TDN[3] and TDN[4]
149    /// are important (original index and degree are not important).
150    TDN m_aOnJoint[2];
151
152    /// Holds information on all neurons that are not placed neither on
153    /// a joint nor on a part. Only TDN[3] and TDN[4]
154    /// are important (original index and degree are not important).
155    TDN m_aAnywhere[2];
156
157    //array of parts neighbourhood
158    int **m_Neighbours[2];
159    //array of "fuzzy neigbourhood" for each of organisms. Dimensions: parts_num x fuzzyDepth
160    float **m_fuzzyNeighb[2];
161
162    /// Two arrays of points which hold information about positions of Parts
163    /// of both of the compared organisms.
164    /// Matching methods which do not use geometry (MatchPartsOld
165    /// and MatchPartsNew) simply copy these positions from models. The only
166    /// matching method which uses geometry (MatchPartsNewGeometry) makes
167    /// use of these arrays extensively.
168    /// At m_aPositions[ iModel ][ iOriginalPart ] there is a Pt3D of
169    /// a Part with index iOriginalPart of the model iModel.
170    /// iOriginalPart means that this index is the original index of a Part,
171    /// (before sorting).
172    Pt3D *m_aPositions[2];
173
174    /// Number of weights in the function which evaluates distance.
175    static const int iNOFactors;
176
177};
178
179
180#endif
Note: See TracBrowser for help on using the repository browser.