• Main Page
  • Classes
  • Files
  • File List
  • File Members

comphom.h

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////
00002 ///
00003 /// \file
00004 ///
00005 /// A generic procedure for the computation of chain contraction
00006 /// of a filtered cell complex stored in a file.
00007 /// This is a complete procedure good for simplicial, cubical,
00008 /// or other complexes.
00009 ///
00010 /////////////////////////////////////////////////////////////////////////////
00011 
00012 // Copyright (C) 2009-2011 by Pawel Pilarczyk.
00013 //
00014 // This file is part of my research software package. This is free software:
00015 // you can redistribute it and/or modify it under the terms of the GNU
00016 // General Public License as published by the Free Software Foundation,
00017 // either version 3 of the License, or (at your option) any later version.
00018 //
00019 // This software is distributed in the hope that it will be useful,
00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00022 // GNU General Public License for more details.
00023 //
00024 // You should have received a copy of the GNU General Public License
00025 // along with this software; see the file "license.txt". If not,
00026 // please, see <http://www.gnu.org/licenses/>.
00027 
00028 // Started on March 24, 2009. Last revision: April 3, 2011.
00029 
00030 
00031 #ifndef _COMPHOM_H_
00032 #define _COMPHOM_H_
00033 
00034 
00035 // include some standard C++ header files
00036 #include <istream>
00037 #include <ostream>
00038 
00039 // include selected header files from the CHomP library
00040 #include "chomp/system/config.h"
00041 #include "chomp/system/timeused.h"
00042 #include "chomp/system/textfile.h"
00043 #include "chomp/struct/hashsets.h"
00044 
00045 // include relevant local header files
00046 #include "chaincon/comblinmap.h"
00047 #include "chaincon/filtcomplex.h"
00048 #include "chaincon/homgvf.h"
00049 
00050 
00051 // --------------------------------------------------
00052 // ---------------- compute homology ----------------
00053 // --------------------------------------------------
00054 
00055 /// Computes the homology of a cellular complex.
00056 /// The cellular complex is read from the given file.
00057 /// Only top-dimensional cells should be listed in the file,
00058 /// or otherwise the filtration may not be generated correctly.
00059 /// If requested, the homology is only computed, without AW diagonal.
00060 template <class CellT>
00061 void computeHomology (const char *filename,
00062         chomp::homology::hashedset<CellT> &H,
00063         tCombLinMap<CellT, CellT> &pi,
00064         tCombLinMap<CellT, CellT> &incl,
00065         tCombLinMap<CellT, CellT> &phi,
00066         bool displayPi, bool displayIncl, bool displayPhi,
00067         bool verify, int algorithmVersion)
00068 {
00069         using chomp::homology::sout;
00070 
00071         // read the filtered cell complex
00072         tFilteredComplex<CellT> K;
00073         {
00074                 sout << "Reading '" << filename << "'... ";
00075                 std::ifstream in (filename);
00076                 if (!in)
00077                         chomp::homology::fileerror (filename);
00078                 in >> K;
00079                 in. close ();
00080                 sout << K. size () << " cells read.\n";
00081         }
00082 //      sout << "Cells read from the input:\n" << K << "\n";
00083 
00084         // make sure that the filtered cell complex is complete
00085         sout << "Adding boundaries... ";
00086         addBoundaries (K);
00087         sout << K. size () << " cells total.\n";
00088 //      sout << "Filtered complex:\n" << K << "==========\n";
00089 
00090         // compute the homology together with the chain contraction
00091         homologyGVF (K, H, pi, incl, phi, algorithmVersion);
00092 
00093         // show the computed maps
00094         if (displayPi)
00095                 sout << "The projection map pi:\n" << pi;
00096         if (displayIncl)
00097                 sout << "The inclusion map incl:\n" << incl;
00098         if (displayPhi)
00099                 sout << "The homology gradient vector field phi:\n" << phi;
00100 
00101         // show the computed homology representants, ordered by dimension
00102         sout << "Homology representants (ordered by dimension):\n";
00103         int_t Hsize = H. size ();
00104         int_t displayed = 0;
00105         for (int dim = 0; displayed < Hsize; ++ dim)
00106         {
00107                 for (int_t i = 0; i < Hsize; ++ i)
00108                 {
00109                         if (H [i]. dim () != dim)
00110                                 continue;
00111                         sout << "gen_" << (displayed ++) << ": " <<
00112                                 H [i] << "\n";
00113                 }
00114         }
00115 
00116         // prepare the boundary map, to be used for verifications
00117         tCombLinMap<CellT, CellT> boundaryMap;
00118 
00119         // do several verifications to make sure the computed maps are good
00120         if (verify)
00121         {
00122                 computeBoundaryMap (K, boundaryMap);
00123                 if (phi * boundaryMap * phi == phi)
00124                         sout << "Verified: 'phi bd phi = phi'.\n";
00125                 else
00126                         sout << "Failed to verify that "
00127                                 "'phi pd phi = phi'.\n";
00128 
00129                 if (boundaryMap * phi * boundaryMap == boundaryMap)
00130                         sout << "Verified: 'bd phi bd = bd'.\n";
00131                 else
00132                         sout << "Failed to verify that 'bd phi pd = bd'.\n";
00133 
00134                 tCombLinMap<CellT, CellT> zeroMap;
00135                 if (phi * phi == zeroMap)
00136                         sout << "Verified: 'phi phi = 0'.\n";
00137                 else
00138                         sout << "Failed to verify that 'phi phi = 0'.\n";
00139 
00140                 tCombLinMap<CellT, CellT> composition (boundaryMap * phi);
00141                 composition. add (phi * boundaryMap);
00142                 addIdentity (K, composition);
00143                 if (incl * pi == composition)
00144                         sout << "Verified: 'i pi = id - bd phi - phi bd'.\n";
00145                 else
00146                         sout << "Failed to verify that "
00147                                 "'i pi = id - bd phi - phi bd'.\n";
00148 
00149                 tCombLinMap<CellT, CellT> idH;
00150                 addIdentity (H, idH);
00151                 if (pi * incl == idH)
00152                         sout << "Verified: 'pi i = id_H'.\n";
00153                 else
00154                         sout << "Failed to verify that 'pi i = id_H'.\n";
00155 
00156                 if (pi * phi == zeroMap)
00157                         sout << "Verified: 'pi phi = 0'.\n";
00158                 else
00159                         sout << "Failed to verify that 'pi phi = 0'.\n";
00160 
00161                 if (phi * incl == zeroMap)
00162                         sout << "Verified: 'phi i = 0'.\n";
00163                 else
00164                         sout << "Failed to verify that 'phi i = 0'.\n";
00165         }
00166 
00167         return;
00168 } /* computeHomology */
00169 
00170 
00171 #endif // _COMPHOM_H_
00172 

Generated on Tue Apr 5 2011 00:06:32 for Chain Contraction Software by  doxygen 1.7.2