Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
TommasoBelluzzo authored Jun 25, 2021
1 parent 6446b87 commit a93d651
Show file tree
Hide file tree
Showing 8 changed files with 457 additions and 140 deletions.
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@ $ conda install -c tommasobelluzzo pydtmc
$ conda update -c tommasobelluzzo pydtmc
```

[GitHub](https://github.com/):

```sh
$ pip install git+https://github.com/TommasoBelluzzo/PyDTMC.git@master#egg=PyDTMC
$ pip install --upgrade git+https://github.com/TommasoBelluzzo/PyDTMC.git@master#egg=PyDTMC
```

## Usage

The core element of the library is the `MarkovChain` class, which can be instantiated as follows:
Expand Down
2 changes: 1 addition & 1 deletion meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test:
about:
home: {{ data['url'] }}
license: {{ data['license'] }}
license_file: {{ data['license_files'] }}
license_file: {{ data['url'] }}/blob/master/LICENSE.md
summary: {{ summary }}
description: {{ description }}
dev_url: {{ data['url'] }}
Expand Down
52 changes: 26 additions & 26 deletions pydtmc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# -*- coding: utf-8 -*-

__title__ = 'PyDTMC'
__version__ = '6.1.0'
__author__ = 'Tommaso Belluzzo'

__all__ = [
'ValidationError',
'MarkovChain',
'plot_eigenvalues', 'plot_graph', 'plot_redistributions', 'plot_walk'
]

from pydtmc.exceptions import (
ValidationError
)

from pydtmc.markov_chain import (
MarkovChain
)

from pydtmc.plotting import (
plot_eigenvalues,
plot_graph,
plot_redistributions,
plot_walk
)
# -*- coding: utf-8 -*-

__title__ = 'PyDTMC'
__version__ = '6.1.0'
__author__ = 'Tommaso Belluzzo'

__all__ = [
'ValidationError',
'MarkovChain',
'plot_eigenvalues', 'plot_graph', 'plot_redistributions', 'plot_walk'
]

from pydtmc.exceptions import (
ValidationError
)

from pydtmc.markov_chain import (
MarkovChain
)

from pydtmc.plotting import (
plot_eigenvalues,
plot_graph,
plot_redistributions,
plot_walk
)
25 changes: 16 additions & 9 deletions pydtmc/markov_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1959,15 +1959,21 @@ def from_graph(graph: tgraphs) -> tmc:
size = len(states)

p = np.zeros((size, size), dtype=float)
edges = list(graph.edges(data='weight', default=0.0))

for state_from, weights in graph.adjacency():
for edge in edges:
i = states.index(edge[0])
j = states.index(edge[1])
p[i, j] = float(edge[2])

i = states.index(state_from)
p_sums = np.sum(p, axis=1)

for state_to, data in weights.items():
j = states.index(state_to)
w = data['weight']
p[i, j] = w
for i in range(size):

if np.isclose(p_sums[i], 0.0): # pragma: no cover
p[i, :] = np.ones(p.shape[0], dtype=float) / size
else:
p[i, :] /= p_sums[i]

mc = MarkovChain(p, states)

Expand Down Expand Up @@ -2069,13 +2075,14 @@ def from_matrix(m: tnumeric, states: olist_str = None) -> tmc:
raise generate_validation_error(e, trace()) from None

p = np.copy(m)
p_size = p.shape[0]
p_sums = np.sum(p, axis=1)

for i in range(p_size):
size = p.shape[0]

for i in range(size):

if np.isclose(p_sums[i], 0.0): # pragma: no cover
p[i, :] = np.ones(p.shape[0], dtype=float) / p_size
p[i, :] = np.ones(p.shape[0], dtype=float) / size
else:
p[i, :] /= p_sums[i]

Expand Down
Loading

0 comments on commit a93d651

Please sign in to comment.