mathematical-optimization

Calculating primes using only odd divisors is slower

南楼画角 提交于 2019-12-11 15:28:35
问题 I've written a small C program to calculate primes and now try to optimize the code as far as I can. In the first revision of the program I was checking if a number was even (modulo 2) and if it was I would continue to the next number. In my second revision I tried only checking odd numbers to be possible primes by incrementing the number I would be checking by 2 (so I would start from 3, then check 5, then 7, then 9, then 11 etc etc). I thought this would be way faster as I had cut an extra

scipy.optimize.fmin_bfgs optimization gives different result from simple function call

拈花ヽ惹草 提交于 2019-12-11 15:13:42
问题 I am exploring some of the numpy/scipy functions and I noticed that scipy.optimize.fmin_bfgs requires a change in the function being called to give correct results compared to a straight function call. My first definition of the fnRSS function returns a correct value when calling the function but refuses to work in the optimization; my second definition gives the wrong result when calling the function but the right one when running the optimization. Can someone tell me what is so crucial

R: Isotonic regression Minimisation

时光总嘲笑我的痴心妄想 提交于 2019-12-11 12:05:51
问题 I want minimize the following equation: F=SUM{u 1:20}sum{w 1:10} Quw(ruw-yuw) with the following constraints: yuw >= yu,w+1 yuw >= yu-1,w y20,0 >= 100 y0,10 >= 0 I have a 20*10 ruw and 20*10 quw matrix, I now need to generate a yuw matrix which adheres to the constraints. I am coding in R and am familiar with the lpsolve and optimx packages, but don't know how to use them for this particular question. 回答1: Because Quw and ruw are both data, all constraints as well as the objective are linear

Ant colony optimization - movement of ants

谁都会走 提交于 2019-12-11 10:56:42
问题 This question was migrated from Software Engineering Stack Exchange because it can be answered on Stack Overflow. Migrated 5 years ago . I am trying to implement ant colony optimization. Tried to refer this paper: Improved ant colony optimization for robot navigation paper. Since I didn't got any answers to those questions I am stuck at half part in my implementation. So am asking specific questions related to ant colony now: What I have done so far is, have setup a 2d array map, with 0 value

AMPL: does the results after using the option “timelimit” for cplex meet all the constraints?

99封情书 提交于 2019-12-11 09:27:20
问题 I have a dummy question that I need to know its answer. I'm working on a project that requires AMPL and CPLEX as a solver. Now this problem normally takes more than 140 seconds to be solved. While I was searching, I came into an option called timelimit . I used this option with value option cplex_options 'timelimit=5' and the results were shown within 5 seconds. Now my questions is, does the output meet all the constraints and is within the boundaries I set in the code? Or did I just

scipy.optimize.minimize(method=‘SLSQP’) memory issues when outside the bounds

泪湿孤枕 提交于 2019-12-11 08:25:47
问题 I am working with scipy.optimize.minimize(method=‘SLSQP’) , the function and constraints are interpolated with scipy.interpolate.LinearNDInterpolator . The start values are random numbers inside the bounds. I am working with: scipy 0.13.3 cython 0.20.1 The optimizations sometimes runs and gives a reasonable results but sometimes the optimizer begins to request huge amounts of memory up to 20GB then my computer stops working. This always occurs with values outside the boundary. Is it possible

How to write several constraint in cvxpy?

这一生的挚爱 提交于 2019-12-11 06:55:54
问题 I want to add many constraint in a optimization problem under cvxpy. In matlab I can do so by adding a line subject to and then use for loop to generate the constraints. How can I do the same work in cvxpy, as there is no 'subject to' concepts in cvxpy. any suggestion please? 回答1: In Python constraints is a list. You can use for loop to append/extend it like this (and CVXPY functions make it easier). import cvxpy as cvx samples = 10 x = cvx.Variable(samples) y = range(1, samples+1)

Optimization with linear constraints in python

社会主义新天地 提交于 2019-12-11 05:39:52
问题 I need to optimize an objective function F(x1,x2,..xn) subjected to constraints of the type xi=xj. Is there any in-built function in scipy/scikit-learn to implement this? Using SLSQP in scipy.optimize.minimize gives an error saying 'singular matrix C in lsq subproblem' 来源: https://stackoverflow.com/questions/37677673/optimization-with-linear-constraints-in-python

Optimizing the value N to split arrays up for vectorizing an array so it runs the quickest

巧了我就是萌 提交于 2019-12-11 05:07:01
问题 I'm trying to optimizing the value N to split arrays up for vectorizing an array so it runs the quickest on different machines. I have some test code below #example use random values clear all, t=rand(1,556790); inner_freq=rand(8193,6); N=100; # use N chunks nn = int32(linspace(1, length(t)+1, N+1)) aa_sig_combined=zeros(size(t)); total_time_so_far=0; for ii=1:N tic; ind = nn(ii):nn(ii+1)-1; aa_sig_combined(ind) = sum(diag(inner_freq(1:end-1,2)) * cos(2 .* pi .* inner_freq(1:end-1,1) * t(ind)

Artifcial Neural Networks for prediction

淺唱寂寞╮ 提交于 2019-12-11 04:39:19
问题 I have been looking at reasearch papers that attempt to predict stock price. I have noticed in these papers that the activation function is applied to the output using one of the following types of activation function. Unipolar sigmoid, Bipolar sigmoid, Tan hyperbolic, Radial basis function. My question If one of the above types of activation function is applied to the output then how can it be used to predict stock price i.e. a value like $103.56? Because most of these functions have min or