Skip to content

How to put a constraint on the expression in a natuarl logarithm function that I am trying to fit into my data? #1004

Closed Answered by newville
nepomnyi asked this question in Q&A
Discussion options

You must be logged in to vote

My main advice would be to prevent negative arguments to np.log() - that would be independent of the values of your coord and the parameter values. Like, you could just use an "abs()" or look for and negative values with np.where((p2*coord + p3)<0) in your lnfit function. That strengthens the function.

If coord is all positive or all negative, and if p3 is positive, setting an upper or lower limit on p2 shouldn't be too hard: just p2 > 0 or p2<0 would be sufficient.

But if coords has both positive and negative values, it is much trickier, as the current value of p3 would need to be known to set a bound on p2. And p3 not being known is sort of one of the points. Since you are asking the qu…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by nepomnyi
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@nepomnyi
Comment options

@newville
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants