Biogeme: Python Library  2.5
bioMatrix.py
Go to the documentation of this file.
1 
5 
6 ## @brief This class implements a matrix object designed to store the
7 # variance covariance matrix.
8 class bioMatrix(object):
9  ## Constructor
10  # @param dim Dimension of the (square) matrix
11  # @param names Array of dimension dim containing the names of the parameters
12  # @param values Two-dimensional array of dimension dim x dim containing the entries of the matrix
13  # @details Example for the diagonal matrix
14  # \f[\begin{array}{cccc} 7 & 0 & 0 & 0 \\ 0 & 7 & 0 & 0 \\ 0 & 0 & 7 & 0 \\ 0 & 0 & 0 & 7 \end{array}\f]
15  # @code
16  # names = ["ASC_TRAIN","B_TIME","B_COST","ASC_CAR"]
17  # values = [[7.0,0.0,0.0,0.0],[0.0,7.0,0.0,0.0],[0.0,0.0,7.0,0.0],[0.0,0.0,0.0,7.0]]
18  # theMatrix = bioMatrix(4,names,values)
19  # @endcode
20  def __init__(self, dim, names, values):
21  ## Dimension of the (square) matrix
22  self.dim = dim
23  self.names = names
24  j = 0
25  self.keys = {}
26  for i in names:
27  self.keys[i] = j
28  j += 1
29  # initialize matrix and fill with zeroes
30  self.matrix = []
31  for i in names:
32  ea_row = []
33  for j in range(dim):
34  ea_row.append(values[self.keys[i]][j])
35  self.matrix.append(ea_row)
36 
37  ## Set an entry of the matrix. If it is an off-diagonal entry, the
38  ## symmetric entry is set to the same value to maintain the
39  ## symmetry of the matrix.
40  # @param rowname Name of the row
41  # @param colname Name of the column
42  # @param v Value
43  def setvalue(self, rowname, colname, v):
44  self.matrix[self.keys[colname]][self.keys[rowname]] = v
45  self.matrix[self.keys[rowname]][self.keys[colname]] = v
46 
47  ## Get an entry of the matrix.
48  # @param rowname Name of the row
49  # @param colname Name of the column
50  # @return Value
51  def getvalue(self, rowname, colname):
52  return self.matrix[self.keys[colname]][self.keys[rowname]]
53 
54  ## Function called by the print statement
55  def __str__(self):
56  outStr = ""
57  for k in self.names:
58  outStr += '%s: %s\n' % (k,self.matrix[self.keys[k]])
59  return outStr
def setvalue(self, rowname, colname, v)
Set an entry of the matrix.
Definition: bioMatrix.py:43
This class implements a matrix object designed to store the variance covariance matrix.
Definition: bioMatrix.py:8
def __str__(self)
Function called by the print statement.
Definition: bioMatrix.py:55
def getvalue(self, rowname, colname)
Get an entry of the matrix.
Definition: bioMatrix.py:51
def __init__(self, dim, names, values)
Constructor.
Definition: bioMatrix.py:20
dim
Dimension of the (square) matrix.
Definition: bioMatrix.py:22
Copyright 2016 Michel Bierlaire