6 #ifndef DISMEC_POINTWISE_H
7 #define DISMEC_POINTWISE_H
53 Eigen::Ref<DenseRealVector> target)
override;
84 return static_cast<const CRTP*
>(
this)->point_wise_value(x);
89 return static_cast<const CRTP*
>(
this)->point_wise_grad(x);
94 return static_cast<const CRTP*
>(
this)->point_wise_quad(x);
104 m_LastWeightIsBias(ignore_bias), m_Scale(scale) {
117 long loop_bound = get_loop_bound(location);
118 for (
long i = 0; i < loop_bound; ++i) {
119 result += point_wise_value_(location->coeff(i));
121 return m_Scale * result;
128 Eigen::Ref<DenseRealVector> target) {
132 long loop_bound = get_loop_bound(location);
133 for (
long i = 0; i < loop_bound; ++i) {
134 target.coeffRef(i) = m_Scale * point_wise_quad_(location->coeff(i)) * direction.coeff(i);
138 if (dont_regularize_bias())
139 target.coeffRef(loop_bound) =
real_t{0};
144 long loop_bound = get_loop_bound(location);
147 for (
long i = 0; i < loop_bound; ++i) {
148 target.coeffRef(i) = m_Scale * point_wise_grad_(location->coeff(i));
152 if (dont_regularize_bias())
153 target.coeffRef(target.size() - 1) =
real_t{0};
161 target.setConstant(grad_at_zero * m_Scale);
164 if (dont_regularize_bias())
165 target.coeffRef(target.size() - 1) =
real_t{0};
171 Eigen::Ref<DenseRealVector> target) {
173 long loop_bound = get_loop_bound(location);
174 for (
long i = 0; i < loop_bound; ++i) {
175 target.coeffRef(i) = m_Scale * point_wise_quad_(location->coeff(i));
178 if (dont_regularize_bias())
179 target.coeffRef(target.size() - 1) =
real_t{0};
185 m_LineStart = location.
get();
186 m_LineDirection = direction;
194 long loop_bound = dont_regularize_bias() ? m_LineStart.size() - 1u: m_LineStart.size();
195 for(
long i = 0; i < loop_bound; ++i) {
196 result += point_wise_value_(m_LineStart.coeff(i) + a * m_LineDirection.coeff(i));
198 return m_Scale * result;
An Eigen vector with versioning information, to implement simple caching of results.
const DenseRealVector & get() const
Gets a constant reference to the data of this vector.
Class that models an optimization objective.
Base class for pointwise regularization functions.
void gradient_at_zero_unchecked(Eigen::Ref< DenseRealVector > target) override
bool dont_regularize_bias() const
void hessian_times_direction_unchecked(const HashVector &location, const DenseRealVector &direction, Eigen::Ref< DenseRealVector > target) override
DenseRealVector m_LineDirection
PointWiseRegularizer(real_t scale=1, bool ignore_bias=false)
real_t point_wise_grad_(real_t x) const
calls point_wise_grad() of the implementing class
real_t value_unchecked(const HashVector &location) override
long get_loop_bound(const HashVector &location) const
void diag_preconditioner_unchecked(const HashVector &location, Eigen::Ref< DenseRealVector > target) override
void gradient_unchecked(const HashVector &location, Eigen::Ref< DenseRealVector > target) override
real_t point_wise_value_(real_t x) const
calls point_wise_value() of the implementing class
real_t scale() const
Returns the common scale factor for the entire regularizer.
DenseRealVector m_LineStart
real_t lookup_on_line(real_t a) override
Looks up the value of the objective on the line defined by the last call to project_to_line().
void project_to_line_unchecked(const HashVector &location, const DenseRealVector &direction) override
long num_variables() const noexcept final
The pointwise regularizer can act on arbitrarily sized vectors, so num_variables() == -1.
real_t point_wise_quad_(real_t x) const
calls point_wise_quad() of the implementing class
types::DenseVector< real_t > DenseRealVector
Any dense, real values vector.
float real_t
The default type for floating point values.
#define THROW_EXCEPTION(exception_type,...)