11 #include <shogun/lib/config.h> 21 using namespace Eigen;
69 "The labels should of type CBinaryLabels! Provided type is %s \n",
75 SG_ERROR(
"Specified features are not of type CDotFeatures\n")
81 REQUIRE(data,
"Features have not been provided.\n")
86 "Number of training examples(%d) should be equal to number of labels " 92 "LDA only works with dense features")
95 return CLDA::train_machine_templated<float32_t>();
97 return CLDA::train_machine_templated<float64_t>();
99 return CLDA::train_machine_templated<floatmax_t>();
104 template <
typename ST>
114 return solver_svd<ST>();
116 return solver_classic<ST>();
119 template <
typename ST>
125 const index_t projection_dim = 1;
126 auto solver = std::unique_ptr<LDACanVarSolver<ST>>(
134 auto class_mean = solver->get_class_mean();
139 float64_t sign = (m_pos > m_neg) ? 1 : -1;
143 for (
index_t i = 0; i < w.size(); ++i)
144 w[i] = sign * w_st[i];
147 set_bias(-0.5 * sign * (m_neg + m_pos));
152 template <
typename ST>
158 auto solver = std::unique_ptr<LDASolver<ST>>(
164 auto class_mean = solver->get_class_mean();
165 auto class_count = solver->get_class_count();
178 linalg::add(class_mean[1], class_mean[0], (ST)1, (ST)-1));
virtual const char * get_name() const =0
virtual bool train_machine(CFeatures *data=NULL)
virtual ELabelType get_label_type() const =0
virtual void set_w(const SGVector< float64_t > src_w)
The class Labels models labels, i.e. class assignments of objects.
virtual int32_t get_num_labels() const =0
SGMatrix< T > cholesky_factor(const SGMatrix< T > &A, const bool lower=true)
virtual int32_t get_num_vectors() const =0
void add(SGVector< T > &a, SGVector< T > &b, SGVector< T > &result, T alpha=1, T beta=1)
T dot(const SGVector< T > &a, const SGVector< T > &b)
CLDA(float64_t gamma=0, ELDAMethod method=AUTO_LDA, bool bdc_svd=true)
virtual void set_features(CDotFeatures *feat)
int32_t get_num_features() const
virtual CDotFeatures * get_features()
Features that support dot products among other operations.
bool train_machine_templated()
Multiclass Labels for multi-class classification.
SGVector< T > cholesky_solver(const SGMatrix< T > &L, const SGVector< T > &b, const bool lower=true)
virtual EFeatureClass get_feature_class() const =0
Class LinearMachine is a generic interface for all kinds of linear machines like classifiers.
all of classes and functions are contained in the shogun namespace
The class Features is the base class of all feature objects.
virtual void set_bias(float64_t b)
bool has_property(EFeatureProperty p) const
virtual void set_labels(CLabels *lab)
virtual EFeatureType get_feature_type() const =0