Marmote Core
The project aims at realizing the prototype of a software environment dedicated to modeling with Markov chains.
|
Class sparseMatrix: implementation of a transition structure using the sparse matrix data structure. Elements of the transition structure (matrix) are stored by row, using two arrays containing indices of columns, and values of entries. A priori, only non-zero entries are stored but this is not a requirement. More...
#include <sparseMatrix.h>
Public Member Functions | |
sparseMatrix (int size) | |
Standard constructor for sparse matrices. The internal structures are initialized. The result is the null matrix. More... | |
sparseMatrix (int rowSize, int colSize) | |
Constructor for non-square sparse matrices. The internal structures are initialized. The result is the null matrix. More... | |
~sparseMatrix () | |
Destructor of the class. More... | |
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 This is because in the context of Markov Reward Processes, there may be several transitions with different reward. It is simpler to handle this by allowing replicated entries in the neighborhood lists. The multiplication algorithm handles this in a natural way. BUT the getEntry(int,int) method must handle this situation carefully. More... | |
double | getEntry (int, int) |
Retrieving an entry from the matrix. Takes into account the fact that columns may be replicated: the different values are then added. More... | |
int | getNbElts (int row) |
Retrieving a the number of elements on some row. More... | |
int | getCol (int row, int numCol) |
Retrieving an low-level entry from the matrix. More... | |
double | getEntryByCol (int row, int numCol) |
Retrieving an low-level entry from the matrix. More... | |
discreteDistribution * | getTransDistrib (int row) |
Retrieving the transitions from some state as a discrete distribution. More... | |
double | rowSum (int row) |
Summing a row. More... | |
void | evaluateMeasure (double *m, double *res) |
Sparse vector/matrix multiplication. The result is stored in an array that must be already allocated. Anciently the "multVM" method. More... | |
void | evaluateMeasure (discreteDistribution *d, discreteDistribution *res) |
void | evaluateValue (double *v, double *res) |
Sparse vector/matrix multiplication. The result is stored in an array that must be already allocated. Anciently the "multMV" method. More... | |
sparseMatrix * | copy () |
Sparse matrix copy. This is a straightforward copy. No optimization is performed, viz replicated columns. More... | |
sparseMatrix * | uniformize () |
Sparse matrix uniformization. Returns a sparse matrix and sets the uniformization factor. If the type is already discrete, returns a copy. More... | |
sparseMatrix * | embed () |
Sparse matrix embedding. Returns a sparse matrix. If the type is already discrete, returns a copy. More... | |
void | diagnose (FILE *out) |
Performs various diagnostics on the transition structure (only written for sparseMatrix objects at the moment) More... | |
void | write (FILE *out, std::string format) |
Writing a sparse matrix to a file. Several formats could be chosen. Supported formats are: "Ers", "Full", "MatrixMarket-sparse", "MatrixMarket-full", "Maple", "MARCA", "R", "scilab", "XBORNE". More... | |
bool | addToEntry (int row, int col, double val) |
Adding a value to an element to the matrix. More... | |
void | normalize () |
Method to normalize transition probabilities/rates across the matrix. The normalized form has strictly increasing column indices for each row. More... | |
![]() | |
virtual | ~transitionStructure () |
Destructor of the class. More... | |
int | size () |
Read accessor for the size of the state space. This is the origin state space by default. More... | |
int | origSize () |
Read accessor for the size of the origin state space. More... | |
int | destSize () |
Read accessor for the size of the destination state space. More... | |
timeType | type () |
Read accessor for the time type. More... | |
double | uniformizationRate () |
Read accessor for the uniformization rate. Relevant mostly for discrete-time structures created by uniformization of a continuous-time one. More... | |
void | setType (timeType t) |
Write accessor for the time type. More... | |
void | setUniformizationRate (double rate) |
Write accessor for the uniformization rate. More... | |
bool | readEntry (FILE *input) |
Reading from a file, and adding an element to the matrix. The field must be in the form "row column value" with blank spaces as separators. More... | |
virtual discreteDistribution * | evaluateMeasure (discreteDistribution *d) |
Computing the action of the transition structure on some probability distribution. More... | |
void | write (FILE *out, std::string format) |
File output method for a transition structure. More... | |
std::string | toString (std::string format) |
String serialization method for a transition structure. More... | |
Additional Inherited Members | |
![]() | |
int | consolidate (int i, int *destinations, double *values) |
Method to consolidate (aggregate) transition probabilities from a given state. The method returns the number of different destination states, and modifies the arrays which will containt the lists of destinations and the corresponding probabilities. These arrays must have been allocated beforehand, with a size large enough to handle safely all possibilities. More... | |
![]() | |
timeType | _type |
the time type of the structure: discrete or continuous. More... | |
long int | _origSize |
size of the origin state space. More... | |
long int | _destSize |
size of the destination state space. More... | |
double | _uniformizationRate |
value related to the uniformization procedure. More... | |
Class sparseMatrix: implementation of a transition structure using the sparse matrix data structure. Elements of the transition structure (matrix) are stored by row, using two arrays containing indices of columns, and values of entries. A priori, only non-zero entries are stored but this is not a requirement.
sparseMatrix::sparseMatrix | ( | int | size | ) |
Standard constructor for sparse matrices. The internal structures are initialized. The result is the null matrix.
size | the number of states/rows and columns in the structure |
Standard constructor for square sparse matrices. The internal structures are initialized. The result is the null matrix.
sparseMatrix::sparseMatrix | ( | int | rowSize, |
int | colSize | ||
) |
Constructor for non-square sparse matrices. The internal structures are initialized. The result is the null matrix.
rowSize | the number of origin states/rows in the structure |
colSize | the number of destination states/columns in the structure |
sparseMatrix::~sparseMatrix | ( | ) |
Destructor of the class.
Standard destructor.
bool sparseMatrix::addToEntry | ( | int | row, |
int | col, | ||
double | val | ||
) |
Adding a value to an element to the matrix.
row | number of the row |
col | number of the column |
val | value to be added |
|
virtual |
Sparse matrix copy. This is a straightforward copy. No optimization is performed, viz replicated columns.
Implements transitionStructure.
void sparseMatrix::diagnose | ( | FILE * | out | ) |
Performs various diagnostics on the transition structure (only written for sparseMatrix objects at the moment)
out | the file descriptor to which the diagnostic is written |
|
virtual |
Sparse matrix embedding. Returns a sparse matrix. If the type is already discrete, returns a copy.
Implements transitionStructure.
|
virtual |
Sparse vector/matrix multiplication. The result is stored in an array that must be already allocated. Anciently the "multVM" method.
m | the measure (row vector) to be multiplied |
res | the resulting vector |
Reimplemented from transitionStructure.
void sparseMatrix::evaluateMeasure | ( | discreteDistribution * | d, |
discreteDistribution * | res | ||
) |
Version of the vector/matrix multiplication that acts on discreteDistribution objects.
d | the distribution to be multiplied |
res | the resulting distribution |
|
virtual |
Sparse vector/matrix multiplication. The result is stored in an array that must be already allocated. Anciently the "multMV" method.
v | the value (column vector) to be multiplied |
res | the resulting vector |
Implements transitionStructure.
|
virtual |
Retrieving an low-level entry from the matrix.
row | the number of the row |
numCol | the number of the entry in the sparse structure |
Implements transitionStructure.
|
virtual |
Retrieving an entry from the matrix. Takes into account the fact that columns may be replicated: the different values are then added.
row | |
col |
Implements transitionStructure.
|
virtual |
Retrieving an low-level entry from the matrix.
row | the number of the row |
numCol | the number of the entry in the sparse structure |
Implements transitionStructure.
|
virtual |
Retrieving a the number of elements on some row.
row | the number of the row |
Implements transitionStructure.
|
virtual |
Retrieving the transitions from some state as a discrete distribution.
row | the number of the row |
Implements transitionStructure.
void sparseMatrix::normalize | ( | ) |
Method to normalize transition probabilities/rates across the matrix. The normalized form has strictly increasing column indices for each row.
|
virtual |
Summing a row.
row | the number of the row |
Implements transitionStructure.
|
virtual |
Inserting an element in the matrix. IMPORTANT NOTE: there is no check for the existence of the column This is because in the context of Markov Reward Processes, there may be several transitions with different reward. It is simpler to handle this by allowing replicated entries in the neighborhood lists. The multiplication algorithm handles this in a natural way. BUT the getEntry(int,int) method must handle this situation carefully.
row | the row number |
col | the column number |
val | the value to be inserted |
Implements transitionStructure.
|
virtual |
Sparse matrix uniformization. Returns a sparse matrix and sets the uniformization factor. If the type is already discrete, returns a copy.
Implements transitionStructure.
void sparseMatrix::write | ( | FILE * | out, |
std::string | format | ||
) |
Writing a sparse matrix to a file. Several formats could be chosen. Supported formats are: "Ers", "Full", "MatrixMarket-sparse", "MatrixMarket-full", "Maple", "MARCA", "R", "scilab", "XBORNE".
out | the file descriptor to which the matrix is written |
format | the name of the format/language to use |