• R/O
  • SSH
  • HTTPS

particle-filter: 提交


Commit MetaInfo

修订版27 (tree)
时间2010-10-28 14:43:48
作者(del#42041)

Log Message

Added manipulate functions for partcles

更改概述

差异

--- src/Makefile.in (revision 26)
+++ src/Makefile.in (revision 27)
@@ -1,6 +1,6 @@
11 CC=@CC@
22 CXX=@CXX@
3-SRCS=particle.cc particles.cc filter.cc edit.cc
3+SRCS=particle.cc particles.cc filter.cc
44 OBJS=$(SRCS:.cc=.o)
55 HEADS=$(SRCS:.cc=.h)
66 TARGETS=libparticle.a
--- src/particle.cc (revision 26)
+++ src/particle.cc (revision 27)
@@ -1,3 +1,6 @@
1+/**
2+ this class repsesents one particle.
3+*/
14 #include <particle.h>
25
36
@@ -12,6 +15,8 @@
1215 template<class C> Particle<C>::~Particle()
1316 {
1417 }
18+
19+// Copy constructor
1520 template<class C> Particle<C>::Particle(const Particle &f)
1621 {
1722 p = f.p;
@@ -35,6 +40,19 @@
3540 p = f;
3641 return(*this);
3742 }
43+template<class C> Particle<C> &Particle<C>::operator+=(Particle<C> a)
44+{
45+ for(int i=0;i<size();++i)
46+ {
47+ p[i] += a[i];
48+ }
49+ return(*this);
50+}
51+template<class C> Particle<C> Particle<C>::operator+(Particle<C> &a)
52+{
53+ Particle<C> c = *this;
54+ return(c+=a);
55+}
3856 template<class C> C &Particle<C>::operator[](unsigned int i)
3957 {
4058 return(p[i]);
@@ -53,7 +71,7 @@
5371 {
5472 return(dimension);
5573 }
56-template<class C> vector<C> Particle<C>::get_particle()
74+template<class C> vector<C> Particle<C>::toVector()
5775 {
5876 return(p);
5977 }
--- src/filter.cc (revision 26)
+++ src/filter.cc (revision 27)
@@ -44,6 +44,15 @@
4444 v.resize(number, dimension);
4545 return(true);
4646 }
47+bool Filter::createInitialParticles(double d)
48+{
49+ if(number<0||dimension<0) return(false);
50+// x = new Particles(number, dimension);
51+// v = new Particles(number, dimension);
52+ x.resize(number, dimension);
53+ v.resize(number, dimension);
54+ return(true);
55+}
4756 bool Filter::create_system_noise()
4857 {
4958 for(int i=0;i<v.size();++i)
@@ -51,7 +60,6 @@
5160 for(int j=0;j<v[i].size();++j)
5261 {
5362 v[i][j] = mtrand.randNorm(0.0, 1.2); // ToDO: functionize
54-//cout<<"noise="<<v[i][j]<<endl;
5563 }
5664 }
5765 return(true);
@@ -66,13 +74,13 @@
6674 v.dump_particles();
6775 return(0);
6876 }
69-string Filter::predict_particles_toString()
77+Particles<double> Filter::get_predict_particles()
7078 {
71- return(x.toString());
79+ return(x);
7280 }
73-string Filter::system_noise_toString()
81+Particles<double> Filter::get_system_noise()
7482 {
75- return(v.toString());
83+ return(v);
7684 }
7785 bool Filter::set_state_func(Particles<double> (*func)(Particles<double> &p, Particles<double> &v))
7886 {
--- src/particle.h (revision 26)
+++ src/particle.h (revision 27)
@@ -19,10 +19,12 @@
1919 Particle& operator=(const Particle &f);
2020 int resize(int n);
2121 int size();
22- vector<C> get_particle();
22+ vector<C> toVector();
2323 string toString();
2424 int dump();
2525 Particle& operator=(vector<C> &f);
26+ Particle<C> &operator+=(Particle<C> a);
27+ Particle<C> operator+(Particle<C> &a);
2628 C &operator[](unsigned int i);
2729 C operator[](unsigned int i) const;
2830 };
--- src/particles.cc (revision 26)
+++ src/particles.cc (revision 27)
@@ -12,6 +12,44 @@
1212 {
1313 resize(number, dimension);
1414 }
15+// Copy constructor
16+template<class C> Particles<C>::Particles(const Particles &f)
17+{
18+ number = f.number;
19+ p.resize(number);
20+ for(unsigned int i=0;i<p.size();++i)
21+ {
22+ p[i] = f[i];
23+ }
24+}
25+// Copy substitution
26+template<class C> Particles<C>& Particles<C>::operator=(const Particles &f)
27+{
28+ if(this != &f)
29+ {
30+ number = f.number;
31+ p.resize(number);
32+ for(unsigned int i=0;i<p.size();++i)
33+ {
34+ p[i] = f[i];
35+ }
36+ }
37+ return(*this);
38+}
39+template<class C> Particles<C> &Particles<C>::operator+=(Particles<C> a)
40+{
41+ for(int i=0;i<size();++i)
42+ {
43+ p[i] += a[i];
44+ }
45+ return(*this);
46+}
47+template<class C> Particles<C> Particles<C>::operator+(Particles<C> &a)
48+{
49+ Particles<C> c = *this;
50+ return(c+=a);
51+}
52+
1553 template<class C> Particles<C>::~Particles()
1654 {
1755 }
@@ -41,7 +79,7 @@
4179 {
4280 return(p.at(i));
4381 }
44-template<class C> vector<Particle<C> > Particles<C>::get_particles()
82+template<class C> vector<Particle<C> > Particles<C>::toVector()
4583 {
4684 return(p);
4785 }
--- src/filter.h (revision 26)
+++ src/filter.h (revision 27)
@@ -29,10 +29,11 @@
2929 bool setDimension(int d);
3030 bool createInitialParticles();
3131 bool create_system_noise();
32+ bool createInitialParticles(double d);
3233 int dump_predict_particles();
3334 Particles<double> get_particles();
34- string predict_particles_toString();
35- string system_noise_toString();
35+ Particles<double> get_predict_particles();
36+ Particles<double> get_system_noise();
3637 bool set_state_func(Particles<double> (*func)(Particles<double> &p, Particles<double> &v));
3738 bool set_robserve_func(double (*func)(Particles<double> &p, Particle<double> &q));
3839 bool set_robserve_jacobian_func(double (*func)(Particles<double> &p, Particle<double> &q));
--- src/particles.h (revision 26)
+++ src/particles.h (revision 27)
@@ -13,12 +13,16 @@
1313 Particles();
1414 Particles(int number);
1515 Particles(int number, int dimension);
16+ Particles(const Particles &f);
17+ Particles<C>&operator=(const Particles &f);
18+ Particles<C> &operator+=(Particles<C> a);
19+ Particles<C> operator+(Particles<C> &a);
1620 ~Particles();
1721 bool resize(int number, int dimension);
1822 int size();
1923 Particle<C> &operator[](unsigned int i);
2024 Particle<C> operator[](unsigned int i) const;
21- vector<Particle<C> > get_particles();
25+ vector<Particle<C> > toVector();
2226 int dump_particles();
2327 string toString();
2428 };
--- src/Makefile (revision 26)
+++ src/Makefile (revision 27)
@@ -1,6 +1,6 @@
11 CC=gcc
22 CXX=g++
3-SRCS=particle.cc particles.cc filter.cc edit.cc
3+SRCS=particle.cc particles.cc filter.cc
44 OBJS=$(SRCS:.cc=.o)
55 HEADS=$(SRCS:.cc=.h)
66 TARGETS=libparticle.a
Show on old repository browser