nelder-mead | Pure Python/Numpy implementation | Machine Learning library
kandi X-RAY | nelder-mead Summary
kandi X-RAY | nelder-mead Summary
Pure Python/Numpy implementation of the Nelder-Mead algorithm.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Nelder - Mead algorithm
nelder-mead Key Features
nelder-mead Examples and Code Snippets
Community Discussions
Trending Discussions on nelder-mead
QUESTION
I would like to determine the travel time of an object moving a certain distance along a parameterized curve. I already learned how to do this mathematically, but I think there should be a better way of implementing this in Python using scipy.optimize.minimize
. However, for some reason, I cannot get it to work. The result always goes to +inf, even though my initial guess should be fairly close. What am I doing wrong?
The problem in more specific terms:
Given the curve (in 2d) parameterized by time, you choose an arbitrary point in time (t_end
), which also specifies a specific point on the curve. From there you go back in time along the curve until the path traveled is equal to some arbitrary distance (d_min
). What I want to know is the travel time along this segment of the curve, or in other words, given t_end
and d_min
, what is t_start
so that the line integral along the curve from t_start
to t_end
is equal to d_min
.
Below is an MWE that contains just the crucial part:
...ANSWER
Answered 2022-Mar-15 at 12:35I will only address your crucial part. Here are a few points that crossed my mind:
According to the comments, you basically want to solve an equation F(t) = d by minimizing the objective q(t) = F(t)-d. However, mathematically, this is not the same in general. To see why, let's consider the quadratic function F(t) = t^2 and d = 1. Then, t = 1 solves the equation F(t) = d. However, minimizing the objective q(t) = t^2 - 1 yields the local minimum t = 0 with objective function value q(0) = -1. And obviously, 0*0 ≠ 1. Note that F(t) = d if and only if q(t) = 0, i.e. the objective q has the objective value 0. Therefore, you need a minimum with an objective value of 0. And since any norm is non-negative by definition, we just minimize the euclidean norm of your function, i.e. we minimize p(t) = ||q(t)|| = ||F(t) - d||.
Because you have a (probably non-convex) scalar optimization problem of one variable, it's highly recommended to use the specialized algorithms behind
scipy.optimize.minimize_scalar
:
QUESTION
I want to find the parameter of a function that will result in a specific integral value in a defined interval. To make things simpler, the example below considers the function to be a straight line, and the parameter I want to find is the slope m
. I use scipy.integrate.quad
to integrate and was trying to use scipy.integrate.minimize
to find the slope:
ANSWER
Answered 2022-Mar-07 at 12:37The minimum is of course negative infinity. To get a zero, I just had to constrain the problem to non negative values, as commented by @ForceBru and @joni. Thanks!
EDIT
here is the final functional full code:
QUESTION
I'm trying to fit a mixed effect model with a constrained parameter, and am struggling to make it work. Adding a small bit of complexity, is that one of the terms should be a polynomial.
Essentially what I'm looking for is something like the following, where var 1 is fixed at a certain value.
mod1 <- lmer(outcome ~ var1 + poly(var2,2) + (1 | Study), df)
It seems like it can be done using lmer with the Nelder-Mead option, but I can quite wrap my head around how to make it work.
I've also tried using the lavaan package, but I've never used it before and am getting hung up somewhere. Here is an example...
...ANSWER
Answered 2022-Mar-04 at 01:32It's tricky because lmer
"profiles out" the fixed-effect parameters, i.e. they're not explicitly fitted as part of the nonlinear optimization step.
Assuming var1
is numeric/continuous and we want to set a coefficient of b
, how about
QUESTION
I'm trying to use scipy minimize to estimate a parameter from an ODE system, which is pretty straightforward, however the methods I used aren't returning values anywhere near what the value should be. My parameter beta
, should have a value estimated to be around 0.42. I am sure that this method is correct, so i can't understand why the estimates are so off
ANSWER
Answered 2022-Feb-23 at 16:40Assuming that the model is OK, the problem is that you assume that beta
should be close to 0.42
when it should not. A simple visual test, plotting the measurements and the modeled data, shows that 0.72
yields much better results than 0.43
. I added the following lines:
QUESTION
I am currently attempting to estimate the parameters of a logistic regression model "by hand" on the iris
dataset via minimisation of cross-entropy. Please note, when I say iris
dataset, it has been changed such that there are only two classes - Setosa and Other. It was also normalised via the scale
function:
ANSWER
Answered 2022-Feb-20 at 10:38The main issue is that you have "complete separation" in your dataset. With those predictors, you can identify Species_n
without any error at all. In this kind of situation, the logistic model has no MLE, it improves more and more as the estimated coefficients get more extreme in the right direction.
The way to detect this is to look at the predicted probabilities or logits. When I ran your model once, I got estimates that were
QUESTION
I am trying to use scipy.optimize.minimize (simplex method) for minimizing the following function
...ANSWER
Answered 2022-Feb-15 at 16:19what about this:
QUESTION
I have code which estimates a parameter beta in an ODE system, given that all parameters are known other than beta and the peak of the 'epidemic' simulation, is 10% of the starting population. However, I realise solving the root might not always work to find the value. Is there any method of using scipy.optimize to find an alternate way of estimating this, by taking the squared difference of sum at the 10% peak, squaring the whole thing, then minimising that? This is the current code:
...ANSWER
Answered 2022-Jan-20 at 15:59Yes, you can do this using scipy.optimize.minimize
.
One approach would be as follows:
QUESTION
I have a code which performs optimization to infer a parameter:
...ANSWER
Answered 2022-Feb-04 at 21:04Your problem occurs at line 52, where you are getting 77 values by solving peak_infections(x, df)[1:]
and you have 11 values of incidence
, as you have mentioned.
This arises because you are solving your ode at t
(line 29) which has 78 values. To avoid this, generate a time vector with 7 values in your peak_infections
function as follows:
QUESTION
I am trying to translate from R to Python the nlm function for non linear minimization from stats package. In the help menu in R it says that "function carries out a minimization of the function f using a Newton-type algorithm"
The original and right code in R is the following:
...ANSWER
Answered 2022-Jan-22 at 12:59I test that if you use the same data
, you can get the similar minimum
.
In R:
QUESTION
I am working with the R programming language.
I am trying to learn more about optimization algorithms, and as a learning exercise - I would like to try an optimize a mathematical function using the (famous) gradient descent algorithm using the R programming language.
For instance, I would like to try and "optimize" (i.e. find out the values of "x1 and x2" that produce the smallest possible value of "y") the following function (this function is called the Rastrign Function, and is a popular function to test optimization algorithms on due to its irregular and complicated shape):
I first defined this function in R:
...ANSWER
Answered 2022-Jan-20 at 17:13As indicated in the comments, (I just learned that) "gradient descent" is the same as "steepest descent":
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install nelder-mead
You can use nelder-mead like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page