8 #define test(s) {cout << s << " " << flush;} 9 #define testOk() {cout << "OK" << endl;} 14 inline operator double()
const {
return w;}
20 for (vector<Particle>::const_iterator it=p.begin(); it!=p.end(); ++it) {
21 os << it->p<<
" " << (double)*it << endl;
29 pn.
p+=.5*(drand48()-.5);
42 double v = 1./(0.1+10*(p.
p-2)*(p.
p-2))+0.5/(0.1+10*(p.
p-8)*(p.
p-8));
47 int main (
unsigned int argc,
const char *
const * argv){
50 nparticles=atoi(argv[1]);
51 vector<Particle> particles(nparticles);
57 for (vector<Particle>::iterator it=particles.begin(); it!=particles.end(); it++){
62 vector<Particle> sirparticles(particles);
63 vector<Particle> auxparticles(particles);
69 vector<Particle> newgeneration;
71 cout <<
"# SIR step" << endl;
72 evolver.
evolve(sirparticles);
73 for (vector<Particle>::iterator it=sirparticles.begin(); it!=sirparticles.end(); it++){
74 it->setWeight(likelyhoodModel.
likelyhood(*it));
76 ofstream os(
"sir.dat");
79 newgeneration=resampler.
resample(sirparticles);
80 sirparticles=newgeneration;
82 cout <<
"# AUX step" << endl;
83 auxevolver.
evolve(auxparticles);
84 for (vector<Particle>::iterator it=auxparticles.begin(); it!=auxparticles.end(); it++){
85 it->setWeight(likelyhoodModel.
likelyhood(*it));
90 newgeneration=resampler.
resample(auxparticles);
91 auxparticles=newgeneration;
92 cout <<
"plot [0:10][0:10]\"sir.dat\" w impulses" << endl;
93 cout <<
"replot 1./(0.1+10*(x-2)*(x-2))+0.5/(0.1+10*(x-8)*(x-8))" << endl;
double likelyhood(const Particle &p) const
void evolve(std::vector< Particle > &particles)
Particle evolve(const Particle &p)
void setWeight(double _w)
Particle evolve(const Particle &p)
void evolve(std::vector< Particle > &particles)
int main(unsigned int argc, const char *const *argv)
ostream & printParticles(ostream &os, const vector< Particle > &p)