DP3
LBFGSSolver.h
Go to the documentation of this file.
1 // Copyright (C) 2021 ASTRON (Netherlands Institute for Radio Astronomy)
2 // SPDX-License-Identifier: GPL-3.0-or-later
3 
4 #ifndef DDECAL_LBFGS_SOLVER_H
5 #define DDECAL_LBFGS_SOLVER_H
6 
7 #include "SolverBase.h"
8 #include "SolveData.h"
9 
10 namespace dp3 {
11 namespace ddecal {
12 
13 #ifdef HAVE_LIBDIRAC
14 class LBFGSSolver final : public SolverBase {
15  public:
16  enum SolverMode { kFull, kDiagonal, kScalar };
17  LBFGSSolver(const double robust_nu, const size_t max_iter,
18  const size_t history_size, const size_t minibatches,
19  const double min_solution, const double max_solution,
20  const SolverMode mode)
21  : robust_nu_(robust_nu),
22  batch_iter_(max_iter),
23  history_size_(history_size),
24  minibatches_(minibatches),
25  min_solution_(min_solution),
26  max_solution_(max_solution),
27  bound_constrained_((min_solution || max_solution) &&
28  (min_solution != max_solution)),
29  mode_(mode){};
30 
38  static xt::xtensor<double, 1> SplitSolutions(
39  const std::vector<DComplex>& solutions);
40 
47  static void MergeSolutions(SolutionTensor& next_solutions, size_t ch_block,
48  const xt::xtensor<double, 1>& d_storage);
49 
50  SolveResult Solve(const FullSolveData& data,
51  std::vector<std::vector<DComplex>>& solutions,
52  double time) override;
53 
54  size_t NSolutionPolarizations() const override {
55  switch (mode_) {
56  case kFull:
57  return 4;
58  case kDiagonal:
59  return 2;
60  case kScalar:
61  return 1;
62  }
63  assert(false);
64  return 0; // will not get here
65  }
66 
67  double GetRobustDOF() const { return robust_nu_; }
68  size_t GetMaxIter() const { return batch_iter_; }
69  size_t GetHistorySize() const { return history_size_; }
70  size_t GetMinibatches() const { return minibatches_; }
71  double GetMinSolution() const { return min_solution_; }
72  double GetMaxSolution() const { return max_solution_; }
73  bool GetBoundConstrained() const { return bound_constrained_; }
74  SolverMode GetMode() const { return mode_; }
75 
76  private:
77  double robust_nu_;
78  size_t batch_iter_;
79  size_t history_size_;
80  size_t minibatches_;
81  double min_solution_;
82  double max_solution_;
83  bool bound_constrained_;
84  SolverMode mode_;
85 };
86 #endif /* HAVE_LIBDIRAC */
87 } // namespace ddecal
88 } // namespace dp3
89 
90 #endif // DDECAL_LBFGS_SOLVER_H
xt::xtensor< std::complex< double >, 4 > SolutionTensor
Definition: Solutions.h:19
SolveData< aocommon::MC2x2F > FullSolveData
Stores all 4 polarizations of the data.
Definition: SolveData.h:197
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53