Skip to content

Commit

Permalink
Merge pull request YingfanWang#78 from YingfanWang/hotfix
Browse files Browse the repository at this point in the history
Release 0.7.4
  • Loading branch information
hyhuang00 authored Nov 9, 2024
2 parents 3637bc5 + 5e17ab6 commit 691dbfa
Show file tree
Hide file tree
Showing 22 changed files with 128 additions and 113 deletions.
34 changes: 0 additions & 34 deletions .github/workflows/python-package-conda.yml

This file was deleted.

4 changes: 2 additions & 2 deletions demo/basic_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# Initialize the pacmap instance
# By default, the n_neighbors is set to 10.
# Setting n_neighbors to "None" can enable an automatic parameter selection
# choice shown in "parameter" section of the README file.
# choice shown in "parameter" section of the README file.
# Notice that from v0.6.0 on, we rename the n_dims parameter to n_components.
reducer = pacmap.PaCMAP(n_components=2, n_neighbors=10, MN_ratio=0.5, FP_ratio=2.0)
reducer = pacmap.PaCMAP(n_components=2, n_neighbors=10, MN_ratio=0.5, FP_ratio=2.0)

# fit the data (The index of transformed data corresponds to the index of the original data)
X_transformed = reducer.fit_transform(X, init="pca")
Expand Down
4 changes: 3 additions & 1 deletion demo/demo_utils.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import matplotlib.pyplot as plt


def generate_figure(embedding, labels, title):
fig, ax = plt.subplots(1, 1, figsize=(6, 6))
ax.scatter(embedding[:, 0], embedding[:, 1], s=0.5, c=labels, cmap='Spectral')
ax.axis('off')
ax.set_title(title)
plt.savefig(f"./{title}.png")


def generate_combined_figure(embeddings, labels, titles, theme_title):
len_subfigs = len(embeddings)
assert len(labels) == len_subfigs
assert len(titles) == len_subfigs
n_rows = (len_subfigs + 2) // 3
fig, axes = plt.subplots(n_rows, 3, figsize = (18, n_rows * 6))
fig, axes = plt.subplots(n_rows, 3, figsize=(18, n_rows * 6))
axes = axes.flatten()
for i in range(len_subfigs):
ax = axes[i]
Expand Down
10 changes: 7 additions & 3 deletions demo/specify_nn_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

nbrs = np.zeros((n, 20), dtype=np.int32)
for i in range(n):
nbrs_ = tree.get_nns_by_item(i, 20 + 1) # The first nbr is always the point itself
nbrs_ = tree.get_nns_by_item(i, 20 + 1) # The first nbr is always the point itself
nbrs[i, :] = nbrs_[1:]

scaled_dist = np.ones((n, n_neighbors)) # No scaling is needed
scaled_dist = np.ones((n, n_neighbors)) # No scaling is needed

# Type casting is needed for numba acceleration
X = X.astype(np.float32)
Expand All @@ -37,7 +37,11 @@

# initializing the pacmap instance
# feed the pair_neighbors into the instance
embedding = pacmap.PaCMAP(n_components=2, n_neighbors=n_neighbors, MN_ratio=0.5, FP_ratio=2.0, pair_neighbors=pair_neighbors)
embedding = pacmap.PaCMAP(n_components=2,
n_neighbors=n_neighbors,
MN_ratio=0.5,
FP_ratio=2.0,
pair_neighbors=pair_neighbors)

# fit the data (The index of transformed data corresponds to the index of the original data)
X_transformed = embedding.fit_transform(X, init="pca")
Expand Down
6 changes: 3 additions & 3 deletions demo/transform_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pacmap
import numpy as np
from sklearn.model_selection import StratifiedKFold
from demo_utils import *
import demo_utils


# MNIST
Expand All @@ -25,7 +25,7 @@
X_train, X_test = mnist[train_index], mnist[test_index]
y_train, y_test = labels[train_index], labels[test_index]
break

# Initialize the instance
reducer = pacmap.PaCMAP(n_components=2, n_neighbors=10, MN_ratio=0.5, FP_ratio=2.0, random_state=20, save_tree=False)

Expand All @@ -41,4 +41,4 @@
embeddings = [embedding, embedding_test, embedding_combined]
labelset = [y_train, y_test, y]
titles = ['Training', 'Test', 'Combined']
generate_combined_figure(embeddings, labelset, titles, f'mnist_transform_{n}')
demo_utils.generate_combined_figure(embeddings, labelset, titles, f'mnist_transform_{n}')
2 changes: 2 additions & 0 deletions evaluation/evaluation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# pylint: skip-file
# flake8: noqa
import os
import json
import matplotlib.cm as cm
Expand Down
3 changes: 3 additions & 0 deletions experiments/FA2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# pylint: skip-file
# flake8: noqa
import os
import json
import numpy as np
Expand All @@ -7,6 +9,7 @@
from fa2 import ForceAtlas2 as FA2
from sklearn.preprocessing import scale
from sklearn.decomposition import PCA
from sklearn.neighbors import NearestNeighbors

def transform_by_FA2(X, n_neighbors=6):
if X.shape[1] > 100:
Expand Down
2 changes: 2 additions & 0 deletions experiments/run_experiments.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# pylint: skip-file
# flake8: noqa
import umap
import trimap
import FlowCal
Expand Down
2 changes: 2 additions & 0 deletions experiments/run_experiments_LargeVis.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# pylint: skip-file
# flake8: noqa
import FlowCal
import pandas as pd

