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 
29 class sparseMatrix : public transitionStructure
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  // destructor
53  ~sparseMatrix();
54 
55 public:
70  bool setEntry(int row, int col, double val); // set A[i,j]
78  double getEntry(int,int); // get A[i,j]
85  int getNbElts(int row); // get the number of entries in row i
92  int getCol(int row, int numCol ); // get the jth column for row i
99  double getEntryByCol(int row, int numCol); // get the value in the jth column for row i
106  discreteDistribution* getTransDistrib(int row); // transitions from some state
113  double rowSum(int row);
121  void evaluateMeasure(double* m, double* res);
136  void evaluateValue(double* v, double* res);
137 
138 public:
145  sparseMatrix* copy();
154 
155  public:
164  void write(FILE* out, std::string format);
165 
166  // methods specific to this class
175  bool addToEntry(int row, int col, double val); // add to A[i,j]
176 
177 private:
178  // specific technical methods
190  int consolidate(int i, int* destinations, double* values);
191 };
192 
193 #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:278
double rowSum(int row)
Summing a row.
Definition: sparseMatrix.cpp:265
sparseMatrix(int size)
Standard constructor for sparse matrices. The internal structures are initialized. The result is the null matrix.
Definition: sparseMatrix.cpp:24
int getCol(int row, int numCol)
Retrieving an low-level entry from the matrix.
Definition: sparseMatrix.cpp:183
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:74
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:388
discreteDistribution * getTransDistrib(int row)
Retrieving the transitions from some state as a discrete distribution.
Definition: sparseMatrix.cpp:215
sparseMatrix * uniformize()
Sparse matrix uniformization. Returns a sparse matrix and sets the uniformization factor...
Definition: sparseMatrix.cpp:340
int getNbElts(int row)
Retrieving a the number of elements on some row.
Definition: sparseMatrix.cpp:166
sparseMatrix * copy()
Sparse matrix copy. This is a straightforward copy. No optimization is performed, viz replicated colu...
Definition: sparseMatrix.cpp:322
~sparseMatrix()
Destructor of the class.
Definition: sparseMatrix.cpp:58
double getEntry(int, int)
Retrieving an entry from the matrix. Takes into account the fact that columns may be replicated: the ...
Definition: sparseMatrix.cpp:151
Abstract class for transition structures. These are structures which describe transitions to one stat...
Definition: transitionStructure.h:17
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:311
bool addToEntry(int row, int col, double val)
Adding a value to an element to the matrix.
Definition: sparseMatrix.cpp:106
Class sparseMatrix: implementation of a transition structure using the sparse matrix data structure...
Definition: sparseMatrix.h:14
int size()
Read accessor for the size of the state space.
Definition: transitionStructure.h:41
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:199