Skip to content
Merged
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
27 changes: 23 additions & 4 deletions src/aspire/abinitio/commonline_sync3n.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,13 +714,26 @@ def _triangle_scores(
* (a + 1)
)
# normalization of 2nd component: B = P*N_delta/sum(f), where f is the component formula
B0 = P ** (self.n_img * (self.n_img - 1) * (self.n_img - 2) / 2) / np.sum(
((1 - hist_x) ** b) * np.exp(-b / (1 - x0) * (1 - hist_x))
)
start_values = np.array([B0, P, b, x0], dtype=np.float64)
# B0 = (
# P
# * (self.n_img * (self.n_img - 1) * (self.n_img - 2) / 2)
# / np.sum(((1 - hist_x) ** b) * np.exp(-b / (1 - x0) * (1 - hist_x)))
# )
# P must be in lower and upper bounds or `curve_fit` will error
# This was not the case for MATLAB...
# P0 = np.clip(P, Pmin**3, Pmax**3)
# Note, MATLAB suggests the following, but I feel it is a bug.
# Will discuss with Yoel about the original code's intent.
# np.array([B0, P0, b, x0], dtype=np.float64)
start_values = None
lower_bounds = np.array([0, Pmin**3, 2, 0], dtype=np.float64)
upper_bounds = np.array([np.inf, Pmax**3, np.inf, 1], dtype=np.float64)

with np.printoptions(precision=2):
logger.info(f"curve_fit lower_bounds:{lower_bounds}")
logger.info(f"curve_fit start_values:{start_values}")
logger.info(f"curve_fit upper_bounds:{upper_bounds}")

# Fit distribution
def fun(x, B, P, b, x0, A=A, a=a):
"""Function to fit. x is data vector."""
Expand All @@ -742,6 +755,8 @@ def fun(x, B, P, b, x0, A=A, a=a):
P = P ** (1 / 3)
sigma = (1 - x0) / peak2sigma

logger.info(f"Estimated CL Errors P,STD:\t{100*P:.2f}%\t{sigma:.2f}")

# Initialize probability computations
# Local histograms analysis
A = a + 1 # distribution 1st component normalization factor
Expand All @@ -768,6 +783,10 @@ def fun(x, B, P, b, x0, A=A, a=a):
)
Pij = np.nan_to_num(Pij)

logger.info(
f"Common lines probabilities to be indicative Pij={100*np.mean(Pij):.2f}%"
)

return P, sigma, Pij, scores_hist

###########################################
Expand Down
Loading