Marmote Core
The project aims at realizing the prototype of a software environment dedicated to modeling with Markov chains.
Public Member Functions | List of all members
sparseMatrix Class Reference

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>

Inheritance diagram for sparseMatrix:
transitionStructure

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...
 
discreteDistributiongetTransDistrib (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...
 
sparseMatrixcopy ()
 Sparse matrix copy. This is a straightforward copy. No optimization is performed, viz replicated columns. More...
 
sparseMatrixuniformize ()
 Sparse matrix uniformization. Returns a sparse matrix and sets the uniformization factor. If the type is already discrete, returns a copy. More...
 
sparseMatrixembed ()
 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...
 
- Public Member Functions inherited from transitionStructure
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 discreteDistributionevaluateMeasure (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

- Protected Member Functions inherited from transitionStructure
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...
 
- Protected Attributes inherited from transitionStructure
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...
 

Detailed Description

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.

Author
Alain Jean-Marie, from the ERS package

Constructor & Destructor Documentation

sparseMatrix::sparseMatrix ( int  size)

Standard constructor for sparse matrices. The internal structures are initialized. The result is the null matrix.

Parameters
sizethe number of states/rows and columns in the structure
Returns
a sparse matrix object

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.

Parameters
rowSizethe number of origin states/rows in the structure
colSizethe number of destination states/columns in the structure
Returns
a sparse matrix object
sparseMatrix::~sparseMatrix ( )

Destructor of the class.

Standard destructor.

Author
Alain Jean-Marie

Member Function Documentation

bool sparseMatrix::addToEntry ( int  row,
int  col,
double  val 
)

Adding a value to an element to the matrix.

Author
Alain Jean-Marie
Parameters
rownumber of the row
colnumber of the column
valvalue to be added
Returns
true if successful,
See also
setEntry()
sparseMatrix * sparseMatrix::copy ( )
virtual

Sparse matrix copy. This is a straightforward copy. No optimization is performed, viz replicated columns.

Author
Alain Jean-Marie
Returns
a copy of the generator

Implements transitionStructure.

void sparseMatrix::diagnose ( FILE *  out)

Performs various diagnostics on the transition structure (only written for sparseMatrix objects at the moment)

Author
Alain Jean-Marie
Parameters
outthe file descriptor to which the diagnostic is written
sparseMatrix * sparseMatrix::embed ( )
virtual

Sparse matrix embedding. Returns a sparse matrix. If the type is already discrete, returns a copy.

Author
Alain Jean-Marie
Returns
the embedded version of the generator

Implements transitionStructure.

void sparseMatrix::evaluateMeasure ( double *  m,
double *  res 
)
virtual

Sparse vector/matrix multiplication. The result is stored in an array that must be already allocated. Anciently the "multVM" method.

Author
Alain Jean-Marie
Parameters
mthe measure (row vector) to be multiplied
resthe resulting vector

Reimplemented from transitionStructure.

void sparseMatrix::evaluateMeasure ( discreteDistribution d,
discreteDistribution res 
)

Version of the vector/matrix multiplication that acts on discreteDistribution objects.

Author
Alain Jean-Marie
Parameters
dthe distribution to be multiplied
resthe resulting distribution
void sparseMatrix::evaluateValue ( double *  v,
double *  res 
)
virtual

Sparse vector/matrix multiplication. The result is stored in an array that must be already allocated. Anciently the "multMV" method.

Author
Alain Jean-Marie
Parameters
vthe value (column vector) to be multiplied
resthe resulting vector

Implements transitionStructure.

int sparseMatrix::getCol ( int  row,
int  numCol 
)
virtual

Retrieving an low-level entry from the matrix.

Author
Alain Jean-Marie
Parameters
rowthe number of the row
numColthe number of the entry in the sparse structure

Implements transitionStructure.

double sparseMatrix::getEntry ( int  row,
int  col 
)
virtual

Retrieving an entry from the matrix. Takes into account the fact that columns may be replicated: the different values are then added.

See also
setEntry()
Author
Alain Jean-Marie
Parameters
row
col

Implements transitionStructure.

double sparseMatrix::getEntryByCol ( int  row,
int  numCol 
)
virtual

Retrieving an low-level entry from the matrix.

Author
Alain Jean-Marie
Parameters
rowthe number of the row
numColthe number of the entry in the sparse structure

Implements transitionStructure.

int sparseMatrix::getNbElts ( int  row)
virtual

Retrieving a the number of elements on some row.

Author
Alain Jean-Marie
Parameters
rowthe number of the row
Returns
the number of columns

Implements transitionStructure.

discreteDistribution * sparseMatrix::getTransDistrib ( int  row)
virtual

Retrieving the transitions from some state as a discrete distribution.

Author
Alain Jean-Marie
Parameters
rowthe number of the row
Returns
the distribution: next states with the corresponding probas

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.

double sparseMatrix::rowSum ( int  row)
virtual

Summing a row.

Author
Alain Jean-Marie
Parameters
rowthe number of the row
Returns
the sum of the entries of the row (including diagonal)

Implements transitionStructure.

bool sparseMatrix::setEntry ( int  row,
int  col,
double  val 
)
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.

Author
Alain Jean-Marie
Parameters
rowthe row number
colthe column number
valthe value to be inserted
Returns
true if successful, that is, if ranges are OK and memory allocation is OK.

Implements transitionStructure.

sparseMatrix * sparseMatrix::uniformize ( )
virtual

Sparse matrix uniformization. Returns a sparse matrix and sets the uniformization factor. If the type is already discrete, returns a copy.

Author
Alain Jean-Marie
Returns
the uniformized version of the generator

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".

Author
Alain Jean-Marie
Parameters
outthe file descriptor to which the matrix is written
formatthe name of the format/language to use

The documentation for this class was generated from the following files: