Skip to content

Commit

Permalink
Enable alteration of unconstrained boundary search
Browse files Browse the repository at this point in the history
  • Loading branch information
nickjcroucher committed Feb 9, 2023
1 parent aa637d7 commit 3306f01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions PopPUNK/refine.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def refineFit(distMat, sample_names, mean0, mean1, scale,
raise RuntimeError("Unconstrained optimization and indiv-refine incompatible")

global_grid_resolution = 20
x_max_start, y_max_start = decisionBoundary(mean0, gradient)
x_max_end, y_max_end = decisionBoundary(mean1, gradient)
x_max_start, y_max_start = decisionBoundary(mean0, gradient, adj = -1*min_move)
x_max_end, y_max_end = decisionBoundary(mean1, gradient, adj = -max_move)

if x_max_start < 0 or y_max_start < 0:
raise RuntimeError("Boundary range below zero")
Expand Down
9 changes: 8 additions & 1 deletion PopPUNK/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ def transformLine(s, mean0, mean1):
return np.array([x, y])


def decisionBoundary(intercept, gradient):
def decisionBoundary(intercept, gradient, adj = 0.0):
"""Returns the co-ordinates where the triangle the decision boundary forms
meets the x- and y-axes.
Expand All @@ -529,12 +529,19 @@ def decisionBoundary(intercept, gradient):
which intercepts the boundary
gradient (float)
Gradient of the line
adj (float)
Distance by which to shift the interception point
Returns:
x (float)
The x-axis intercept
y (float)
The y-axis intercept
"""
if adj != 0.0:
original_hypotenuse = (intercept[0]**2 + intercept[1]**2)**0.5
length_ratio = (original_hypotenuse + adj)/original_hypotenuse
intercept[0] = intercept[0] * length_ratio
intercept[1] = intercept[1] * length_ratio
x = intercept[0] + intercept[1] * gradient
y = intercept[1] + intercept[0] / gradient
return(x, y)
Expand Down

0 comments on commit 3306f01

Please sign in to comment.