mathematical-optimization

scipy optimise minimize — parallelisation options

自作多情 提交于 2021-02-19 05:49:05
问题 When running scipy optimize minimum using the L-BFGS-B method, I found that on certain computers, it uses all 8 cpu cores (see photo 1), on others it uses 4 out of 8 cores (see photo 2) and on others it only uses 1 core. I have not used any libraries/code to make it parallel -- it seems to be doing that by default. Is there a way that I can specify how many cores it should use easily? I couldn't find anything online that suggested scipy optimize uses parallelisation by default. fmin = scipy

Optimizing (minimizing) the number of lines in file: an optimization problem in line with permutations and agenda scheduling

旧巷老猫 提交于 2021-02-18 09:55:12
问题 I have a calendar, typically a csv file containing a number of lines. Each line corresponds to an individual and is a sequence of consecutive values '0' and '1' where '0' refers to an empty time slot and '1' to an occupied slot. There cannot be two separated sequences in a line ( e.g. two sequences of '1' separated by a '0' such as '1,1,1,0,1,1,1,1'). The problem is to minimize the number of lines by combining the individuals and resolving the collisions between time slots. Note the time

Logistic regression in Julia using Optim.jl

江枫思渺然 提交于 2021-02-17 22:53:13
问题 I'm trying to implement a simple regularized logistic regression algorithm in Julia. I'd like to use Optim.jl library to minimize my cost function, but I can't get it to work. My cost function and gradient are as follows: function cost(X, y, theta, lambda) m = length(y) h = sigmoid(X * theta) reg = (lambda / (2*m)) * sum(theta[2:end].^2) J = (1/m) * sum( (-y).*log(h) - (1-y).*log(1-h) ) + reg return J end function grad(X, y, theta, lambda, gradient) m = length(y) h = sigmoid(X * theta) #

Basic optimization — pairing widgets and rotors

只愿长相守 提交于 2021-02-16 20:09:06
问题 I know little of optimization problems, so hopefully this will be didactic for me: rotors = [1, 2, 3, 4...] widgets = ['a', 'b', 'c', 'd' ...] assert len(rotors) == len(widgets) part_values = [ (1, 'a', 34), (1, 'b', 26), (1, 'c', 11), (1, 'd', 8), (2, 'a', 5), (2, 'b', 17), .... ] Given a fixed number of widgets and a fixed number of rotors, how can you get a series of widget-rotor pairs that maximizes the total value where each widget and rotor can only be used once? 回答1: What you have is a

How to minimize a real function with only integer input

北战南征 提交于 2021-02-11 15:33:03
问题 Which optimization algorithms work for integer input, float output? One thought is just using Brent search but making up a method that interpolates two nearest points to fake a real number input as opposed to an integer input. My second thought is that seems like such a common need, there must already be something in scipy to do it and/or an algorithm more suited for it? Bisect certainly works for this, but for huge inputs, its convergence time could be improved. Something hybrid like Brent

Function returns a vector, how to minimize in via NumPy

为君一笑 提交于 2021-02-10 14:50:25
问题 I'm trying to minimize function, that returns a vector of values, and here is an error: setting an array element with a sequence Code: P = np.matrix([[0.3, 0.1, 0.2], [0.01, 0.4, 0.2], [0.0001, 0.3, 0.5]]) Ps = np.array([10,14,5]) def objective(x): x = np.array([x]) res = np.square(Ps - np.dot(x, P)) return res def main(): x = np.array([10, 11, 15]) print minimize(objective, x, method='Nelder-Mead') At these values of P, Ps, x function returns [[ 47.45143225 16.81 44.89 ]] Thank you for any

Minimum removed nodes required to cut path from A to B algorithm in Python

北城以北 提交于 2021-02-07 19:54:16
问题 I am trying to solve a problem related to graph theory but can't seem to remember/find/understand the proper/best approach so I figured I'd ask the experts... I have a list of paths from two nodes (1 and 10 in example code). I'm trying to find the minimum number of nodes to remove to cut all paths. I'm also only able to remove certain nodes. I currently have it implemented (below) as a brute force search. This works fine on my test set but is going to be an issue when scaling up to a graphs

Minimum removed nodes required to cut path from A to B algorithm in Python

余生长醉 提交于 2021-02-07 19:54:08
问题 I am trying to solve a problem related to graph theory but can't seem to remember/find/understand the proper/best approach so I figured I'd ask the experts... I have a list of paths from two nodes (1 and 10 in example code). I'm trying to find the minimum number of nodes to remove to cut all paths. I'm also only able to remove certain nodes. I currently have it implemented (below) as a brute force search. This works fine on my test set but is going to be an issue when scaling up to a graphs

Getting standard error associated with parameter estimates from scipy.optimize.curve_fit

ぃ、小莉子 提交于 2021-02-07 03:00:53
问题 I am using scipy.optimize.curve_fit to fit a curve to some data i have. The curves, for the most part, seem to fit very well. For some reason, pcov = inf when i print it off. What i really need is to calculate the error associated with the parameters i'm fitting, and am not sure how exactly to do this even if it does give me the covariance matrix. The model being fit to is: def intensity(x,R_out,R_in,K_in,K_out,a,b,c): K_in,K_out = abs(0.0),abs(K_out) if x<=R_in: return 2*R_out*(K_out*np.sqrt

Getting standard error associated with parameter estimates from scipy.optimize.curve_fit

别来无恙 提交于 2021-02-07 03:00:41
问题 I am using scipy.optimize.curve_fit to fit a curve to some data i have. The curves, for the most part, seem to fit very well. For some reason, pcov = inf when i print it off. What i really need is to calculate the error associated with the parameters i'm fitting, and am not sure how exactly to do this even if it does give me the covariance matrix. The model being fit to is: def intensity(x,R_out,R_in,K_in,K_out,a,b,c): K_in,K_out = abs(0.0),abs(K_out) if x<=R_in: return 2*R_out*(K_out*np.sqrt