Python scipy provides a good number of optimizers/solvers. You can use these optimizers to solve various non-linear and linear equations. However, sometimes things might get tricky and you will not be able to calculate and provide jacobian to these solvers. Well, this at-least happened with us.
So, we developed our own optimizer to suit our problem and got the perfect result. In this "how to" I will provide a simple way to design and develop your own solver to minimize the polynomial equations of type xˆ2 + yˆ2
Idea is pretty simple, we need to vary x and y in small steps and then store the result of equation for each value of x and y. We will need to run our optimizer twice to find the perfect values of x and y. So, if total number of variables are n then we will need to run optimizer n times. Once for each variable.
Below steps will further help you understand this.
def calcPoly(this, X, diff, deg=2):
min_idx = diff.index(min(diff))-5
if min_idx<0: min_idx = 0
max_idx = min_idx + 10
x, y = X[min_idx:max_idx], diff[min_idx:max_idx]
co = np.polyfit(x, y, deg)
x = abs(co[1]/(2*co[0]))
return x
Similar to first optimization we need to run our two loops again. But, this time, we will not vary X. We know the value of X from our previous optimization.
You can now run your objective function again to check if calculated x and y values are really giving you an optimized result. If your equations are of type xˆ3 + yˆ3, you can still use the same code. Just pass deg=3 to calcPoly method.
I hope this will help.
Python is an interpreted, object-oriented, high-level programming language with dynamic semantics.
Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance.
Python supports modules and packages, which encourages program modularity and code reuse.
Python is an interpreted, object-oriented and extensible programming language. Python can run on many different operating systems.
A freelancer well versed in Python can handle your workload quite easily. To hire freelance programming help for Python post a job today!
A freelancer or freelance worker, is a term commonly used for a person who is self-employed and is not necessarily committed to a particular employer long-term.
If there is a long lead time for them to get up and running, using that investment on a full-time employee might be a better option. And if the position requires oversight, hire an employee.
A freelancer might choose to perform the work outside of normal business hours, when you're not able to monitor their progress.