-
Notifications
You must be signed in to change notification settings - Fork 15
Add a sample rejection procedure based on a simple likelihood threshold. #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,13 @@ | |
from scipy.linalg import expm | ||
|
||
from .densities import Tanh | ||
from ._tools import fuse_mask | ||
|
||
|
||
def core_picard(X, density=Tanh(), ortho=False, extended=False, m=7, | ||
max_iter=1000, tol=1e-7, lambda_min=0.01, ls_tries=10, | ||
verbose=False, covariance=None): | ||
verbose=False, covariance=None, ll_reject=None, | ||
reject_every=None): | ||
'''Runs the Picard algorithm | ||
|
||
The algorithm is detailed in:: | ||
|
@@ -78,12 +80,25 @@ def core_picard(X, density=Tanh(), ortho=False, extended=False, m=7, | |
current_loss = _loss(Y, W, density, signs, ortho, extended) | ||
requested_tolerance = False | ||
sign_change = False | ||
rejection = ll_reject is not None | ||
gradient_norm = 1. | ||
if extended: | ||
if covariance is None: # Need this for extended | ||
covariance = X.dot(X.T) / T | ||
C = covariance.copy() | ||
if rejection: # create a mask | ||
mask = np.zeros(T, dtype=np.bool_) | ||
for n in range(max_iter): | ||
# Rejection | ||
if rejection and (n + 1) % reject_every == 0: | ||
ll = density.log_lik(Y) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering how to make it work for |
||
rejected = np.sum(ll > ll_reject, axis=0) > 0 | ||
# Exclude rejected data | ||
Y = Y[:, ~rejected] | ||
# Fuse the mask to keep track of the total mask | ||
mask = fuse_mask(mask, rejected) | ||
# Compute the new loss | ||
current_loss = _loss(Y, W, density, signs, ortho, extended) | ||
# Compute the score function | ||
psiY, psidY = density.score_and_der(Y) | ||
# Compute the relative gradient and the Hessian off-diagonal | ||
|
@@ -169,6 +184,8 @@ def core_picard(X, density=Tanh(), ortho=False, extended=False, m=7, | |
n_iterations=n) | ||
if extended: | ||
infos['signs'] = signs | ||
if rejection: | ||
infos['rejected'] = mask | ||
return Y, W, infos | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,3 +89,13 @@ def _ica_par(X, fun, max_iter, w_init, verbose): | |
if verbose: | ||
print('Running Picard...') | ||
return W | ||
|
||
|
||
def fuse_mask(mask1, mask2): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is much much faster in numba. This is not really a bottleneck of the algorithm though. |
||
idx_m2 = 0 | ||
N = len(mask1) | ||
for i in range(N): | ||
if not mask1[i]: | ||
mask1[i] = mask2[idx_m2] | ||
idx_m2 += 1 | ||
return mask1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how to set a default value for
ll_reject
if the user wants to use rejection