Commit a6f0a83a authored by Hanna  JULIENNE's avatar Hanna JULIENNE

treat case when inversion fail

parent 6f7622ee
Pipeline #44871 passed with stages
in 1 minute and 7 seconds
......@@ -55,11 +55,9 @@ def compute_var(sig_i_t, sig_t_inv, lamb, batch=True):
def check_inversion(sig_t, sig_t_inv):
print("sig_t")
print(sig_t)
print(np.any(np.isnan(sig_t)))
print("sig_t_inv")
print(sig_t_inv)
print("has na")
print(np.any(np.isnan(sig_t_inv)))
return np.allclose(sig_t, np.dot(sig_t, np.dot(sig_t_inv, sig_t)))
def var_in_boundaries(var,lamb):
......@@ -96,19 +94,20 @@ def raiss_model(zt, sig_t, sig_i_t, lamb=0.01, rcond=0.01, batch=True):
make inversion biased but much more numerically robust
"""
sig_t_inv = invert_sig_t(sig_t, lamb, rcond)
if batch:
condition_number = np.array([np.linalg.cond(sig_t)]*sig_i_t.shape[0])
correct_inversion = np.array([check_inversion(sig_t, sig_t_inv)]*sig_i_t.shape[0])
if sig_t_inv is None:
return({"var" : [], "mu" : [], "ld_score" : [], "condition_number" : [], "correct_inversion":[] })
else:
condition_number = np.linalg.cond(sig_t)
correct_inversion = check_inversion(sig_t, sig_t_inv)
var, ld_score = compute_var(sig_i_t, sig_t_inv, lamb, batch)
mu = compute_mu(sig_i_t, sig_t_inv, zt)
var_norm = var_in_boundaries(var, lamb)
R2 = ((1+lamb)-var_norm)
mu = mu / np.sqrt(R2)
return({"var" : var, "mu" : mu, "ld_score" : ld_score, "condition_number" : condition_number, "correct_inversion":correct_inversion })
if batch:
condition_number = np.array([np.linalg.cond(sig_t)]*sig_i_t.shape[0])
correct_inversion = np.array([check_inversion(sig_t, sig_t_inv)]*sig_i_t.shape[0])
else:
condition_number = np.linalg.cond(sig_t)
correct_inversion = check_inversion(sig_t, sig_t_inv)
var, ld_score = compute_var(sig_i_t, sig_t_inv, lamb, batch)
mu = compute_mu(sig_i_t, sig_t_inv, zt)
var_norm = var_in_boundaries(var, lamb)
R2 = ((1+lamb)-var_norm)
mu = mu / np.sqrt(R2)
return({"var" : var, "mu" : mu, "ld_score" : ld_score, "condition_number" : condition_number, "correct_inversion":correct_inversion })
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment