Skip to content

Commit

Permalink
Prevent potential future bugs when normalizing distributions througho…
Browse files Browse the repository at this point in the history
…ut (#335)
luisfabib authored Jun 9, 2022
1 parent 738f6dd commit 8b4e91a
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion deerlab/dipolarmodel.py
Original file line number Diff line number Diff line change
@@ -293,7 +293,8 @@ def dipolarpenalty(Pmodel, r, type, selection=None):
# Define the compactness penalty function
def compactness_penalty(*args):
P = Pmodel(*[r]*Nconstants,*args)
P = P/np.trapz(P,r)
if not np.all(P==0):
P = P/np.trapz(P,r)
return np.sqrt(P*(r - np.trapz(P*r,r))**2*np.mean(np.diff(r)))
# Add the penalty to the Pmodel
penalty = Penalty(compactness_penalty,selection,
2 changes: 1 addition & 1 deletion deerlab/diststats.py
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ def analyze_rmode(V):

# Auxiliary functions
# -------------------
int = np.trapz(P,r)
int = np.trapz(P,r) if not np.all(P==0) else 1
def normalize(P):
return P/int
# Percentile function

0 comments on commit 8b4e91a

Please sign in to comment.