SOPT
Sparse OPTimisation
Namespaces | Classes | Typedefs | Functions
sopt Namespace Reference

Namespaces

 algorithm
 
 cppflowutils
 
 credible_region
 
 details
 
 gradient_operator
 
 logging
 
 mpi
 
 objective_functions
 
 proximal
 Holds some standard proximals.
 
 tools
 
 utilities
 
 wavelets
 

Classes

class  ConjugateGradient
 Solves $Ax = b$ for $x$, given $A$ and $b$. More...
 
class  Exception
 Root exception for sopt. More...
 
class  IterationState
 
class  L2DifferentiableFunc
 
class  LinearTransform
 Joins together direct and indirect operators. More...
 
class  ONNXDifferentiableFunc
 
class  ORTsession
 Sopt interface class to hold a ONNXrt session. More...
 
struct  is_complex
 True if underlying type is complex. More...
 
struct  is_complex< std::complex< T >, void >
 True if underlying type is complex. More...
 
class  RelativeVariation
 
class  ScalarRelativeVariation
 
class  Sampling
 An operator that samples a set of measurements. More...
 
struct  CData
 

Typedefs

template<typename T >
using real_type = details::underlying_value_type< T >
 Gets to the underlying real type. More...
 
using t_int = int
 Root of the type hierarchy for signed integers. More...
 
using t_uint = size_t
 Root of the type hierarchy for unsigned integers. More...
 
using t_real = double
 Root of the type hierarchy for real numbers. More...
 
using t_complex = std::complex< t_real >
 Root of the type hierarchy for (real) complex numbers. More...
 
template<typename T = t_real>
using Vector = Eigen::Matrix< T, Eigen::Dynamic, 1 >
 A vector of a given type. More...
 
template<typename T = t_real>
using Matrix = Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic >
 A matrix of a given type. More...
 
template<typename T = t_real>
using Array = Eigen::Array< T, Eigen::Dynamic, 1 >
 A 1-dimensional list of elements of given type. More...
 
template<typename T = t_real>
using Image = Eigen::Array< T, Eigen::Dynamic, Eigen::Dynamic >
 A 2-dimensional list of elements of given type. More...
 
template<typename VECTOR = Vector<>>
using OperatorFunction = std::function< void(VECTOR &, VECTOR const &)>
 Typical function out = A*x. More...
 
template<typename SCALAR = t_real>
using ProximalFunction = std::function< void(Vector< SCALAR > &output, typename real_type< SCALAR >::type const weight, Vector< SCALAR > const &input)>
 Typical function signature for calls to proximal. More...
 
template<typename SCALAR = t_real>
using ConvergenceFunction = std::function< bool(Vector< SCALAR > const &)>
 Typical function signature for convergence. More...
 

Functions

template<typename K >
std::enable_if< std::is_same< t_real, K >::value, K >::type bisection_method (const K &function_value, const std::function< K(K)> &func, const K &a, const K &b, const t_real &rel_convergence=1e-4)
 Find root to a function within an interval. More...
 
template<typename T0 , typename... T>
OperatorFunction< T0 > chained_operators (OperatorFunction< T0 > const &arg0, T const &... args)
 
std::string version ()
 Returns library version. More...
 
std::tuple< uint8_t, uint8_t, uint8_t > version_tuple ()
 Returns library version. More...
 
std::string gitref ()
 Returns library git reference, if known. More...
 
std::string default_logging_level ()
 Default logging level. More...
 
std::string default_logger_name ()
 Default logger name. More...
 
constexpr std::size_t number_of_threads_in_tests ()
 Number of threads used during testing. More...
 
template<typename VECTOR >
LinearTransform< VECTOR > linear_transform (OperatorFunction< VECTOR > const &direct, OperatorFunction< VECTOR > const &indirect, std::array< t_int, 3 > const &sizes={{1, 1, 0}})
 
template<typename VECTOR >
LinearTransform< VECTOR > linear_transform (OperatorFunction< VECTOR > const &direct, std::array< t_int, 3 > const &dsizes, OperatorFunction< VECTOR > const &indirect, std::array< t_int, 3 > const &isizes)
 
template<typename VECTOR >
LinearTransform< VECTOR > & linear_transform (LinearTransform< VECTOR > &passthrough)
 Convenience no-op function. More...
 
template<typename VECTOR >
LinearTransform< VECTOR > linear_transform (details::WrapFunction< VECTOR > const &direct, details::WrapFunction< VECTOR > const &adjoint)
 Creates a linear transform from a pair of wrappers. More...
 
template<typename DERIVED >
LinearTransform< Vector< typename DERIVED::Scalar > > linear_transform (Eigen::MatrixBase< DERIVED > const &A)
 Helper function to creates a function operator. More...
 
template<typename SCALAR >
LinearTransform< Vector< SCALAR > > linear_transform_identity ()
 Helper function to create a linear transform that's just the identity. More...
 
template<typename T >
real_type< typename T::Scalar >::type standard_deviation (Eigen::ArrayBase< T > const &x)
 Computes the standard deviation of a vector. More...
 
template<typename T >
real_type< typename T::Scalar >::type standard_deviation (Eigen::MatrixBase< T > const &x)
 Computes the standard deviation of a vector. More...
 
template<typename SCALAR >
std::enable_if< std::is_arithmetic< SCALAR >::value or is_complex< SCALAR >::value, SCALAR >::type soft_threshhold (SCALAR const &x, typename real_type< SCALAR >::type const &threshhold)
 abs(x) < threshhold ? 0: x - sgn(x) * threshhold More...
 
