14 using namespace shogun;
26 void CLinearARDKernel::init()
35 #ifdef HAVE_LINALG_LIB
55 CDotKernel::init(l, r);
56 int32_t dim=((
CDotFeatures*) l)->get_dim_feature_space();
88 linalg::elementwise_product(
m_weights, rtmp, right);
90 linalg::matrix_product(
m_weights, rtmp, right);
92 SG_ERROR(
"Unsupported ARD kernel\n");
115 linalg::elementwise_product(
m_weights, ltmp, left_transpose);
117 linalg::matrix_product(
m_weights, ltmp, left_transpose);
119 SG_ERROR(
"Unsupported ARD kernel\n");
124 linalg::matrix_product(left, right, res);
125 return res[0]*scalar_weight;
135 return compute_helper(avec, bvec);
145 result=2.0*avec[index]*bvec[index]*
m_weights[index];
155 linalg::matrix_product(left, right, res);
167 linalg::matrix_product(left, row_vec_r, res);
168 result=res[0]*bvec[col_index];
171 linalg::matrix_product(row_vec_l, right, res);
172 result+=res[0]*avec[col_index];
177 SG_ERROR(
"Unsupported ARD kernel\n");
190 int32_t row_index, col_index;
193 REQUIRE(index>=0,
"Index (%d) must be non-negative\n",index);
204 "Row index (%d) must be within #row of weights (%d)\n",
207 "Column index (%d) must be within #column of weights (%d)\n",
211 if (!strcmp(param->
m_name,
"weights"))
221 derivative(j,k)=compute_gradient_helper(avec, bvec, 1.0, index);
228 SG_ERROR(
"Can't compute derivative wrt %s parameter\n", param->
m_name);
241 "Weight Matrix (%d-by-%d) must not be empty\n",
261 void CLinearARDKernel::set_scalar_weights(
float64_t weight)
265 set_weights(weights);
272 set_weights(weights_mat);
277 set_weights(weights);
279 #endif //HAVE_LINALG_LIB
SGVector< T > get_row_vector(index_t row) const
int32_t num_rhs
number of feature vectors on right hand side
Linear Kernel with Automatic Relevance Detection computed on CDotFeatures.
SGMatrix< float64_t > m_weights
virtual float64_t compute(int32_t idx_a, int32_t idx_b)
Features that support dot products among other operations.
EARDKernelType m_ARD_type
Template class DotKernel is the base class for kernels working on DotFeatures.
virtual ~CLinearARDKernel()
int32_t num_lhs
number of feature vectors on left hand side
virtual bool init_normalizer()
CFeatures * rhs
feature vectors to occur on right hand side
CFeatures * lhs
feature vectors to occur on left hand side
The class Features is the base class of all feature objects.
virtual SGMatrix< float64_t > get_parameter_gradient(const TParameter *param, index_t index=-1)
void set_const(T const_elem)