|
Ublas : |
From: dvir schirman (dvir.boost_at_[hidden])
Date: 2006-06-06 10:28:32
ok here is my code:
main.C
--------------
#include "tdagent.H"
#include "simple_env.H"
#include <iostream.h>
#include <vector>
int main()
{
simple_env *env;
tdagent *agent;
boost::numeric::ublas::vector<float> aaa;
aaa.resize(3);
std::vector<float> uu;
env->create();
int flag=1;
while(flag)
{
boost::numeric::ublas::vector<float> v1(3);
v1=env->get_state();
boost::numeric::ublas::vector<float> v2(3);
v2=env->get_final_state();
if(v1(0)==v2(0) && v1(1)==v2(1) && v1(2)==v2(2))
flag=0;
uu=agent->find_next_action();
env->preform(uu[0]);
}
return 1;
}
simple_env.H
-----------------------------
#ifndef SIMPLE_ENV_H
#define SIMPLE_ENV_H
#include <math.h>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
#include <boost/numeric/ublas/vector_proxy.hpp>
#define PI 3.1415926535897932384626433832795
class simple_env
{
public:
simple_env();
~simple_env();
void create();
float preform(float u);
float get_reward();
boost::numeric::ublas::vector<float> get_state();
boost::numeric::ublas::vector<float> get_previous_state();
boost::numeric::ublas::vector<float> get_final_state();
boost::numeric::ublas::vector<float> get_cov();
int get_actions_num();
float get_min_reward();
float get_max_reward();
private:
float sigmoid(float u);
float reward;
boost::numeric::ublas::vector<float> state;
boost::numeric::ublas::vector<float> prev_state;
boost::numeric::ublas::vector<float> final_state;
boost::numeric::ublas::vector<float> cov;
};
#endif
simple_env.C
---------------------------------
include "simple_env.H"
namespace ublas = boost::numeric::ublas;
using namespace boost::numeric::ublas;
simple_env::simple_env()
{
cov(3);
}
simple_env::~simple_env()
{
}
void simple_env::create()
{
cov.resize(3);
for (unsigned int i = 0; i < 3; ++ i)
cov (i) = 1;
vector<float> initial_state(3);
for (unsigned int i = 0; i < initial_state.size (); ++ i)
initial_state (i) = 0;
vector<float> final_state(3);
for (unsigned int i = 0; i < final_state.size (); ++ i)
final_state (i) = 5;
state=initial_state;
return;
}
at main.C when I write:
boost::numeric::ublas::vector<float> aaa;
aaa.resize(3);
there is no problem.
but when the program enters env->create()
and reaches, cov.resize(3), it failes with a segmentation fault.
Thanks,
Dvir
On 6/6/06, Ian McCulloch <ianmcc_at_[hidden]> wrote:
>
> dvir schirman wrote:
>
> > I see I didnt make myself clear.
> >
> > I wrote:
> > boost::numeric::ublas::vector a;
> >
> > at my header file.
> >
> > and wrote:
> > a.resize(3);
> >
> > at my implementation file.
> > So, as I see it, it should work this way.
> >
>
> Threads like this are practically useless without a full example (but as
> short as possible!) that demonstrates the problem.
>
> Can you post the exact code that you compiled (after trimming out anything
> that is unnecessary), and the steps we need to follow to reproduce the
> problem.
>
> Cheers,
> Ian
>
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
>