18 #define SUBSTRUCT_RATEWEIGHT 1.0f 19 #define STRUCT_SHAPEWEIGHT 0.1f 20 #define SUBSTRUCT_RATETH 0.0f 25 : m_PStructTable(psTable), m_Size(1.0f), m_Weight(1.0f)
100 const string& key = is.
getKey();
101 const string& value = is.
getValue();
102 if(key ==
"struct") {
104 "struct inside struct. (rather use substruct?)");
109 }
else if(
m_Name.empty()) {
111 }
else if(key ==
"end") readon =
false;
112 else if(key ==
"model") {
117 }
else if(key ==
"size") {
118 istringstream(value) >>
m_Size;
119 }
else if(key ==
"weight") {
121 }
else if(key ==
"shapeweight") {
126 else is.
setParseError(
string(
"(parsing struct) unknown token ") + key);
128 if(is.
error())
return false;
135 os <<
"struct " <<
m_Name << endl;
143 os <<
" model " << filename << endl;
148 os <<
" size " <<
m_Size << endl;
149 for(map<string,SubStructure>::const_iterator si =
m_SubStructures.begin();
154 os <<
"end # of struct" << endl << endl;
161 fn = fn.substr(0, fn.rfind(
'.'));
162 }
else fn =
"struct";
163 fn = fn +
"_" +
m_Name +
"_" + suffix +
".dm";
170 bool readf = model.
readFile(filename.c_str());
176 map<dword,PropVec>::const_iterator rp =
m_RefProp.find(
id);
222 ofstream os(filename.c_str());
224 for(map<dword,PropVec>::const_iterator rp=
m_RefProp.begin();
228 os << rp->first <<
" " << rp->second << endl;
235 getRefModelIDs( insert_iterator<set<dword> >(refmod, refmod.begin()) );
244 insert_iterator<set<dword> >(strefmod, strefmod.begin()) );
246 set_intersection( refmod.begin(), refmod.end(),
247 strefmod.begin(), strefmod.end(),
248 back_inserter(comod) );
249 dword ncomod = comod.size();
252 for(list<dword>::const_iterator idi = comod.begin();
253 idi != comod.end(); idi++, rowind++)
255 Point2D pivot(0,0);
bool usepivot =
false;
262 }
else cout <<
"error: could not find reference model " 272 }
else cerr <<
"error getting propvec for " <<
m_Name 273 <<
" or " << st.
m_Name <<
" for species " 293 for(list<dword>::const_iterator idi = refmod.begin();
294 idi != refmod.end(); idi++)
306 lenrat.at(0,i) += lr;
314 float minlr = 1/scmax;
316 float refallrl=0, nallrl=0;
319 float rl = rlen.at(0,i) /= nmod;
320 lenrat.at(0,i) /= nmod;
328 float rl = rlen.at(0,i);
329 float sc = lenrat.at(0,i);
332 if(sc>minlr) sc = 1/sc;
338 #define SHAPEADAPTTIMESTEP 0.01 342 float liveliness = 0;
353 if(!timeout) cout <<
"timeout reached while calming model" << endl;
354 #undef SHAPEADAPTTIMESTEP 392 if(exhaust>1.f) exhaust = 0.f;
393 else exhaust = 1.f-exhaust;
398 subs.
getLBUB(lb, ub, frameprop, ppmm);
408 dword nwinners = winners.size();
409 if(!nwinners)
return false;
411 map<dword,Winner>::const_iterator wi = winners.begin();
412 for(
dword i=0; i<nwinners; i++, wi++)
413 qof.
at(0,i) = wi->second.m_Model->getQualityOfFit();
416 float maxqof = qof.
max(), minqof = qof.
min();
417 if(maxqof<0.0000001)
return false;
419 float bestrating = 0;
421 for(wi = winners.begin(); wi!= winners.end(); wi++) {
422 const Winner& winner = wi->second;
425 #ifdef _SPAWN_FROM_BEST_ 427 if(rating > bestrating) {
435 const Winner& winner = *thebest;
447 if(maxshoot < emdist->getShootCount())
448 maxshoot = emdist->getShootCount();
451 if(exhaust>1.f) exhaust = 0.f;
452 else exhaust = 1.f-exhaust;
453 emdist->setIntegral((wqof/maxqof)*exhaust);
456 subs.
getLBUB(lb, ub, wprop, ppmm);
467 if(thebest &&
false) {
478 DUMP(maxshoot <<
" --------------------" );
503 #ifdef _USE_BACKGROUND_DIST_ 517 #if DO_INVERSE_TRANSFORM 535 for(map<dword,Winner>::iterator wi = wl.begin(); wi!=wl.end(); wi++)
537 for(Winner::Ratings::iterator refstruct = wi->second.m_Ratings.begin();
538 refstruct != wi->second.m_Ratings.end(); refstruct++)
542 map<dword,float>::iterator wr= refstruct->second.begin();
543 while(wr != refstruct->second.end())
545 map<dword,float>::iterator nextwr = wr; nextwr++;
550 refstruct->second.erase(wr);
554 }
else okcount += refstruct->second.size();
556 wi->second.updateBestRating();
558 cout << okcount <<
" good connections to struct " <<
m_Name << endl;
566 getRefModelIDs( insert_iterator<set<dword> >(refmod, refmod.begin()) );
570 insert_iterator<set<dword> >(strefmod, strefmod.begin()) );
572 set_intersection( refmod.begin(), refmod.end(),
573 strefmod.begin(), strefmod.end(),
574 back_inserter(comod) );
575 dword ncomod = comod.size();
579 for(list<dword>::const_iterator idi = comod.begin();
580 idi != comod.end(); idi++, rowind++)
582 Point2D pivot(0,0);
bool usepivot =
false;
589 }
else os <<
"error: could not find reference model " 604 os << *idi <<
": " << ratings.
at(0,rowind) <<
" pv:" 607 }
else os <<
"error generating exp.distr. for " << *idi << endl;
608 }
else os <<
"error getting propvec for " <<
m_Name 609 <<
" or " << st.
m_Name <<
" for species " 621 os <<
"average: " <<
dmutil::avg(ratings).at(0,0) << endl;
624 os <<
"min : " << ratings.
min() << endl;
625 os <<
"max : " << ratings.
max() << endl;
627 }
else os <<
"error generating exp.distr." << endl;
637 const std::string& supStructName,
638 const PropTF& transform,
int pivot)
639 : m_SubStructName(subStructName),m_SupStructName(subStructName),
640 m_Transform(transform), m_Pivot(pivot),
656 if(show)
DUMP(tfmat);
672 ntfmat -= mavg; ntfmat /= mstdev;
677 tfcov *= (1.f/(ntfmat.
sizeY()));
678 if(show)
DUMP(tfcov);
682 float relvar = 1.f/4;
689 if(show)
DUMP(mU << mS << mV);
729 #ifndef _PROPTF_NORMALIZE_SCALE_ 747 #ifndef _PROPTF_NORMALIZE_SCALE_ 751 PropVec olb(wprop), oub(wprop);
768 #ifndef _PROPTF_NORMALIZE_SCALE_ 786 #ifndef _PROPTF_NORMALIZE_SCALE_ 804 const PropVec& wprop,
float ppmm,
float radius)
const 811 #ifndef _PROPTF_NORMALIZE_SCALE_ 836 if(is.
getKey() !=
"substruct")
return false;
841 const string& key = is.
getKey();
842 const string& value = is.
getValue();
843 if(key ==
"transform") {
845 }
else if(key ==
"pivot") {
848 }
else if(key ==
"rateweight") {
850 }
else if(key ==
"rateth") {
852 }
else if(key ==
"mode") {
853 if(value.find(
"nospawn") != value.npos)
855 if(value.find(
"showstats") != value.npos)
857 }
else if (key ==
"end") readon =
false;
858 else { is.
setParseError(
"error parsing substructure");
return false; }
860 if(is.
error())
return false;
869 os <<
" pivot " << ss.
m_Pivot+1 << endl;
870 if(ss.
m_Polar) os <<
" polar" << endl;
879 os <<
" end # of substruct" << endl;
float getLiveliness() const
ExpectationMap & getExpectationMap()
static ParticleParam global
std::string getInfoFilename(const std::string &suffix) const
float getGeneration(const Model *model) const
void analyseTF(const DMatrixf &tfmat)
std::string m_SubStructName
void setExpectationMap(const ExpectationMap &em)
bool writeFile(const char *filename) const
float getQualityOfFit() const
void showStats(const SubStructure &subs, std::ostream &os=std::cout) const
DMatrix< T > inverse(const DMatrix< T > &dmat)
PropVec & convertPropToMM(PropVec &prop) const
const std::string & getPath() const
std::map< dword, Winner > & getWinList()
void attachDataset(dataset_cptr dataset)
T & fromString(const std::string &str, T &v)
std::map< std::string, SubStructure > m_SubStructures
const Winner * getWinner(dword wid) const
std::map< std::string, SubStructure * > m_SupStructures
void mergeSensorCollection(SensorCollection *sensors)
void clear(bool oldonly=false)
std::map< std::string, MStructure > & getStructs()
#define SHAPEADAPTTIMESTEP
PropVec getPropertiesMM() const
return property vector using millimeter scale
StructTable * m_PStructTable
const PropVec & getProperties() const
#define STRUCT_SHAPEWEIGHT
void setShapeWeight(float shapeweight)
MStructure & operator=(const MStructure &rhs)
EMDistribution * getEDist(dword wid)
Point2D getPropPos(const PropVec &prop)
float m_PCTH
threshold for principle components
VVector< float, 4 > PropVec
std::string toString(T v)
PropVec & invPropTF(PropVec &to, const PropTF &tf)
static void correctLBUB(PropVec &lb, PropVec &ub)
dword getShootCount() const
PropTF getIdentityPropTF()
Implements an Edge with spring functionality.
ParticleParam phys
physical parameter set
float getPropScale(const PropVec &prop)
float m_ScaleStd
scale stdev of link
void scale(float factor, bool movepoints=false)
multiply all rest lengths by factor
float m_Size
stdradius in mm
void add(EMDistribution *ed)
PropTF getPropTF(const PropVec &from, const PropVec &to)
std::map< dword, PropVec > m_RefProp
const std::string & getValue() const
friend std::ostream & operator<<(std::ostream &os, const SubStructure &ss)
void setShootCount(dword scount)
void setCreator(const Winner &creator)
dword getRefModelIDs(Iter iter) const
const Point getCenter() const
int m_MaxShoot
maximum number of spawns from an exp map
bool getRefModel(dword id, Model &model) const
std::string m_SupStructName
PropVec & setPropDir(PropVec &prop, float dir)
const Searcher & getSearcher() const
bool getRefProp(dword id, PropVec &prop) const
void verifyWinnerRating()
const std::string & getFilename() const
PropVec & setPropPos(PropVec &prop, const Point2D &p)
float springconstant
spring constant
void setName(const std::string &name)
void setUB(const PropVec &ub)
SensorCollection * getSensors()
void addSubStruct(const SubStructure &substruct)
const std::string & getPath() const
const std::string & getKey() const
void refSubSuper(bool doclear=false)
SubStructure(const std::string &subStructName="", const std::string &supStructName="", const PropTF &transform=PropTF(0.f), int pivot=-1)
DMatrix< T > & abs(DMatrix< T > &mat)
const Winner * getWinner(dword id) const
float getShapeWeight() const
Point2D & convertPointToMM(Point2D &pt) const
void write(std::ostream &os) const
const Node & getNode(int index) const
virtual float ratePropVec(const PropVec &prop, Winner *winner=NULL) const
void setName(const std::string &name)
bool SVD(const DMatrix< T > &dmat, DMatrix< T > &mU, DMatrix< T > &mS, DMatrix< T > &mV)
MT & resize(dword _sx, dword _sy, const T &inival=T())
const PropVec & getLB() const
float lengthRatio() const
SearcherParams & getSearchPara()
void setRefProp(dword id, const PropVec &prop)
static DMatrixf & adjustByAvgDir(DMatrixf &mat)
MT mulLeft(const MT &rhs) const
PropVec & fwdPropTF(PropVec &from, const PropTF &tf)
void setRefModel(dword id, const Model &model)
Model & getRepresentative()
const Edge & getEdge(int index) const
void updateParticles(float dt, int method=0)
virtual void setIntegral(float integral)
const PropVec & getUB() const
const std::string & getFilename() const
void setParseError(const std::string &msg="")
DMatrix< T > avg(const DMatrix< T > &mat)
bool buildMasterModel(float scscale=1.f)
MT & setRange(dword ox, dword oy, const MT &mat)
DMatrix< T > stdev(const DMatrix< T > &mat)
bool readFile(const char *filename, bool fullread=true)
void clear()
remove and destroy all geometry information (nodes and edges)
EMDistribution * generateEMDist(const PropVec &wprop, float ppmm, bool inverse=false, dword dtype=EMD_RECT) const
MT & getRange(dword ox, dword oy, MT &mat) const
PropVec & setPropScale(PropVec &prop, float pscale)
void pushLine(const std::string &line)
bool stepSearch(float dt)
DMatrix< T > expand(const DMatrix< T > &mat, dword mx, dword my)
void getLBUB(PropVec &lb, PropVec &ub, const PropVec &wprop, float ppmm, float radius=3) const
#define SUBSTRUCT_RATEWEIGHT
dword getDataScale() const
static unsigned int size()
bool addExpectation(const SubStructure &subs, ExpectationMap &expmap, bool inverse=false) const
void setLB(const PropVec &lb)
MStructure(const std::string &name="", StructTable *psTable=NULL)
void setRepresentative(const Model &model)
MT mulRight(const MT &rhs) const
DMatrix< T > & sqrt(DMatrix< T > &mat)