Skip to content

Commit a4219bc

Browse files
committed
Examples and line wrapping in utils/transform.py
1 parent 69858dd commit a4219bc

1 file changed

Lines changed: 54 additions & 3 deletions

File tree

src/liana/utils/transform.py

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,52 @@
55

66
def zi_minmax(X: ArrayLike, cutoff: float = 0.5) -> csr_matrix:
77
"""
8-
Zero-inflated min-max scaling, adopted from CiteFuse (Kim et al., 2020; https://academic.oup.com/bioinformatics/article/36/14/4137/5827474).
8+
Zero-inflated min-max scaling, adopted from CiteFuse (Kim et al., 2020;
9+
https://academic.oup.com/bioinformatics/article/36/14/4137/5827474).
910
10-
This function scales the data to the range [0, 1] and sets values below a specified cutoff to 0.
11+
This function scales the data to the range [0, 1] for each column of a
12+
two-dimensional array and sets values below a specified cutoff to 0 (after
13+
scaling).
1114
1215
Parameters
1316
----------
1417
X
1518
Data to be scaled.
1619
cutoff
17-
Cutoff value for zero-inflation - values less than this are set to 0. Default is 0.5.
20+
Cutoff value for zero-inflation - values less than this are set to 0.
21+
Default is 0.5.
1822
1923
Returns
2024
-------
2125
X
2226
The scaled data matrix
2327
28+
Examples
29+
--------
30+
>>> x = np.array([[0.1, 0.3],
31+
... [2.0, 4.0],
32+
... [5.5, 7.1]])
33+
>>> print(zi_minmax(x))
34+
<Compressed Sparse Row sparse matrix of dtype 'float64'
35+
with 6 stored elements and shape (3, 2)>
36+
Coords Values
37+
(0, 0) 0.0
38+
(0, 1) 0.0
39+
(1, 0) 0.0
40+
(1, 1) 0.5441176470588236
41+
(2, 0) 1.0
42+
(2, 1) 1.0
43+
>>> print(zi_minmax(x, cutoff=0.1))
44+
<Compressed Sparse Row sparse matrix of dtype 'float64'
45+
with 6 stored elements and shape (3, 2)>
46+
Coords Values
47+
(0, 0) 0.0
48+
(0, 1) 0.0
49+
(1, 0) 0.3518518518518518
50+
(1, 1) 0.5441176470588236
51+
(2, 0) 1.0
52+
(2, 1) 1.0
53+
2454
"""
2555
X = X.copy()
2656
if not isspmatrix_csr(X):
@@ -59,6 +89,27 @@ def neg_to_zero(X: ArrayLike, cutoff: float = 0) -> csr_matrix:
5989
-------
6090
The modified data matrix
6191
92+
Examples
93+
--------
94+
>>> x = np.array([-1, -0.5, 0.1, 0.4, 2])
95+
>>> print(neg_to_zero(x))
96+
<Compressed Sparse Row sparse matrix of dtype 'float64'
97+
with 5 stored elements and shape (1, 5)>
98+
Coords Values
99+
(0, 0) 0.0
100+
(0, 1) 0.0
101+
(0, 2) 0.1
102+
(0, 3) 0.4
103+
(0, 4) 2.0
104+
>>> print(neg_to_zero(x, cutoff=0.5))
105+
<Compressed Sparse Row sparse matrix of dtype 'float64'
106+
with 5 stored elements and shape (1, 5)>
107+
Coords Values
108+
(0, 0) 0.0
109+
(0, 1) 0.0
110+
(0, 2) 0.0
111+
(0, 3) 0.0
112+
(0, 4) 2.0
62113
"""
63114
X = X.copy()
64115
if not isspmatrix_csr(X):

0 commit comments

Comments
 (0)