Marmote Core
The project aims at realizing the prototype of a software environment dedicated to modeling with Markov chains.
sparseMatrix.h
1 /* Marmote is free software: you can redistribute it and/or modify
2 it under the terms of the GNU General Public License as published by
3 the Free Software Foundation, either version 3 of the License, or
4 (at your option) any later version.
5 
6 Marmote is distributed in the hope that it will be useful,
7 but WITHOUT ANY WARRANTY; without even the implied warranty of
8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 GNU General Public License for more details.
10 
11 You should have received a copy of the GNU General Public License
12 along with Marmote. If not, see <http://www.gnu.org/licenses/>.
13 
14 Copyright 2015 Alain Jean-Marie, Jean-Michel Fourneau, Jean-Marc Vincent, Issam Rabhi */
15 
16 #ifndef SPARSEMATRIX_H
17 #define SPARSEMATRIX_H
18 
19 #include "transitionStructure.h"
20 
30 {
31 
32 private:
33  // specific variables of the class
34  int* _nbElts;
35  int** _elts;
36  double** _vals;
37  bool _debug;
39 public:
40  // constructors
47  sparseMatrix(int size);
48 
49  // constructors
57  sparseMatrix(int rowSize, int colSize);
58 
59  // destructor
63  ~sparseMatrix();
64 
65 public:
80  bool setEntry(int row, int col, double val); // set A[i,j]
88  double getEntry(int,int); // get A[i,j]
95  int getNbElts(int row); // get the number of entries in row i
102  int getCol(int row, int numCol ); // get the jth column for row i
109  double getEntryByCol(int row, int numCol); // get the value in the jth column for row i
116  discreteDistribution* getTransDistrib(int row); // transitions from some state
123  double rowSum(int row);
131  void evaluateMeasure(double* m, double* res);
146  void evaluateValue(double* v, double* res);
147 
148 public:
155  sparseMatrix* copy();
170  sparseMatrix* embed();
171 
172  public:
179  void diagnose(FILE* out);
188  void write(FILE* out, std::string format);
189 
190  // methods specific to this class
199  bool addToEntry(int row, int col, double val); // add to A[i,j]
200 
201 private:
202  // specific technical methods
214  int consolidate(int i, int* destinations, double* values);
215 
216 public:
221  void normalize();
222 };
223 
224 #endif // SPARSEMATRIX_H
void evaluateMeasure(double *m, double *res)
Sparse vector/matrix multiplication. The result is stored in an array that must be already allocated...
Definition: sparseMatrix.cpp:321
double rowSum(int row)
Summing a row.
Definition: sparseMatrix.cpp:308
sparseMatrix(int size)
Standard constructor for sparse matrices. The internal structures are initialized. The result is the null matrix.
Definition: sparseMatrix.cpp:30
int getCol(int row, int numCol)
Retrieving an low-level entry from the matrix.
Definition: sparseMatrix.cpp:222
bool setEntry(int row, int col, double val)
Inserting an element in the matrix. IMPORTANT NOTE: there is no check for the existence of the column...
Definition: sparseMatrix.cpp:113
void normalize()
Method to normalize transition probabilities/rates across the matrix. The normalized form has strictl...
Definition: sparseMatrix.cpp:751
void write(FILE *out, std::string format)
Writing a sparse matrix to a file. Several formats could be chosen. Supported formats are: "Ers"...
Definition: sparseMatrix.cpp:545
discreteDistribution * getTransDistrib(int row)
Retrieving the transitions from some state as a discrete distribution.
Definition: sparseMatrix.cpp:254
sparseMatrix * uniformize()
Sparse matrix uniformization. Returns a sparse matrix and sets the uniformization factor...
Definition: sparseMatrix.cpp:383
int getNbElts(int row)
Retrieving a the number of elements on some row.
Definition: sparseMatrix.cpp:205
sparseMatrix * copy()
Sparse matrix copy. This is a straightforward copy. No optimization is performed, viz replicated colu...
Definition: sparseMatrix.cpp:365
void diagnose(FILE *out)
Performs various diagnostics on the transition structure (only written for sparseMatrix objects at th...
Definition: sparseMatrix.cpp:480
~sparseMatrix()
Destructor of the class.
Definition: sparseMatrix.cpp:97
double getEntry(int, int)
Retrieving an entry from the matrix. Takes into account the fact that columns may be replicated: the ...
Definition: sparseMatrix.cpp:190
Abstract class for transition structures. These are structures which describe transitions to one stat...
Definition: transitionStructure.h:33
void evaluateValue(double *v, double *res)
Sparse vector/matrix multiplication. The result is stored in an array that must be already allocated...
Definition: sparseMatrix.cpp:354
bool addToEntry(int row, int col, double val)
Adding a value to an element to the matrix.
Definition: sparseMatrix.cpp:145
sparseMatrix * embed()
Sparse matrix embedding. Returns a sparse matrix. If the type is already discrete, returns a copy.
Definition: sparseMatrix.cpp:438
Class sparseMatrix: implementation of a transition structure using the sparse matrix data structure...
Definition: sparseMatrix.h:29
int size()
Read accessor for the size of the state space. This is the origin state space by default.
Definition: transitionStructure.h:59
The general discrete distribution with finite support.
Definition: discreteDistribution.h:25
double getEntryByCol(int row, int numCol)
Retrieving an low-level entry from the matrix.
Definition: sparseMatrix.cpp:238