Skip to content

Commit

Permalink
Merge branch 'master' into deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
wannesm committed Jun 13, 2024
2 parents e08812c + 4ef9493 commit c27568e
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 25 deletions.
21 changes: 11 additions & 10 deletions dtaidistance/dtw_weighted.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ def dt_windows(features, targets, classifier, patternlen, max_clfs, min_ig, min_
clf = classifier()
cur_features = features[:, idx_s:idx_e]
clf.fit(cur_features, targets, ignore_features=ignore_features, min_ig=min_ig)
logger.debug(f"Learned classifier {len(clfss) + 1}: idx = f{idx}/{idx_s}:f{idx+patternlen}/{idx_e}, "
f"nb nodes = {clf.tree_.nb_nodes}, used features = {clf.tree_.used_features}")
# logger.debug(f"Learned classifier {len(clfss) + 1}: idx = f{idx}/{idx_s}:f{idx+patternlen}/{idx_e}, "
# f"nb nodes = {clf.tree_.nb_nodes}, used features = {clf.tree_.used_features}")
if clf.tree_.nb_nodes <= 1:
continue
clf.set_features(list(range(idx_s, idx_e)))
Expand All @@ -304,8 +304,8 @@ def dt_windows(features, targets, classifier, patternlen, max_clfs, min_ig, min_
clfs = []
for clf_idx, clf in enumerate(clfss):
score = clf.score(max_kd)
logger.debug(f"Clf[{clf_idx:<2}] - Score = {score}, Entropy = {clf.avg_impurity()}, "
f"depth = {clf.tree_.depth}, nbnodes = {clf.tree_.nb_nodes}")
# logger.debug(f"Clf[{clf_idx:<2}] - Score = {score}, Entropy = {clf.avg_impurity()}, "
# f"depth = {clf.tree_.depth}, nbnodes = {clf.tree_.nb_nodes}")
clfs.append((score, -clf.tree_.nb_nodes, clf))
clfs.sort(reverse=True)
min_score = clfs[-1][0]
Expand All @@ -321,7 +321,7 @@ def dt_windows(features, targets, classifier, patternlen, max_clfs, min_ig, min_

if max_clfs is not None:
clfs = clfs[:max_clfs]
logger.debug(f"Kept {len(clfs)} classifiers with score >= {minallowed_score}, clfs_use = {clfs_use}")
# logger.debug(f"Kept {len(clfs)} classifiers with score >= {minallowed_score}, clfs_use = {clfs_use}")
for clf_score, clf_nbnodes, clf in clfs:
new_cl_values, used_features = decisiontree_to_clweights(clf, min_purity)
# if len(used_features) == 0:
Expand All @@ -347,14 +347,14 @@ def dt_onewindow(features, targets, classifier, max_clfs, min_ig, min_purity):
while not_empty and not (max_clfs is not None and len(clfs) >= max_clfs):
clf = classifier()
clf.fit(features, targets, ignore_features=ignore_features, min_ig=min_ig)
logger.debug(f"Learned classifier {len(clfs) + 1}: nb nodes = {clf.tree_.nb_nodes}")
# logger.debug(f"Learned classifier {len(clfs) + 1}: nb nodes = {clf.tree_.nb_nodes}")
if clf.tree_.nb_nodes <= 1:
not_empty = False
continue
clfs.append(clf)
new_cl_values, used_features = decisiontree_to_clweights(clf, min_purity)
if len(used_features) == 0:
logger.debug(f"No features used, ignore all features in tree: {clf.tree_.used_features}")
# logger.debug(f"No features used, ignore all features in tree: {clf.tree_.used_features}")
used_features.update(clf.tree_.used_features)
update_cl_values(cl_values, new_cl_values)
update_importances(importances, new_cl_values, clf_w)
Expand Down Expand Up @@ -423,15 +423,16 @@ def decisiontree_to_clweights(clf, min_purity=1.0):


def clweights_updatefrompath(cl_values, path):
logger.debug(f"Path to CL: {path}")
# logger.debug(f"Path to CL: {path}")
used_features = set()
for feature, threshold, leq in path:
index = feature // 2
dneg = ((feature % 2) == 0)
if leq: # f <= t
logger.debug(f"Ignore: CL with f{index} <= {threshold} (d is negative={dneg}, feature={feature})")
# logger.debug(f"Ignore: CL with f{index} <= {threshold} (d is negative={dneg}, feature={feature})")
pass
else: # f > t
logger.debug(f"Accept: CL with f{index} > {threshold} (d is negative={dneg}, feature={feature})")
# logger.debug(f"Accept: CL with f{index} > {threshold} (d is negative={dneg}, feature={feature})")
cl_values[index][0 if dneg else 1].append(threshold)
used_features.add(feature)
return used_features
Expand Down
2 changes: 1 addition & 1 deletion dtaidistance/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def smoothing(series, smooth):
b, a = signal.butter(N=2, Wn=Wn, btype='low', analog=False, output='ba')
except ValueError as exc:
raise ValueError("Cannot construct filter, change the smoothing factor. "
f"Requires 0<smooth<0.5 (now {smooth=}, {Wn=})") from exc
"Requires 0<smooth<0.5 (now Smooth={}, Wn={})".format(smooth, Wn)) from exc
try:
series = signal.filtfilt(b, a, series, axis=axis, method="gust")
except ValueError as exc:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def test_substitution_function():

if __name__ == "__main__":
directory = Path(os.environ.get('TESTDIR', Path(__file__).parent))
print(f"Saving files to {directory}")
print("Saving files to {}".format(directory))
test_sequences1()
test_sequences2()
test_sequences3()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_barycenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def test_ndim_kmeans2():
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler(sys.stdout))
directory = Path(os.environ.get('TESTDIR', Path(__file__).parent))
print(f"Saving files to {directory}")
print("Saving files to {}".format(directory))
# test_pair()
# test_trace()
# test_trace_mask()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bugsvis.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_bug4():
logger.addHandler(sh)
logger.propagate = 0
directory = Path(os.environ.get('TESTDIR', Path(__file__).parent))
print(f"Saving files to {directory}")
print("Saving files to {}".format(directory))
# test_bug1()
test_bug2()
# test_bug3()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def test_clustering_centroid():
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler(sys.stdout))
directory = Path(os.environ.get('TESTDIR', Path(__file__).parent))
print(f"Saving files to {directory}")
print("Saving files to {}".format(directory))
# test_clustering_tree()
# test_clustering_tree_ndim()
# test_clustering_tree_maxdist()
Expand Down
16 changes: 8 additions & 8 deletions tests/test_dtw_weighted.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def test_distance2():
prototypeidx = 0
ml_values, cl_values, clfs, importances = \
dtww.series_to_dt(s, l, prototypeidx, max_clfs=50, savefig=savefig)
logger.debug(f"ml_values = {dict(ml_values)}")
logger.debug(f"cl_values = {dict(cl_values)}")
# logger.debug(f"ml_values = {dict(ml_values)}")
# logger.debug(f"cl_values = {dict(cl_values)}")
weights = dtww.compute_weights_from_mlclvalues(s[prototypeidx], ml_values, cl_values, only_max=False, strict_cl=True)

