Structural deformable models
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
ExpectationMap Class Reference

#include <ExpMap.h>

Inheritance diagram for ExpectationMap:
Inheritance graph
[legend]
Collaboration diagram for ExpectationMap:
Collaboration graph
[legend]

Public Types

typedef std::map< dword, EMDistribution * > EDistributions
 
- Public Types inherited from EMDistribution
enum  EDFlags { ED_NONE =0, ED_OLD =1 }
 

Public Member Functions

 ExpectationMap ()
 
 ExpectationMap (const Model &model)
 
 ExpectationMap (const ExpectationMap &rhs)
 
virtual ~ExpectationMap ()
 
ExpectationMapoperator= (const ExpectationMap &rhs)
 
virtual EMDistributioncopy () const
 
float ratePropVec (const PropVec &prop, Winner *winner=NULL) const
 
void setRepresentative (const Model &model)
 
ModelgetRepresentative ()
 
void add (EMDistribution *ed)
 
void add (EMDistribution *ed, dword wid)
 
void add (const EDistributions &distlist)
 
bool erase (dword wid)
 
bool hasDist (dword wid) const
 
EMDistributiongetEDist (dword wid)
 
const EMDistributiongetEDist (dword wid) const
 
EDistributionsgetDistList ()
 
virtual PropVec getPropVec () const
 
ModelgenerateInstance () const
 
float updateIntegral ()
 
void clear (bool oldonly=false)
 
void markAllOld ()
 
dword getShootCount (dword wid) const
 
 operator bool () const
 
- Public Member Functions inherited from EMDRect
 EMDRect (const PropVec &lb=PropVec(0.f), const PropVec &ub=PropVec(1.f))
 
virtual ~EMDRect ()
 
PropVecclamp (PropVec &v)
 
const PropVecgetUB () const
 
const PropVecgetLB () const
 
void setUB (const PropVec &ub)
 
void setLB (const PropVec &lb)
 
- Public Member Functions inherited from EMDistribution
 EMDistribution ()
 
virtual ~EMDistribution ()
 
virtual void setIntegral (float integral)
 
void setCreator (const Winner &creator)
 
void setShootCount (dword scount)
 
dword getShootCount () const
 
bool hasFlags (dword flags) const
 
void setFlags (dword flags)
 
void unsetFlags (dword flags=0xffffffff)
 

Static Public Member Functions

static void correctLBUB (PropVec &lb, PropVec &ub)
 

Protected Attributes

Model m_Representative
 
EDistributions m_Distributions
 
std::map< float, EMDistribution * > m_SortDist
 

Additional Inherited Members

- Public Attributes inherited from EMDRect
PropVec m_LB
 
PropVec m_UB
 
- Public Attributes inherited from EMDistribution
float m_Integral
 
Winner m_Creator
 
dword m_ShootCount
 
dword m_Flags
 

Detailed Description

Definition at line 142 of file ExpMap.h.

Member Typedef Documentation

Definition at line 144 of file ExpMap.h.

Constructor & Destructor Documentation

ExpectationMap::ExpectationMap ( )
inline

Definition at line 146 of file ExpMap.h.

Referenced by copy().

146 {}
ExpectationMap::ExpectationMap ( const Model model)
inline

Definition at line 147 of file ExpMap.h.

148  { setRepresentative(model); }
void setRepresentative(const Model &model)
Definition: ExpMap.cpp:18
ExpectationMap::ExpectationMap ( const ExpectationMap rhs)
inline

Definition at line 149 of file ExpMap.h.

149  {
150  operator=(rhs); }
ExpectationMap & operator=(const ExpectationMap &rhs)
Definition: ExpMap.cpp:4
virtual ExpectationMap::~ExpectationMap ( )
inlinevirtual

Definition at line 151 of file ExpMap.h.

References NULL.

151 { clear(); }
void clear(bool oldonly=false)
Definition: ExpMap.cpp:141

