Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address numpy.matrix deprecation #10

Open
open-risk opened this issue Feb 7, 2021 · 1 comment
Open

Address numpy.matrix deprecation #10

open-risk opened this issue Feb 7, 2021 · 1 comment
Labels
design fundamental design / API aspects

Comments

@open-risk
Copy link
Owner

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

@open-risk open-risk added the design fundamental design / API aspects label Feb 7, 2021
@epogrebnyak
Copy link
Contributor

epogrebnyak commented Feb 7, 2021

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):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design fundamental design / API aspects
Projects
None yet
Development

No branches or pull requests

2 participants