robust-mixed-dist 0.1.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.
- robust_mixed_dist/__init__.py +0 -0
- robust_mixed_dist/binary.py +110 -0
- robust_mixed_dist/mixed.py +776 -0
- robust_mixed_dist/multiclass.py +57 -0
- robust_mixed_dist/quantitative.py +666 -0
- robust_mixed_dist-0.1.0.dist-info/METADATA +27 -0
- robust_mixed_dist-0.1.0.dist-info/RECORD +10 -0
- robust_mixed_dist-0.1.0.dist-info/WHEEL +5 -0
- robust_mixed_dist-0.1.0.dist-info/licenses/LICENSE +19 -0
- robust_mixed_dist-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import polars as pl
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from scipy.spatial import distance
|
|
4
|
+
from scipy.spatial.distance import pdist, squareform
|
|
5
|
+
|
|
6
|
+
################################################################################
|
|
7
|
+
|
|
8
|
+
def hamming_dist_matrix(X):
|
|
9
|
+
"""
|
|
10
|
+
Calculates the hamming distance matrix for a data matrix `X` using SciPy.
|
|
11
|
+
|
|
12
|
+
Parameters (inputs)
|
|
13
|
+
----------
|
|
14
|
+
X: a pandas/polars DataFrame or a NumPy array. It represents a data matrix.
|
|
15
|
+
|
|
16
|
+
Returns (outputs)
|
|
17
|
+
-------
|
|
18
|
+
M: the hamming distance matrix between the rows of X.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
if isinstance(X, pl.DataFrame):
|
|
22
|
+
X = X.to_numpy()
|
|
23
|
+
if isinstance(X, pd.DataFrame):
|
|
24
|
+
X = X.to_numpy()
|
|
25
|
+
|
|
26
|
+
# Compute the pairwise distances using pdist and convert to a square form.
|
|
27
|
+
M = squareform(pdist(X, metric='matching'))
|
|
28
|
+
|
|
29
|
+
return M
|
|
30
|
+
|
|
31
|
+
################################################################################
|
|
32
|
+
|
|
33
|
+
def hamming_dist(xi, xr) :
|
|
34
|
+
"""
|
|
35
|
+
Calculates the hamming distance between a pair of vectors.
|
|
36
|
+
|
|
37
|
+
Parameters (inputs)
|
|
38
|
+
----------
|
|
39
|
+
xi, xr: a pair of quantitative vectors. They represent a couple of statistical observations.
|
|
40
|
+
|
|
41
|
+
Returns (outputs)
|
|
42
|
+
-------
|
|
43
|
+
The hamming distance between the observations `xi` and `xr`.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
if isinstance(xi, (pl.DataFrame, pd.DataFrame)) :
|
|
47
|
+
xi = xi.to_numpy().flatten()
|
|
48
|
+
elif isinstance(xi, (pd.Series, pl.Series)) :
|
|
49
|
+
xi = xi.to_numpy()
|
|
50
|
+
if isinstance(xr, (pl.DataFrame, pd.DataFrame)) :
|
|
51
|
+
xr = xr.to_numpy().flatten()
|
|
52
|
+
elif isinstance(xr, (pd.Series, pl.Series)) :
|
|
53
|
+
xr = xr.to_numpy()
|
|
54
|
+
|
|
55
|
+
return distance.hamming(xi, xr)
|
|
56
|
+
|
|
57
|
+
################################################################################
|