Member Function Documentation

void ExpectationMap::add ( EMDistribution ed)

Definition at line 23 of file ExpMap.cpp.

References EMDistribution::m_Creator, m_Distributions, Winner::m_WinnerID, Winner::WID_EMPTY, and Winner::WID_FIRSTFREE.

Referenced by add(), MStructure::addExpectation(), main(), operator=(), MStructure::rebuildExpMap(), and Brain::setupSearch().

24 {
25  if(!ed) return;
26  dword wid = ed->m_Creator.m_WinnerID;
27  if(wid == Winner::WID_EMPTY) {
28  if(!m_Distributions.empty()) wid = m_Distributions.rbegin()->first+1;
30  }
31  add(ed,wid);
32 }
EDistributions m_Distributions
Definition: ExpMap.h:176
void add(EMDistribution *ed)
Definition: ExpMap.cpp:23
unsigned long dword
Definition: simpletypes.h:6
dword m_WinnerID
Definition: ExpMap.h:37
Winner m_Creator
Definition: ExpMap.h:68
void ExpectationMap::add ( EMDistribution ed,
dword  wid 
)

Definition at line 34 of file ExpMap.cpp.

References erase(), m_Distributions, and updateIntegral().

35 {
36  if(!ed) return;
37  erase(wid);
38  m_Distributions[wid] = ed;
40 }
EDistributions m_Distributions
Definition: ExpMap.h:176
bool erase(dword wid)
Definition: ExpMap.cpp:51
float updateIntegral()
Definition: ExpMap.cpp:167
void ExpectationMap::add ( const EDistributions distlist)

Definition at line 42 of file ExpMap.cpp.

References add().

43 {
44  for(EDistributions::const_iterator dl=distlist.begin();
45  dl != distlist.end(); dl++)
46  {
47  add(dl->second->copy());
48  }
49 }
void add(EMDistribution *ed)
Definition: ExpMap.cpp:23
void ExpectationMap::clear ( bool  oldonly = false)

Definition at line 141 of file ExpMap.cpp.

References EMDistribution::ED_OLD, m_Distributions, and updateIntegral().

Referenced by Searcher::clear(), operator=(), and MStructure::rebuildExpMap().

142 {
143  EDistributions::iterator dl=m_Distributions.begin();
144  while(dl != m_Distributions.end())
145  {
146  EDistributions::iterator cd = dl++;
147  if(cd->second)
148  {
149  if(!oldonly || cd->second->hasFlags(EMDistribution::ED_OLD)) {
150  delete cd->second;
151  if(oldonly) m_Distributions.erase(cd);
152  }
153  } else if(oldonly) m_Distributions.erase(cd);
154  }
155  if(!oldonly) m_Distributions.clear();
156  if(oldonly) updateIntegral();
157 }
EDistributions m_Distributions
Definition: ExpMap.h:176
float updateIntegral()
Definition: ExpMap.cpp:167
EMDistribution * ExpectationMap::copy ( ) const
virtual

Reimplemented from EMDRect.

Definition at line 13 of file ExpMap.cpp.

References ExpectationMap().

14 {
15  return (EMDistribution*) new ExpectationMap(*this);
16 }
ExpectationMap()
Definition: ExpMap.h:146
void ExpectationMap::correctLBUB ( PropVec lb,
PropVec ub 
)
static

Definition at line 193 of file ExpMap.cpp.

References VVector< T, D >::clampLB(), VVector< T, D >::clampUB(), getPropDir(), getPropScale(), M_PI, mapAngle2PI(), MIN_SCALE, setPropDir(), and setPropScale().

Referenced by MStructure::addExpectation(), SubStructure::generateEMDist(), MStructure::rebuildExpMap(), Searcher::setExpectationMap(), and Brain::setupSearch().

194 {
195  float la = mapAngle2PI(getPropDir(lb));
196  float ua = mapAngle2PI(getPropDir(ub), la);
197  if(ua-la < 0.00001) ua += 2*M_PI;
198  setPropDir(lb, la); setPropDir(ub, ua);
199  PropVec cub(ub); ub.clampLB(lb); lb.clampUB(cub); //conditional swap
200  float ls = getPropScale(lb);
201  if(ls < MIN_SCALE) setPropScale(lb, MIN_SCALE);
202 }
float getPropScale(const PropVec &prop)
Definition: PropVec.h:19
float mapAngle2PI(float a)
Definition: mathutil.h:97
PropVec & setPropDir(PropVec &prop, float dir)
Definition: PropVec.h:28
VT & clampUB(const VT &ub)
Definition: VVector.h:247
float getPropDir(const PropVec &prop)
Definition: PropVec.h:25
#define M_PI
Definition: mathutil.h:9
VT & clampLB(const VT &lb)
Definition: VVector.h:241
#define MIN_SCALE
Definition: ExpMap.cpp:192
PropVec & setPropScale(PropVec &prop, float pscale)
Definition: PropVec.h:22
bool ExpectationMap::erase ( dword  wid)

Definition at line 51 of file ExpMap.cpp.

References m_Distributions.

Referenced by add().

52 {
53  EDistributions::iterator ed = m_Distributions.find(wid);
54  if(ed == m_Distributions.end()) return false;
55  if(ed->second) delete ed->second;
56  m_Distributions.erase(ed);
57  return true;
58 }
EDistributions m_Distributions
Definition: ExpMap.h:176
Model * ExpectationMap::generateInstance ( ) const

Definition at line 184 of file ExpMap.cpp.

References Model::adaptProperties(), getPropVec(), and m_Representative.

Referenced by Searcher::distribute(), Searcher::evolve(), and main().

185 {
186  Model *model = new Model(m_Representative);
187  PropVec v = getPropVec();
188  model->adaptProperties(v);
189  return model;
190 }
Model m_Representative
Definition: ExpMap.h:175
Definition: Model.h:33
void adaptProperties(const PropVec &prop)
Definition: Model.cpp:1249
virtual PropVec getPropVec() const
Definition: ExpMap.cpp:86
EDistributions& ExpectationMap::getDistList ( )
inline

Definition at line 164 of file ExpMap.h.

164 { return m_Distributions; }
EDistributions m_Distributions
Definition: ExpMap.h:176
EMDistribution * ExpectationMap::getEDist ( dword  wid)

Definition at line 65 of file ExpMap.cpp.

References m_Distributions, and NULL.

Referenced by MStructure::addExpectation(), and getShootCount().

66 {
67  EDistributions::iterator ed = m_Distributions.find(wid);
68  if(ed == m_Distributions.end()) return NULL;
69  else return ed->second;
70 }
#define NULL
Definition: simpletypes.h:9
EDistributions m_Distributions
Definition: ExpMap.h:176
const EMDistribution * ExpectationMap::getEDist ( dword  wid) const

Definition at line 72 of file ExpMap.cpp.

References m_Distributions, and NULL.

73 {
74  EDistributions::const_iterator ed = m_Distributions.find(wid);
75  if(ed == m_Distributions.end()) return NULL;
76  else return ed->second;
77 }
#define NULL
Definition: simpletypes.h:9
EDistributions m_Distributions
Definition: ExpMap.h:176
PropVec ExpectationMap::getPropVec ( ) const
virtual

Reimplemented from EMDRect.

Definition at line 86 of file ExpMap.cpp.

References VVector< T, D >::clamp(), frand, getIdentityPropTF(), getPropDir(), m_Distributions, EMDistribution::m_Integral, EMDRect::m_LB, m_SortDist, EMDRect::m_UB, mapAngle2PI(), and setPropDir().

Referenced by generateInstance(), and main().

