34 void CShareBoost::init_sb_params()
41 return m_activeset.
clone();
51 SG_ERROR(
"No features given for training\n")
53 SG_ERROR(
"No labels given for training\n")
55 if (m_nonzero_feas <= 0)
56 SG_ERROR(
"Set a valid (> 0) number of non-zero features to seek before training\n")
58 SG_ERROR(
"Number of non-zero features (%d) cannot be larger than number of features (%d) in the data\n",
77 for (int32_t t=0; t < m_nonzero_feas; ++t)
81 int32_t i_fea = choose_feature();
83 m_activeset.
vlen += 1;
86 optimize_coefficients();
89 SG_SDEBUG(
" SB[round %03d]: (%8.4f + %8.4f) sec.\n", t,
90 t_compute_pred + t_choose_feature, t_optimize);
108 void CShareBoost::compute_pred()
125 void CShareBoost::compute_pred(
const float64_t *W)
127 int32_t w_len = m_activeset.
vlen;
133 std::copy(W + i*w_len, W + (i+1)*w_len, w.vector);
140 void CShareBoost::compute_rho()
143 for (int32_t i=0; i < m_rho.
num_rows; ++i)
145 for (int32_t j=0; j < m_rho.
num_cols; ++j)
149 m_rho(i,j) =
CMath::exp((label == i) - m_pred(j, label) + m_pred(j, i));
154 for (int32_t j=0; j < m_rho.
num_cols; ++j)
157 for (int32_t i=0; i < m_rho.
num_rows; ++i)
158 m_rho_norm[j] += m_rho(i,j);
162 int32_t CShareBoost::choose_feature()
165 for (int32_t j=0; j < m_fea.
num_rows; ++j)
167 if (std::find(&m_activeset[0], &m_activeset[m_activeset.
vlen], j) !=
168 &m_activeset[m_activeset.
vlen])
179 for (int32_t ii=0; ii < m_fea.
num_cols; ++ii)
181 abssum += m_fea(j, ii)*(m_rho(k, ii)/m_rho_norm[ii] -
193 void CShareBoost::optimize_coefficients()
196 optimizer.optimize();
203 SG_ERROR(
"Require DenseFeatures<float64_t>\n")
Class Time that implements a stopwatch based on either cpu time or wall clock time.
SGVector< int32_t > get_activeset()
Real Labels are real-valued labels.
static int32_t arg_max(T *vec, int32_t inc, int32_t len, T *maxv_ptr=NULL)
virtual CRegressionLabels * apply_regression(CFeatures *data=NULL)
int32_t get_num_features() const
virtual void set_w(const SGVector< float64_t > src_w)
SGMatrix< ST > get_feature_matrix()
void set_features(CFeatures *f)
CDynamicObjectArray * m_machines
SGVector< float64_t > get_labels()
Multiclass Labels for multi-class classification.
float64_t cur_time_diff(bool verbose=false)
generic linear multiclass machine
CMulticlassStrategy * m_multiclass_strategy
int32_t get_int_label(int32_t idx)
float64_t start(bool verbose=false)
T * get_column_vector(index_t col) const
Class LinearMachine is a generic interface for all kinds of linear machines like classifiers.
int32_t get_num_classes() const
all of classes and functions are contained in the shogun namespace
void set_features(CDotFeatures *f)
virtual bool train_machine(CFeatures *data=NULL)
The class Features is the base class of all feature objects.
static float64_t exp(float64_t x)
SGVector< T > clone() const
CSGObject * get_element(int32_t index) const
void push_back(CSGObject *e)
CDotFeatures * m_features
multiclass one vs rest strategy used to train generic multiclass machines for K-class problems with b...