template<typename T >
Eigen::CwiseUnaryOp< const details::ProjectPositiveQuadrant< typename T::Scalar >, const T > positive_quadrant (Eigen::DenseBase< T > const &input)
 Expression to create projection onto positive quadrant. More...
 
template<typename T >
Eigen::CwiseUnaryOp< const details::SoftThreshhold< typename T::Scalar >, const T > soft_threshhold (Eigen::DenseBase< T > const &input, typename real_type< typename T::Scalar >::type const &threshhold)
 Expression to create soft-threshhold. More...
 
template<typename T0 , typename T1 >
std::enable_if< std::is_arithmetic< typename T0::Scalar >::value and std::is_arithmetic< typename T1::Scalar >::value, Eigen::CwiseBinaryOp< typename T0::Scalar(*)(typename T0::Scalar const &, typename T1::Scalar const &), const T0, const T1 > >::type soft_threshhold (Eigen::DenseBase< T0 > const &input, Eigen::DenseBase< T1 > const &threshhold)
 Expression to create soft-threshhold with multiple parameters. More...
 
template<typename T0 , typename T1 >
std::enable_if< is_complex< typename T0::Scalar >::value and std::is_arithmetic< typename T1::Scalar >::value, Eigen::CwiseBinaryOp< typename T0::Scalar(*)(typename T0::Scalar const &, typename T0::Scalar const &), const T0, decltype(std::declval< const T1 >).template cast< typename T0::Scalar >))> >::type soft_threshhold (Eigen::DenseBase< T0 > const &input, Eigen::DenseBase< T1 > const &threshhold)
 Expression to create soft-threshhold with multiple parameters. More...
 
template<typename T0 , typename T1 >
real_type< typename T0::Scalar >::type l1_norm (Eigen::ArrayBase< T0 > const &input, Eigen::ArrayBase< T1 > const &weights)
 Computes weighted L1 norm. More...
 
template<typename T0 , typename T1 >
real_type< typename T0::Scalar >::type l1_norm (Eigen::MatrixBase< T0 > const &input, Eigen::MatrixBase< T1 > const &weight)
 Computes weighted L1 norm. More...
 
template<typename T0 >
real_type< typename T0::Scalar >::type l1_norm (Eigen::ArrayBase< T0 > const &input)
 Computes L1 norm. More...
 
template<typename T0 >
real_type< typename T0::Scalar >::type l1_norm (Eigen::MatrixBase< T0 > const &input)
 Computes L1 norm. More...
 
template<typename T0 , typename T1 >
real_type< typename T0::Scalar >::type l2_norm (Eigen::ArrayBase< T0 > const &input, Eigen::ArrayBase< T1 > const &weights)
 Computes weighted L2 norm. More...
 
template<typename T0 , typename T1 >
real_type< typename T0::Scalar >::type l2_norm (Eigen::MatrixBase< T0 > const &input, Eigen::MatrixBase< T1 > const &weights)
 Computes weighted L2 norm. More...
 
template<typename T0 >
real_type< typename T0::Scalar >::type l2_norm (Eigen::ArrayBase< T0 > const &input)
 Computes weighted L2 norm. More...
 
template<typename T0 >
real_type< typename T0::Scalar >::type l2_norm (Eigen::MatrixBase< T0 > const &input)
 Computes weighted L2 norm. More...
 
template<typename T0 , typename T1 >
real_type< typename T0::Scalar >::type tv_norm (Eigen::ArrayBase< T0 > const &input, Eigen::ArrayBase< T1 > const &weights)
 Computes weighted TV norm. More...
 
template<typename T0 , typename T1 >
real_type< typename T0::Scalar >::type tv_norm (Eigen::MatrixBase< T0 > const &input, Eigen::MatrixBase< T1 > const &weights)
 Computes weighted TV norm. More...
 
template<typename T0 >
real_type< typename T0::Scalar >::type tv_norm (Eigen::ArrayBase< T0 > const &input)
 Computes weighted tv norm. More...
 
template<typename T0 >
real_type< typename T0::Scalar >::type tv_norm (Eigen::MatrixBase< T0 > const &input)
 Computes weighted TV norm. More...
 
template<typename T >
LinearTransform< Vector< T > > linear_transform (Sampling const &sampling)
 Returns linear transform version of this object. More...
 
template<typename T >
LinearTransform< Vector< T > > linear_transform (wavelets::Wavelet const &wavelet)
 Thin linear-transform wrapper around 1d wavelets. More...
 
template<typename T >
LinearTransform< Vector< T > > linear_transform (wavelets::SARA const &sara)
 Thin linear-transform wrapper around 1d sara operator. More...
 
template<typename T >
LinearTransform< Vector< T > > linear_transform (wavelets::Wavelet const &wavelet, t_uint rows, t_uint cols=1)
 Thin linear-transform wrapper around 2d wavelets. More...
 
template<typename T >
LinearTransform< Vector< T > > linear_transform (wavelets::SARA const &sara, t_uint rows, t_uint cols=1)
 Thin linear-transform wrapper around 2d wavelets. More...
 
template<typename T >
void direct_transform (void *out, void *in, void **data)
 
template<typename T >
void adjoint_transform (void *out, void *in, void **data)
 
template<typename T >
Vector< T > target (sopt::LinearTransform< Vector< T >> const &sampling, sopt::Image< T > const &image)
 
template<typename T >
real_type< T >::type sigma (sopt::LinearTransform< Vector< T >> const &sampling, sopt::Image< T > const &image)
 
template<typename T , typename RANDOM >
Vector< T > dirty (sopt::LinearTransform< Vector< T >> const &sampling, sopt::Image< T > const &image, RANDOM &mersenne)
 
template<typename T >
real_type< T >::type epsilon (sopt::LinearTransform< Vector< T >> const &sampling, sopt::Image< T > const &image)
 

Typedef Documentation

◆ Array

template<typename T = t_real>
using sopt::Array = typedef Eigen::Array<T, Eigen::Dynamic, 1>

A 1-dimensional list of elements of given type.

Operates coefficient-wise, not matrix-vector-wise

Definition at line 34 of file types.h.

◆ ConvergenceFunction

template<typename SCALAR = t_real>
using sopt::ConvergenceFunction = typedef std::function<bool(Vector<SCALAR> const &)>

Typical function signature for convergence.

Definition at line 52 of file types.h.

◆ Image

template<typename T = t_real>
using sopt::Image = typedef Eigen::Array<T, Eigen::Dynamic, Eigen::Dynamic>

A 2-dimensional list of elements of given type.

Operates coefficient-wise, not matrix-vector-wise

Definition at line 39 of file types.h.

◆ Matrix

template<typename T = t_real>
using sopt::Matrix = typedef Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>

A matrix of a given type.

Operates as mathematical matrix.

Definition at line 29 of file types.h.

◆ OperatorFunction

template<typename VECTOR = Vector<>>
using sopt::OperatorFunction = typedef std::function<void(VECTOR &, VECTOR const &)>

Typical function out = A*x.

Definition at line 43 of file types.h.

◆ ProximalFunction

template<typename SCALAR = t_real>
using sopt::ProximalFunction = typedef std::function<void(Vector<SCALAR> &output, typename real_type<SCALAR>::type const weight, Vector<SCALAR> const &input)>

Typical function signature for calls to proximal.

Definition at line 47 of file types.h.

◆ real_type

template<typename T >
using sopt::real_type = typedef details::underlying_value_type<T>

Gets to the underlying real type.

Definition at line 56 of file real_type.h.

◆ t_complex

using sopt::t_complex = typedef std::complex<t_real>

Root of the type hierarchy for (real) complex numbers.

Definition at line 19 of file types.h.

◆ t_int

using sopt::t_int = typedef int

Root of the type hierarchy for signed integers.

Definition at line 13 of file types.h.

◆ t_real

using sopt::t_real = typedef double

Root of the type hierarchy for real numbers.

Definition at line 17 of file types.h.

◆ t_uint

using sopt::t_uint = typedef size_t

Root of the type hierarchy for unsigned integers.

Definition at line 15 of file types.h.

◆ Vector

template<typename T = t_real>
using sopt::Vector = typedef Eigen::Matrix<T, Eigen::Dynamic, 1>

A vector of a given type.

Operates as mathematical vector.

Definition at line 24 of file types.h.

Function Documentation

◆ adjoint_transform()

template<typename T >
void sopt::adjoint_transform ( void *  out,
void *  in,
void **  data 
)

Definition at line 27 of file cdata.h.

27  {
28  CData<T> const &cdata = *(CData<T> *)data;
29  using t_Vector = Eigen::Matrix<T, Eigen::Dynamic, 1>;
30  t_Vector const eval = cdata.transform.adjoint() * t_Vector::Map((T *)in, cdata.nout);
31  ++(((CData<T> *)data)->adjoint_calls);
32  t_Vector::Map((T *)out, cdata.nin) = eval;
33 }
sopt::Vector< Scalar > t_Vector

References sopt::LinearTransform< VECTOR >::adjoint(), sopt::CData< T >::nin, sopt::CData< T >::nout, and sopt::CData< T >::transform.

◆ bisection_method()

template<typename K >
std::enable_if< std::is_same< t_real, K >::value, K >::type sopt::bisection_method ( const K &  function_value,
const std::function< K(K)> &  func,
const K &  a,
const K &  b,
const t_real rel_convergence = 1e-4 
)

Find root to a function within an interval.

Definition at line 18 of file bisection_method.h.

20  {
21  t_real lower_eta = a;
22  t_real upper_eta = b;
23  t_real relative_difference = 1;
24  t_real eta = (a + b) * 0.5;
25  SOPT_LOW_LOG("Starting bisection method over x ∈ [{}, {}], to estimate f(x) = {}", a, b,
26  function_value);
27  const auto estimate = [&](const K &x) { return func(x) - function_value; };
28  const t_real eb = estimate(b);
29  const t_real ea = estimate(a);
30  if (eb == 0) return b;
31  if (ea == 0) return a;
32  if ((ea > 0 and eb > 0) or (ea < 0 and eb < 0))
33  SOPT_THROW("f(a) = " << ea << " and f(b) = " << eb
34  << " have the wrong sign."
35  "Where a = "
36  << a << " and b = " << b
37  << " Bisection Method not applicable for "
38  "this function.");
39  const auto sign = [&](const K &x) { return (x > 0) ? 1 : ((x < 0) ? -1 : 0); };
40  // SOPT_LOW_LOG("Convergence when: |f((a+b)/2) -f(x)| < {} or |a - b| < {}", rel_convergence,
41  // rel_convergence);
42  while (rel_convergence < relative_difference or
43  std::abs(upper_eta - lower_eta) > rel_convergence) {
44  if (upper_eta == lower_eta) SOPT_THROW("a == b, something is wrong.");
45  eta = (lower_eta + upper_eta) * 0.5;
46  auto const function_est = estimate(eta);
47  if (sign(estimate(lower_eta)) == sign(estimate(eta)))
48  lower_eta = eta;
49  else
50  upper_eta = eta;
51  relative_difference = std::abs(function_est);
52  assert(!(estimate(lower_eta) > 0 and estimate(upper_eta) > 0) and
53  !(estimate(lower_eta) < 0 and estimate(upper_eta) < 0));
54  // SOPT_LOW_LOG("|f(x_0) - f(x)| = {}, x = {}, [{}, {}]", relative_difference, eta, lower_eta,
55  // upper_eta);
56  }
57  return eta;
58 }
constexpr Scalar b
constexpr Scalar a
#define SOPT_THROW(MSG)
Definition: exception.h:46
sopt::t_real t_real
#define SOPT_LOW_LOG(...)
Low priority message.
Definition: logging.h:227