87 {
88  if(m_SortDist.empty() || m_Integral==0.0) {
89  if(!m_Distributions.empty()) {
90  ((ExpectationMap*)this)->updateIntegral();
91  if(m_SortDist.empty() || m_Integral==0.0)
92  return getIdentityPropTF();
93  } else return getIdentityPropTF();
94  }
95  float rint = frand(m_Integral);
96  std::map<float, EMDistribution*>::const_iterator
97  ed = m_SortDist.lower_bound(rint);
98  if(ed == m_SortDist.end()) ed = m_SortDist.begin();
99  ed->second->m_ShootCount++;
100  PropVec prop = ed->second->getPropVec();
101  setPropDir(prop, mapAngle2PI(getPropDir(prop),
102  getPropDir(m_LB)));
103  return prop.clamp(m_LB,m_UB);
104  //return m_Distributions.begin()->getPropVec(); // is this fair?
105 }
float m_Integral
Definition: ExpMap.h:67
#define frand(max)
Definition: mathutil.h:48
EDistributions m_Distributions
Definition: ExpMap.h:176
PropTF getIdentityPropTF()
Definition: PropVec.h:81
VT & clamp(const VT &lb, const VT &ub)
Definition: VVector.h:253
PropVec m_UB
Definition: ExpMap.h:90
float mapAngle2PI(float a)
Definition: mathutil.h:97
PropVec m_LB
Definition: ExpMap.h:90
std::map< float, EMDistribution * > m_SortDist
Definition: ExpMap.h:177
PropVec & setPropDir(PropVec &prop, float dir)
Definition: PropVec.h:28
float getPropDir(const PropVec &prop)
Definition: PropVec.h:25
Model& ExpectationMap::getRepresentative ( )
inline
dword ExpectationMap::getShootCount ( dword  wid) const

Definition at line 79 of file ExpMap.cpp.

References getEDist(), and EMDistribution::getShootCount().

80 {
81  const EMDistribution* ed = getEDist(wid);
82  if(!ed) return 0;
83  else return ed->getShootCount();
84 }
EMDistribution * getEDist(dword wid)
Definition: ExpMap.cpp:65
dword getShootCount() const
Definition: ExpMap.h:62
bool ExpectationMap::hasDist ( dword  wid) const

Definition at line 60 of file ExpMap.cpp.

References m_Distributions.

61 {
62  return m_Distributions.find(wid) != m_Distributions.end();
63 }
EDistributions m_Distributions
Definition: ExpMap.h:176
void ExpectationMap::markAllOld ( )

Definition at line 159 of file ExpMap.cpp.

References EMDistribution::ED_OLD, and m_Distributions.

Referenced by MStructure::rebuildExpMap().

159  {
160  for(EDistributions::iterator dl=m_Distributions.begin();
161  dl != m_Distributions.end(); dl++)
162  {
163  if(dl->second) dl->second->setFlags(EMDistribution::ED_OLD);
164  }
165 }
EDistributions m_Distributions
Definition: ExpMap.h:176
ExpectationMap::operator bool ( ) const
inline

Definition at line 171 of file ExpMap.h.

171 { return !m_Distributions.empty(); }
EDistributions m_Distributions
Definition: ExpMap.h:176
ExpectationMap & ExpectationMap::operator= ( const ExpectationMap rhs)

Definition at line 4 of file ExpMap.cpp.

References add(), clear(), m_Distributions, and m_Representative.

4  {
5  if(&rhs == this) return *this;
6  EMDRect::operator=(rhs);
8  clear();
9  add(rhs.m_Distributions);
10  return *this;
11 }
Model m_Representative
Definition: ExpMap.h:175
void clear(bool oldonly=false)
Definition: ExpMap.cpp:141
EDistributions m_Distributions
Definition: ExpMap.h:176
void add(EMDistribution *ed)
Definition: ExpMap.cpp:23
float ExpectationMap::ratePropVec ( const PropVec prop,
Winner winner = NULL 
) const
virtual

Reimplemented from EMDRect.

Definition at line 107 of file ExpMap.cpp.

