bowdbeg commited on
Commit
51e08a8
·
1 Parent(s): b0556db

add matching_indices

Browse files
Files changed (3) hide show
  1. README.md +5 -0
  2. __main__.py +1 -1
  3. matching_series.py +17 -1
README.md CHANGED
@@ -131,6 +131,7 @@ At minium, the metric requires the original time-series and the generated time-s
131
  - **return_distance**: (bool, optional): Whether to return the distance matrix. Default is False.
132
  - **return_matching**: (bool, optional): Whether to return the matching matrix. Default is False.
133
  - **return_each_features**: (bool, optional): Whether to return the results for each feature. Default is False.
 
134
  - **return_coverages**: (bool, optional): Whether to return the coverages. Default is False.
135
  - **return_all**: (bool, optional): Whether to return all the results. Default is False.
136
  - **dtype**: (str, optional): The data type used for computation. Default is "float32".
@@ -154,6 +155,10 @@ Let prediction instances be $P = \{p_1, p_2, \ldots, p_n\}$ and reference instan
154
  - **distance**: (numpy.ndarray): The distance matrix between the generated instances and the reference instances.
155
  - **match**: (numpy.ndarray): The matching matrix between the generated instances and the reference instances.
156
  - **match_inv**: (numpy.ndarray): The matching matrix between the reference instances and the generated instances.
 
 
 
 
157
 
158
  <!-- #### Values from Popular Papers -->
159
  <!-- *Give examples, preferrably with links to leaderboards or publications, to papers that have reported this metric, along with the values they have reported.* -->
 
131
  - **return_distance**: (bool, optional): Whether to return the distance matrix. Default is False.
132
  - **return_matching**: (bool, optional): Whether to return the matching matrix. Default is False.
133
  - **return_each_features**: (bool, optional): Whether to return the results for each feature. Default is False.
134
+ - **return_matching_indices**: (bool, optional): Whether to return the indices of matching. Default is False.
135
  - **return_coverages**: (bool, optional): Whether to return the coverages. Default is False.
136
  - **return_all**: (bool, optional): Whether to return all the results. Default is False.
137
  - **dtype**: (str, optional): The data type used for computation. Default is "float32".
 
155
  - **distance**: (numpy.ndarray): The distance matrix between the generated instances and the reference instances.
156
  - **match**: (numpy.ndarray): The matching matrix between the generated instances and the reference instances.
157
  - **match_inv**: (numpy.ndarray): The matching matrix between the reference instances and the generated instances.
158
+ - **g2r_index**: (numpy.ndarray): The index of the reference instance that matches the generated instance for each feature.
159
+ - **r2g_index**: (numpy.ndarray): The index of the generated instance that matches the reference instance for each feature.
160
+ - **mean_g2r_index**: (numpy.ndarray): The index of the reference instance that matches the generated instance.
161
+ - **mean_r2g_index**: (numpy.ndarray): The index of the generated instance that matches the reference instance.
162
 
163
  <!-- #### Values from Popular Papers -->
164
  <!-- *Give examples, preferrably with links to leaderboards or publications, to papers that have reported this metric, along with the values they have reported.* -->
__main__.py CHANGED
@@ -43,7 +43,7 @@ results = metric.compute(
43
  predictions=predictions,
44
  references=references,
45
  batch_size=args.batch_size,
46
- num_processes=args.num_process,
47
  return_each_features=True,
48
  return_coverages=True,
49
  dtype=args.dtype,
 
43
  predictions=predictions,
44
  references=references,
45
  batch_size=args.batch_size,
46
+ num_processes=args.num_processes,
47
  return_each_features=True,
48
  return_coverages=True,
49
  dtype=args.dtype,
matching_series.py CHANGED
@@ -229,6 +229,7 @@ class matching_series(evaluate.Metric):
229
  return_matching: bool = False,
230
  return_each_features: bool = False,
231
  return_coverages: bool = False,
 
232
  return_all: bool = False,
233
  dtype=np.float32,
234
  eps: float = 1e-8,
@@ -249,6 +250,7 @@ class matching_series(evaluate.Metric):
249
  return_matching: bool, optional: Whether to return the matching matrix. Default is False.
250
  return_each_features: bool, optional: Whether to return the results for each feature. Default is False.
251
  return_coverages: bool, optional: Whether to return the coverages. Default is False.
 
252
  return_all: bool, optional: Whether to return all the results. Default is False.
253
  dtype: str, optional: The data type used for computation. Default is "float32".
254
  eps: float, optional: The epsilon value to avoid division by zero. Default is 1e-8.
@@ -301,8 +303,9 @@ class matching_series(evaluate.Metric):
301
  dtype=dtype,
302
  )
303
 
 
304
  metrics = self._compute_metrics(
305
- distance=distance.mean(axis=-1),
306
  eps=eps,
307
  cuc_n_calculation=cuc_n_calculation,
308
  cuc_n_samples=cuc_n_samples,
@@ -341,6 +344,19 @@ class matching_series(evaluate.Metric):
341
  "coverages_features": [m["coverages"] for m in metrics_feature],
342
  }
343
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
344
  return out
345
 
346
  def compute_cuc(
 
229
  return_matching: bool = False,
230
  return_each_features: bool = False,
231
  return_coverages: bool = False,
232
+ return_matching_indices: bool = False,
233
  return_all: bool = False,
234
  dtype=np.float32,
235
  eps: float = 1e-8,
 
250
  return_matching: bool, optional: Whether to return the matching matrix. Default is False.
251
  return_each_features: bool, optional: Whether to return the results for each feature. Default is False.
252
  return_coverages: bool, optional: Whether to return the coverages. Default is False.
253
+ return_matching_indices: bool, optional: Whether to return the indices of matching. Default is False.
254
  return_all: bool, optional: Whether to return all the results. Default is False.
255
  dtype: str, optional: The data type used for computation. Default is "float32".
256
  eps: float, optional: The epsilon value to avoid division by zero. Default is 1e-8.
 
303
  dtype=dtype,
304
  )
305
 
306
+ distance_mean = distance.mean(axis=-1)
307
  metrics = self._compute_metrics(
308
+ distance=distance_mean,
309
  eps=eps,
310
  cuc_n_calculation=cuc_n_calculation,
311
  cuc_n_samples=cuc_n_samples,
 
344
  "coverages_features": [m["coverages"] for m in metrics_feature],
345
  }
346
  )
347
+ if return_matching_indices:
348
+ # matching index
349
+ g2r_index = distance.argmin(axis=1)
350
+ r2g_index = distance.argmin(axis=0)
351
+ # mean
352
+ mean_g2r_index = distance_mean.argmin(axis=1)
353
+ mean_r2g_index = distance_mean.argmin(axis=0)
354
+
355
+ out["g2r_index"] = g2r_index
356
+ out["r2g_index"] = r2g_index
357
+ out["mean_g2r_index"] = mean_g2r_index
358
+ out["mean_r2g_index"] = mean_r2g_index
359
+
360
  return out
361
 
362
  def compute_cuc(