|
Ublas : |
From: Gunter Winkler (guwi17_at_[hidden])
Date: 2006-06-08 06:08:50
On Thursday 08 June 2006 11:33, dvir schirman wrote:
> I am not sure that my mistake is with ublas, but it seems to me that it is.
> I'm using Cygwin g++ 3.4.4
It looks like a C++ issue, so I give some general advice. Maybe you have a
look at
http://www.amazon.de/exec/obidos/ASIN/1852334886/ref=cm_lm_fullview_prod_4/302-8023137-4072851?%5Fencoding=UTF8
about your code:
* put all initializations between : and {}
* use copy constructor wherever possible
base_functions::base_functions(ublas::vector<float> covariance,
ublas::vector<float> x)
: function_num(0) <- new
, initial_cov(covariance) <- new
, weights(new C_weights())
{
//function_num=0;
//initial_cov=covariance; <-- var. may not be initialized
//weights=new_weights;
build_new_function((float)INITIAL_VALUE,(float) INITIAL_DELTA,x);
}
-----------------------
* use references if you want to modify parameters
* use const (ref) if you don't
* (advanced technique) use const member functions if you don't modify the data
of your class/instance
* initialize _all_ variables at the time of declaration
void base_functions::update(ublas::vector<float> &x, const float eta, const
float noise, const float delta)
{
get_previous_b_vec();
weights->update_weights(eta, noise,delta,b_vec ,get_function_num());
boost::numeric::ublas::vector<float> new_x, vec, vec2, vec3, delta_mu;
[...]
new_x.resize( x.size()); <- bad style, may fail if new_x is not initialized
vec.resize(x.size());
[...]
* better:
boost::numeric::ublas::vector<float> new_x(x.size())
, vec(x.size())
, vec2(x.size()) ...
HTH
Gunter
PS: prefer attachements over inlined code