References a, b, SOPT_LOW_LOG, and SOPT_THROW.

Referenced by sopt::credible_region::find_credible_interval(), and TEST_CASE().

◆ chained_operators()

template<typename T0 , typename... T>
OperatorFunction<T0> sopt::chained_operators ( OperatorFunction< T0 > const &  arg0,
T const &...  args 
)

Definition at line 12 of file chained_operators.h.

12  {
13  if (sizeof...(args) == 0) return arg0;
14 
15  std::vector<OperatorFunction<T0>> const funcs = {arg0, args...};
16  const std::shared_ptr<T0> buffer = std::make_shared<T0>();
17  OperatorFunction<T0> result = [funcs, buffer](T0 &output, T0 const &input) -> void {
18  auto first = funcs.rbegin();
19  auto const last = funcs.rend();
20  if (funcs.size() == 1)
21  (*first)(output, input);
22  else if (funcs.size() % 2 == 1)
23  (*first)(output, input);
24  else {
25  (*first)(*buffer, input);
26  first++;
27  (*first)(output, *buffer);
28  }
29  for (++first; first != last; first++) {
30  (*first)(*buffer, output);
31  first++;
32  (*first)(output, *buffer);
33  }
34  };
35  return result;
36 }

Referenced by TEST_CASE().

◆ default_logger_name()

std::string sopt::default_logger_name ( )
inline

Default logger name.

Definition at line 47 of file config.in.h.

47 { return "@SOPT_LOGGER_NAME@"; }

◆ default_logging_level()

std::string sopt::default_logging_level ( )
inline

Default logging level.

Definition at line 44 of file config.in.h.

44 { return "@SOPT_TEST_LOG_LEVEL@"; }

◆ direct_transform()

template<typename T >
void sopt::direct_transform ( void *  out,
void *  in,
void **  data 
)

Definition at line 19 of file cdata.h.

19  {
20  CData<T> const &cdata = *(CData<T> *)data;
21  using t_Vector = Eigen::Matrix<T, Eigen::Dynamic, 1>;
22  t_Vector const eval = cdata.transform * t_Vector::Map((T *)in, cdata.nin);
23  ++(((CData<T> *)data)->direct_calls);
24  t_Vector::Map((T *)out, cdata.nout) = eval;
25 }

References sopt::CData< T >::nin, sopt::CData< T >::nout, and sopt::CData< T >::transform.

◆ dirty()

template<typename T , typename RANDOM >
Vector<T> sopt::dirty ( sopt::LinearTransform< Vector< T >> const &  sampling,
sopt::Image< T > const &  image,
RANDOM &  mersenne 
)

Definition at line 25 of file inpainting.h.

26  {
27  // values near the mean are the most likely
28  // standard deviation affects the dispersion of generated values from the mean
29  auto const y0 = target(sampling, image);
30  std::normal_distribution<> gaussian_dist(0, sigma(sampling, image));
31  Vector<T> y(y0.size());
32  for (t_int i = 0; i < y0.size(); i++) y(i) = y0(i) + gaussian_dist(mersenne);
33 
34  return y;
35 }
std::unique_ptr< std::mt19937_64 > mersenne(new std::mt19937_64(0))
int t_int
Root of the type hierarchy for signed integers.
Definition: types.h:13
Vector< T > target(sopt::LinearTransform< Vector< T >> const &sampling, sopt::Image< T > const &image)
Definition: inpainting.h:12
real_type< T >::type sigma(sopt::LinearTransform< Vector< T >> const &sampling, sopt::Image< T > const &image)
Definition: inpainting.h:17
sopt::Vector< Scalar > Vector
Definition: inpainting.cc:28

References mersenne(), sigma(), and target().

Referenced by main().

◆ epsilon()

template<typename T >
real_type<T>::type sopt::epsilon ( sopt::LinearTransform< Vector< T >> const &  sampling,
sopt::Image< T > const &  image 
)

Definition at line 38 of file inpainting.h.

39  {
40  auto const y0 = target(sampling, image);
41  auto const nmeasure = y0.size();
42  return std::sqrt(nmeasure + 2 * std::sqrt(nmeasure)) * sigma(sampling, image);
43 }

References sigma(), and target().

Referenced by function_cg(), main(), matrix_cg(), and TEST_CASE().

◆ gitref()

std::string sopt::gitref ( )
inline

Returns library git reference, if known.

Definition at line 41 of file config.in.h.

41 { return "@SOPT_GITREF@"; }

◆ l1_norm() [1/4]

template<typename T0 >
real_type<typename T0::Scalar>::type sopt::l1_norm ( Eigen::ArrayBase< T0 > const &  input)

Computes L1 norm.

Definition at line 129 of file maths.h.

129  {
130  return input.cwiseAbs().sum();
131 }

◆ l1_norm() [2/4]

