Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 35 additions & 84 deletions example_basic_usage.ipynb

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions hyperbolicTSNE/cost_functions_.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def exact_tsne(cls):
"degrees_of_freedom": 1,
"skip_num_points": 0,
"num_threads": _openmp_effective_n_threads(),
"verbose": False
"verbose": False,
"grad_fix": False, # tells the cost function calculation to use the correct gradient
}
}

Expand All @@ -129,8 +130,13 @@ def bh_tsne(cls, angle=0.5):
"""
return {
"method": "barnes-hut",
"params": {"angle": angle, "degrees_of_freedom": 1, "num_threads": _openmp_effective_n_threads(),
"verbose": False}
"params": {
"angle": angle,
"degrees_of_freedom": 1,
"num_threads": _openmp_effective_n_threads(),
"verbose": False,
"grad_fix": False, # tells the cost function calculation to use the correct gradient
}
}

#########################
Expand Down
5 changes: 3 additions & 2 deletions hyperbolicTSNE/solver_.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def gradient_descent(
y0, cf, cf_params, *, start_it=0, n_iter=100, n_iter_check=np.inf, n_iter_without_progress=300,
threshold_cf=0., threshold_its=-1, threshold_check_size=-1.,
momentum=0.8, learning_rate=200.0, min_gain=0.01, vanilla=False, min_grad_norm=1e-7, error_tol=1e-9, size_tol=None,
verbose=0, rescale=None, n_iter_rescale=np.inf, gradient_mask=np.ones, grad_scale_fix=False,
verbose=0, rescale=None, n_iter_rescale=np.inf, gradient_mask=np.ones, grad_scale_fix=True,
logging_dict=None, logging_key=None,
):
"""Batch gradient descent with momentum and individual gains.
Expand Down Expand Up @@ -246,7 +246,8 @@ def gradient_descent(
error, grad = cf.obj_grad(y, **cf_params)

if isinstance(cf, HyperbolicKL):
# New Fix
# New Fix: Inverse metric tensor factor that multiplies the derivative of the cost function
# leading to a correct gradient update step
if grad_scale_fix:
grad = ((1. - np.linalg.norm(y.reshape(n_samples, 2), axis=1)
** 2) ** 2)[:, np.newaxis] * grad.reshape(n_samples, 2) / 4
Expand Down