optimization

scipy.optimize with non linear constraints

∥☆過路亽.° 提交于 2020-01-24 13:58:48
问题 I have non-linear function with non-linear constraints and I'd like to optimize it. I don't know how to define non-linear constraints using scipy.optimize. My code so far looks like: from math import cos, atan import numpy as np from scipy.optimize import minimize import sympy as sy def f(x): return 0.1*x*y def ineq_constraint(x): x**2 + y**2 - (5+2.2*sy.cos(10*sy.atan(x/y)))**2 return x,y con = {'type': 'ineq', 'fun': ineq_constraint} minimize(f,x0,method='SLSQP',constraints=con) 回答1: The

Jacobian in scipy.optimize.minimize form

杀马特。学长 韩版系。学妹 提交于 2020-01-24 12:04:10
问题 My goal is to optimize least squares ofth degree polynomial functios with some constraints, so my goal is to use scipy.optimize.minimize(...., method = 'SLSQP', ....) . In optimalization, it is always good to pass Jacobian in the method. I am not sure, however, how to desing my 'jac' function. My objective function is desinged like this: def least_squares(args_pol, x, y): a, b, c, d, e = args_pol return ((y-(a*x**4 + b*x**3 + c*x**2 + d*x + e))**2).sum() where x and y are numpy arrays and

Removing slow int64 division from fixed point atan2() approximation

大兔子大兔子 提交于 2020-01-24 10:10:48
问题 I made a function to compute a fixed-point approximation of atan2(y, x). The problem is that of the ~83 cycles it takes to run the whole function, 70 cycles (compiling with gcc 4.9.1 mingw-w64 -O3 on an AMD FX-6100) are taken entirely by a simple 64-bit integer division! And sadly none of the terms of that division are constant. Can I speed up the division itself? Is there any way I can remove it? I think I need this division because since I approximate atan2(y, x) with a 1D lookup table I

How can I add new root element to a C# XmlDocument?

旧城冷巷雨未停 提交于 2020-01-24 04:08:29
问题 I have, outside of my control, an XmlDocument which has a structure like the following: <parent1> ...minor amount of data... </parent1> I have another XmlDocument, also outside of my control, which has the following structure: <parent2> ..very large amount of data... </parent2> I need an XmlDocument in the format: <parent1> ...minor amount of data... <parent2> ..very large amount of data... </parent2> </parent1> I don't want to make a copy of parent2. How can I get the structure I need,

How can I add new root element to a C# XmlDocument?

送分小仙女□ 提交于 2020-01-24 04:08:27
问题 I have, outside of my control, an XmlDocument which has a structure like the following: <parent1> ...minor amount of data... </parent1> I have another XmlDocument, also outside of my control, which has the following structure: <parent2> ..very large amount of data... </parent2> I need an XmlDocument in the format: <parent1> ...minor amount of data... <parent2> ..very large amount of data... </parent2> </parent1> I don't want to make a copy of parent2. How can I get the structure I need,

Using character instead of String for single-character values in StringBuffer append

无人久伴 提交于 2020-01-24 02:18:07
问题 I was going through the PMD rule AppendCharacterWithChar . It says Avoid concatenating characters as strings in StringBuffer.append. StringBuffer sb = new StringBuffer(); // Avoid this sb.append("a"); // use instead something like this StringBuffer sb = new StringBuffer(); sb.append('a'); Do I really need this PMD rule ? Is there much performance difference between the following two piece of code? String text = new StringBuffer().append("some string").append('c').toString(); String text = new

Is there a more efficient search factor than midpoint for binary search?

痞子三分冷 提交于 2020-01-24 00:23:10
问题 The naive binary search is a very efficient algorithm: you take the midpoint of your high and low points in a sorted array and adjust your high or low point accordingly. Then you recalculate your endpoint and iterate until you find your target value (or you don't, of course.) Now, quite clearly, if you don't use the midpoint, you introduce some risk to the system. Let's say you shift your search target away from the midpoint and you create two sides - I'll call them a big side and small side.

CNF simplification

…衆ロ難τιáo~ 提交于 2020-01-23 22:07:45
问题 Given a set of clauses, I want to first check whether they are satisfiable. If they are, I want to simplify them and create a CNF, eg., (a OR b) ^ (NOT b) should simplify to: a ^ (NOT b). I'm only working with propositional formulas. I've tried to use Java SAT4j library for doing this. It can show me whether the set of clauses are satisfiable, but doesn't seem to have any method for returning me a simplified CNF. What can I do for simplifying CNF efficiently? Are there any Java or Python

CNF simplification

三世轮回 提交于 2020-01-23 22:05:13
问题 Given a set of clauses, I want to first check whether they are satisfiable. If they are, I want to simplify them and create a CNF, eg., (a OR b) ^ (NOT b) should simplify to: a ^ (NOT b). I'm only working with propositional formulas. I've tried to use Java SAT4j library for doing this. It can show me whether the set of clauses are satisfiable, but doesn't seem to have any method for returning me a simplified CNF. What can I do for simplifying CNF efficiently? Are there any Java or Python

How to install the optimization pack pyOpt in Python on windows

守給你的承諾、 提交于 2020-01-23 18:23:09
问题 I have Anaconda pack for Python installed on my windows 7 laptop. I followed all the installation steps as explained at: http://www.pyopt.org/install.html#installation After some trial and error, I could install pyOpt using the following command: python setup.py install --compiler=mingw32 But still, I can't run even the simplest tutorial example at .. http://www.pyopt.org/tutorial.html .. maybe because the optimizer SLSQP is missing in the installation. I get following error message when I