template<typename T0 , typename T1 >
real_type<typename T0::Scalar>::type sopt::l1_norm ( Eigen::ArrayBase< T0 > const &  input,
Eigen::ArrayBase< T1 > const &  weights 
)

Computes weighted L1 norm.

Definition at line 116 of file maths.h.

117  {
118  if (weights.size() == 1) return input.cwiseAbs().sum() * std::abs(weights(0));
119  return (input * weights).cwiseAbs().sum();
120 }

Referenced by sopt::algorithm::L1GProximal< SCALAR >::function(), sopt::algorithm::TFGProximal< SCALAR >::function(), l1_norm(), main(), sopt::proximal::L1TightFrame< SCALAR >::objective(), TEST_CASE(), and sopt::objective_functions::unconstrained_l1_regularisation().

◆ l1_norm() [3/4]

template<typename T0 >
real_type<typename T0::Scalar>::type sopt::l1_norm ( Eigen::MatrixBase< T0 > const &  input)

Computes L1 norm.

Definition at line 134 of file maths.h.

134  {
135  return l1_norm(input.array());
136 }
real_type< typename T0::Scalar >::type l1_norm(Eigen::MatrixBase< T0 > const &input)
Computes L1 norm.
Definition: maths.h:134

References l1_norm().

◆ l1_norm() [4/4]

template<typename T0 , typename T1 >
real_type<typename T0::Scalar>::type sopt::l1_norm ( Eigen::MatrixBase< T0 > const &  input,
Eigen::MatrixBase< T1 > const &  weight 
)

Computes weighted L1 norm.

Definition at line 123 of file maths.h.

124  {
125  return l1_norm(input.array(), weight.array());
126 }

References l1_norm().

◆ l2_norm() [1/4]

template<typename T0 >
real_type<typename T0::Scalar>::type sopt::l2_norm ( Eigen::ArrayBase< T0 > const &  input)

Computes weighted L2 norm.

Definition at line 153 of file maths.h.

153  {
154  typename T0::PlainObject w(1);
155  w(0) = 1;
156  return l2_norm(input, w);
157 }
real_type< typename T0::Scalar >::type l2_norm(Eigen::MatrixBase< T0 > const &input)
Computes weighted L2 norm.
Definition: maths.h:160

References l2_norm().

◆ l2_norm() [2/4]

template<typename T0 , typename T1 >
real_type<typename T0::Scalar>::type sopt::l2_norm ( Eigen::ArrayBase< T0 > const &  input,
Eigen::ArrayBase< T1 > const &  weights 
)

Computes weighted L2 norm.

Definition at line 140 of file maths.h.

141  {
142  if (weights.size() == 1) return input.matrix().stableNorm() * std::abs(weights(0));
143  return (input * weights).matrix().stableNorm();
144 }

Referenced by l2_norm(), main(), TEST_CASE(), and sopt::objective_functions::unconstrained_regularisation().

◆ l2_norm() [3/4]

template<typename T0 >
real_type<typename T0::Scalar>::type sopt::l2_norm ( Eigen::MatrixBase< T0 > const &  input)

Computes weighted L2 norm.

Definition at line 160 of file maths.h.

160  {
161  typename T0::PlainObject w(1);
162  w(0) = 1;
163  return l2_norm(input.derived().array(), w.array());
164 }

References l2_norm().

◆ l2_norm() [4/4]

template<typename T0 , typename T1 >
real_type<typename T0::Scalar>::type sopt::l2_norm ( Eigen::MatrixBase< T0 > const &  input,
Eigen::MatrixBase< T1 > const &  weights 
)

Computes weighted L2 norm.

Definition at line 147 of file maths.h.

148  {
149  return l2_norm(input.derived().array(), weights.derived().array());
150 }

References l2_norm().

◆ linear_transform() [1/10]

template<typename VECTOR >
LinearTransform<VECTOR> sopt::linear_transform ( details::WrapFunction< VECTOR > const &  direct,
details::WrapFunction< VECTOR > const &  adjoint 
)

Creates a linear transform from a pair of wrappers.

Definition at line 153 of file linear_transform.h.

154  {
155  return {direct, adjoint};
156 }

◆ linear_transform() [2/10]

template<typename DERIVED >
LinearTransform<Vector<typename DERIVED::Scalar> > sopt::linear_transform ( Eigen::MatrixBase< DERIVED > const &  A)

Helper function to creates a function operator.

Definition at line 234 of file linear_transform.h.

235  {
236  details::MatrixToLinearTransform<Matrix<typename DERIVED::Scalar>> const matrix(A);
237  if (A.rows() == A.cols())
238  return {matrix, matrix.adjoint()};
239  else {
240  t_int const gcd = details::gcd(A.cols(), A.rows());
241  t_int const a = A.cols() / gcd;
242  t_int const b = A.rows() / gcd;
243  return {matrix, matrix.adjoint(), {{b, a, 0}}};
244  }
245 }
t_int gcd(t_int a, t_int b)
Greatest common divisor.
Definition: maths.h:207

References a, sopt::details::MatrixToLinearTransform< EIGEN >::adjoint(), b, and sopt::details::gcd().

◆ linear_transform() [3/10]

template<typename VECTOR >
LinearTransform<VECTOR>& sopt::linear_transform ( LinearTransform< VECTOR > &  passthrough)

Convenience no-op function.

Definition at line 148 of file linear_transform.h.

148  {
149  return passthrough;
150 }

◆ linear_transform() [4/10]