Expand Down
2 changes: 2 additions & 0 deletions experiments/run_experiments_tSNE.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# pylint: skip-file
# flake8: noqa
import FlowCal
import json

Expand Down
22 changes: 12 additions & 10 deletions rainbow_plot/rainbow_plots_for_good_loss.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# pylint: skip-file
# flake8: noqa
import matplotlib.pyplot as plt
import numpy as np
import umap
from scipy import integrate
from pacmap import PaCMAP
from experiments.run_experiments import data_prep


cmap_fig = plt.cm.get_cmap("Spectral")
Expand All @@ -20,56 +19,66 @@ def ladder_map(grids, ladder_range):
l_map /= len(ladder_range)
return l_map


# parameter "a" and "b" use default values as below
def attr(x):
return -pow(x, 0.79)/(1 + pow(x, 2))


def repul(x):
return 0.895 * x/(1 + pow(x, 2))/(0.001 + pow(x, 2))


def integ_attr(b):
res = np.zeros(b.shape)
for i in range(b.shape[1]):
res[0][i] = integrate.quad(attr, 0, b[0][i], points=[0])[0]
return res


def integ_repul(b):
res = np.zeros(b.shape)
for i in range(b.shape[0]):
res[i][0] = integrate.quad(repul, 0, b[i][0], points=[0])[0]
return res


# For t-SNE we choose a neighbor and further point to visualize forces on them (using COIL20 dataset, 300 iterations)
def t_attr(x):
qij = 1.0 / (x ** 2 + 1.0) / 11500
qij = np.maximum(qij, 1e-12)
force = - (8.58 * 1e-5 - qij) * x / (1.0 + x ** 2)
return force


def t_repul(x):
qij = 1.0 / (x ** 2 + 1.0) / 11500
qij = np.maximum(qij, 1e-12)
force = - 10 * (1.19 * 1e-8 - qij) * x / (1.0 + x ** 2)
return force


def t_integ_attr(b):
res = np.zeros(b.shape[0])
for i in range(b.shape[0]):
res[i] = integrate.quad(t_attr, 0, b[i], points=[0])[0]
return res


def t_integ_repul(b):
res = np.zeros(b.shape[0])
for i in range(b.shape[0]):
res[i] = integrate.quad(t_repul, 0, b[i], points=[0])[0]
return res


def t_integ_attr_(b):
res = np.zeros(b.shape)
for i in range(b.shape[1]):
res[0][i] = integrate.quad(t_attr, 0, b[0][i], points=[0])[0]
return res


def t_integ_repul_(b):
res = np.zeros(b.shape)
for i in range(b.shape[0]):
Expand All @@ -79,8 +88,6 @@ def t_integ_repul_(b):

plt.figure(figsize=(28, 15))



plt.axes([0.047, 0.52, 0.2, 0.44])
x = np.linspace(0.0001, 100, num=7000)# d_ij
y = np.linspace(0.0001, 100, num=7000)# d_ik
Expand Down Expand Up @@ -115,8 +122,6 @@ def t_integ_repul_(b):
plt.xlabel(r'$d_{ij}$', fontsize=38)
plt.ylabel(r'$d_{ik}$', fontsize=38)



plt.axes([0.293, 0.52, 0.2, 0.44])
x = np.linspace(0.0001, 25, num=7000) # d_ij
y = np.linspace(0.0001, 25, num=7000) # d_ik
Expand Down Expand Up @@ -150,7 +155,6 @@ def t_integ_repul_(b):
plt.xlabel(r'$d_{ij}$', fontsize=38)
plt.ylabel(r'$d_{ik}$', fontsize=38)


plt.axes([0.543, 0.52, 0.2, 0.44])
x = np.linspace(0.0001, 200, num=7000) # d_ij
y = np.linspace(0.0001, 200, num=7000) # d_ik
Expand Down Expand Up @@ -184,7 +188,6 @@ def t_integ_repul_(b):
plt.xlabel(r'$d_{ij}$', fontsize=38)
plt.ylabel(r'$d_{ik}$', fontsize=38)


plt.axes([0.795, 0.52, 0.2, 0.44])
x = np.linspace(0.0001, 50, num=7000) # d_ij
y = np.linspace(0.0001, 50, num=7000) # d_ik
Expand Down Expand Up @@ -218,5 +221,4 @@ def t_integ_repul_(b):
plt.xlabel(r'$d_{ij}$', fontsize=38)
plt.ylabel(r'$d_{ik}$', fontsize=38)


plt.savefig('rainbow_good_loss')
4 changes: 4 additions & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

- 0.7.4
Fix the problem that `sample_FP_pair` and `sample_FP_pair_deterministic` may create
FP pairs on NN.

- 0.7.3

Fix the problem when the sample size is smaller than the number of neighbors,
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pacmap
version = 0.7.3
version = 0.7.4
author = Yingfan Wang, Haiyang Huang, Cynthia Rudin, Yaron Shaposhnik
author_email = yingfan.wang@duke.edu
description = The official implementation for PaCMAP: Pairwise Controlled Manifold Approximation Projection
Expand Down
2 changes: 1 addition & 1 deletion source/pacmap/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .pacmap import *
from .pacmap import PaCMAP, sample_neighbors_pair

import pkg_resources
__version__ = pkg_resources.get_distribution('pacmap').version
Expand Down
Loading

0 comments on commit 691dbfa

Please sign in to comment.