PLearn 0.1
Public Member Functions | Public Attributes
PLearn::BasisSelectionRegressor::thread_wawr Struct Reference
Collaboration diagram for PLearn::BasisSelectionRegressor::thread_wawr:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 thread_wawr (int thread_id_, int n_threads_, const TVec< RealFunc > &functions_, real &wsum_, Vec &E_x_, Vec &E_xx_, real &E_y_, real &E_yy_, Vec &E_xy_, const Vec &Y_, boost::mutex &ts_mx_, const VMat &train_set_, boost::mutex &pb_mx_, PP< ProgressBar > pb_, int thread_subtrain_length_)
void operator() ()

Public Attributes

int thread_id
int n_threads
const TVec< RealFunc > & functions
realwsum
VecE_x
VecE_xx
realE_y
realE_yy
VecE_xy
const VecY
boost::mutex & ts_mx
const VMattrain_set
boost::mutex & pb_mx
PP< ProgressBarpb
int thread_subtrain_length

Detailed Description

Definition at line 717 of file BasisSelectionRegressor.cc.


Constructor & Destructor Documentation

PLearn::BasisSelectionRegressor::thread_wawr::thread_wawr ( int  thread_id_,
int  n_threads_,
const TVec< RealFunc > &  functions_,
real wsum_,
Vec E_x_,
Vec E_xx_,
real E_y_,
real E_yy_,
Vec E_xy_,
const Vec Y_,
boost::mutex &  ts_mx_,
const VMat train_set_,
boost::mutex &  pb_mx_,
PP< ProgressBar pb_,
int  thread_subtrain_length_ 
) [inline]

Definition at line 734 of file BasisSelectionRegressor.cc.

        : thread_id(thread_id_), 
          n_threads(n_threads_),
          functions(functions_),
          wsum(wsum_),
          E_x(E_x_),
          E_xx(E_xx_),
          E_y(E_y_),
          E_yy(E_yy_),
          E_xy(E_xy_),
          Y(Y_),
          ts_mx(ts_mx_),
          train_set(train_set_),
          pb_mx(pb_mx_),
          pb(pb_),
          thread_subtrain_length(thread_subtrain_length_)
    {}

Member Function Documentation

void PLearn::BasisSelectionRegressor::thread_wawr::operator() ( ) [inline]

Definition at line 761 of file BasisSelectionRegressor.cc.

References PLearn::TVec< T >::append(), PLearn::TMat< T >::appendRow(), E_x, E_xx, E_xy, E_y, E_yy, PLearn::evaluate_functions(), PLearn::TVec< T >::fill(), functions, PLearn::VMat::getExample(), i, PLearn::BasisSelectionRegressor::input, j, PLearn::VMat::length(), PLearn::TVec< T >::length(), PLearn::min(), n_threads, pb, pb_mx, PLearn::TMat< T >::resize(), PLearn::TVec< T >::resize(), PLearn::BasisSelectionRegressor::targ, thread_id, thread_subtrain_length, train_set, ts_mx, w, wsum, and x.

    {
        Vec input, targ;
        real w;
        Vec candidate_features;
        int n_candidates = functions.length();
        int train_len = train_set->length();
     
        E_x.resize(n_candidates);
        E_x.fill(0.);
        E_xx.resize(n_candidates);
        E_xx.fill(0.);
        E_y = 0.;
        E_yy = 0.;
        E_xy.resize(n_candidates);
        E_xy.fill(0.);
        wsum = 0.;

        // Used when thread_subtrain_length > 1
        Mat all_inputs;
        Vec all_w;
        int input_size = train_set->inputsize();
        if (thread_subtrain_length > 1)
        {
            // pre-allocate memory
            all_inputs.resize(thread_subtrain_length, input_size);
            all_w.resize(thread_subtrain_length);
        }
   
        for(int i=thread_id; i<train_len; i+= n_threads)
        {
            if (thread_subtrain_length > 1)
            {
                int j = (i-thread_id)/n_threads;
                int j_mod = j % thread_subtrain_length;
                if (j_mod == 0)  // on doit faire le plein de donnees
                {
                    all_inputs.resize(0, input_size);
                    all_w.resize(0);

                    boost::mutex::scoped_lock lock(ts_mx);
                    int max_train = min(train_len, i + thread_subtrain_length*n_threads);
                    for (int ii=i; ii<max_train; ii+= n_threads)
                    {
                        train_set->getExample(ii, input, targ, w);
                        all_inputs.appendRow(input);
                        all_w.append(w);
                    }
                }
                input = all_inputs(j_mod);
                w = all_w[j_mod];
            }
            else
            {
                boost::mutex::scoped_lock lock(ts_mx);
                train_set->getExample(i, input, targ, w);
            }
            evaluate_functions(functions, input, candidate_features);
            wsum += w;
            real y = Y[i];
            real wy = w*y;
            E_y  += wy;
            E_yy  += wy*y;
            for(int j=0; j<n_candidates; j++)
            {
                real x = candidate_features[j];
                real wx = w*x;
                E_x[j] += wx;
                E_xx[j] += wx*x;
                E_xy[j] += wx*y;
            }
            if(pb)
            {
                boost::mutex::scoped_lock lock(pb_mx);
                if(pb->currentpos < static_cast<unsigned int>(i))
                    pb->update(i);
            }
        }
    }

Here is the call graph for this function:


Member Data Documentation

Definition at line 722 of file BasisSelectionRegressor.cc.

Referenced by operator()().

Definition at line 723 of file BasisSelectionRegressor.cc.

Referenced by operator()().

Definition at line 726 of file BasisSelectionRegressor.cc.

Referenced by operator()().

Definition at line 724 of file BasisSelectionRegressor.cc.

Referenced by operator()().

Definition at line 725 of file BasisSelectionRegressor.cc.

Referenced by operator()().

Definition at line 720 of file BasisSelectionRegressor.cc.

Referenced by operator()().

Definition at line 719 of file BasisSelectionRegressor.cc.

Referenced by operator()().

Definition at line 731 of file BasisSelectionRegressor.cc.

Referenced by operator()().

Definition at line 730 of file BasisSelectionRegressor.cc.

Referenced by operator()().

Definition at line 719 of file BasisSelectionRegressor.cc.

Referenced by operator()().

Definition at line 732 of file BasisSelectionRegressor.cc.

Referenced by operator()().

Definition at line 729 of file BasisSelectionRegressor.cc.

Referenced by operator()().

Definition at line 728 of file BasisSelectionRegressor.cc.

Referenced by operator()().

Definition at line 721 of file BasisSelectionRegressor.cc.

Referenced by operator()().

Definition at line 727 of file BasisSelectionRegressor.cc.


The documentation for this struct was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines