37 #endif //USE_GPL_SHOGUN
45 using namespace Eigen;
50 #ifndef DOXYGEN_SHOULD_SKIP_THIS
56 virtual ~SingleSparseInferenceCostFunction() {
SG_UNREF(m_obj); }
57 virtual const char* get_name()
const {
return "SingleSparseInferenceCostFunction"; }
60 REQUIRE(obj,
"Object not set\n");
67 REQUIRE(m_obj->m_fully_sparse,
"Can not compute gradient\n");
70 void unset_target(
bool is_unref)
80 REQUIRE(m_obj,
"Object not set\n");
81 float64_t nlz=m_obj->get_negative_log_marginal_likelihood();
86 REQUIRE(m_obj,
"Object not set\n");
93 REQUIRE(m_obj,
"Object not set\n");
94 m_obj->compute_gradient();
95 TParameter* param=m_obj->m_gradient_parameters->get_parameter(
"inducing_features");
101 REQUIRE(m_obj,
"Object not set\n");
102 return m_obj->m_lower_bound;
106 REQUIRE(m_obj,
"Object not set\n");
107 return m_obj->m_upper_bound;
120 #endif //DOXYGEN_SHOULD_SKIP_THIS
135 void CSingleSparseInference::init()
148 "max number of iterations used in inducing features optimization",
MS_NOT_AVAILABLE);
152 "opt_inducing_features",
"whether optimize inducing features",
MS_NOT_AVAILABLE);
155 "inducing_minimizer",
"Minimizer used in optimize inducing features",
MS_NOT_AVAILABLE);
183 SG_WARNING(
"The provided kernel does not support to optimize inducing features\n");
192 REQUIRE(param,
"Param not set\n");
194 && strcmp(param->
m_name,
"log_inducing_noise")
195 && strcmp(param->
m_name,
"inducing_features")),
196 "Can't compute derivative of"
197 " the nagative log marginal likelihood wrt %s.%s parameter\n",
200 if (!strcmp(param->
m_name,
"log_inducing_noise"))
204 else if (!strcmp(param->
m_name,
"inducing_features"))
212 SG_WARNING(
"Derivative wrt %s cannot be computed since the kernel does not support fully sparse inference\n",
243 REQUIRE(param,
"Param not set\n");
245 int64_t len=
const_cast<TParameter *
>(param)->m_datatype.get_num_elements();
288 "The length of inducing features (%dx%d)",
289 " and the length of bound constraints (%d) are different\n",
292 else if(bound.
vlen==1)
294 SG_WARNING(
"All inducing_features (%dx%d) are constrainted by the single value (%f) in the %s bound\n",
312 REQUIRE(it>0,
"Iteration (%d) must be positive\n",it);
318 REQUIRE(tol>0,
"Tolearance (%f) must be positive\n",tol);
327 REQUIRE(
m_fully_sparse,
"Please use a kernel which has the functionality about optimizing inducing features\n");
342 #ifdef USE_GPL_SHOGUN
348 SG_WARNING(
"We require NLOPT library for using default minimizer.\nYou can use other minimizer. (eg, LBFGSMinimier)\n");
352 SG_WARNING(
"We require NLOPT (GPL License) library for using default minimizer.\nYou can use other minimizer. (eg, LBFGSMinimier)");
353 #endif //USE_GPL_SHOGUN
364 cost_fun->set_target(
this);
366 if(this->ref_count()>1)
369 #ifdef USE_GPL_SHOGUN
375 #endif //USE_GPL_SHOGUN
380 cost_fun->unset_target(cleanup);
virtual const char * get_name() const =0
virtual bool init(CFeatures *lhs, CFeatures *rhs)
float64_t m_max_ind_iterations
virtual SGVector< float64_t > get_derivative_wrt_inference_method(const TParameter *param)
virtual void check_fully_sparse()
virtual void optimize_inducing_features()
The class Labels models labels, i.e. class assignments of objects.
virtual SGVector< float64_t > get_derivative_wrt_inducing_features(const TParameter *param)=0
virtual void set_kernel(CKernel *kern)
virtual void set_max_iterations_for_inducing_features(int32_t it)
SGVector< float64_t > m_upper_bound
FirstOrderMinimizer * m_inducing_minimizer
virtual void enable_optimizing_inducing_features(bool is_optmization, FirstOrderMinimizer *minimizer=NULL)
An abstract class of the mean function.
float64_t m_ind_tolerance
The first order cost function base class with bound constrains.
virtual void set_tolearance_for_inducing_features(float64_t tol)
Class SGObject is the base class of all shogun objects.
Class Lock used for synchronization in concurrent programs.
The sparse inference base class for classification and regression for 1-D labels (1D regression and b...
virtual ~CSingleSparseInference()
virtual const char * get_name() const
virtual SGVector< float64_t > get_derivative_wrt_kernel(const TParameter *param)
virtual void unset_cost_function(bool is_unref=true)
virtual void set_upper_bound_of_inducing_features(SGVector< float64_t > bound)
friend class SingleSparseInferenceCostFunction
virtual CFeatures * get_inducing_features()
virtual void set_kernel(CKernel *kern)
SGMatrix< float64_t > m_kuu
virtual float64_t minimize()=0
virtual void check_bound(SGVector< float64_t > bound, const char *name)
SGVector< float64_t > m_ktrtr_diag
SGVector< float64_t > m_lower_bound
virtual void set_lower_bound_of_inducing_features(SGVector< float64_t > bound)
all of classes and functions are contained in the shogun namespace
SGMatrix< float64_t > m_inducing_features
The class Features is the base class of all feature objects.
virtual float64_t get_derivative_related_cov(SGVector< float64_t > ddiagKi, SGMatrix< float64_t > dKuui, SGMatrix< float64_t > dKui)=0
static float64_t exp(float64_t x)
virtual SGMatrix< float64_t > get_parameter_gradient(const TParameter *param, index_t index=-1)
SGVector< T > clone() const
SGMatrix< float64_t > m_ktru
virtual SGVector< float64_t > get_derivative_wrt_inducing_noise(const TParameter *param)=0
The Fully Independent Conditional Training inference base class.
bool m_opt_inducing_features
virtual SGVector< float64_t > get_parameter_gradient_diagonal(const TParameter *param, index_t index=-1)
The Likelihood model base class.
virtual void set_cost_function(FirstOrderCostFunction *fun)
The first order minimizer base class.