References Winner::clearRatings(), getPropDir(), Winner::m_BestRating, m_Distributions, EMDRect::m_LB, mapAngle2PI(), Winner::rateBy(), EMDRect::ratePropVec(), and setPropDir().

Referenced by Searcher::evolve().

108 {
109  if(m_Distributions.empty()) return 0;
110  PropVec pv(prop);
112  if(EMDRect::ratePropVec(pv) == 0.0) {
113  return 0; //clamped?
114  }
115 
116  float rate = 0.f;
117  if(winner) {
118  winner->clearRatings();
119  for(EDistributions::const_iterator dl=m_Distributions.begin();
120  dl != m_Distributions.end(); dl++)
121  {
122  float tr = dl->second->ratePropVec(prop);
123  if(dl->second->m_Creator.m_WinnerID) {
124  const std::string& creatorname = dl->second->m_Creator.m_StructName;
125  dword creatorid = dl->second->m_Creator.m_WinnerID;
126  winner->rateBy(creatorname, creatorid, tr);
127  } else if(winner->m_BestRating < tr) winner->m_BestRating = tr;
128  }
129  rate = winner->m_BestRating;
130  } else {
131  for(EDistributions::const_iterator dl=m_Distributions.begin();
132  dl != m_Distributions.end(); dl++)
133  {
134  float tr = dl->second->ratePropVec(prop);
135  if(rate<tr) rate = tr;
136  }
137  }
138  return rate;
139 }
void clearRatings()
Definition: ExpMap.cpp:288
EDistributions m_Distributions
Definition: ExpMap.h:176
float mapAngle2PI(float a)
Definition: mathutil.h:97
PropVec m_LB
Definition: ExpMap.h:90
PropVec & setPropDir(PropVec &prop, float dir)
Definition: PropVec.h:28
float m_BestRating
Definition: ExpMap.h:39
float getPropDir(const PropVec &prop)
Definition: PropVec.h:25
unsigned long dword
Definition: simpletypes.h:6
float rateBy(const std::string &creatorname, dword creatorid, float rating)
Definition: ExpMap.cpp:295
float ratePropVec(const PropVec &prop, Winner *winner=NULL) const
Definition: ExpMap.cpp:213
void ExpectationMap::setRepresentative ( const Model model)

Definition at line 18 of file ExpMap.cpp.

References m_Representative.

Referenced by MStructure::rebuildExpMap(), and Brain::setupSearch().

19 {
20  m_Representative = model;
21 }
Model m_Representative
Definition: ExpMap.h:175
float ExpectationMap::updateIntegral ( )

Definition at line 167 of file ExpMap.cpp.

References m_Distributions, EMDistribution::m_Integral, and m_SortDist.

Referenced by add(), clear(), main(), and Searcher::setExpectationMap().

168 {
169  m_Integral = 0.f;
170  m_SortDist.clear();
171  for(EDistributions::const_iterator dl=m_Distributions.begin();
172  dl != m_Distributions.end(); dl++)
173  {
174  if(dl->second) {
175  if(dl->second->m_Integral > 0.00001) {
176  m_Integral += dl->second->m_Integral;
177  m_SortDist[m_Integral] = dl->second;
178  }
179  }
180  }
181  return m_Integral;
182 }
float m_Integral
Definition: ExpMap.h:67
EDistributions m_Distributions
Definition: ExpMap.h:176
std::map< float, EMDistribution * > m_SortDist
Definition: ExpMap.h:177

Member Data Documentation

EDistributions ExpectationMap::m_Distributions
protected
Model ExpectationMap::m_Representative
protected

Definition at line 175 of file ExpMap.h.

Referenced by generateInstance(), operator=(), and setRepresentative().

std::map<float, EMDistribution*> ExpectationMap::m_SortDist
protected

Definition at line 177 of file ExpMap.h.

Referenced by getPropVec(), and updateIntegral().


The documentation for this class was generated from the following files: