Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "uniform.h"
00019
00020 #include "../wrappers/rng/rng.h"
00021
00022 #include <cmath>
00023 #include <cassert>
00024
00025 namespace BFL
00026 {
00027 using namespace MatrixWrapper;
00028
00029 Uniform::Uniform (const ColumnVector& center, const ColumnVector& width)
00030 : Pdf<ColumnVector> ( center.rows() )
00031 , _samples(DimensionGet())
00032 {
00033
00034 assert (center.rows() == width.rows());
00035 _Lower = center - width/2.0;
00036 _Higher = center + width/2.0;
00037 _Height = 1;
00038 for (int i=1 ; i < width.rows()+1 ; i++ )
00039 {
00040 _Height = _Height / width(i);
00041 }
00042 }
00043
00044 Uniform::Uniform (int dimension)
00045 : Pdf<ColumnVector>(dimension)
00046 , _samples(dimension)
00047 {
00048 _Lower.resize(dimension);
00049 _Higher.resize(dimension);
00050 }
00051
00052 Uniform::~Uniform(){}
00053
00054 std::ostream& operator<< (std::ostream& os, const Uniform& u)
00055 {
00056 os << "\nCenter: \n" << u.CenterGet()
00057 << "\nWidth: \n" << u.WidthGet() << endl;
00058 return os;
00059 }
00060
00061
00062 Uniform* Uniform::Clone() const
00063 {
00064 return new Uniform(*this);
00065 }
00066
00067 Probability Uniform::ProbabilityGet(const ColumnVector& input) const
00068 {
00069
00070 for (int i=1; i<input.rows()+1; i++)
00071 {
00072 if ( ( input(i)>_Higher(i) ) || ( input(i) < _Lower(i) ) ) return 0;
00073 }
00074 return _Height;
00075 }
00076
00077 bool
00078 Uniform::SampleFrom (vector<Sample<ColumnVector> >& list_samples, const int num_samples, int method, void * args) const
00079 {
00080
00081 list_samples.resize(num_samples);
00082 vector<Sample<ColumnVector> >::iterator rit = list_samples.begin();
00083 switch(method)
00084 {
00085 case DEFAULT:
00086 {
00087 while (rit != list_samples.end())
00088 {
00089 for (unsigned int j=1; j < DimensionGet()+1; j++) _samples(j) = runif(_Lower(j) , _Higher(j) );
00090 rit->ValueSet(_samples);
00091 rit++;
00092 }
00093 return true;
00094 }
00095 default:
00096 return false;
00097 }
00098 }
00099
00100 bool
00101 Uniform::SampleFrom (Sample<ColumnVector>& one_sample, int method, void * args) const
00102 {
00103 switch(method)
00104 {
00105 case DEFAULT:
00106 {
00107 for (unsigned int j=1; j < DimensionGet()+1; j++) _samples(j) = runif(_Lower(j) , _Higher(j) );
00108 one_sample.ValueSet(_samples);
00109 return true;
00110 }
00111 default:
00112 return false;
00113 }
00114 }
00115
00116 ColumnVector
00117 Uniform::CenterGet ( ) const
00118 {
00119 return (_Higher+_Lower)/2.0;
00120 }
00121
00122 ColumnVector
00123 Uniform::WidthGet () const
00124 {
00125 return (_Higher-_Lower);
00126 }
00127
00128 void
00129 Uniform::UniformSet (const ColumnVector& center,const ColumnVector& width)
00130 {
00131 assert(center.rows() == width.rows());
00132 _Lower = center - width/2.0;
00133 _Higher = center + width/2.0;
00134 _Height = 1;
00135 for (int i=1 ; i < width.rows()+1 ; i++ )
00136 {
00137 _Height = _Height / width(i);
00138 }
00139 if (this->DimensionGet() == 0) this->DimensionSet(center.rows());
00140 assert(this->DimensionGet() == center.rows());
00141 }
00142
00143
00144 }
bfl
Author(s): Klaas Gadeyne, Wim Meeussen, Tinne Delaet and many others. See web page for a full contributor list. ROS package maintained by Wim Meeussen.
autogenerated on Fri Aug 28 2015 10:10:21