Skip to content

Commit

Permalink
remove adjustOccs from Candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasbtnfr committed Mar 20, 2023
1 parent 50865d3 commit e5188e1
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 52 deletions.
17 changes: 0 additions & 17 deletions skmine/periodic/candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,23 +289,6 @@ def getCostUncoveredRatio(self):
def isEfficient(self, dcosts):
return (self.getCost() / self.getNbUncovered()) < np.mean([dcosts[unc[1]] for unc in self.uncov])

def adjustOccs(self):
"""
Adds to self.P["occs_up"], the list of uncov timestamps
Returns
-------
None
"""
if not self.isPattern() and (self.uncov is not None) and (self.getNbUncovered() < self.getNbOccs()):
okk = self.getEvOccs()
mni, mxi = (0, len(self.O) - 1)
while okk[mni] not in self.uncov:
mni += 1
while okk[mxi] not in self.uncov:
mxi -= 1
self.P["occs_up"] = [self.O[kk] for kk in range(mni, mxi + 1)]

def getProps(self, nkey=0, max_offset=None):
if max_offset is None:
max_offset = PROPS_MAX_OFFSET
Expand Down
9 changes: 3 additions & 6 deletions skmine/periodic/run_mine.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,15 +732,14 @@ def makeCandOnOrder(cand_pids, data_details, patterns_props, cpool):
return new_cand


def filter_candidates_cover(cands, dcosts, min_cov=1, adjust_occs=False, cis=None):
def filter_candidates_cover(cands, dcosts, min_cov=1, cis=None):
"""
Filters a list of candidates based on their coverage and cost efficiency.
Parameters:
cands (dict or list): A dictionary or list of Candidate objects.
dcosts (dict): A dictionary of costs for each data point.
min_cov (int): The minimum number of data points a candidate must cover to be selected. Default is 1.
adjust_occs (bool): Whether to adjust occurrences of patterns. Default is False.
cis (list): A list of candidate indices to consider. If not provided, all candidates will be considered.
Returns:
Expand All @@ -750,7 +749,7 @@ def filter_candidates_cover(cands, dcosts, min_cov=1, adjust_occs=False, cis=Non
------
>>> cands = [Candidate(...), Candidate(...), ...]
>>> dcosts = {'data1': 0.5, 'data2': 0.8, ...}
>>> selected = filter_candidates_cover(cands, dcosts, min_cov=2, adjust_occs=True, cis=[0, 2, 5])
>>> selected = filter_candidates_cover(cands, dcosts, min_cov=2, cis=[0, 2, 5])
"""
if cis is None:
if type(cands) is dict:
Expand All @@ -771,8 +770,6 @@ def filter_candidates_cover(cands, dcosts, min_cov=1, adjust_occs=False, cis=Non
nxti = cis.pop(0)
if cands[nxti].getCostUncoveredRatio() <= max_eff:
if cands[nxti].getNbUncovered() >= min_cov and cands[nxti].isEfficient(dcosts):
if not cands[nxti].isPattern() and adjust_occs:
cands[nxti].adjustOccs()

selected.append(nxti)
covered.update(cands[nxti].getUncovered())
Expand Down Expand Up @@ -1013,7 +1010,7 @@ def mine_seqs(seqs, complex=True, max_p=None):
results["Final_selection_TIME"] = str(tac_comb)

selected = filter_candidates_cover(
cdict, dcosts, min_cov=3, adjust_occs=True)
cdict, dcosts, min_cov=3)
pc = PatternCollection([cdict[c].getPattT0E() for c in selected])
tac = datetime.datetime.now()

Expand Down
29 changes: 0 additions & 29 deletions skmine/periodic/tests/test_candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,42 +147,13 @@ def test___str__(cand):
50.22386061518789, 3, cand.getCostRatio(), 3, {'alpha': 1, 'p': 50, 'source': (2, 0)}, 0)


def test_adjustOccs_no_changes(cand, cand_pattern):
P = cand.P
cand.adjustOccs()
assert cand.P == P

P = cand_pattern.P
cand_pattern.adjustOccs()
assert cand_pattern.P == P


def test_initUncovered(cand, cand_pattern):
cand.initUncovered()
assert cand.uncov == {(0, 1), (51, 1), (100, 1)}
cand_pattern.initUncovered()
assert cand_pattern.uncov == {(0, 4), (60480, 4), (120961, 4), (181441, 4), (241921, 4)}


def test_adjustOccs():
cid = 1
pattern = {
'alpha': 10,
'p': 75,
'pos': [8, 9, 11, 12, 14, 15, 16],
'uncov': {8, 9, 11, 12, 14, 15, 16},
'source': (1, 1)
}
O = [159626778, 159626862, 159626934, 159627012, 159627090, 159627162, 159627234]
E = [9, -3, 3, 3, -3, -3]
cost = 78.81334894354123
cand = Candidate(cid, pattern, O, E, cost)
cand.uncov = {(159626862, 10), (159626934, 10), (159627012, 10), (159627090, 10), (159627162, 10), (159627234, 10)}
# 6 uncovered and 7 occurrences
cand.adjustOccs()
assert cand.P["occs_up"] == [159626862, 159626934, 159627012, 159627090, 159627162, 159627234]


def test_factorizePattern():
cid = 1
pattern = Pattern(
Expand Down

0 comments on commit e5188e1

Please sign in to comment.