Skip to content

Commit

Permalink
fix multiple nodes with same events
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasbtnfr committed Mar 21, 2023
1 parent d6ff57c commit d7dd8f3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
6 changes: 5 additions & 1 deletion skmine/periodic/cycles.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from sklearn.base import BaseEstimator, TransformerMixin

from .data_sequence import DataSequence
from .pattern import Pattern, getEDict
from .pattern import Pattern, getEDict, draw_pattern
from .pattern_collection import PatternCollection
from .run_mine import mine_seqs

Expand Down Expand Up @@ -413,3 +413,7 @@ def get_residuals(self, *patterns_id, sort="time"):
residuals_transf_pd = residuals_transf_pd.sort_values(by=['event'])

return residuals_transf_pd


def draw_pattern(self, pattern_id):
return draw_pattern(self.cycles.loc[pattern_id]["pattern_json_tree"])
13 changes: 9 additions & 4 deletions skmine/periodic/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,27 @@ def draw_pattern_rec(graph, pattern, id_to_pr_event=None, id=0, id_parent=-1, di

if "p" in element: # node
id_to_pr_event[id] = "p=" + str(element["p"]) + "\nr=" + str(element["r"])
graph.node(id_to_pr_event[id], shape="box")
graph.node(name=str(id), label=id_to_pr_event[id], shape="box")

if id_parent != -1:
graph.edge(id_to_pr_event[id_parent], id_to_pr_event[id], dir="none")
graph.edge(str(id_parent), str(id), dir="none")

if distance != (-1, -1):
graph.edge(id_to_pr_event[distance[0]], id_to_pr_event[id], label=str(distance[1]), style="dotted")
graph.edge(str(distance[0]), str(id), label=str(distance[1]), style="dotted")

for i, child in enumerate(element["children"]):
distance = (element["children"][i - 1][0], child[1]) if child[1] != 0 else (-1, -1)
# id of the node where the distance starts + distance
draw_pattern_rec(graph, pattern, id_to_pr_event=id_to_pr_event, id=child[0], id_parent=id,
distance=distance)

else: # leaf
id_to_pr_event[id] = str(element["event"])
graph.edge(id_to_pr_event[id_parent], id_to_pr_event[id], dir="none")
graph.node(name=str(id), label=id_to_pr_event[id])
graph.edge(str(id_parent), str(id), dir="none")

if distance != (-1, -1):
graph.edge(str(distance[0]), str(id), label=str(distance[1]), style="dotted")

return graph

Expand Down
4 changes: 1 addition & 3 deletions skmine/periodic/pattern_collection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import json

import numpy as np

from .class_patterns import cost_one
Expand Down Expand Up @@ -215,7 +213,7 @@ def output_pattern_list_and_cost(self, data_seq, print_simple=True):
pattern_tree["next_id"] = p.next_id
pattern_tree["t0"] = int(t0)
pattern_tree["E"] = [int(e) for e in E]
pattern_tree = json.dumps(_change_int64_toint(pattern_tree))
pattern_tree = _change_int64_toint(pattern_tree)

dict_pattern["t0"] = t0
dict_pattern["pattern_json_tree"] = pattern_tree
Expand Down

0 comments on commit d7dd8f3

Please sign in to comment.