/usr/include/sopt/relative_variation.h is in libsopt-dev 2.0.0-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #ifndef SOPT_RELATIVE_VARIATION_H
#define SOPT_RELATIVE_VARIATION_H
#include "sopt/config.h"
#include <Eigen/Core>
#include "sopt/logging.h"
#include "sopt/maths.h"
namespace sopt {
template <class TYPE> class RelativeVariation {
public:
//! Underlying scalar type
typedef TYPE Scalar;
//! Underlying scalar type
typedef typename real_type<Scalar>::type Real;
//! Maximum variation from one step to the next
RelativeVariation(Real epsilon) : epsilon_(epsilon), previous(typename Array<Scalar>::Index(0)){};
//! Copy constructor
RelativeVariation(RelativeVariation const &c) : epsilon_(c.epsilon_), previous(c.previous){};
//! True if object has changed by less than epsilon
template <class T> bool operator()(Eigen::MatrixBase<T> const &input) {
return operator()(input.array());
}
//! True if object has changed by less than epsilon
template <class T> bool operator()(Eigen::ArrayBase<T> const &input) {
if(previous.size() != input.size()) {
previous = input;
return false;
}
auto const norm = (input - previous).matrix().squaredNorm();
previous = input;
SOPT_LOW_LOG(" - relative variation: {} <? {}", std::sqrt(norm), epsilon());
return norm < epsilon() * epsilon();
}
//! Allowed variation
Real epsilon() const { return epsilon_; }
//! Allowed variation
RelativeVariation &epsilon(Real &e) const {
epsilon_ = e;
return *this;
}
protected:
Real epsilon_;
Array<Scalar> previous;
};
} /* sopt */
#endif
|