The ChainCon Software (Release 0.03)
atmodcomp.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// \file
4 ///
5 /// A generic procedure for the computation of chain contraction
6 /// of a filtered cell complex stored in a file.
7 /// This is a complete procedure good for simplicial, cubical,
8 /// or other complexes.
9 /// It computes an algebraic topological model.
10 /// This computation fails if homology is not torsion-free.
11 ///
12 /////////////////////////////////////////////////////////////////////////////
13 
14 // Copyright (C) 2009-2016 by Pawel Pilarczyk.
15 //
16 // This file is part of my research software package. This is free software:
17 // you can redistribute it and/or modify it under the terms of the GNU
18 // General Public License as published by the Free Software Foundation,
19 // either version 3 of the License, or (at your option) any later version.
20 //
21 // This software is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License
27 // along with this software; see the file "license.txt". If not,
28 // please, see <http://www.gnu.org/licenses/>.
29 
30 // Started on March 24, 2009. Last revision: August 21, 2013.
31 
32 
33 #ifndef _ATMODCOMP_H_
34 #define _ATMODCOMP_H_
35 
36 
37 // include some standard C++ header files
38 #include <istream>
39 #include <ostream>
40 
41 // include selected header files from the CHomP library
42 #include "chomp/system/config.h"
43 #include "chomp/system/textfile.h"
44 #include "chomp/system/timeused.h"
45 #include "chomp/struct/hashsets.h"
46 
47 // include relevant local header files
48 #include "chaincon/cellnames.h"
49 #include "chaincon/filtcomplex.h"
50 #include "chaincon/readfcompl.h"
51 #include "chaincon/boundary.h"
52 #include "chaincon/atmodel.h"
53 #include "chaincon/homcohom.h"
54 
55 
56 // --------------------------------------------------
57 // ---------------- compute AT model ----------------
58 // --------------------------------------------------
59 
60 /// Computes an AT model and the homology of a cellular complex.
61 /// The cellular complex is read from the given file.
62 /// Only top-dimensional cells should be listed in the file,
63 /// or otherwise the filtration may not be generated correctly.
64 template <class CellT, class LinMap, class CellNames>
66  bool relativeComplex,
67  chomp::homology::hashedset<CellT> &H,
68  LinMap &pi, LinMap &incl, LinMap &phi,
69  CellNames &cellNames,
70  bool displayPi, bool displayIncl, bool displayPhi,
71  bool displayRepr, bool verify, int algorithmVersion)
72 {
73  using chomp::homology::sout;
74 
75  // determine the type of coefficients (for displaying homology only)
76  typedef typename LinMap::CoefType CoefT;
77 
78  // compute the homology together with the chain contraction
79  if (relativeComplex)
80  {
81  algTopModel (K, H, pi, incl, phi, algorithmVersion, K);
82  }
83  else
84  {
85  algTopModel (K, H, pi, incl, phi, algorithmVersion,
86  Unrestricted ());
87  }
88 
89  // show the computed homology groups
90  chomp::homology::hashedset<CellT> emptyCellArray;
91  chomp::homology::hashedset<CoefT> emptyCoefArray;
92  std::vector<std::vector<CellT> > representants;
93  std::vector<int> bettiNumbers;
94  std::vector<std::vector<CoefT> > torsion;
95  getHomCohom (H, emptyCellArray, emptyCellArray, emptyCoefArray,
96  &representants, &bettiNumbers, &torsion, false);
97  sout << "Homology groups:\n";
98  sout << homcohom2text (bettiNumbers, torsion, "H_", false);
99 
100  // prepare correct cell names and show them if requested to
101  if (displayRepr)
102  sout << "Representants of homology generators:\n";
103  int reprSize = representants. size ();
104  for (int dim = 0; dim < reprSize; ++ dim)
105  {
106  int size = representants [dim]. size ();
107  for (int i = 0; i < size; ++ i)
108  {
109  const CellT &cell (representants [dim] [i]);
110  if (displayRepr)
111  {
112  sout << cellNames (cell) << ": " <<
113  cell << ".\n";
114  }
115  else
116  {
117  cellNames (cell);
118  }
119  }
120  }
121 
122  // show the computed maps
123  tCellOwnNames<CellT> cellOwnNames;
124  if (displayPi)
125  {
126  sout << "The projection map pi:\n" <<
127  cells2names (pi, cellOwnNames, cellNames);
128  }
129  if (displayIncl)
130  {
131  sout << "The inclusion map incl:\n" <<
132  cells2names (incl, cellNames, cellOwnNames);
133  }
134  if (displayPhi)
135  {
136  sout << "The homology gradient vector field phi:\n" << phi;
137  }
138 
139  // prepare the boundary map, to be used for verifications
140  LinMap boundaryMap;
141 
142  // do several verifications to make sure the computed maps are good
143  if (verify)
144  {
145  if (relativeComplex)
146  computeBoundaryMap (K, boundaryMap, K);
147  else
148  computeBoundaryMap (K, boundaryMap, Unrestricted ());
149  if (phi * boundaryMap * phi == phi)
150  sout << "Verified: 'phi bd phi = phi'.\n";
151  else
152  sout << "Failed to verify that "
153  "'phi pd phi = phi'.\n";
154 
155  if (boundaryMap * phi * boundaryMap == boundaryMap)
156  sout << "Verified: 'bd phi bd = bd'.\n";
157  else
158  sout << "Failed to verify that 'bd phi bd = bd'.\n";
159 
160  LinMap zeroMap;
161  if (phi * phi == zeroMap)
162  sout << "Verified: 'phi phi = 0'.\n";
163  else
164  sout << "Failed to verify that 'phi phi = 0'.\n";
165 
166  LinMap composition (boundaryMap * phi);
167  composition += phi * boundaryMap;
168  composition. negate ();
169  addIdentity (K, composition);
170  if (incl * pi == composition)
171  sout << "Verified: 'i pi = id - bd phi - phi bd'.\n";
172  else
173  sout << "Failed to verify that "
174  "'i pi = id - bd phi - phi bd'.\n";
175 
176  LinMap idH;
177  addIdentity (H, idH);
178  if (pi * incl == idH)
179  sout << "Verified: 'pi i = id_H'.\n";
180  else
181  sout << "Failed to verify that 'pi i = id_H'.\n";
182 
183  if (pi * phi == zeroMap)
184  sout << "Verified: 'pi phi = 0'.\n";
185  else
186  sout << "Failed to verify that 'pi phi = 0'.\n";
187 
188  if (phi * incl == zeroMap)
189  sout << "Verified: 'phi i = 0'.\n";
190  else
191  sout << "Failed to verify that 'phi i = 0'.\n";
192  }
193 
194  return;
195 } /* computeAlgTopModel */
196 
197 
198 #endif // _ATMODCOMP_H_
199 
Boundary computation at the level of chains of cells.
void algTopModel(const CellArray1 &K, CellArray2 &H, tCombLinMap< CellT, CellT > &pi, tCombLinMap< CellT, CellT > &incl, tCombLinMap< CellT, CellT > &phi, int version, const CellRestrT &restr)
Computes a combinatorial algebraic topological model for a given filtered finite cell complex "K"...
Definition: atmodel.h:56
std::string homcohom2text(int bettiNumber, const std::vector< CoefT > &torsion, bool torsion_subscript)
Returns a text description of one (co)homology group.
Definition: homcohom.h:148
Algebraic topological model computation: An interface to all the algorithms available in this package...
void computeBoundaryMap(const CellArray &cells, tCombLinMap< CellT, CellT > &f, const CellRestrT &restr)
Computes the full boundary map for a cellular complex that contains the cells in a provided set and a...
Definition: boundary.h:323
A filtered cell complex.
A class for providing the cells as their names.
Definition: cellnames.h:238
A filtered complex.
Definition: filtcomplex.h:53
void getHomCohom(const CellArray1 &H, const CellArray2 &A, const CellArray3 &B, const CoefArray &Q, std::vector< std::vector< CellT > > *representants, std::vector< int > *bettiNumbers, std::vector< std::vector< CoefT > > *torsion, bool cohomology)
Computes Betti numbers and torsion coefficients for (co)homology from an algebraic minimal model (set...
Definition: homcohom.h:57
A class for naming cells for nice text data output.
NamesT::NameType cells2names(const CellT &in, NamesT &names)
Returns the name of a cell according to the given naming object.
Definition: cellnames.h:343
A generic procedure for reading a filtered cell complex or a pair of filtered cell complexes from tex...
void addIdentity(const CellArray &domain, tCombLinMap< CellT, CellT > &f)
Adds the identity map on the given domain to the map &#39;f&#39;.
Definition: comblinmap.h:416
void computeAlgTopModel(const tFilteredComplex< CellT > &K, bool relativeComplex, chomp::homology::hashedset< CellT > &H, LinMap &pi, LinMap &incl, LinMap &phi, CellNames &cellNames, bool displayPi, bool displayIncl, bool displayPhi, bool displayRepr, bool verify, int algorithmVersion)
Computes an AT model and the homology of a cellular complex.
Definition: atmodcomp.h:65
A template of a simple class for unrestricted cell selection in the boundary computation procedures...
Definition: boundary.h:56
Computation of the (co)homology groups of an algebraic minimal model.