CoreMS 4.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. corems/__init__.py +63 -0
  2. corems/chroma_peak/__init__.py +0 -0
  3. corems/chroma_peak/calc/ChromaPeakCalc.py +480 -0
  4. corems/chroma_peak/calc/__init__.py +0 -0
  5. corems/chroma_peak/calc/subset.py +196 -0
  6. corems/chroma_peak/factory/__init__.py +0 -0
  7. corems/chroma_peak/factory/chroma_peak_classes.py +1178 -0
  8. corems/encapsulation/__init__.py +0 -0
  9. corems/encapsulation/constant.py +1283 -0
  10. corems/encapsulation/factory/__init__.py +0 -0
  11. corems/encapsulation/factory/parameters.py +392 -0
  12. corems/encapsulation/factory/processingSetting.py +1244 -0
  13. corems/encapsulation/input/__init__.py +0 -0
  14. corems/encapsulation/input/parameter_from_json.py +579 -0
  15. corems/encapsulation/output/__init__.py +0 -0
  16. corems/encapsulation/output/parameter_to_dict.py +142 -0
  17. corems/encapsulation/output/parameter_to_json.py +332 -0
  18. corems/mass_spectra/__init__.py +0 -0
  19. corems/mass_spectra/calc/GC_Calc.py +84 -0
  20. corems/mass_spectra/calc/GC_Deconvolution.py +558 -0
  21. corems/mass_spectra/calc/GC_RI_Calibration.py +44 -0
  22. corems/mass_spectra/calc/MZSearch.py +249 -0
  23. corems/mass_spectra/calc/SignalProcessing.py +656 -0
  24. corems/mass_spectra/calc/__init__.py +0 -0
  25. corems/mass_spectra/calc/lc_calc.py +5790 -0
  26. corems/mass_spectra/calc/lc_calc_operations.py +1127 -0
  27. corems/mass_spectra/factory/GC_Class.py +791 -0
  28. corems/mass_spectra/factory/__init__.py +0 -0
  29. corems/mass_spectra/factory/chromat_data.py +51 -0
  30. corems/mass_spectra/factory/lc_class.py +2721 -0
  31. corems/mass_spectra/input/__init__.py +0 -0
  32. corems/mass_spectra/input/andiNetCDF.py +200 -0
  33. corems/mass_spectra/input/boosterHDF5.py +216 -0
  34. corems/mass_spectra/input/brukerSolarix.py +153 -0
  35. corems/mass_spectra/input/brukerSolarix_utils.py +73 -0
  36. corems/mass_spectra/input/corems_hdf5.py +1710 -0
  37. corems/mass_spectra/input/massList.py +133 -0
  38. corems/mass_spectra/input/mzml.py +668 -0
  39. corems/mass_spectra/input/parserbase.py +239 -0
  40. corems/mass_spectra/input/rawFileReader.py +1839 -0
  41. corems/mass_spectra/output/__init__.py +0 -0
  42. corems/mass_spectra/output/export.py +2800 -0
  43. corems/mass_spectrum/__init__.py +0 -0
  44. corems/mass_spectrum/calc/AutoRecalibration.py +237 -0
  45. corems/mass_spectrum/calc/Calibration.py +602 -0
  46. corems/mass_spectrum/calc/CalibrationCalc.py +253 -0
  47. corems/mass_spectrum/calc/KendrickGroup.py +239 -0
  48. corems/mass_spectrum/calc/MassErrorPrediction.py +436 -0
  49. corems/mass_spectrum/calc/MassSpectrumCalc.py +303 -0
  50. corems/mass_spectrum/calc/MeanResolvingPowerFilter.py +212 -0
  51. corems/mass_spectrum/calc/NoiseCalc.py +371 -0
  52. corems/mass_spectrum/calc/NoiseCalc_Bayes.py +93 -0
  53. corems/mass_spectrum/calc/PeakPicking.py +994 -0
  54. corems/mass_spectrum/calc/__init__.py +0 -0
  55. corems/mass_spectrum/factory/MassSpectrumClasses.py +1753 -0
  56. corems/mass_spectrum/factory/__init__.py +0 -0
  57. corems/mass_spectrum/input/__init__.py +0 -0
  58. corems/mass_spectrum/input/baseClass.py +531 -0
  59. corems/mass_spectrum/input/boosterHDF5.py +161 -0
  60. corems/mass_spectrum/input/coremsHDF5.py +475 -0
  61. corems/mass_spectrum/input/massList.py +402 -0
  62. corems/mass_spectrum/input/numpyArray.py +133 -0
  63. corems/mass_spectrum/output/__init__.py +0 -0
  64. corems/mass_spectrum/output/export.py +841 -0
  65. corems/molecular_formula/__init__.py +0 -0
  66. corems/molecular_formula/calc/MolecularFormulaCalc.py +885 -0
  67. corems/molecular_formula/calc/__init__.py +0 -0
  68. corems/molecular_formula/factory/MolecularFormulaFactory.py +895 -0
  69. corems/molecular_formula/factory/__init__.py +0 -0
  70. corems/molecular_formula/input/__init__.py +0 -0
  71. corems/molecular_formula/input/masslist_ref.py +355 -0
  72. corems/molecular_id/__init__.py +0 -0
  73. corems/molecular_id/calc/ClusterFilter.py +251 -0
  74. corems/molecular_id/calc/MolecularFilter.py +122 -0
  75. corems/molecular_id/calc/SpectralSimilarity.py +632 -0
  76. corems/molecular_id/calc/__init__.py +0 -0
  77. corems/molecular_id/calc/math_distance.py +1637 -0
  78. corems/molecular_id/data/FAMES_REF.msp +980 -0
  79. corems/molecular_id/data/PNNLMetV20191015.msp +157267 -0
  80. corems/molecular_id/factory/EI_SQL.py +650 -0
  81. corems/molecular_id/factory/MolecularLookupTable.py +914 -0
  82. corems/molecular_id/factory/__init__.py +0 -0
  83. corems/molecular_id/factory/classification.py +884 -0
  84. corems/molecular_id/factory/lipid_molecular_metadata.py +50 -0
  85. corems/molecular_id/factory/molecularSQL.py +827 -0
  86. corems/molecular_id/factory/spectrum_search_results.py +119 -0
  87. corems/molecular_id/input/__init__.py +0 -0
  88. corems/molecular_id/input/nistMSI.py +148 -0
  89. corems/molecular_id/search/__init__.py +0 -0
  90. corems/molecular_id/search/compoundSearch.py +214 -0
  91. corems/molecular_id/search/database_interfaces.py +1527 -0
  92. corems/molecular_id/search/findOxygenPeaks.py +330 -0
  93. corems/molecular_id/search/lcms_spectral_search.py +348 -0
  94. corems/molecular_id/search/molecularFormulaSearch.py +1117 -0
  95. corems/molecular_id/search/priorityAssignment.py +723 -0
  96. corems/ms_peak/__init__.py +0 -0
  97. corems/ms_peak/calc/MSPeakCalc.py +1010 -0
  98. corems/ms_peak/calc/__init__.py +0 -0
  99. corems/ms_peak/factory/MSPeakClasses.py +542 -0
  100. corems/ms_peak/factory/__init__.py +0 -0
  101. corems/transient/__init__.py +0 -0
  102. corems/transient/calc/TransientCalc.py +362 -0
  103. corems/transient/calc/__init__.py +0 -0
  104. corems/transient/factory/TransientClasses.py +457 -0
  105. corems/transient/factory/__init__.py +0 -0
  106. corems/transient/input/__init__.py +0 -0
  107. corems/transient/input/brukerSolarix.py +461 -0
  108. corems/transient/input/midasDatFile.py +172 -0
  109. corems-4.0.0.dist-info/METADATA +475 -0
  110. corems-4.0.0.dist-info/RECORD +171 -0
  111. corems-4.0.0.dist-info/WHEEL +5 -0
  112. corems-4.0.0.dist-info/licenses/LICENSE +22 -0
  113. corems-4.0.0.dist-info/top_level.txt +4 -0
  114. examples/archive/scripts/CoreMS_tutorial.py +94 -0
  115. examples/archive/scripts/DI HR-MS Halogens Bruker.py +196 -0
  116. examples/archive/scripts/DI HR-MS MassList.py +385 -0
  117. examples/archive/scripts/GC-MS MetabRef.py +213 -0
  118. examples/archive/scripts/GC-MS NetCDF.py +217 -0
  119. examples/archive/scripts/HR-MS Thermo Raw 21T.py +136 -0
  120. examples/archive/scripts/LC-ICPMS_metal_peaks.py +297 -0
  121. examples/archive/scripts/LCMS-Thermo.py +460 -0
  122. examples/archive/scripts/LCMS_isotopes.py +283 -0
  123. examples/archive/scripts/MSParams_example.py +21 -0
  124. examples/archive/scripts/Molecular Formula Data Aggreation.py +84 -0
  125. examples/archive/scripts/Single Mz Search.py +69 -0
  126. examples/test_notebooks.py +145 -0
  127. ext_lib/ChemstationMSFileReader.dll +0 -0
  128. ext_lib/ChemstationMSFileReader.xml +126 -0
  129. ext_lib/RawFileReaderLicense.doc +0 -0
  130. ext_lib/ThermoFisher.CommonCore.BackgroundSubtraction.dll +0 -0
  131. ext_lib/ThermoFisher.CommonCore.BackgroundSubtraction.xml +2307 -0
  132. ext_lib/ThermoFisher.CommonCore.Data.dll +0 -0
  133. ext_lib/ThermoFisher.CommonCore.Data.xml +28974 -0
  134. ext_lib/ThermoFisher.CommonCore.MassPrecisionEstimator.dll +0 -0
  135. ext_lib/ThermoFisher.CommonCore.MassPrecisionEstimator.xml +241 -0
  136. ext_lib/ThermoFisher.CommonCore.RawFileReader.dll +0 -0
  137. ext_lib/ThermoFisher.CommonCore.RawFileReader.xml +31174 -0
  138. ext_lib/__init__.py +0 -0
  139. ext_lib/dotnet/OpenMcdf.Extensions.dll +0 -0
  140. ext_lib/dotnet/OpenMcdf.dll +0 -0
  141. ext_lib/dotnet/OpenMcdf.xml +1154 -0
  142. ext_lib/dotnet/System.IO.FileSystem.AccessControl.dll +0 -0
  143. ext_lib/dotnet/System.IO.FileSystem.AccessControl.xml +506 -0
  144. ext_lib/dotnet/System.Security.AccessControl.dll +0 -0
  145. ext_lib/dotnet/System.Security.AccessControl.xml +2043 -0
  146. ext_lib/dotnet/System.Security.Principal.Windows.dll +0 -0
  147. ext_lib/dotnet/System.Security.Principal.Windows.xml +1011 -0
  148. ext_lib/dotnet/ThermoFisher.CommonCore.BackgroundSubtraction.dll +0 -0
  149. ext_lib/dotnet/ThermoFisher.CommonCore.BackgroundSubtraction.xml +2307 -0
  150. ext_lib/dotnet/ThermoFisher.CommonCore.Data.dll +0 -0
  151. ext_lib/dotnet/ThermoFisher.CommonCore.Data.xml +29148 -0
  152. ext_lib/dotnet/ThermoFisher.CommonCore.MassPrecisionEstimator.dll +0 -0
  153. ext_lib/dotnet/ThermoFisher.CommonCore.MassPrecisionEstimator.xml +241 -0
  154. ext_lib/dotnet/ThermoFisher.CommonCore.RawFileReader.dll +0 -0
  155. ext_lib/dotnet/ThermoFisher.CommonCore.RawFileReader.xml +31492 -0
  156. ext_lib/version +18 -0
  157. support_code/atom_parsers/AtomsDescription.py +359 -0
  158. support_code/atom_parsers/CreateAtomsDescription.py +56 -0
  159. support_code/nmdc/filefinder.py +90 -0
  160. support_code/nmdc/lipidomics/lipidomics_workflow.py +748 -0
  161. support_code/nmdc/lipidomics/manifest_examples.py +49 -0
  162. support_code/nmdc/metabolomics/gcms_workflow.py +158 -0
  163. support_code/nmdc/metabolomics/lcms_metabolomics_targeted_search.py +59 -0
  164. support_code/nmdc/metabolomics/lcms_metabolomics_workflow.py +248 -0
  165. support_code/nmdc/metabolomics/metabolomics_collection.py +628 -0
  166. support_code/nmdc/metadata/dms_api.py +42 -0
  167. support_code/nmdc/nom/archived_scripts/nmdc_metadata_gen.py +288 -0
  168. support_code/nmdc/nom/archived_scripts/nom_grow_workflow.py +209 -0
  169. support_code/nmdc/nom/nom_workflow.py +312 -0
  170. support_code/windows_only_importers/BrukerCompassXtract.py +180 -0
  171. support_code/windows_only_importers/ThermoMSFileReader.py +405 -0
