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 Jul 2, 2021
1 parent 41cdbd3 commit eb5f532
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 31 deletions.
2 changes: 2 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ def run(self, **kwargs):
if not search(r'markov_chain_[A-Z_]+\.rst$', self.document['source'], flags=flag_ignorecase):
return

print(self.document)

for node in self.document.traverse(addnodes.desc):

if not node.hasattr('objtype') or node['objtype'] != 'class':
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ PyDTMC
genindex

| PyDTMC is a full-featured, lightweight library for discrete-time Markov chains analysis.
| It provides classes and functions for creating, manipulating and simulating markovian stochastic processes.
| It provides classes and functions for creating, manipulating, simulating and visualizing markovian stochastic processes.
| Current Version: |version|
4 changes: 2 additions & 2 deletions meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ about:
license_file: {{ data['url'] }}/blob/master/LICENSE.md
summary: {{ summary }}
description: {{ description }}
dev_url: {{ data['url'] }}
doc_url: https://{{ name.lower() }}.readthedocs.io/
doc_source_url: {{ data['url'] }}/blob/master/README.md
doc_source_url: {{ data['url'] }}/blob/master/docs/source/index.rst
dev_url: {{ data['url'] }}

extra:
maintainers:
Expand Down
21 changes: 12 additions & 9 deletions pydtmc/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,8 @@ def validate_rewards(rewards: tany, size: int) -> tarray:

rewards = rewards.astype(float)

if (rewards.ndim < 1) or ((rewards.ndim == 2) and (rewards.shape[0] != 1)) or (rewards.ndim > 2):
raise ValueError('The "@arg@" parameter must be a vector.')
if (rewards.ndim > 2) or (rewards.ndim == 2 and rewards.shape[0] != 1):
raise ValueError('The "@arg@" parameter must be a valid vector.')

rewards = np.ravel(rewards)

Expand Down Expand Up @@ -642,7 +642,7 @@ def validate_status(status: tany, current_states: tlist_str) -> tarray:

status = status.astype(float)

if status.ndim < 1 or (status.ndim == 2 and status.shape[0] != 1 and status.shape[1] != 1) or status.ndim > 2:
if status.ndim > 2 or (status.ndim == 2 and status.shape[0] != 1):
raise ValueError('The "@arg@" parameter must be a valid vector.')

status = np.ravel(status)
Expand All @@ -666,13 +666,14 @@ def validate_state_names(states: tany, size: oint = None) -> tlist_str:
except Exception as e:
raise TypeError('The "@arg@" parameter is null or wrongly typed.') from e

if not all(isinstance(state, str) for state in states):
raise TypeError('The "@arg@" parameter must contain only string values.')

if not all(state is not None and (len(state) > 0) for state in states):
if not all(state is not None and isinstance(state, str) and (len(state) > 0) for state in states):
raise TypeError('The "@arg@" parameter must contain only valid string values.')

states_length = len(states)

if states_length < 2:
raise ValueError('The "@arg@" parameter must contain at least two elements.')

states_unique = len(set(states))

if states_unique < states_length:
Expand Down Expand Up @@ -794,7 +795,9 @@ def validate_time_points(time_points: tany) -> ttimes_in:
if time_points_length < 1:
raise ValueError('The "@arg@" parameter must contain at least one element.')

if len(set(time_points)) < time_points_length:
time_points_unique = len(set(time_points))

if time_points_unique < time_points_length:
raise ValueError('The "@arg@" parameter must contain only unique values.')