template<typename VECTOR >
LinearTransform<VECTOR> sopt::linear_transform ( OperatorFunction< VECTOR > const &  direct,
OperatorFunction< VECTOR > const &  indirect,
std::array< t_int, 3 > const &  sizes = {{1, 1, 0}} 
)

Helper function to creates a function operator

Parameters
[in]directfunction with signature void(VECTOR&, VECTOR const&) which applies a linear operator to a vector.
[in]indirectfunction with signature void(VECTOR&, VECTOR const&) which applies a the conjugate transpose linear operator to a vector.
[in]sizes3 integer elements (a, b, c) such that if the input to linear operator is of size N, then the output is of size (a * N) / b + c. A similar quantity is deduced for the indirect operator.

Definition at line 124 of file linear_transform.h.

126  {{1, 1, 0}}) {
127  return {direct, indirect, sizes};
128 }

Referenced by sopt::algorithm::SDMM< SCALAR >::append(), main(), sopt::algorithm::ImagingForwardBackward< SCALAR >::Phi(), sopt::algorithm::ImagingProximalADMM< SCALAR >::Phi(), sopt::algorithm::ImagingPrimalDual< SCALAR >::Phi(), sopt::algorithm::L2ForwardBackward< SCALAR >::Phi(), sopt::algorithm::ProximalADMM< SCALAR >::Phi(), sopt::algorithm::PrimalDual< SCALAR >::Phi(), sopt::algorithm::TVPrimalDual< SCALAR >::Phi(), sopt::algorithm::ImagingPrimalDual< SCALAR >::Psi(), sopt::proximal::L1TightFrame< SCALAR >::Psi(), sopt::algorithm::PrimalDual< SCALAR >::Psi(), sopt::algorithm::TVPrimalDual< SCALAR >::Psi(), and TEST_CASE().

◆ linear_transform() [5/10]

template<typename VECTOR >
LinearTransform<VECTOR> sopt::linear_transform ( OperatorFunction< VECTOR > const &  direct,
std::array< t_int, 3 > const &  dsizes,
OperatorFunction< VECTOR > const &  indirect,
std::array< t_int, 3 > const &  isizes 
)

Helper function to creates a function operator

Parameters
[in]directfunction with signature void(VECTOR&, VECTOR const&) which applies a linear operator to a vector.
[in]dsizes3 integer elements (a, b, c) such that if the input to the linear operator is of size N, then the output is of size (a * N) / b + c.
[in]indirectfunction with signature void(VECTOR&, VECTOR const&) which applies a the conjugate transpose linear operator to a vector.
[in]dsizes3 integer elements (a, b, c) such that if the input to the indirect linear operator is of size N, then the output is of size (a * N) / b + c.

Definition at line 139 of file linear_transform.h.

142  {
143  return {direct, dsizes, indirect, isizes};
144 }

◆ linear_transform() [6/10]

template<typename T >
LinearTransform<Vector<T> > sopt::linear_transform ( Sampling const &  sampling)

Returns linear transform version of this object.

Definition at line 82 of file sampling.h.

82  {
83  return linear_transform<Vector<T>>(
84  [sampling](Vector<T> &out, Vector<T> const &x) { sampling(out, x); },
85  {{0, 1, static_cast<t_int>(sampling.rows())}},
86  [sampling](Vector<T> &out, Vector<T> const &x) { sampling.adjoint(out, x); },
87  {{0, 1, static_cast<t_int>(sampling.cols())}});
88 }

References sopt::Sampling::adjoint(), sopt::Sampling::cols(), and sopt::Sampling::rows().

◆ linear_transform() [7/10]

template<typename T >
LinearTransform<Vector<T> > sopt::linear_transform ( wavelets::SARA const &  sara)

Thin linear-transform wrapper around 1d sara operator.

Note
Because of the way Purify defines things, Ψ^T is actually the transform from signal to coefficients.

Definition at line 183 of file wavelets.h.

183  {
184  return details::linear_transform<T, wavelets::SARA>(sara);
185 }

◆ linear_transform() [8/10]

template<typename T >
LinearTransform<Vector<T> > sopt::linear_transform ( wavelets::SARA const &  sara,
t_uint  rows,
t_uint  cols = 1 
)

Thin linear-transform wrapper around 2d wavelets.

Parameters
[in]saraSARA wavelet dictionary
[in]rowsNumber of rows in the image
[in]colsNumber of columns in the image
Note
Because of the way Purify defines things, Ψ^T is actually the transform from signal to coefficients.

Definition at line 202 of file wavelets.h.

203  {
204  return details::linear_transform<T, wavelets::SARA>(sara, rows, cols, sara.size());
205 }
t_uint rows
t_uint cols

References cols, and rows.

◆ linear_transform() [9/10]

template<typename T >
LinearTransform<Vector<T> > sopt::linear_transform ( wavelets::Wavelet const &  wavelet)

Thin linear-transform wrapper around 1d wavelets.

Warning
Because of the way Purify defines things, Ψ^T is actually the transform from signal to coefficients.

Definition at line 175 of file wavelets.h.

175  {
176  return details::linear_transform<T, wavelets::Wavelet>(wavelet);
177 }

◆ linear_transform() [10/10]

template<typename T >
LinearTransform<Vector<T> > sopt::linear_transform ( wavelets::Wavelet const &  wavelet,
t_uint  rows,
t_uint  cols = 1 
)

Thin linear-transform wrapper around 2d wavelets.

Note
Because of the way Purify defines things, Ψ^T is actually the transform from signal to coefficients.

Definition at line 191 of file wavelets.h.

192  {
193  return details::linear_transform<T, wavelets::Wavelet>(wavelet, rows, cols);
194 }

