00001
00002
00003 #ifndef LOADED_ParticleFilter_h
00004 #define LOADED_ParticleFilter_h
00005
00006 #include <vector>
00007 #include <string>
00008
00009 #include "Particle.h"
00010 #include "ParticleShapes.h"
00011 #include "ShapePolygon.h"
00012
00013 using namespace std;
00014
00015 namespace DualCoding {
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 class ParticleFilter {
00026 public:
00027 static const int NUM_PARTICLES = 2000;
00028 static const int NUM_GENERATIONS = 15;
00029 static const int NUM_TRIES = 5;
00030 static const float INITIAL_XY_NOISE = 100;
00031 static const float INITIAL_THETA_NOISE = 30 * M_PI/180;
00032 static const float NOISE_REDUCTION_XY = 0.85;
00033 static const float NOISE_REDUCTION_T = 0.9;
00034 static const float INFINITE_DISTANCE = 10000000;
00035 static const float STDEV = 50;
00036 static const float ADDITION_PENALTY = 0.1;
00037 static const float PERCENT_RANDOM = 0.1;
00038
00039 ShapeSpace &localShS;
00040 ShapeSpace &worldShS;
00041 int numParticles;
00042 int numGenerations;
00043 int numTries;
00044 float noiseFactorXY;
00045 float noiseFactorT;
00046 Shape<PolygonData> worldBounds;
00047 int nlocal;
00048 int nworld;
00049
00050
00051 float xmin, xmax, xrange;
00052 float ymin, ymax, yrange;
00053
00054 vector<Particle> *curParticles;
00055 int bestIndex;
00056
00057
00058 vector<Particle> *newParticles;
00059 vector<PfRoot*> *localLms;
00060 vector<PfRoot*> *worldLms;
00061 vector<float> particleViewX;
00062 vector<float> particleViewY;
00063 vector<float> particleViewX2;
00064 vector<float> particleViewY2;
00065 vector<float> localScores;
00066 vector<int> localMatches;
00067
00068 public:
00069 ParticleFilter(ShapeSpace &LocalShS, ShapeSpace &WorldShS) :
00070 localShS(LocalShS), worldShS(WorldShS),
00071 numParticles(NUM_PARTICLES),
00072 numGenerations(NUM_GENERATIONS),
00073 numTries(NUM_TRIES),
00074 noiseFactorXY(INITIAL_XY_NOISE),
00075 noiseFactorT(INITIAL_THETA_NOISE),
00076 worldBounds(),
00077 nlocal(0),
00078 nworld(0),
00079 xmin(0), xmax(0), xrange(0),
00080 ymin(0), ymax(0), yrange(0),
00081 curParticles(NULL),
00082 bestIndex(-1),
00083 newParticles(NULL),
00084 localLms(), worldLms(),
00085 particleViewX(), particleViewY(),
00086 particleViewX2(), particleViewY2(),
00087 localScores(), localMatches()
00088 {};
00089
00090
00091 void reinitialize();
00092
00093
00094 void setWorldBounds(const Shape<PolygonData> &poly) { worldBounds = poly; }
00095
00096
00097 int localize();
00098
00099
00100 void uniformlyDistribute();
00101
00102
00103 void moveBy(float const xdelta, float const ydelta, AngPi const tdelta);
00104
00105
00106
00107
00108
00109 void makeParticles();
00110
00111
00112
00113
00114 void loadLms();
00115
00116
00117 void resizeParticles();
00118
00119
00120 void randomizeNewParticle(int const i);
00121
00122
00123 void getInitialGuess();
00124
00125
00126 void computeParticleScores();
00127
00128
00129 void setParticleView(int const i);
00130
00131
00132 void computeLocalMatch(int const i, int const j);
00133
00134 static float distanceFromLine(coordinate_t x, coordinate_t y, PfLine &wline);
00135
00136
00137 void resample();
00138
00139 void spawnInto(int const i, int const j);
00140
00141 void determineAdditions(int const i);
00142
00143
00144
00145 public:
00146 static inline float normpdf(float const distsq) { return exp(-distsq/(STDEV*STDEV)); }
00147
00148 private:
00149 ParticleFilter& operator=(const ParticleFilter&);
00150 ParticleFilter(const ParticleFilter&);
00151
00152 };
00153
00154
00155
00156 }
00157
00158 #endif
00159