21 m_TMarks.resize(TM_LAST, 0.0f);
38 m_TMarks.resize(TM_LAST, 0.0f);
40 m_Interpretations.clear();
45 return m_Brain->getSensorData().shared_from_base<
Dataset>();
53 for(map<string,MStructure>::iterator si = m_Structs.begin();
54 si != m_Structs.end(); si++)
56 si->second.getModel().reattachSensors();
62 for(map<string,MStructure>::iterator si = m_Structs.begin();
63 si != m_Structs.end(); si++)
65 si->second.getModel().adaptDataScale();
71 if(filename.empty())
return false;
72 cout <<
"loading " << filename << endl;
74 if(is) m_FileName = filename;
85 if(cstructure.
read(is)) {
86 if(cstructure) m_Structs[cstructure.
getName()] = cstructure;
87 }
else if(!readInterpreations(is))
89 string(
"error reading structure table. ") +
90 "(A structure has to begin with struct <name>)");
101 m_Interpretations.clear();
102 bool readon =
true, allright =
false;
104 if(is.
getKey() ==
"interpretations") allright =
true;
105 else if(!allright) { is.
pushLine();
return false; }
106 else if(is.
getKey() ==
"end") readon =
false;
108 set<string>& elements = m_Interpretations[is.
getKey()];
112 string structure; slist >> structure;
113 if(structure.empty())
break;
114 elements.insert(structure);
126 for(map<string,MStructure>::const_iterator si = m_Structs.begin();
127 si != m_Structs.end(); si++)
129 si->second.write(os);
131 if(!m_Interpretations.empty()) {
132 os <<
"interpretations" << endl;
133 for(map<
string,set<string> >::const_iterator ip =
134 m_Interpretations.begin(); ip != m_Interpretations.end(); ip++)
136 os <<
" " << ip->first;
137 for(set<string>::const_iterator sp = ip->second.begin();
138 sp != ip->second.end(); sp++)
142 os <<
"end" << endl << endl;
148 return m_Structs.find(sname) != m_Structs.end();
153 return m_Structs.find(sname)->second;
159 if(m_Structs.empty())
return nostruc;
160 if(m_CurStruct.empty()) {
161 m_CurStruct = m_Structs.begin()->first;
162 return m_Structs.begin()->second;
164 map<string,MStructure>::iterator st = m_Structs.find(m_CurStruct);
165 if(st == m_Structs.end()) {
166 m_CurStruct = m_Structs.begin()->first;
167 return m_Structs.begin()->second;
171 if(st == m_Structs.end()) {
172 if(wrap) st = m_Structs.begin();
173 else { m_CurStruct.clear();
return nostruc; }
175 m_CurStruct = st->first;
177 if(st == m_Structs.begin()) {
178 if(wrap) st = m_Structs.end();
179 else { m_CurStruct.clear();
return nostruc; }
182 m_CurStruct = st->first;
191 for(map<string,MStructure>::iterator si = m_Structs.begin();
192 si != m_Structs.end(); si++)
194 si->second.buildAllStats();
201 for(map<string,MStructure>::iterator si = m_Structs.begin();
202 si != m_Structs.end(); si++)
203 si->second.rebuildExpMap();
208 for(map<string,MStructure>::iterator si = m_Structs.begin();
209 si != m_Structs.end(); si++)
210 si->second.refSubSuper(
true);
211 for(map<string,MStructure>::iterator si = m_Structs.begin();
212 si != m_Structs.end(); si++)
213 si->second.refSubSuper();
220 for(
dword ind=0; ind<mat.
size(); ind++, el++)
222 float avgdir = dir.
angle();
224 for(
dword ind=0; ind<mat.
size(); ind++, el++)
241 for(map<string,MStructure>::iterator si = m_Structs.begin();
242 si != m_Structs.end(); si++)
243 si->second.buildMasterModel();
248 findBestConnection();
256 m_State = m_State ^ ST_RESULT;
259 cout <<
"starting structure search" << endl;
263 cout <<
"stopping structure search" << endl;
270 }
if(what == KEY_s) {
272 }
else if(what == KEY_r) {
274 m_TMarks[TM_UPDEM] = m_TMarks[TM_TIMEOUT] = 0;
278 for(map<string,MStructure>::iterator si = m_Structs.begin();
279 si != m_Structs.end(); si++)
280 ret = si->second.m_Searcher.triggerTest(mx,my,what);
291 m_State&=~(ST_DONE|ST_TIMEOUT);
293 m_TMarks[TM_UPDEM] = m_TMarks[TM_TIMEOUT] = 0;
296 }
else m_State &= ~ST_RUN;
297 for(map<string,MStructure>::iterator si = m_Structs.begin();
298 si != m_Structs.end(); si++)
300 if(dostart) si->second.m_Searcher.clear();
301 si->second.m_Searcher.startSearch(dostart);
307 bool dotimeout=
false;
309 if((m_State&ST_DONE))
return true;
310 if((m_State&ST_RUN) == 0)
return false;
313 for(map<string,MStructure>::iterator si = m_Structs.begin();
314 si != m_Structs.end(); si++)
315 si->second.buildMasterModel();
318 if(dotimeout && m_TMarks[TM_TIMEOUT] - m_Time <= 0) {
321 m_State |= ST_RESULT;
324 bool doupdate = m_TMarks[TM_UPDEM] - m_Time <= 0;
329 for(map<string,MStructure>::iterator si = m_Structs.begin();
330 si != m_Structs.end(); si++)
332 if(doupdate) si->second.m_Searcher.evolve();
333 ret &= si->second.stepSearch(dt);
335 if(doupdate) findBestConnection();
340 cout <<
"search terminated after " << m_Time <<
" seconds." << endl;
348 Interpretations::const_iterator cip = m_Interpretations.find(m_CurIP);
349 if(cip == m_Interpretations.end()) {
350 if(m_Interpretations.empty()) {
354 cip = m_Interpretations.begin();
358 if(cip==m_Interpretations.end()) {
359 cip = m_Interpretations.begin();
363 cip = m_Interpretations.end(); cip--;
364 }
else if(dir == -1) {
365 if(cip==m_Interpretations.begin()) {
366 cip = m_Interpretations.end();
370 }
else if(dir < -1) {
371 cip = m_Interpretations.begin();
373 m_CurIP = cip->first;
379 const string& ipname = getShownIP();
380 map<string,StructPath>::const_iterator spath = m_IPaths.find(ipname);
381 for(map<string,MStructure>::const_iterator si = m_Structs.begin();
382 si != m_Structs.end(); si++)
384 if((m_State & ST_RESULT) == 0) si->second.m_Searcher.draw();
385 if(spath != m_IPaths.end()) {
386 StructPath::const_iterator wi = spath->second.find(si->first);
387 if(wi != spath->second.end()) {
388 const Winner *nw = si->second.getWinner(wi->second);
402 if(m_Structs.empty())
return m_BestPath.m_Goodness;
403 m_BestPath.unprotectWinners(*
this);
405 for(map<string,MStructure>::iterator si = m_Structs.begin();
406 si != m_Structs.end(); si++)
408 si->second.verifyWinnerRating();
412 for(Interpretations::const_iterator ip=m_Interpretations.begin();
413 ip != m_Interpretations.end(); ip++)
415 cout <<
"scanning interpretation " << ip->first << endl;
417 for(map<string,MStructure>::iterator si = m_Structs.begin();
418 si != m_Structs.end(); si++)
423 for(map<dword,Winner>::const_iterator wi = winners.begin();
424 wi != winners.end(); wi++)
428 findBestConnection(path, wi->second);
434 if(bestpath.
m_Goodness > m_IPaths[ip->first].m_Goodness)
436 m_IPaths[ip->first] = bestpath;
438 cout <<
" best cost for " << si->first <<
": " 443 if(m_IPaths[ip->first].getRelGoodness() > m_BestPath.getRelGoodness())
445 m_BestPath = m_IPaths[ip->first];
446 m_BestIP = ip->first;
449 cout <<
"best interpretation is " << m_BestIP << endl;
450 m_BestPath.protectWinners(*
this);
451 m_BestPath.print(cout, *
this);
460 return m_BestPath.getRelGoodness();
464 const Winner& winner)
const 468 if(csname.empty()) {
TRACE0;
return false; }
477 NodePaths::const_iterator wpath = np.find(winner.
m_WinnerID);
478 if(wpath != np.end()) {
479 path.
merge(wpath->second);
485 const MStructure& cstruct = getStructure(csname);
492 for(Winner::Ratings::const_iterator wr = winner.
m_Ratings.begin();
495 map<string,MStructure>::const_iterator sti =
496 m_Structs.find(wr->first);
497 if(sti != m_Structs.end()) {
502 for(map<dword,float>::const_iterator wi = wr->second.begin();
503 wi != wr->second.end(); wi++)
507 if(nextWinner && wi->second > subs.
m_RateTH) {
508 if(findBestConnection(cpath, *nextWinner)) {
518 path.
merge(bestpath);
524 m_WinnersProtected(false)
540 map<string,dword>::operator=(rhs);
550 map<string,dword>::clear();
558 iterator wi = find(struc.
getName());
559 if(wi != end() && wi->second) {
561 if(!winner) wi->second = 0;
568 const_iterator wi = find(struc.
getName());
569 if(wi != end() && wi->second)
572 if(!winner) (
dword&)(wi->second) = 0;
580 for(iterator wi = begin(); wi != end(); wi++)
585 .getWinner(wi->second);
586 if(winner && winner->
m_Model) {
588 }
else wi->second = 0;
597 for(iterator wi = begin(); wi != end(); wi++)
602 .getWinner(wi->second);
603 if(winner && winner->
m_Model) {
605 }
else wi->second = 0;
614 for(map<string,MStructure>::const_iterator
618 if(freepath.find(st->second.getName()) == freepath.end())
629 for(const_iterator wi = begin(); wi != end(); wi++)
634 os <<
" " << wi->first;
641 else os <<
"\t (no model)"<<endl;
642 for(const_iterator ri = begin(); ri != end(); ri++)
650 os <<
" <--[" << ri->first
656 os <<
" (best: " << winner->
m_BestRating <<
")" << endl;
657 }
else os <<
" (deleted)"<< endl;
660 os << setw(0) << flush;
667 for(iterator wi = bp.begin(); wi != bp.end(); wi++)
675 for(const_iterator wi = mp.begin(); wi != mp.end(); wi++)
678 operator[](wi->first) = wi->second;
std::shared_ptr< Dataset > dataset_ptr
void startSearch(bool dostart=true)
void merge(const StructPath &mp)
float getQualityOfFit() const
std::map< dword, Winner > & getWinList()
std::map< std::string, SubStructure > m_SubStructures
const Winner * getWinner(dword wid) const
std::map< std::string, MStructure > & getStructs()
bool triggerTest(int mx, int my, int what)
Winner * getWinner(MStructure &struc)
float findBestConnection()
float m_Goodness
goodness of path
float getRelGoodness() const
const std::string & getValue() const
bool hasStructure(const std::string &sname) const
bool stepSearch(float dt)
const Searcher & getSearcher() const
bool load(const std::string &filename)
bool showNextIP(int dir=1) const
std::map< dword, StructPath > NodePaths
float angle(const Point2D &rhs=Point2D(1, 0)) const
SensorCollection * getSensors()
const std::string & getPath() const
void blockOtherPaths(const std::set< std::string > &freepath, const StructTable &structs)
std::ostream & print(std::ostream &os, const StructTable &structs) const
const std::string & getKey() const
float getConnection(const std::string &sname, dword wid) const
dword & unsetFlags(dword flags)
StructPath & operator=(const StructPath &rhs)
float m_EvolveCycle
time in seconds for one evolution cycle
const Point2D rotate(float angle) const
SearcherParams & getSearchPara()
static DMatrixf & adjustByAvgDir(DMatrixf &mat)
const std::string & getName() const
void unprotectWinners(StructTable &structs)
void draw(bool drawPoints=false) const
Draw using OpenGL.
void write(std::ostream &os) const
void setParseError(const std::string &msg="")
StructPath branch() const
std::vector< float >::iterator iterator
std::string getErrorMsg() const
dword & setFlags(dword flags)
const MStructure & getStructure(const std::string &sname) const
float mapAnglePI(float a)
float m_Maxness
maximum goodness
void pushLine(const std::string &line)
MStructure & getNextStruct(int dir=1, bool wrap=true)
bool readInterpreations(ParseFile &is)
bool hasSupStruct(const std::string sname) const
void protectWinners(StructTable &structs)
const SubStructure & getSupStruct(const std::string sname) const
std::vector< T > & getData()
StructTable(Brain &brain, const std::string &filename=std::string())