References cols, and rows.

◆ linear_transform_identity()

template<typename SCALAR >
LinearTransform<Vector<SCALAR> > sopt::linear_transform_identity ( )

Helper function to create a linear transform that's just the identity.

Definition at line 249 of file linear_transform.h.

249  {
250  return {[](Vector<SCALAR> &out, Vector<SCALAR> const &in) { out = in; },
251  [](Vector<SCALAR> &out, Vector<SCALAR> const &in) { out = in; }};
252 }

◆ number_of_threads_in_tests()

constexpr std::size_t sopt::number_of_threads_in_tests ( )
inlineconstexpr

Number of threads used during testing.

Definition at line 51 of file config.in.h.

51 { return @SOPT_DEFAULT_OPENMP_THREADS@; }

◆ positive_quadrant()

template<typename T >
Eigen::CwiseUnaryOp<const details::ProjectPositiveQuadrant<typename T::Scalar>, const T> sopt::positive_quadrant ( Eigen::DenseBase< T > const &  input)

Expression to create projection onto positive quadrant.

Definition at line 60 of file maths.h.

60  {
61  using Projector = details::ProjectPositiveQuadrant<typename T::Scalar>;
62  using UnaryOp = Eigen::CwiseUnaryOp<const Projector, const T>;
63  return UnaryOp(input.derived(), Projector());
64 }

Referenced by main(), sopt::proximal::positive_quadrant(), and TEST_CASE().

◆ sigma()

template<typename T >
real_type<T>::type sopt::sigma ( sopt::LinearTransform< Vector< T >> const &  sampling,
sopt::Image< T > const &  image 
)

Definition at line 17 of file inpainting.h.

18  {
19  auto constexpr snr = 30.0;
20  auto const y0 = target(sampling, image);
21  return y0.stableNorm() / std::sqrt(y0.size()) * std::pow(10.0, -(snr / 20.0));
22 }

References target().

Referenced by dirty(), epsilon(), sopt::ONNXDifferentiableFunc< SCALAR >::function(), sopt::ONNXDifferentiableFunc< SCALAR >::gradient(), sopt::L2DifferentiableFunc< SCALAR >::L2DifferentiableFunc(), main(), and TEST_CASE().

◆ soft_threshhold() [1/4]

template<typename T >
Eigen::CwiseUnaryOp<const details::SoftThreshhold<typename T::Scalar>, const T> sopt::soft_threshhold ( Eigen::DenseBase< T > const &  input,
typename real_type< typename T::Scalar >::type const &  threshhold 
)

Expression to create soft-threshhold.

Definition at line 68 of file maths.h.

70  {
71  using Scalar = typename T::Scalar;
72  using Real = typename real_type<Scalar>::type;
73  return Eigen::CwiseUnaryOp<const details::SoftThreshhold<typename T::Scalar>, const T>{
74  input.derived(), std::bind(soft_threshhold<Scalar>, std::placeholders::_1, Real(threshhold))};
75 }
sopt::t_real Scalar

◆ soft_threshhold() [2/4]

template<typename T0 , typename T1 >
std::enable_if<std::is_arithmetic<typename T0::Scalar>::value and std::is_arithmetic<typename T1::Scalar>::value, Eigen::CwiseBinaryOp<typename T0::Scalar (*)(typename T0::Scalar const &, typename T1::Scalar const &), const T0, const T1> >::type sopt::soft_threshhold ( Eigen::DenseBase< T0 > const &  input,
Eigen::DenseBase< T1 > const &  threshhold 
)

Expression to create soft-threshhold with multiple parameters.

Operates over a vector of threshholds: out(i) = soft_threshhold(x(i), h(i)) Threshhold and input vectors must have the same size and type. The latter condition is enforced by CwiseBinaryOp, unfortunately.

Definition at line 87 of file maths.h.

87  {
88  if (input.size() != threshhold.size())
89  SOPT_THROW("Threshhold and input should have the same size");
90  return {input.derived(), threshhold.derived(), soft_threshhold<typename T0::Scalar>};
91 }

References SOPT_THROW.

◆ soft_threshhold() [3/4]

template<typename T0 , typename T1 >
std::enable_if< is_complex<typename T0::Scalar>::value and std::is_arithmetic<typename T1::Scalar>::value, Eigen::CwiseBinaryOp< typename T0::Scalar (*)(typename T0::Scalar const &, typename T0::Scalar const &), const T0, decltype(std::declval<const T1>).template cast<typename T0::Scalar>))> >::type sopt::soft_threshhold ( Eigen::DenseBase< T0 > const &  input,
Eigen::DenseBase< T1 > const &  threshhold 
)

Expression to create soft-threshhold with multiple parameters.

Operates over a vector of threshholds: out(i) = soft_threshhold(x(i), h(i)) Threshhold and input vectors must have the same size and type. The latter condition is enforced by CwiseBinaryOp, unfortunately. So we cast threshhold from real to complex and back.

Definition at line 103 of file maths.h.

103  {
104  if (input.size() != threshhold.size())
105  SOPT_THROW("Threshhold and input should have the same size: ")
106  << threshhold.size() << " vs " << input.size();
107  using Complex = typename T0::Scalar;
108  auto const func = [](Complex const &x, Complex const &t) -> Complex {
109  return soft_threshhold(x, t.real());
110  };
111  return {input.derived(), threshhold.derived().template cast<Complex>(), func};
112 }
std::enable_if< is_complex< typename T0::Scalar >::value and std::is_arithmetic< typename T1::Scalar >::value, Eigen::CwiseBinaryOp< typename T0::Scalar(*)(typename T0::Scalar const &, typename T0::Scalar const &), const T0, decltype(std::declval< const T1 >).template cast< typename T0::Scalar >))> >::type soft_threshhold(Eigen::DenseBase< T0 > const &input, Eigen::DenseBase< T1 > const &threshhold)
Expression to create soft-threshhold with multiple parameters.
Definition: maths.h:103