time_points = sorted(time_points)
Expand Down Expand Up @@ -868,7 +871,7 @@ def validate_vector(vector: tany, vector_type: str, flex: bool, size: oint = Non

vector = vector.astype(float)

if vector.ndim < 1 or vector.ndim > 2 or ((vector.ndim == 2) and (vector.shape[0] != 1) and (vector.shape[1] != 1)):
if vector.ndim > 2 or (vector.ndim == 2 and vector.shape[0] != 1):
raise ValueError('The "@arg@" parameter must be a valid vector.')

vector = np.ravel(vector)
Expand Down
184 changes: 165 additions & 19 deletions tests/fixtures/fixtures_validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,6 @@
"size": 3,
"is_valid": true
},
{
"value": -1,
"size": null,
"is_valid": false
},
{
"value": [[0.3, 0.0, 0.0, 0.7], [0.0, 0.0, 1.0, 0.0], [0.5, 0.3, 0.1, 0.1], [0.2, 0.4, 0.2, 0.2]],
"size": 6,
Expand All @@ -223,6 +218,11 @@
"size": null,
"is_valid": false
},
{
"value": -1,
"size": null,
"is_valid": false
},
{
"value": [],
"size": 0,
Expand Down Expand Up @@ -470,12 +470,12 @@
},
{
"value": null,
"size": [],
"size": null,
"is_valid": false
},
{
"value": [],
"size": [],
"size": 0,
"is_valid": false
}
],
Expand Down Expand Up @@ -663,17 +663,17 @@
},
{
"value": null,
"size": 0,
"size": null,
"is_valid": false
},
{
"value": true,
"size": 0,
"size": null,
"is_valid": false
},
{
"value": [[], []],
"size": 0,
"size": 2,
"is_valid": false
}
],
Expand Down Expand Up @@ -722,47 +722,47 @@
"validate_partitions_data": [
{
"value": [["A", "B"], ["C"]],
"current_states": ["A", "B", "C"],
"current_states": ["A", "B", "C"],
"is_valid": true
},
{
"value": [["A", "B"], ["C", "D"]],
"current_states": ["A", "B", "C", "D"],
"current_states": ["A", "B", "C", "D"],
"is_valid": true
},
{
"value": [[0], [1, 2]],
"current_states": ["A", "B", "C"],
"current_states": ["A", "B", "C"],
"is_valid": true
},
{
"value": [["A", "B", "C", "D"]],
"current_states": ["A", "B", "C", "D"],
"current_states": ["A", "B", "C", "D"],
"is_valid": false
},
{
"value": [[1, 2], [3]],
"current_states": ["A", "B", "C"],
"current_states": ["A", "B", "C"],
"is_valid": false
},
{
"value": [true, [0, 1, 2]],
"current_states": ["A", "B", "C", "D"],
"current_states": ["A", "B", "C", "D"],
"is_valid": false
},
{
"value": [["A"], ["B", "D"]],
"current_states": ["A", "B", "C"],
"current_states": ["A", "B", "C"],
"is_valid": false
},
{
"value": [[0], [true, 2], [3]],
"current_states": ["A", "B", "C", "D"],
"current_states": ["A", "B", "C", "D"],
"is_valid": false
},
{
"value": [["A"], ["C", "D"], ["E"]],
"current_states": ["A", "B", "C", "D", "E"],
"current_states": ["A", "B", "C", "D", "E"],
"is_valid": false
},
{
Expand All @@ -771,6 +771,58 @@
"is_valid": false
}
],
"validate_rewards_data": [
{
"value": [-2, 0, 2],
"size": 3,
"is_valid": true
},
{
"value": [0.5, 8.6, -2.5, 0.0, 0.0, 6.3],
"size": 6,
"is_valid": true
},
{
"value": [0.0, 11.4],
"size": 3,
"is_valid": false
},
{
"value": ["Infinity", 2.3, -0.9, "Infinity"],
"size": 4,
"is_valid": false
},
{
"value": [[0.3, 0.8, 0.1], [0.2, 0.0, -0.6], [-0.25, 0.4, -0.3]],
"size": 3,
"is_valid": false
},
{
"value": [[3.5], [-4.4], [9.4]],
"size": 3,
"is_valid": false
},
{
"value": null,
"size": null,
"is_valid": false
},
{
"value": 3,
"size": null,
"is_valid": false
},
{
"value": [],
"size": 0,
"is_valid": false
},
{
"value": [[], []],
"size": 0,
"is_valid": false
}
],
"validate_state_data": [
{
"value": 0,
Expand Down Expand Up @@ -823,6 +875,100 @@
"is_valid": false
}
],
"validate_state_names_data": [
{
"value": ["1", "2", "3"],
"size": 3,
"is_valid": true
},
{
"value": ["A", "B", "C"],
"size": null,
"is_valid": true
},
{
"value": ["S4", "S1", "S9", "S6", "S5"],
"size": null,
"is_valid": true
},
{
"value": ["S4", "S1", "S9", "S6", "S5"],
"size": 7,
"is_valid": false
},
{
"value": ["1", "2", "2", "3"],
"size": null,
"is_valid": false
},
{
"value": ["1", "", "2"],
"size": 3,
"is_valid": false
},
{
"value": [false, true, 2],
"size": 3,
"is_valid": false
},
{
"value": null,
"size": null,
"is_valid": false
},
{
"value": "A",
"size": null,
"is_valid": false
},
{
"value": [],
"size": 0,
"is_valid": false
}
],
"validate_time_points_data": [
{
"value": 5,
"is_valid": true
},
{
"value": [100, 1000],
"is_valid": true
},
{
"value": [0, 2, 4, 6, 8, 10],
"is_valid": true
},
{
"value": -3,
"is_valid": false
},
{
"value": [-1, 0, 1],
"is_valid": false
},
{
"value": [3, 6, 6, 6, 9],
"is_valid": false
},
{
"value": [1.4, 3.3, 4.7],
"is_valid": false
},
{
"value": ["10", "20"],
"is_valid": false
},
{
"value": null,
"is_valid": false
},
{
"value": [],
"is_valid": false
}
],
"validate_transition_function_data": [
{
"value": "def f(x_index, x_value, y_index, y_value): return 0",
Expand Down
Loading

0 comments on commit eb5f532

Please sign in to comment.