open-risk/transitionMatrix

Address numpy.matrix deprecation

open-risk opened this issue · 1 comments

numpy.matrix is on a deprecation path, given than a transitionMatrix object derives from it, some alternative should be developed

I think the depreciation is an opportunity to revisit the structure of the classes - they are so overloaded now with IO operations, matrix validation, manipulation, etc.

Can anything simple as below work?

from typing import List
import numpy as np

TM = np.ndarray
TMSet = List[TM]

def empty(dimensions: int) -> TM:
   return np.identity(dimension)

Another idea is to hide ndarray behind a dataclass, but leave non-essential methods out:

from dataclasses import dataclass

@dataclass
class TransitionMatrix:
    matrix: np.ndarray

def matrix(values) -> TransitionMatrix:
    pass

def read_csv(filename) -> TransitionMatrix:
    pass

class TransitionMatrix(np.matrix):
""" The _`TransitionMatrix` object implements a typical (one period) `transition matrix <https://www.openriskmanual.org/wiki/Transition_Matrix>`_.
The class inherits from numpy matrices and implements additional properties specific transition matrices. It forms the building block of the
TransitionMatrixSet_ which holds a collection of matrices in increasing temporal order
"""
def __new__(cls, values=None, dimension=2, json_file=None, csv_file=None):