linear programming with python - python

I'am trying to solve a following problem.
In fact, this is Least Absolute Deviation Regression problem. I want to know how to solve this with python. I know that scipy has "linprog" which solve linear system with linear inequality constraints. But here there is two variable in inequality constraints, t, x. So, I want to know how to apply the "linprog" or is there other library which can solve this problem? Thanks

You have to write your problem in standard form, splitting the second inequality constraint and concatenating the two optimization variables. Then, you can feed it to linprog.
It is more of a math problem than an implementation one.

Related

Why the objective function and some constraints doesn't labeled as indexed in pyomo

I have modeled a mathematical optimization problem into pyomo Python as bellow.
I do not understand why just my "constraint2" is labeled as "indexed" in pyomo?
Is that affect the problem solving? Cause I use "ipopt" as solver but my results seems much different when I use "Gekko" library and the same "ipopt" solver.
Thanks in advance.

Alternatives to fmincon in python for constrained non-linear optimisation problems

I am having trouble solving an optimisation problem in python, involving ~20,000 decision variables. The problem is non-linear and I wish to apply both bounds and constraints to the problem. In addition to this, the gradient with respect to each of the decision variables may be calculated.
The bounds are simply that each decision variable must lie in the interval [0, 1] and there is a monotonic constraint placed upon the variables, i.e each decision variable must be greater than the previous one.
I initially intended to use the L-BFGS-B method provided by the scipy.optimize package however I found out that, while it supports bounds, it does not support constraints.
I then tried using the SQLSP method which does support both constraints and bounds. However, because it requires more memory than L-BFGS-B and I have a large number of decision variables, I ran into memory errors fairly quickly.
The paper which this problem comes from used the fmincon solver in Matlab to optimise the function, which, to my knowledge, supports the application of both bounds and constraints in addition to being more memory efficient than the SQLSP method provided by scipy. I do not have access to Matlab however.
Does anyone know of an alternative I could use to solve this problem?
Any help would be much appreciated.

PDE solver that handles constraints

I am trying to solve a system of partial differential equations of the general form
F(f(x,y), f'(x,y), f''(x,y), g(x,y), g'(x,y), g''(x,y)) = 0
where the derivatives may be taken with respect to both x and y and f(x,y) and g(x,y) are subject to some constraint
G(f(x,y),g(x,y)) = 0
I wonder if there exists any (preferably Python based) solver (not a method, as I know the methods) that can deal with a problem of this kind? Would appreciate any help and apologise if my question seems to general.
Such a problem will require initial conditions and boundary conditions to be satisfied to obtain an unique solution. Also you will need to provide a domain (geometry) to the solver. I think you must look at finite element solvers in python.
Just a quick Google search provided few finite element solvers in python, however I have not tested any. So I guess that would be a good starting point.
If you are looking for a finite element solver, Fenics has python bindings.

parameter within an interval while optimizing

Usually I use Mathematica, but now trying to shift to python, so this question might be a trivial one, so I am sorry about that.
Anyways, is there any built-in function in python which is similar to the function named Interval[{min,max}] in Mathematica ? link is : http://reference.wolfram.com/language/ref/Interval.html
What I am trying to do is, I have a function and I am trying to minimize it, but it is a constrained minimization, by that I mean, the parameters of the function are only allowed within some particular interval.
For a very simple example, lets say f(x) is a function with parameter x and I am looking for the value of x which minimizes the function but x is constrained within an interval (min,max) . [ Obviously the actual problem is just not one-dimensional rather multi-dimensional optimization, so different paramters may have different intervals. ]
Since it is an optimization problem, so ofcourse I do not want to pick the paramter randomly from an interval.
Any help will be highly appreciated , thanks!
If it's a highly non-linear problem, you'll need to use an algorithm such as the Generalized Reduced Gradient (GRG) Method.
The idea of the generalized reduced gradient algorithm (GRG) is to solve a sequence of subproblems, each of which uses a linear approximation of the constraints. (Ref)
You'll need to ensure that certain conditions known as the KKT conditions are met, etc. but for most continuous problems with reasonable constraints, you'll be able to apply this algorithm.
This is a good reference for such problems with a few examples provided. Ref. pg. 104.
Regarding implementation:
While I am not familiar with Python, I have built solver libraries in C++ using templates as well as using function pointers so you can pass on functions (for the objective as well as constraints) as arguments to the solver and you'll get your result - hopefully in polynomial time for convex problems or in cases where the initial values are reasonable.
If an ability to do that exists in Python, it shouldn't be difficult to build a generalized GRG solver.
The Python Solution:
Edit: Here is the python solution to your problem: Python constrained non-linear optimization

python solving differential equation with complex variables

folks,
Is it possible to solve ODE with complex variable in python? The equation I have has the following form
dx/dt = -a x -i y(t)
where y(t) is a known function, a is a known number and i is the root of -1.
I tried to use odeint() but it gives many error messages.
I am guessing odeint() does not work with complex variables. So one way out would be to separate the real and imaginary parts of x and treat the original ODE as two coupled ODEs.
But I am also wondering if there are some more convenient way for this task? Solving ODE/PDE with complex variables is a general problem and it will be quite a hassle to make this complex -> real conversion by hand all the time.
Thanks very much.
I'd suggest using scipy.integrate.complex_ode instead of scipy.integrate.odeint which performs the conversion automatically.

Categories

Resources