if not dtwvis.test_without_visualization():
Expand Down Expand Up @@ -165,8 +165,8 @@ def test_distance4():
prototypeidx = 0
ml_values, cl_values, clf, importances = \
dtww.series_to_dt(s, l, prototypeidx, window=2, min_ig=0.1, savefig=savefig)
logger.debug(f"ml_values = {dict(ml_values)}")
logger.debug(f"cl_values = {dict(cl_values)}")
# logger.debug(f"ml_values = {dict(ml_values)}")
# logger.debug(f"cl_values = {dict(cl_values)}")
weights = dtww.compute_weights_from_mlclvalues(s[prototypeidx], ml_values, cl_values,
only_max=False, strict_cl=True)
if directory:
Expand All @@ -191,8 +191,8 @@ def test_distance5():

prototypeidx = 0
ml_values, cl_values, clf, importances = dtww.series_to_dt(s, l, prototypeidx, window=4)
logger.debug(f"ml_values = {dict(ml_values)}")
logger.debug(f"cl_values = {dict(cl_values)}")
# logger.debug(f"ml_values = {dict(ml_values)}")
# logger.debug(f"cl_values = {dict(cl_values)}")
weights = dtww.compute_weights_from_mlclvalues(s[prototypeidx], ml_values, cl_values,
only_max=False, strict_cl=True)
if directory:
Expand All @@ -218,8 +218,8 @@ def test_distance6():
labels[l == l[prototypeidx]] = 1
ml_values, cl_values, clf, importances = \
dtww.series_to_dt(s, labels, prototypeidx, window=0, min_ig=0.1, savefig=savefig)
logger.debug(f"ml_values = {dict(ml_values)}")
logger.debug(f"cl_values = {dict(cl_values)}")
# logger.debug(f"ml_values = {dict(ml_values)}")
# logger.debug(f"cl_values = {dict(cl_values)}")
weights = dtww.compute_weights_from_mlclvalues(s[prototypeidx], ml_values, cl_values,
only_max=False, strict_cl=True)
if directory:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_warping.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_warping_path1():
path3 = [(0, 0), (1, 0), (2, 1), (3, 2), (4, 3), (5, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10)]
assert len(path1) == len(path3)
assert len(path2) == len(path3)
assert d1 == pytest.approx(d2), f"{d1} != {d2}"
assert d1 == pytest.approx(d2), "{} != {}".format(d1, d2)
assert all(ai1 == bi1 and ai2 == bi2 for ((ai1, ai2), (bi1, bi2)) in zip(path1, path3))
assert all(ai1 == bi1 and ai2 == bi2 for ((ai1, ai2), (bi1, bi2)) in zip(path2, path3))

Expand Down Expand Up @@ -296,7 +296,7 @@ def test_subsequence():
with util_numpy.test_uses_numpy() as np:
np.set_printoptions(precision=2, linewidth=120)
directory = Path(os.environ.get('TESTDIR', Path(__file__).parent))
print(f"Saving files to {directory}")
print("Saving files to {}".format(directory))
# test_normalize()
test_normalize2()
# test_normalize2_prob()
Expand Down

0 comments on commit c27568e

Please sign in to comment.