Skip to content

Commit 0da3db2

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 1aa6b33 commit 0da3db2

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

machine_learning/tsne.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from numpy import ndarray
1616
from sklearn.datasets import load_iris
1717

18+
1819
def _compute_pairwise_affinities(data_x: ndarray, sigma: float = 1.0) -> ndarray:
1920
"""
2021
Compute high-dimensional affinities using Gaussian kernel.
@@ -58,7 +59,12 @@ def _compute_low_dim_affinities(low_dim_embedding: ndarray) -> tuple[ndarray, nd
5859
(2, 2)
5960
"""
6061
sum_y = np.sum(np.square(low_dim_embedding), axis=1)
61-
num = 1 / (1 + np.add(np.add(-2 * np.dot(low_dim_embedding, low_dim_embedding.T), sum_y).T, sum_y))
62+
num = 1 / (
63+
1
64+
+ np.add(
65+
np.add(-2 * np.dot(low_dim_embedding, low_dim_embedding.T), sum_y).T, sum_y
66+
)
67+
)
6268
np.fill_diagonal(num, 0)
6369
q = num / np.sum(num)
6470
return q, num
@@ -82,7 +88,9 @@ class TSNE:
8288
(150, 2)
8389
"""
8490

85-
def __init__(self, *, n_components: int = 2, learning_rate: float = 200.0, n_iter: int = 500) -> None:
91+
def __init__(
92+
self, *, n_components: int = 2, learning_rate: float = 200.0, n_iter: int = 500
93+
) -> None:
8694
if n_components < 1:
8795
raise ValueError("n_components must be >= 1")
8896
if n_iter < 1:
@@ -195,5 +203,6 @@ def main() -> None:
195203

196204
if __name__ == "__main__":
197205
import doctest
206+
198207
doctest.testmod()
199208
main()

0 commit comments

Comments
 (0)