Spaces:
Sleeping
Sleeping
fix non-seriarizable bug
Browse files- __main__.py +1 -1
- matching_series.py +7 -7
__main__.py
CHANGED
@@ -50,7 +50,7 @@ results = metric.compute(
|
|
50 |
)
|
51 |
logger.info(f"Time taken: {time.time() - s}")
|
52 |
|
53 |
-
print(results)
|
54 |
if args.output:
|
55 |
with open(args.output, "w") as f:
|
56 |
json.dump(results, f)
|
|
|
50 |
)
|
51 |
logger.info(f"Time taken: {time.time() - s}")
|
52 |
|
53 |
+
print(json.dumps(results))
|
54 |
if args.output:
|
55 |
with open(args.output, "w") as f:
|
56 |
json.dump(results, f)
|
matching_series.py
CHANGED
@@ -208,7 +208,7 @@ class matching_series(evaluate.Metric):
|
|
208 |
else:
|
209 |
distance = self._compute_metric(predictions[:, None], references, metric=metric, axis=1)
|
210 |
|
211 |
-
index_distance = distance.diagonal(axis1=0, axis2=1).mean()
|
212 |
|
213 |
# matching scores
|
214 |
distance_mean = distance.mean(axis=-1)
|
@@ -218,12 +218,12 @@ class matching_series(evaluate.Metric):
|
|
218 |
|
219 |
# matching distance
|
220 |
# shape: (num_generation,)
|
221 |
-
precision_distance = distance_mean[np.arange(len(best_match)), best_match].mean()
|
222 |
|
223 |
# best match for each reference time series
|
224 |
# shape: (num_reference,)
|
225 |
best_match_inv = np.argmin(distance_mean, axis=0)
|
226 |
-
recall_distance = distance_mean[best_match_inv, np.arange(len(best_match_inv))].mean()
|
227 |
|
228 |
f1_distance = 2 / (1 / precision_distance + 1 / recall_distance)
|
229 |
mean_distance = (precision_distance + recall_distance) / 2
|
@@ -246,11 +246,11 @@ class matching_series(evaluate.Metric):
|
|
246 |
cuc_features = []
|
247 |
for f in range(predictions.shape[-1]):
|
248 |
distance_f = distance[:, :, f]
|
249 |
-
index_distance_f = distance_f.diagonal(axis1=0, axis2=1).mean()
|
250 |
best_match_f = np.argmin(distance_f, axis=-1)
|
251 |
-
precision_distance_f = distance_f[np.arange(len(best_match_f)), best_match_f].mean()
|
252 |
best_match_inv_f = np.argmin(distance_f, axis=0)
|
253 |
-
recall_distance_f = distance_f[best_match_inv_f, np.arange(len(best_match_inv_f))].mean()
|
254 |
f1_distance_f = 2 / (1 / precision_distance_f + 1 / recall_distance_f)
|
255 |
mean_distance_f = (precision_distance_f + recall_distance_f) / 2
|
256 |
precision_distance_features.append(precision_distance_f)
|
@@ -361,7 +361,7 @@ class matching_series(evaluate.Metric):
|
|
361 |
sample = np.random.choice(match, size=n_sample, replace=False) # type: ignore
|
362 |
coverage += len(np.unique(sample)) / n_reference
|
363 |
coverages.append(coverage / n_calculation)
|
364 |
-
cuc = np.trapz(coverages, n_samples) / len(n_samples) / max(n_samples)
|
365 |
return coverages, cuc
|
366 |
|
367 |
@staticmethod
|
|
|
208 |
else:
|
209 |
distance = self._compute_metric(predictions[:, None], references, metric=metric, axis=1)
|
210 |
|
211 |
+
index_distance = distance.diagonal(axis1=0, axis2=1).mean().item()
|
212 |
|
213 |
# matching scores
|
214 |
distance_mean = distance.mean(axis=-1)
|
|
|
218 |
|
219 |
# matching distance
|
220 |
# shape: (num_generation,)
|
221 |
+
precision_distance = distance_mean[np.arange(len(best_match)), best_match].mean().item()
|
222 |
|
223 |
# best match for each reference time series
|
224 |
# shape: (num_reference,)
|
225 |
best_match_inv = np.argmin(distance_mean, axis=0)
|
226 |
+
recall_distance = distance_mean[best_match_inv, np.arange(len(best_match_inv))].mean().item()
|
227 |
|
228 |
f1_distance = 2 / (1 / precision_distance + 1 / recall_distance)
|
229 |
mean_distance = (precision_distance + recall_distance) / 2
|
|
|
246 |
cuc_features = []
|
247 |
for f in range(predictions.shape[-1]):
|
248 |
distance_f = distance[:, :, f]
|
249 |
+
index_distance_f = (distance_f.diagonal(axis1=0, axis2=1).mean()).item()
|
250 |
best_match_f = np.argmin(distance_f, axis=-1)
|
251 |
+
precision_distance_f = (distance_f[np.arange(len(best_match_f)), best_match_f].mean()).item()
|
252 |
best_match_inv_f = np.argmin(distance_f, axis=0)
|
253 |
+
recall_distance_f = (distance_f[best_match_inv_f, np.arange(len(best_match_inv_f))].mean()).item()
|
254 |
f1_distance_f = 2 / (1 / precision_distance_f + 1 / recall_distance_f)
|
255 |
mean_distance_f = (precision_distance_f + recall_distance_f) / 2
|
256 |
precision_distance_features.append(precision_distance_f)
|
|
|
361 |
sample = np.random.choice(match, size=n_sample, replace=False) # type: ignore
|
362 |
coverage += len(np.unique(sample)) / n_reference
|
363 |
coverages.append(coverage / n_calculation)
|
364 |
+
cuc = (np.trapz(coverages, n_samples) / len(n_samples) / max(n_samples)).item()
|
365 |
return coverages, cuc
|
366 |
|
367 |
@staticmethod
|