References soft_threshhold(), and SOPT_THROW.

◆ soft_threshhold() [4/4]

template<typename SCALAR >
std::enable_if<std::is_arithmetic<SCALAR>::value or is_complex<SCALAR>::value, SCALAR>::type sopt::soft_threshhold ( SCALAR const &  x,
typename real_type< SCALAR >::type const &  threshhold 
)

abs(x) < threshhold ? 0: x - sgn(x) * threshhold

Definition at line 29 of file maths.h.

29  {
30  auto const normalized = std::abs(x);
31  return normalized < threshhold ? SCALAR(0) : (x * (SCALAR(1) - threshhold / normalized));
32 }

Referenced by sopt::proximal::l1_norm(), main(), sopt::proximal::L1TightFrame< SCALAR >::operator()(), soft_threshhold(), and TEST_CASE().

◆ standard_deviation() [1/2]

template<typename T >
real_type<typename T::Scalar>::type sopt::standard_deviation ( Eigen::ArrayBase< T > const &  x)

Computes the standard deviation of a vector.

Definition at line 16 of file maths.h.

16  {
17  return (x - x.mean()).matrix().stableNorm() / std::sqrt(x.size());
18 }

Referenced by sopt::algorithm::Reweighted< ALGORITHM >::operator()(), standard_deviation(), and TEST_CASE().

◆ standard_deviation() [2/2]

template<typename T >
real_type<typename T::Scalar>::type sopt::standard_deviation ( Eigen::MatrixBase< T > const &  x)

Computes the standard deviation of a vector.

Definition at line 21 of file maths.h.

21  {
22  return standard_deviation(x.array());
23 }
real_type< typename T::Scalar >::type standard_deviation(Eigen::MatrixBase< T > const &x)
Computes the standard deviation of a vector.
Definition: maths.h:21

References standard_deviation().

◆ target()

template<typename T >
Vector<T> sopt::target ( sopt::LinearTransform< Vector< T >> const &  sampling,
sopt::Image< T > const &  image 
)

Definition at line 12 of file inpainting.h.

12  {
13  return sampling * Vector<T>::Map(image.data(), image.size());
14 }

Referenced by dirty(), epsilon(), sopt::algorithm::L2ForwardBackward< SCALAR >::operator()(), sigma(), sopt::algorithm::L2ForwardBackward< SCALAR >::target(), and TEST_CASE().

◆ tv_norm() [1/4]

template<typename T0 >
real_type<typename T0::Scalar>::type sopt::tv_norm ( Eigen::ArrayBase< T0 > const &  input)

Computes weighted tv norm.

Definition at line 192 of file maths.h.

192  {
193  typename T0::PlainObject w(1);
194  w(0) = 1;
195  return tv_norm(input, w);
196 }
real_type< typename T0::Scalar >::type tv_norm(Eigen::MatrixBase< T0 > const &input)
Computes weighted TV norm.
Definition: maths.h:199

References tv_norm().

◆ tv_norm() [2/4]

template<typename T0 , typename T1 >
real_type<typename T0::Scalar>::type sopt::tv_norm ( Eigen::ArrayBase< T0 > const &  input,
Eigen::ArrayBase< T1 > const &  weights 
)

Computes weighted TV norm.

Definition at line 168 of file maths.h.

169  {
170  const auto size = input.size() / 2;
171  if (weights.size() == 1)
172  return (input.segment(0, size).square() + input.segment(size, size).square())
173  .cwiseAbs()
174  .sqrt()
175  .matrix()
176  .sum() *
177  std::abs(weights(0));
178  return std::abs(
179  ((input.segment(0, size).square() + input.segment(size, size).square()).cwiseAbs().sqrt() *
180  weights)
181  .matrix()
182  .sum());
183 }

Referenced by tv_norm().

◆ tv_norm() [3/4]

template<typename T0 >
real_type<typename T0::Scalar>::type sopt::tv_norm ( Eigen::MatrixBase< T0 > const &  input)

Computes weighted TV norm.

Definition at line 199 of file maths.h.

199  {
200  typename T0::PlainObject w(1);
201  w(0) = 1;
202  return tv_norm(input.derived().array(), w.array());
203 }

References tv_norm().

◆ tv_norm() [4/4]

template<typename T0 , typename T1 >
real_type<typename T0::Scalar>::type sopt::tv_norm ( Eigen::MatrixBase< T0 > const &  input,
Eigen::MatrixBase< T1 > const &  weights 
)

Computes weighted TV norm.

Definition at line 186 of file maths.h.

187  {
188  return tv_norm(input.derived().array(), weights.derived().array());
189 }

References tv_norm().

◆ version()

std::string sopt::version ( )
inline

Returns library version.

Definition at line 32 of file config.in.h.

32 { return "@SOPT_VERSION@"; }

◆ version_tuple()

std::tuple<uint8_t, uint8_t, uint8_t> sopt::version_tuple ( )
inline

Returns library version.

Definition at line 35 of file config.in.h.

35  {
36  return std::tuple<uint8_t, uint8_t, uint8_t>(
37  @SOPT_VERSION_MAJOR@, @SOPT_VERSION_MINOR@, @SOPT_VERSION_PATCH@);
38 }