12 #include "spdlog/spdlog.h"
24 std::unique_ptr<Objective> regularizer):
29 throw std::logic_error(
"feature matrix is not compressed.");
53 Eigen::Ref<DenseRealVector> gradient,
54 Eigen::Ref<DenseRealVector> pre)
59 template<
class T,
class U>
62 constexpr
bool calc_grad = !std::is_same_v<T, std::nullptr_t>;
63 constexpr
bool calc_pre = !std::is_same_v<U, std::nullptr_t>;
65 const auto& cost_vec =
costs();
66 const auto& label_vec =
labels();
74 for (
long i = 0; i < shortlist_size; ++i)
81 if constexpr (calc_grad) {
82 gradient.coeffRef(it.col()) += it.value() * vi;
84 if constexpr (calc_pre) {
85 pre.coeffRef(it.col()) += it.value() * it.value() * cost;
93 const auto& cost_vec =
costs();
94 const auto& label_vec =
labels();
96 for (
int i = 0; i < cost_vec.size(); ++i)
100 real_t vi = -cost * label_vec.coeff(i) ;
103 target.coeffRef(it.col()) += it.value() * vi;
125 const auto& lbl =
labels();
127 for(Eigen::Index i = 0; i < lbl.size(); ++i) {
128 real_t label = lbl.coeff(i);
This is an almost verbatim copy of the SparseFeatures::InnerIterator provided by Eigen.
An Eigen vector with versioning information, to implement simple caching of results.
VectorHash hash() const
Gets the unique id of this vector.
const SparseFeatures & sparse_features() const
const DenseRealVector & costs() const
const BinaryLabelVector & labels() const
const DenseRealVector & x_times_w(const HashVector &w)
Calculates the vector of feature matrix times weights w
Implementation helper for linear classifier derived classes.
void gradient(const HashVector &location, Eigen::Ref< DenseRealVector > target)
Evaluate the gradient at location.
std::vector< real_t > m_MVVal
void gradient_imp(const HashVector &location, Eigen::Ref< DenseRealVector > target)
void margin_error(const HashVector &w)
void hessian_times_direction_imp(const HashVector &location, const DenseRealVector &direction, Eigen::Ref< DenseRealVector > target)
void gradient_and_pre_conditioner_tpl(const HashVector &location, T &&gradient, U &&pre)
SparseFeatures features_t
void diag_preconditioner_imp(const HashVector &location, Eigen::Ref< DenseRealVector > target)
void gradient_and_pre_conditioner_imp(const HashVector &location, Eigen::Ref< DenseRealVector > gradient, Eigen::Ref< DenseRealVector > pre)
Regularized_SquaredHingeSVC(std::shared_ptr< const GenericFeatureMatrix > X, std::unique_ptr< Objective > regularizer)
void gradient_at_zero_imp(Eigen::Ref< DenseRealVector > target)
const features_t & features() const
std::vector< int > m_MVPos
void invalidate_labels() override
void record(stat_id_t stat, T &&value)
Record statistics. This function just forwards all its arguments to the internal StatisticsCollection...
void declare_stat(stat_id_t index, StatisticMetaData meta)
Declares a new statistics. This function just forwards all its arguments to the internal StatisticsCo...
constexpr const stat_id_t STAT_GRAD_SPARSITY
void htd_sum(const std::vector< int > &indices, Eigen::Ref< DenseRealVector > output, const SparseFeatures &features, const DenseRealVector &costs, const DenseRealVector &direction)
opaque_int_type< detail::stat_id_tag > stat_id_t
An opaque int-like type that is used to identify a statistic in a StatisticsCollection.
constexpr long to_long(T value)
Convert the given value to long, throwing an error if the conversion is not possible.
types::DenseVector< real_t > DenseRealVector
Any dense, real values vector.
float real_t
The default type for floating point values.