Mackey  V3.3
A C++ library for computing RO(G) graded homology
Morse.hpp
Go to the documentation of this file.
1 #pragma once
2 #include "Chains.hpp"
3 #include <Eigen/Sparse>
4 
7 
8 namespace mackey {
9 
14  template<typename diff_t>
15  class AMT {
16  public:
17 
19  const auto& original_to_reduced() const;
20 
22  const auto& reduced_to_original() const;
23 
25  double reduction_ratio() const;
26 
28  AMT(std::vector<diff_t>& A, bool compute_original_to_reduced, bool compute_reduced_to_original);
29 
30  protected:
31 
33  AMT(std::vector<diff_t>& A, bool compute_original_to_reduced, bool compute_reduced_to_original, bool onlyresize);
34 
35  typedef typename diff_t::StorageIndex ind;
36  typedef typename diff_t::Scalar scalar_t;
37  typedef Eigen::SparseMatrix<scalar_t, 1, ind> row_major_t;
38 
39  std::vector<diff_t>& diff;
40  std::vector<std::map<ind, ind>> morse;
41  std::vector<std::vector<ind>> critical;
42 
44  void reduce();
45 
47  void find_Morse_matching(int k, bool normalize);
48 
50  void normalize(int k);
51 
53  void erase_matchings(int k, const std::vector<std::pair<ind, ind>>& toremove);
54 
55  private:
56  const bool getf;
57  const bool getg;
58 
59  size_t original_size;
60  std::vector<diff_t> f;
61  std::vector<diff_t> g;
62  std::vector<std::map<ind, ind>> morse_inverse;
63  std::vector<std::map<ind, scalar_t>> normalizing_coefficients;
64  size_t compute_size() const;
65  void resize();
66  void set_critical();
67  void kill_dead_paths();
68  auto zig_zag_differential(int k, ind col) const;
69  auto zig_zag_f(int k, ind col) const;
70  auto zig_zag_g(int k, ind col) const;
71  void set_f(int k);
72  void set_g(int k);
73  void reduce_diff(int k);
74 
75  };
76 
82  template<typename rank_t, typename diff_t>
83  class EquivariantAMT : public AMT<diff_t> {
84 
85  public:
87  EquivariantAMT(Chains<rank_t, diff_t>& C, bool compute_original_to_reduced, bool compute_reduced_to_original);
88 
89  private:
90 
91  using typename AMT<diff_t>::ind;
92  using typename AMT<diff_t>::scalar_t;
93 
95  std::vector<std::vector<int64_t>> rank_sums;
96  auto find_index(int k, ind element) const;
97  auto find_orbit(int k, ind element) const;
98  auto find_non_equivariant_matching(int k) const;
99  void set_rank_sums();
100  void compute_ranks();
101  void compute();
102  };
103 }
104 #include "impl/Morse.ipp"
Contains the classes mackey::Arrow, mackey::Chains and mackey::Junction.
Performs algebraic Morse theory reduction.
Definition: Morse.hpp:15
diff_t::StorageIndex ind
The storage type of the differential matrices (eg size_t)
Definition: Morse.hpp:35
void erase_matchings(int k, const std::vector< std::pair< ind, ind >> &toremove)
Erase the given morse matchings (eg if they are not equivariant).
std::vector< std::map< ind, ind > > morse
The morse matching.
Definition: Morse.hpp:40
void reduce()
Performs the reduction and sets the "change of basis" f,g.
const auto & reduced_to_original() const
Returns vector of "change of basis" matrices from the reduced to the original basis.
const auto & original_to_reduced() const
Returns vector of "change of basis" matrices from the original to the reduced basis.
double reduction_ratio() const
Returns the average compression ratio as a double in [0,1]. Ideally as close to 0 as possible.
std::vector< diff_t > & diff
The reduced differential.
Definition: Morse.hpp:39
diff_t::Scalar scalar_t
The scalar type of the differential matrices (eg int or Z2)
Definition: Morse.hpp:36
AMT(std::vector< diff_t > &A, bool compute_original_to_reduced, bool compute_reduced_to_original)
Constructor that reduces.
void find_Morse_matching(int k, bool normalize)
Sets the morse matchiing and normalizes diff if normalize=1 (this speeds up the AMT algorithm)
Eigen::SparseMatrix< scalar_t, 1, ind > row_major_t
The type of row major of the differential matrices (eg size_t)
Definition: Morse.hpp:37
AMT(std::vector< diff_t > &A, bool compute_original_to_reduced, bool compute_reduced_to_original, bool onlyresize)
Constructor that allows only to resize.
void normalize(int k)
Normalize diff if not done in find_Morse_matching.
std::vector< std::vector< ind > > critical
The critical basis elements.
Definition: Morse.hpp:41
Performs algebraic Morse theory reduction preserving equivariance.
Definition: Morse.hpp:83
EquivariantAMT(Chains< rank_t, diff_t > &C, bool compute_original_to_reduced, bool compute_reduced_to_original)
Constructor that performs the computation.
Everything in this library is under this namespace.
Definition: Box.hpp:9