@@ -0,0 +1,1637 @@
1
+ import warnings
2
+
3
+ import numpy as np
4
+ import scipy.stats
5
+
6
+ """ Collection of spectral similarity methods.
7
+
8
+ Based on Yuanyue Li code at https://github.com/YuanyueLi/SpectralEntropy/blob/master/spectral_entropy/math_distance.py
9
+ and paper: Li, Y., Kind, T., Folz, J. et al. Spectral entropy outperforms MS/MS dot product similarity for small-molecule compound identification. Nat Methods 18, 1524–1531 (2021). https://doi.org/10.1038/s41592-021-01331-z
10
+ """
11
+
12
+
13
+ def entropy_distance(v, y):
14
+ """Calculate entropy distance between two vectors
15
+
16
+ Parameters
17
+ ----------
18
+ v : array_like
19
+ Vector 1
20
+ y : array_like
21
+ Vector 2
22
+
23
+ Returns
24
+ -------
25
+ float
26
+ Entropy distance between v and y
27
+
28
+ """
29
+ merged = v + y
30
+ entropy_increase = (
31
+ 2 * scipy.stats.entropy(merged)
32
+ - scipy.stats.entropy(v)
33
+ - scipy.stats.entropy(y)
34
+ )
35
+ return entropy_increase
36
+
37
+
38
+ def _weight_intensity_for_entropy(x):
39
+ """Weight intensity for entropy
40
+
41
+ Parameters
42
+ ----------
43
+ x : array_like
44
+ Vector
45
+
46
+ Returns
47
+ -------
48
+ array_like
49
+ Weighted vector
50
+ """
51
+ if sum(x) > 0:
52
+ WEIGHT_START = 0.25
53
+ WEIGHT_SLOPE = 0.5
54
+
55
+ entropy_x = scipy.stats.entropy(x)
56
+ weight = WEIGHT_START + WEIGHT_SLOPE * entropy_x
57
+ x = np.power(x, weight)
58
+ x = x / sum(x)
59
+ return x
60
+
61
+
62
+ def weighted_entropy_distance(v, y):
63
+ """Calculate weighted entropy distance between two vectors
64
+
65
+ Parameters
66
+ ----------
67
+ v : array_like
68
+ Vector 1
69
+ y : array_like
70
+ Vector 2
71
+
72
+ Returns
73
+ -------
74
+ float
75
+ Weighted entropy distance between v and y
76
+ """
77
+ v = _weight_intensity_for_entropy(v)
78
+ y = _weight_intensity_for_entropy(y)
79
+
80
+ merged = v + y
81
+ entropy_increase = (
82
+ 2 * scipy.stats.entropy(merged)
83
+ - scipy.stats.entropy(v)
84
+ - scipy.stats.entropy(y)
85
+ )
86
+ return entropy_increase
87
+
88
+
89
+ def chebyshev_distance(v, y):
90
+ r"""Chebyshev distance
91
+
92
+ Parameters
93
+ ----------
94
+ v : array_like
95
+ Vector 1
96
+ y : array_like
97
+ Vector 2
98
+
99
+ Returns
100
+ -------
101
+ float
102
+ Chebyshev distance between v and y
103
+
104
+ Notes
105
+ -----
106
+ .. math::
107
+
108
+ \underset{i}{\max}{(|v_{i}\ -\ y_{i}|)}
109
+ """
110
+ return np.max(np.abs(v - y))
111
+
112
+
113
+ def squared_euclidean_distance(v, y):
114
+ r"""Squared Euclidean distance:
115
+
116
+ Parameters
117
+ ----------
118
+ v : array_like
119
+ Vector 1
120
+ y : array_like
121
+ Vector 2
122
+
123
+ Returns
124
+ -------
125
+ float
126
+ Squared Euclidean distance between v and y
127
+
128
+ Notes
129
+ -----
130
+ .. math::
131
+
132
+ \sum(v_{i}-y_{i})^2
133
+ """
134
+ return np.sum(np.power(v - y, 2))
135
+
136
+
137
+ def fidelity_similarity(v, y):
138
+ r"""Fidelity similarity:
139
+
140
+ Parameters
141
+ ----------
142
+ v : array_like
143
+ Vector 1
144
+ y : array_like
145
+ Vector 2
146
+
147
+ Returns
148
+ -------
149
+ float
150
+ Fidelity similarity between v and y
151
+ Notes
152
+ -----
153
+ .. math::
154
+
155
+ \sum\sqrt{v_{i}y_{i}}
156
+ """
157
+ return np.sum(np.sqrt(v * y))
158
+
159
+
160
+ def matusita_distance(v, y):
161
+ r"""Matusita distance:
162
+
163
+ Parameters
164
+ ----------
165
+ v : array_like
166
+ Vector 1
167
+ y : array_like
168
+ Vector 2
169
+
170
+ Returns
171
+ -------
172
+ float
173
+ Matusita distance between v and y
174
+
175
+ Notes
176
+ -----
177
+ .. math::
178
+
179
+ \sqrt{\sum(\sqrt{v_{i}}-\sqrt{y_{i}})^2}
180
+ """
181
+ return np.sqrt(np.sum(np.power(np.sqrt(v) - np.sqrt(y), 2)))
182
+
183
+
184
+ def squared_chord_distance(v, y):
185
+ r"""Squared-chord distance:
186
+
187
+ Parameters
188
+ ----------
189
+ v : array_like
190
+ Vector 1
191
+ y : array_like
192
+ Vector 2
193
+
194
+ Returns
195
+ -------
196
+ float
197
+ Squared-chord distance between v and y
198
+
199
+ Notes
200
+ -----
201
+ .. math::
202
+
203
+ \sum(\sqrt{v_{i}}-\sqrt{y_{i}})^2
204
+ """
205
+ return np.sum(np.power(np.sqrt(v) - np.sqrt(y), 2))
206
+
207
+
208
+ def bhattacharya_1_distance(v, y):
209
+ r"""Bhattacharya 1 distance:
210
+
211
+ Parameters
212
+ ----------
213
+ v : array_like
214
+ Vector 1
215
+ y : array_like
216
+ Vector 2
217
+
218
+ Returns
219
+ -------
220
+ float
221
+ Bhattacharya 1 distance between v and y
222
+
223
+ Notes
224
+ -----
225
+ .. math::
226
+
227
+ (\arccos{(\sum\sqrt{v_{i}y_{i}})})^2
228
+ """
229
+ s = np.sum(np.sqrt(v * y))
230
+ # TODO:Fix this!
231
+ if s > 1:
232
+ if s > 1 + 1e-6:
233
+ warnings.warn(
234
+ "Error in calculating Bhattacharya 1 distance, got arccos {}".format(s)
235
+ )
236
+ s = 1
237
+ return np.power(np.arccos(s), 2)
238
+
239
+
240
+ def bhattacharya_2_distance(v, y):
241
+ r"""Bhattacharya 2 distance:
242
+
243
+ Parameters
244
+ ----------
245
+ v : array_like
246
+ Vector 1
247
+ y : array_like
248
+ Vector 2
249
+
250
+ Returns
251
+ -------
252
+ float
253
+ Bhattacharya 2 distance between v and y
254
+ Notes
255
+ -----
256
+ .. math::
257
+
258
+ -\ln{(\sum\sqrt{v_{i}y_{i}})}
259
+ """
260
+ s = np.sum(np.sqrt(v * y))
261
+ if s == 0:
262
+ return np.inf
263
+ else:
264
+ return -np.log(s)
265
+
266
+
267
+ def harmonic_mean_similarity(v, y):
268
+ r"""Harmonic mean similarity:
269
+
270
+ Parameters
271
+ ----------
272
+ v : array_like
273
+ Vector 1
274
+ y : array_like
275
+ Vector 2
276
+
277
+ Returns
278
+ -------
279
+ float
280
+ Harmonic mean similarity between v and y
281
+
282
+ Notes
283
+ -----
284
+ .. math::
285
+
286
+ #1-2\sum(\frac{v_{i}y_{i}}{v_{i}+y_{i}})
287
+ 2\sum(\frac{v_{i}y_{i}}{v_{i}+y_{i}})
288
+ """
289
+ # return 1 - 2 * np.sum(v * y / (v + y))
290
+ return 2 * np.sum(v * y / (v + y))
291
+
292
+
293
+ # def pearson_chi_squared_distance(v, y):
294
+ # r"""
295
+ # Pearson χ2 distance:
296
+ #
297
+ # .. math::
298
+ #
299
+ # \sum\frac{(v_{i}-y_{i})^2}{y_{i}}
300
+ # """
301
+ # return np.sum(np.power(v - y, 2) / y)
302
+
303
+
304
+ # def neyman_chi_squared_distance(v, y):
305
+ # r"""
306
+ # Neyman χ2 distance:
307
+ #
308
+ # .. math::
309
+ #
310
+ # \sum\frac{(v_{i}-y_{i})^2}{v_{i}}
311
+ # """
312
+ # return np.sum(np.power(v - y, 2) / v)
313
+
314
+
315
+ # def probabilistic_symmetric_chi_squared_distance(v, y):
316
+ # r"""
317
+ # Probabilistic symmetric χ2 distance:
318
+ #
319
+ # .. math::
320
+ #
321
+ # \frac{1}{2} \times \sum\frac{(v_{i}-y_{i}\ )^2}{v_{i}+y_{i}\ }
322
+ # """
323
+ # return 1 / 2 * np.sum(np.power(v - y, 2) / (v + y))
324
+
325
+
326
+ # def topsoe_distance(v, y):
327
+ # r"""
328
+ # Topsøe distance:
329
+ #
330
+ # .. math::
331
+ #
332
+ # \sum{(v_{i}ln\frac{v_{i}}{Z_i}+y_{i}ln\frac{y_{i}}{Z_i}),\ \ \ Z_i=\frac{1}{2}(v_{i}+y_{i})}
333
+ # """
334
+ # z = 1 / 2 * (v + y)
335
+ # z[z == 0] = 1
336
+ # vz = v / z
337
+ # yz = y / z
338
+ # vz[v == 0] = 1
339
+ # yz[y == 0] = 1
340
+ # return np.sum(v * np.log(vz) + y * np.log(yz))
341
+
342
+
343
+ def chernoff_distance(v, y):
344
+ r"""Chernoff distance:
345
+
346
+ Parameters
347
+ ----------
348
+ v : array_like
349
+ Vector 1
350
+ y : array_like
351
+ Vector 2
352
+
353
+ Returns
354
+ -------
355
+ float
356
+ Chernoff distance between v and y
357
+
358
+ Notes
359
+ -----
360
+ .. math::
361
+
362
+ \max{(-ln\sum(v_{i}^ty_{i}^{1-t})^{1-t})},\ t=0.1,\ 0\le\ t<1
363
+ """
364
+ t = 0.1
365
+ return np.max(-np.log(np.sum(np.power(np.power(v, t) * np.power(y, 1 - t), 1 - t))))
366
+
367
+
368
+ def ruzicka_distance(v, y):
369
+ r"""Ruzicka distance:
370
+
371
+ Parameters
372
+ ----------
373
+ v : array_like
374
+ Vector 1
375
+ y : array_like
376
+ Vector 2
377
+
378
+ Returns
379
+ -------
380
+ float
381
+ Ruzicka distance between v and y
382
+
383
+ Notes
384
+ -----
385
+ .. math::
386
+
387
+ \frac{\sum{|v_{i}-y_{i}|}}{\sum{\max(v_{i},y_{i})}}
388
+ """
389
+ dist = np.sum(np.abs(v - y)) / np.sum(np.maximum(v, y))
390
+ return dist
391
+
392
+
393
+ def roberts_distance(v, y):
394
+ r"""Roberts distance:
395
+
396
+ Parameters
397
+ ----------
398
+ v : array_like
399
+ Vector 1
400
+ y : array_like
401
+ Vector 2
402
+
403
+ Returns
404
+ -------
405
+ float
406
+ Roberts distance between v and y
407
+
408
+ Notes
409
+ -----
410
+ .. math::
411
+
412
+ 1-\sum\frac{(v_{i}+y_{i})\frac{\min{(v_{i},y_{i})}}{\max{(v_{i},y_{i})}}}{\sum(v_{i}+y_{i})}
413
+ """
414
+ return 1 - np.sum((v + y) * np.minimum(v, y) / np.maximum(v, y) / np.sum(v + y))
415
+
416
+
417
+ def intersection_distance(v, y):
418
+ r"""Intersection distance:
419
+
420
+ Parameters
421
+ ----------
422
+ v : array_like
423
+ Vector 1
424
+ y : array_like
425
+ Vector 2
426
+
427
+ Returns
428
+ -------
429
+ float
430
+ Intersection distance between v and y
431
+
432
+ Notes
433
+ -----
434
+ .. math::
435
+
436
+ 1-\frac{\sum\min{(v_{i},y_{i})}}{\min(\sum{v_{i},\sum{y_{i})}}}
437
+ """
438
+ return 1 - np.sum(np.minimum(v, y)) / min(np.sum(v), np.sum(y))
439
+
440
+
441
+ def motyka_distance(v, y):
442
+ r"""Motyka distance:
443
+
444
+ Parameters
445
+ ----------
446
+ v : array_like
447
+ Vector 1
448
+ y : array_like
449
+ Vector 2
450
+
451
+ Returns
452
+ -------
453
+ float
454
+ Motyka distance between v and y
455
+ Notes
456
+ -----
457
+ .. math::
458
+
459
+ -\frac{\sum\min{(y_{i},v_{i})}}{\sum(y_{i}+v_{i})}
460
+ """
461
+ dist = np.sum(np.minimum(v, y)) / np.sum(v + y)
462
+ return dist
463
+
464
+
465
+ def canberra_distance(v, y):
466
+ r"""Canberra distance:
467
+
468
+ Parameters
469
+ ----------
470
+ v : array_like
471
+ Vector 1
472
+ y : array_like
473
+ Vector 2
474
+
475
+ Returns
476
+ -------
477
+ float
478
+ Canberra distance between v and y
479
+
480
+ Notes
481
+ -----
482
+ .. math::
483
+
484
+ #\sum\frac{|v_{i}-y_{i}|}{|v_{i}|+|y_{i}|}
485
+ \sum_{i}\frac{|y_{i} - v_{i}|}{y_{i} + v_{i}}
486
+ """
487
+ # return np.sum(np.abs(v - y) / (np.abs(v) + np.abs(y)))
488
+ return np.sum(np.abs(y - v) / (y + v))
489
+
490
+
491
+ def canberra_metric(v, y):
492
+ r"""Canberra Metric
493
+
494
+ Parameters
495
+ ----------
496
+ v : array_like
497
+ Vector 1
498
+ y : array_like
499
+ Vector 2
500
+
501
+ Returns
502
+ -------
503
+ float
504
+ Canberra metric between v and y
505
+ Notes
506
+ -----
507
+ .. math::
508
+
509
+ \frac{1}{\sum_{i}I(v_{i}\neq 0)}\sum_{i}\frac{|y_{i}-v_{i}|}{(y_{i}+v_{i})}
510
+ """
511
+
512
+ return (1 / np.sum(v > 0)) * np.sum(np.abs(y - v) / (y + v))
513
+
514
+
515
+ def kulczynski_1_distance(v, y):
516
+ r"""Kulczynski 1 distance:
517
+
518
+ Parameters
519
+ ----------
520
+ v : array_like
521
+ Vector 1
522
+ y : array_like
523
+ Vector 2
524
+
525
+ Returns
526
+ -------
527
+ float
528
+ Kulczynski 1 distance between v and y
529
+
530
+ Notes
531
+ -----
532
+ .. math::
533
+
534
+ \frac{\sum{|v_i}-y_i|}{\sum m\ i\ n\ (v_i,y_i)}
535
+ """
536
+ return np.sum(np.abs(y - v)) / np.sum(np.minimum(y, v))
537
+
538
+
539
+ def baroni_urbani_buser_distance(v, y):
540
+ r"""Baroni-Urbani-Buser distance:
541
+
542
+ Parameters
543
+ ----------
544
+ v : array_like
545
+ Vector 1
546
+ y : array_like
547
+ Vector 2
548
+
549
+ Returns
550
+ -------
551
+ float
552
+ Baroni-Urbani-Buser distance between v and y
553
+
554
+ Notes
555
+ -----
556
+ .. math::
557
+
558
+ 1-\frac{\sum\min{(v_i,y_i)}+\sqrt{\sum\min{(v_i,y_i)}\sum(\max{(v)}-\max{(v_i,y_i)})}}{\sum{\max{(v_i,y_i)}+\sqrt{\sum{\min{(v_i,y_i)}\sum(\max{(v)}-\max{(v_i,y_i)})}}}}
559
+ """
560
+ if np.max(v) < np.max(y):
561
+ v, y = y, v
562
+ d1 = np.sqrt(np.sum(np.minimum(v, y) * np.sum(max(v) - np.maximum(v, y))))
563
+ return 1 - (np.sum(np.minimum(v, y)) + d1) / (np.sum(np.maximum(v, y)) + d1)
564
+
565
+
566
+ def penrose_size_distance(v, y):
567
+ r"""Penrose size distance:
568
+
569
+ Parameters
570
+ ----------
571
+ v : array_like
572
+ Vector 1
573
+ y : array_like
574
+ Vector 2
575
+
576
+ Returns
577
+ -------
578
+ float
579
+ Penrose size distance between v and y
580
+
581
+ Notes
582
+ -----
583
+ .. math::
584
+
585
+ \sqrt N\sum{|y_i-v_i|}
586
+ """
587
+ n = np.sum(v > 0)
588
+ return np.sqrt(n) * np.sum(np.abs(y - v))
589
+
590
+
591
+ def mean_character_distance(v, y):
592
+ r"""
593
+ Mean character distance:
594
+
595
+ Parameters
596
+ ----------
597
+ v : array_like
598
+ Vector 1
599
+ y : array_like
600
+ Vector 2
601
+
602
+ Returns
603
+ -------
604
+ float
605
+ Mean character distance between v and y
606
+
607
+ Notes
608
+ -----
609
+ .. math::
610
+
611
+ \frac{1}{N}\sum{|y_i-v_i|}
612
+ """
613
+ n = np.sum(v > 0)
614
+ return 1 / n * np.sum(np.abs(y - v))
615
+
616
+
617
+ def lorentzian_distance(v, y):
618
+ r"""
619
+ Lorentzian distance:
620
+
621
+ Parameters
622
+ ----------
623
+ v : array_like
624
+ Vector 1
625
+ y : array_like
626
+ Vector 2
627
+
628
+ Returns
629
+ -------
630
+ float
631
+ Lorentzian distance between v and y
632
+
633
+ Notes
634
+ -----
635
+ .. math::
636
+
637
+ \sum{\ln(1+|v_i-y_i|)}
638
+ """
639
+ return np.sum(np.log(1 + np.abs(y - v)))
640
+
641
+
642
+ def penrose_shape_distance(v, y):
643
+ r"""
644
+ Penrose shape distance:
645
+
646
+ Parameters
647
+ ----------
648
+ v : array_like
649
+ Vector 1
650
+ y : array_like
651
+ Vector 2
652
+
653
+ Returns
654
+ -------
655
+ float
656
+ Penrose shape distance between v and y
657
+ Notes
658
+ -----
659
+ .. math::
660
+
661
+ \sqrt{\sum((v_i-\bar{v})-(y_i-\bar{y}))^2}
662
+ """
663
+ v_avg = np.mean(v)
664
+ y_avg = np.mean(y)
665
+ return np.sqrt(np.sum(np.power((y - y_avg) - (v - v_avg), 2)))
666
+
667
+
668
+ def clark_distance(v, y):
669
+ r"""
670
+ Clark distance:
671
+
672
+ Parameters
673
+ ----------
674
+ v : array_like
675
+ Vector 1
676
+ y : array_like
677
+ Vector 2
678
+
679
+ Returns
680
+ -------
681
+ float
682
+ Clark distance between v and y
683
+
684
+ Notes
685
+ -----
686
+ .. math::
687
+
688
+ #(\frac{1}{N}\sum(\frac{v_i-y_i}{|v_i|+|y_i|})^2)^\frac{1}{2}
689
+ \sqrt{\sum(\frac{|v_i-y_i|}{v_i+y_i})^2}
690
+ """
691
+ # n = np.sum(v > 0)
692
+ # return np.sqrt(1 / n * np.sum(np.power((v - y) / (np.abs(v) + np.abs(y)), 2)))
693
+ return np.sqrt(np.sum(np.power(np.abs(y - v) / (y + v), 2)))
694
+
695
+
696
+ def hellinger_distance(v, y):
697
+ r"""
698
+ Hellinger distance:
699
+
700
+ Parameters
701
+ ----------
702
+ v : array_like
703
+ Vector 1
704
+ y : array_like
705
+ Vector 2
706
+
707
+ Returns
708
+ -------
709
+ float
710
+ Hellinger distance between v and y
711
+
712
+ Notes
713
+ -----
714
+ .. math::
715
+
716
+ #\sqrt{2\sum(\sqrt{\frac{v_i}{\bar{v}}}-\sqrt{\frac{y_i}{\bar{y}}})^2}
717
+ \sqrt{2\sum(\sqrt{v_i}-\sqrt{y_i})^2}
718
+ """
719
+ # v_avg = np.mean(v)
720
+ # y_avg = np.mean(y)
721
+ # return np.sqrt(2 * np.sum(np.power(np.sqrt(v / v_avg) - np.sqrt(y / y_avg), 2)))
722
+ return np.sqrt(2 * np.sum(np.power(np.sqrt(y) - np.sqrt(v), 2)))
723
+
724
+
725
+ def whittaker_index_of_association_distance(v, y):
726
+ r"""
727
+ Whittaker index of association distance:
728
+
729
+ Parameters
730
+ ----------
731
+ v : array_like
732
+ Vector 1
733
+ y : array_like
734
+ Vector 2
735
+
736
+ Returns
737
+ -------
738
+ float
739
+ Whittaker index of association distance between v and y
740
+
741
+ Notes
742
+ -----
743
+ .. math::
744
+
745
+ \frac{1}{2}\sum|\frac{v_i}{\bar{v}}-\frac{y_i}{\bar{y}}|
746
+ """
747
+ v_avg = np.mean(v)
748
+ y_avg = np.mean(y)
749
+ return 1 / 2 * np.sum(np.abs(v / v_avg - y / y_avg))
750
+
751
+
752
+ # def symmetric_chi_squared_distance(v, y):
753
+ # r"""
754
+ # Symmetric χ2 distance:
755
+ #
756
+ # .. math::
757
+ #
758
+ # \sqrt{\sum{\frac{\bar{v}+\bar{y}}{N(\bar{v}+\bar{y})^2}\frac{(v_i\bar{y}-y_i\bar{v})^2}{v_i+y_i}\ }}
759
+ # """
760
+ # v_avg = np.mean(v)
761
+ # y_avg = np.mean(y)
762
+ # n = np.sum(v > 0)
763
+ #
764
+ # d1 = (v_avg + y_avg) / (n * np.power(v_avg + y_avg, 2))
765
+ # return np.sqrt(d1 * np.sum(np.power(v * y_avg - y * v_avg, 2) / (v + y)))
766
+
767
+
768
+ def similarity_index_distance(v, y):
769
+ r"""
770
+ Similarity Index Distance:
771
+
772
+ Parameters
773
+ ----------
774
+ v : array_like
775
+ Vector 1
776
+ y : array_like
777
+ Vector 2
778
+
779
+ Returns
780
+ -------
781
+ float
782
+ Similarity Index Distance between v and y
783
+
784
+ Notes
785
+ -----
786
+ .. math::
787
+
788
+ \sqrt{\frac{\sum\{\frac{v_i-y_i}{y_i}\}^2}{N}}
789
+ """
790
+ n = np.sum(v > 0)
791
+ return np.sqrt(1 / n * np.sum(np.power((v - y) / y, 2)))
792
+
793
+
794
+ def improved_similarity_distance(v, y):
795
+ r"""
796
+ Improved Similarity Index:
797
+
798
+ Parameters
799
+ ----------
800
+ v : array_like
801
+ Vector 1
802
+ y : array_like
803
+ Vector 2
804
+
805
+ Returns
806
+ -------
807
+ float
808
+ Improved Similarity Index between v and y
809
+
810
+ Notes
811
+ -----
812
+ .. math::
813
+
814
+ \sqrt{\frac{1}{N}\sum\{\frac{y_i-v_i}{y_i+v_i}\}^2}
815
+ """
816
+ n = np.sum(v > 0)
817
+ return np.sqrt(1 / n * np.sum(np.power((y - v) / (y + v), 2)))
818
+
819
+
820
+ def absolute_value_distance(v, y):
821
+ r"""
822
+ Absolute Value Distance:
823
+
824
+ Parameters
825
+ ----------
826
+ v : array_like
827
+ Vector 1
828
+ y : array_like
829
+ Vector 2
830
+
831
+ Returns
832
+ -------
833
+ float
834
+ Absolute Value Distance between v and y
835
+
836
+ Notes
837
+ -----
838
+ .. math::
839
+
840
+ \frac { \sum(|y_i-v_i|)}{\sum v_i}
841
+
842
+ """
843
+ dist = np.sum(np.abs(y - v)) / np.sum(v)
844
+ return dist
845
+
846
+
847
+ def spectral_contrast_angle_distance(v, y):
848
+ r"""
849
+ Spectral Contrast Angle:
850
+
851
+ Parameters
852
+ ----------
853
+ v : array_like
854
+ Vector 1
855
+ y : array_like
856
+ Vector 2
857
+
858
+ Returns
859
+ -------
860
+ float
861
+ Spectral Contrast Angle between v and y
862
+
863
+ Notes
864
+ -----
865
+ .. math::
866
+
867
+ 1 - \frac{\sum{y_iv_i}}{\sqrt{\sum y_i^2\sum v_i^2}}
868
+ \arccos(\frac{\sum_{P}y_{p}^* v_{p}^*}{\sqrt{\sum_{P}y_{p}^{*2} \sum_{P}v_{p}^{*2}}})
869
+ """
870
+ # return 1 - np.sum(y * v) / \
871
+ # np.sqrt(np.sum(np.power(y, 2)) * np.sum(np.power(v, 2)))
872
+
873
+ return np.arccos(
874
+ np.sum(y * v) / (np.sqrt(np.sum(np.power(y, 2)) * np.sum(np.power(v, 2))))
875
+ )
876
+
877
+
878
+ def wave_hedges_distance(v, y):
879
+ r"""
880
+ Wave Hedges distance:
881
+
882
+ Parameters
883
+ ----------
884
+ v : array_like
885
+ Vector 1
886
+ y : array_like
887
+ Vector 2
888
+
889
+ Returns
890
+ -------
891
+ float
892
+ Wave Hedges distance between v and y
893
+
894
+ Notes
895
+ -----
896
+ .. math::
897
+
898
+ \sum\frac{|v_i-y_i|}{\max{(v_i,y_i)}}
899
+ """
900
+ return np.sum(np.abs(v - y) / np.maximum(v, y))
901
+
902
+
903
+ def dice_similarity(v, y):
904
+ r"""
905
+ Dice similarity:
906
+
907
+ Parameters
908
+ ----------
909
+ v : array_like
910
+ Vector 1
911
+ y : array_like
912
+ Vector 2
913
+
914
+ Returns
915
+ -------
916
+ float
917
+ Dice similarity between v and y
918
+
919
+ Notes
920
+ -----
921
+ .. math::
922
+
923
+ \frac{\sum(v_i-y_i)^2}{\sum v_i^2+\sum y_i^2}
924
+ \frac{2 * \sum_{i}v_{i}y_{i}}{\sum_{i}y_{i}^2 + \sum_{i}v_{i}^2}
925
+ """
926
+ return 2 * np.sum(v * y) / (np.sum(np.power(v, 2)) + np.sum(np.power(y, 2)))
927
+
928
+
929
+ def inner_product_distance(v, y):
930
+ r"""
931
+ Inner Product distance:
932
+
933
+ Parameters
934
+ ----------
935
+ v : array_like
936
+ Vector 1
937
+ y : array_like
938
+ Vector 2
939
+
940
+ Returns
941
+ -------
942
+ float
943
+ Inner product distance between v and y
944
+
945
+ Notes
946
+ -----
947
+ .. math::
948
+
949
+ 1-\sum{v_iy_i}
950
+ """
951
+ return 1 - np.sum(v * y)
952
+
953
+
954
+ def divergence_distance(v, y):
955
+ r"""
956
+ Divergence distance:
957
+
958
+ Parameters
959
+ ----------
960
+ v : array_like
961
+ Vector 1
962
+ y : array_like
963
+ Vector 2
964
+
965
+ Returns
966
+ -------
967
+ float
968
+ Divergence distance between v and y
969
+
970
+ Notes
971
+ -----
972
+ .. math::
973
+
974
+ 2\sum\frac{(v_i-y_i)^2}{(v_i+y_i)^2}
975
+ """
976
+ return 2 * np.sum((np.power(v - y, 2)) / np.power(v + y, 2))
977
+
978
+
979
+ def _chi_squared_distance(v, y):
980
+ r"""
981
+ Additive symmetric χ2 distance:
982
+
983
+ Parameters
984
+ ----------
985
+ v : array_like
986
+ Vector 1
987
+ y : array_like
988
+ Vector 2
989
+
990
+ Returns
991
+ -------
992
+ float
993
+ Additive symmetric χ2 distance between v and y
994
+
995
+ Notes
996
+ -----
997
+ .. math::
998
+
999
+ \sum\frac{(v_i-y_i)^2(v_i+y_i)}{v_iy_i}
1000
+ """
1001
+ dist = np.sum(np.power(v - y, 2) * (v + y) / (v * y))
1002
+ return dist
1003
+
1004
+
1005
+ def jensen_difference_distance(v, y):
1006
+ r"""
1007
+ Jensen difference:
1008
+
1009
+ Parameters
1010
+ ----------
1011
+ v : array_like
1012
+ Vector 1
1013
+ y : array_like
1014
+ Vector 2
1015
+
1016
+ Returns
1017
+ -------
1018
+ float
1019
+ Jensen difference distance between v and y
1020
+
1021
+ Notes
1022
+ -----
1023
+ .. math::
1024
+
1025
+ \sum[\frac{1}{2}(v_i\ln{v_i}+y_i\ln{y_i})-(\frac{v_i+y_i}{2})\ln{(\frac{v_i+y_i}{2})}]
1026
+ """
1027
+ y_v_avg = (y + v) / 2
1028
+ return np.sum(1 / 2 * (y * np.log(y) + v * np.log(v)) - y_v_avg * np.log(y_v_avg))
1029
+
1030
+
1031
+ def kumar_johnson_distance(v, y):
1032
+ r"""
1033
+ Kumar-Johnson distance:
1034
+
1035
+ Parameters
1036
+ ----------
1037
+ v : array_like
1038
+ Vector 1
1039
+ y : array_like
1040
+ Vector 2
1041
+
1042
+ Returns
1043
+ -------
1044
+ float
1045
+ Kumar Johnson distance between v and y
1046
+
1047
+ Notes
1048
+ -----
1049
+ .. math::
1050
+
1051
+ \sum\frac{(v_i^2-y_i^2)^2}{2(v_iy_i)^\frac{3}{2}}
1052
+ """
1053
+ return np.sum(
1054
+ np.power(np.power(v, 2) - np.power(y, 2), 2) / (2 * np.power(v * y, 3 / 2))
1055
+ )
1056
+
1057
+
1058
+ def avg_l_distance(v, y):
1059
+ r"""
1060
+ Avg (L1, L∞) distance:
1061
+
1062
+ Parameters
1063
+ ----------
1064
+ v : array_like
1065
+ Vector 1
1066
+ y : array_like
1067
+ Vector 2
1068
+
1069
+ Returns
1070
+ -------
1071
+ float
1072
+ Average L distance between v and y
1073
+
1074
+ Notes
1075
+ -----
1076
+ .. math::
1077
+
1078
+ \frac{1}{2}(\sum|v_i-y_i|+\underset{i}{\max}{|v_i-y_i|})
1079
+ """
1080
+ return 1 / 2 * (np.sum(np.abs(v - y)) + max(np.abs(v - y)))
1081
+
1082
+
1083
+ def vicis_wave_hadges_distance(v, y):
1084
+ r"""
1085
+ Vicis-Wave Hadges distance:
1086
+
1087
+ Parameters
1088
+ ----------
1089
+ v : array_like
1090
+ Vector 1
1091
+ y : array_like
1092
+ Vector 2
1093
+
1094
+ Returns
1095
+ -------
1096
+ float
1097
+ Vicis Wave Hadges distance between v and y
1098
+
1099
+ Notes
1100
+ -----
1101
+ .. math::
1102
+
1103
+ \sum\frac{|v_i-y_i|}{\min{(v_i,\ y_i)}}
1104
+ """
1105
+ return np.sum(np.abs(v - y) / np.minimum(v, y))
1106
+
1107
+
1108
+ def vicis_symmetric_chi_squared_1_distance(v, y):
1109
+ r"""
1110
+ Vicis-Symmetric χ2 1 distance:
1111
+
1112
+ Parameters
1113
+ ----------
1114
+ v : array_like
1115
+ Vector 1
1116
+ y : array_like
1117
+ Vector 2
1118
+
1119
+ Returns
1120
+ -------
1121
+ float
1122
+ Vici Symmetric χ2 1 distance between v and y
1123
+
1124
+ Notes
1125
+ -----
1126
+ .. math::
1127
+
1128
+ \sum\frac{(v_i-y_i)^2}{\min{(v_i,y_i)^2}}
1129
+ """
1130
+ return np.sum(np.power(v - y, 2) / np.power(np.minimum(v, y), 2))
1131
+
1132
+
1133
+ def vicis_symmetric_chi_squared_2_distance(v, y):
1134
+ r"""
1135
+ Vicis-Symmetric χ2 2 distance:
1136
+
1137
+ Parameters
1138
+ ----------
1139
+ v : array_like
1140
+ Vector 1
1141
+ y : array_like
1142
+ Vector 2
1143
+
1144
+ Returns
1145
+ -------
1146
+ float
1147
+ Vicis Symmetric χ2 2 distance between v and y
1148
+
1149
+ Notes
1150
+ -----
1151
+
1152
+ .. math::
1153
+
1154
+ \sum\frac{(v_i-y_i)^2}{\min{(v_i,y_i)}}
1155
+ """
1156
+ return np.sum(np.power(v - y, 2) / np.minimum(v, y))
1157
+
1158
+
1159
+ def vicis_symmetric_chi_squared_3_distance(v, y):
1160
+ r"""
1161
+ Vicis-Symmetric χ2 3 distance:
1162
+
1163
+ Parameters
1164
+ ----------
1165
+ v : array_like
1166
+ Vector 1
1167
+ y : array_like
1168
+ Vector 2
1169
+
1170
+ Returns
1171
+ -------
1172
+ float
1173
+ Vici Symmetric χ2 3 distance between v and y
1174
+
1175
+ Notes
1176
+ -----
1177
+
1178
+ .. math::
1179
+
1180
+ \sum\frac{(v_i-y_i)^2}{\max{(v_i,y_i)}}
1181
+ """
1182
+ return np.sum(np.power(v - y, 2) / np.maximum(v, y))
1183
+
1184
+
1185
+ def max_symmetric_chi_squared_distance(v, y):
1186
+ r"""
1187
+ Max-Symmetric χ2 distance:
1188
+
1189
+ Parameters
1190
+ ----------
1191
+ v : array_like
1192
+ Vector 1
1193
+ y : array_like
1194
+ Vector 2
1195
+
1196
+ Returns
1197
+ -------
1198
+ float
1199
+ Max-Symmetric χ2 distance between v and y
1200
+
1201
+ Notes
1202
+ -----
1203
+ .. math::
1204
+
1205
+ \max{(\sum\frac{(v_i-y_i)^2}{v_i},\sum\frac{(v_i-y_i)^2}{y_i})}
1206
+ """
1207
+ return max(np.sum(np.power(v - y, 2) / v), np.sum(np.power(v - y, 2) / y))
1208
+
1209
+
1210
+ def min_symmetric_chi_squared_distance(v, y):
1211
+ r"""
1212
+ Min-Symmetric χ2 distance:
1213
+
1214
+ Parameters
1215
+ ----------
1216
+ v : array_like
1217
+ Vector 1
1218
+ y : array_like
1219
+ Vector 2
1220
+
1221
+ Returns
1222
+ -------
1223
+ float
1224
+ Min-Symmetric χ2 distance between v and y
1225
+
1226
+ Notes
1227
+ -----
1228
+ .. math::
1229
+
1230
+ \min{(\sum\frac{(v_i-y_i)^2}{v_i},\sum\frac{(v_i-y_i)^2}{y_i})}
1231
+ """
1232
+ return min(np.sum(np.power(v - y, 2) / v), np.sum(np.power(v - y, 2) / y))
1233
+
1234
+
1235
+ def additive_sym_chi_sq(v, y):
1236
+ r"""
1237
+ Additive Symmetric χ2 distance:
1238
+
1239
+ Parameters
1240
+ ----------
1241
+ v : array_like
1242
+ Vector 1
1243
+ y : array_like
1244
+ Vector 2
1245
+
1246
+ Returns
1247
+ -------
1248
+ float
1249
+ Additive Symmetric χ2 distance between v and y
1250
+
1251
+ Notes
1252
+ -----
1253
+ .. math::
1254
+
1255
+ \sum_{i}\frac{(y_{i} - v_{i})^2(y_{i}+v_{i})}{y_{i}v_{i}}
1256
+ """
1257
+ return np.sum((np.power(y - v, 2) * (y + v)) / (y * v))
1258
+
1259
+
1260
+ def bhattacharya_distance(v, y):
1261
+ r"""
1262
+ Bhattacharya Distance:
1263
+
1264
+ Parameters
1265
+ ----------
1266
+ v : array_like
1267
+ Vector 1
1268
+ y : array_like
1269
+ Vector 2
1270
+
1271
+ Returns
1272
+ -------
1273
+ float
1274
+ Bhattcharya distance between v and y
1275
+
1276
+ Notes
1277
+ -----
1278
+ .. math::
1279
+
1280
+ -ln(\sum_{i}\sqrt{y_{i}v_{i}})
1281
+ """
1282
+ return -1 * np.log(np.sum(np.sqrt(y * v)))
1283
+
1284
+
1285
+ def generalized_ochiai_index(v, y):
1286
+ r"""
1287
+ Generalized Ochiai Index
1288
+
1289
+ Parameters
1290
+ ----------
1291
+ v : array_like
1292
+ Vector 1
1293
+ y : array_like
1294
+ Vector 2
1295
+
1296
+ Returns
1297
+ -------
1298
+ float
1299
+ Generalized Ochiai Index between v and y
1300
+
1301
+ Notes
1302
+ -----
1303
+ .. math::
1304
+
1305
+ 1 - \frac{\sum_{i}min(y_{i}, v_{i})}{\sqrt{\sum_{i}y_{i} \sum_{i}v_{i}}}
1306
+ """
1307
+
1308
+ ind = np.sum(np.minimum(y, v)) / np.sqrt(np.sum(y) * np.sum(v))
1309
+ return 1 - ind
1310
+
1311
+
1312
+ def gower_distance(v, y):
1313
+ r"""
1314
+ Gower Distance
1315
+
1316
+ Parameters
1317
+ ----------
1318
+ v : array_like
1319
+ Vector 1
1320
+ y : array_like
1321
+ Vector 2
1322
+
1323
+ Returns
1324
+ -------
1325
+ float
1326
+ Gower distance between v and y
1327
+
1328
+ Notes
1329
+ -----
1330
+
1331
+ .. math::
1332
+
1333
+ \frac{1}{N}\sum_{i}|y_{i} - v_{i}|
1334
+ """
1335
+
1336
+ n = np.sum(y > 0)
1337
+ return (1 / n) * np.sum(np.abs(y - v))
1338
+
1339
+
1340
+ def impr_sqrt_cosine_sim(v, y):
1341
+ r"""
1342
+ Improved Square Root Cosine Similarity
1343
+
1344
+ Parameters
1345
+ ----------
1346
+ v : array_like
1347
+ Vector 1
1348
+ y : array_like
1349
+ Vector 2
1350
+
1351
+ Returns
1352
+ -------
1353
+ float
1354
+ Improved Square Root Cosine Similarity between v and y
1355
+
1356
+ Notes
1357
+ -----
1358
+ .. math::
1359
+
1360
+ \frac{\sum_{i}\sqrt{y_{i}v_{i}}}{\sum_{i}\sqrt{y_{i}}\sum_{i}\sqrt{v_{i}}}
1361
+ """
1362
+
1363
+ return np.sum(np.sqrt(y * v)) / (np.sum(np.sqrt(y)) * np.sum(np.sqrt(v)))
1364
+
1365
+
1366
+ def intersection_sim(v, y):
1367
+ r"""
1368
+ Intersection Similarity
1369
+
1370
+ Parameters
1371
+ ----------
1372
+ v : array_like
1373
+ Vector 1
1374
+ y : array_like
1375
+ Vector 2
1376
+
1377
+ Returns
1378
+ -------
1379
+ float
1380
+ Intersection Similarity between v and y
1381
+
1382
+ Notes
1383
+ -----
1384
+ .. math::
1385
+
1386
+ \sum_{i}min(y_{i}, v_{i})
1387
+ """
1388
+
1389
+ return np.sum(np.minimum(y, v))
1390
+
1391
+
1392
+ def j_divergence(v, y):
1393
+ r"""
1394
+ J Divergence
1395
+
1396
+ Parameters
1397
+ ----------
1398
+ v : array_like
1399
+ Vector 1
1400
+ y : array_like
1401
+ Vector 2
1402
+
1403
+ Returns
1404
+ -------
1405
+ float
1406
+ J Divergence between v and y
1407
+
1408
+ Notes
1409
+ -----
1410
+ .. math::
1411
+
1412
+ \sum_{i}(y_{i} - v_{i}) ln(\frac{y_{i}}{v_{i}})
1413
+ """
1414
+
1415
+ return np.sum((v - y) * np.log(v / y))
1416
+
1417
+
1418
+ def jensen_shannon_index(v, y):
1419
+ r"""
1420
+ Jensen-Shannon Index
1421
+
1422
+ Parameters
1423
+ ----------
1424
+ v : array_like
1425
+ Vector 1
1426
+ y : array_like
1427
+ Vector 2
1428
+
1429
+ Returns
1430
+ -------
1431
+ float
1432
+ Jensen Shannon Index between v and y
1433
+
1434
+ Notes
1435
+ -----
1436
+ .. math::
1437
+
1438
+ \frac{1}{2}[\sum_{i}y_{i}ln(\frac{2y_{i}}{y_{i} + v_{i}}) + \sum_{i}v_{i}ln(\frac{2v_{i}}{y_{i}+v_{i}})]
1439
+ """
1440
+
1441
+ return (1 / 2) * (
1442
+ np.sum(y * np.log(2 * y / (y + v))) + np.sum(v * np.log(2 * v / (y + v)))
1443
+ )
1444
+
1445
+
1446
+ def k_divergence(v, y):
1447
+ r"""
1448
+ K-Divergence
1449
+
1450
+ Parameters
1451
+ ----------
1452
+ v : array_like
1453
+ Vector 1
1454
+ y : array_like
1455
+ Vector 2
1456
+
1457
+ Returns
1458
+ -------
1459
+ float
1460
+ K-Divergence between v and y
1461
+
1462
+ Notes
1463
+ -----
1464
+ .. math::
1465
+
1466
+ \sum_{i}y_{i}ln(\frac{2y_{i}}{y_{i} + v_{i}})
1467
+ """
1468
+
1469
+ return np.sum(v * np.log((2 * v) / (y + v)))
1470
+
1471
+
1472
+ def topsoe_distance(v, y):
1473
+ r"""Topsoe distance
1474
+
1475
+ Parameters
1476
+ ----------
1477
+ v : array_like
1478
+ Vector 1
1479
+ y : array_like
1480
+ Vector 2
1481
+
1482
+ Returns
1483
+ -------
1484
+ float
1485
+ Topsoe distance between v and y
1486
+
1487
+ Notes
1488
+ -----
1489
+ """
1490
+ # [Chae] commented out the previous one; please review
1491
+ # v[v==0] = 1 #added by amt
1492
+ # y[y==0] = 1 #added by amt
1493
+ return np.sum((y * np.log((2 * y) / (y + v))) + (v * np.log((2 * v) / (y + v))))
1494
+
1495
+
1496
+ def probabilistic_symmetric_chi_squared_distance(v, y):
1497
+ r"""Fixed
1498
+ "I commented out the previous one; please review"
1499
+ """
1500
+ return 2 * np.sum(np.sum(np.power(y - v, 2) / (y + v)))
1501
+
1502
+
1503
+ def VW6(v, y):
1504
+ r"""
1505
+ "appears to be the same as max_symmetric_chi_squared_distance"
1506
+ """
1507
+ return min(np.sum(np.power(y - v, 2) / y), np.sum(np.power(y - v, 2) / v))
1508
+
1509
+
1510
+ def VW5(v, y):
1511
+ r"""
1512
+ "appears to be the same as max_symmetric_chi_squared_distance"
1513
+ """
1514
+ return max(np.sum(np.power(y - v, 2) / y), np.sum(np.power(y - v, 2) / v))
1515
+
1516
+
1517
+ def VW4(v, y):
1518
+ r"""
1519
+ "Tecnically the Symmetric chi2 eq63"
1520
+ """
1521
+ return np.sum(np.power(y - v, 2) / np.maximum(y, v))
1522
+
1523
+
1524
+ def VW3(v, y):
1525
+ r"""
1526
+ "New"
1527
+ """
1528
+ return np.sum(np.power(y - v, 2) / np.minimum(y, v))
1529
+
1530
+
1531
+ def VW2(v, y):
1532
+ r"""
1533
+ "New"
1534
+ """
1535
+ return np.sum(np.power(y - v, 2) / np.power(np.minimum(y, v), 2))
1536
+
1537
+
1538
+ def VW1(v, y):
1539
+ r"""
1540
+ "New"
1541
+ """
1542
+ return np.sum(np.abs(y - v) / np.minimum(y, v))
1543
+
1544
+
1545
+ def taneja_divergence(v, y):
1546
+ r"""
1547
+ "New"
1548
+ """
1549
+ return np.sum(((y + v) / 2) * np.log((y + v) / (2 * np.sqrt(y * v))))
1550
+
1551
+
1552
+ def symmetric_chi_squared_distance(v, y):
1553
+ r"""
1554
+ "New"
1555
+ """
1556
+ return np.sum(np.power(y - v, 2) / (y * v))
1557
+
1558
+
1559
+ def squared_chi_squared_distance(v, y):
1560
+ r"""
1561
+ "New"
1562
+ """
1563
+ return np.sum(np.power(y - v, 2) / (y + v))
1564
+
1565
+
1566
+ def square_root_cosine_correlation(v, y):
1567
+ r"""
1568
+ "New"
1569
+ """
1570
+ return np.sum(np.sqrt(y * v)) / (np.sum(y) * np.sum(v))
1571
+
1572
+
1573
+ def sorensen_distance(v, y):
1574
+ r"""
1575
+ "New"
1576
+ """
1577
+ return np.sum(np.abs(y - v)) / (np.sum(y + v))
1578
+
1579
+
1580
+ def Pearson_chi_squared_distance(v, y):
1581
+ r"""
1582
+ "New"
1583
+ """
1584
+ return np.sum(np.power(y - v, 2) / v)
1585
+
1586
+
1587
+ def Neyman_chi_squared_distance(v, y):
1588
+ r"""
1589
+ "New"
1590
+ """
1591
+ return np.sum(np.power(y - v, 2) / y)
1592
+
1593
+
1594
+ def Minokowski_3(v, y):
1595
+ r"""
1596
+ "New"
1597
+ """
1598
+ return np.power(np.sum(np.power(np.abs(y - v), 3)), 1 / 3)
1599
+
1600
+
1601
+ def Minokowski_4(v, y):
1602
+ r"""
1603
+ "New"
1604
+ """
1605
+ return np.power(np.sum(np.power(np.abs(y - v), 4)), 1 / 4)
1606
+
1607
+
1608
+ def kumarjohnson_divergence(v, y):
1609
+ r"""
1610
+ "New"
1611
+ """
1612
+ return np.sum(
1613
+ np.power(np.power(y, 2) + np.power(v, 2), 2) / (2 * np.power(y * v, 3 / 2))
1614
+ )
1615
+
1616
+
1617
+ def kumarhassebrook_similarity(v, y):
1618
+ r"""
1619
+ "New"
1620
+ """
1621
+ return np.sum(y * v) / (
1622
+ np.sum(np.power(y, 2)) + np.sum(np.power(v, 2)) - np.sum(y * v)
1623
+ )
1624
+
1625
+
1626
+ def kullbackleibler_divergence(v, y):
1627
+ r"""
1628
+ "New"
1629
+ """
1630
+ return np.sum(v * np.log(v / y))
1631
+
1632
+
1633
+ def soergel_distance(v, y):
1634
+ r"""
1635
+ "New"
1636
+ """
1637
+ return np.sum(np.abs(y - v)) / np.sum(np.maximum(y, v))