mathematical-optimization

How can I get R to use more CPU usage?

僤鯓⒐⒋嵵緔 提交于 2019-12-01 20:52:22
问题 I noticed that R doesn't use all of my CPU, and I want to increase that tremendously (upwards to 100%). I don't want it to just parallelize a few functions; I want R to use more of my CPU resources. I am trying to run a pure IP set packing program using the lp() function. Currently, I run windows and I have 4 cores on my computer. I have tried to experiment with snow, doParallel, and foreach (though I do not know what I am doing with them really). In my code I have this... library(foreach)

How can I get R to use more CPU usage?

╄→гoц情女王★ 提交于 2019-12-01 18:36:01
I noticed that R doesn't use all of my CPU, and I want to increase that tremendously (upwards to 100%). I don't want it to just parallelize a few functions; I want R to use more of my CPU resources. I am trying to run a pure IP set packing program using the lp() function. Currently, I run windows and I have 4 cores on my computer. I have tried to experiment with snow, doParallel, and foreach (though I do not know what I am doing with them really). In my code I have this... library(foreach) library(doParallel) library(snowfall) cl <- makeCluster(4) registerDoParallel(cl) sfInit(parallel = TRUE,

Speeding up Math calculations in Java

断了今生、忘了曾经 提交于 2019-12-01 15:27:44
I have a neural network written in Java which uses a sigmoid transfer function defined as follows: private static double sigmoid(double x) { return 1 / (1 + Math.exp(-x)); } and this is called many times during training and computation using the network. Is there any way of speeding this up? It's not that it's slow, it's just that it is used a lot, so a small optimisation here would be a big overall gain. tangens For neural networks, you don't need the exact value of the sigmoid function. So you can precalculate 100 values and reuse the value that is closest to your input, or even better (as a

Minimise objective function using R

百般思念 提交于 2019-12-01 11:52:12
问题 Can somebody help me in solving this to multivariate function parameters optimization in R, I have a data set like this. This is just a subset of data, dimension of the full dataset is n type * m regions * 12 months . Month region type physics maths allsub Jan r1 1 4 5 9 Feb r1 1 3 8 11 Mar r1 1 5 4 9 Apr r1 1 6 7 13 May r1 1 4 4 8 Jun r1 1 8 9 17 Jul r1 1 4 3 7 Aug r1 1 5 4 9 Sep r1 1 3 8 11 Oct r1 1 9 2 11 Nov r1 1 4 7 11 Dec r1 1 7 3 10 Jan r1 2 5 8 13 Feb r1 2 4 9 13 Mar r1 2 8 3 11 Apr

how to apply gradients manually in pytorch

 ̄綄美尐妖づ 提交于 2019-12-01 07:13:50
问题 Starting to learn pytorch and was trying to do something very simple, trying to move a randomly initialized vector of size 5 to a target vector of value [1,2,3,4,5]. But my distance is not decreasing!! And my vector x just goes crazy. No idea what I am missing. import torch import numpy as np from torch.autograd import Variable # regress a vector to the goal vector [1,2,3,4,5] dtype = torch.cuda.FloatTensor # Uncomment this to run on GPU x = Variable(torch.rand(5).type(dtype), requires_grad

How to find the best straight line separating two regions having points with 2 different properties

久未见 提交于 2019-12-01 06:51:49
问题 I have a bunch of points in a 2D plot. The red points indicate when my experiment is stable, the black when it is unstable. The two region are clearly separated by a line in this log-log plot, and I would like to find the best "separating line", i.e. the line that gives the criterion to separate the 2 regions and has the minimum error on this criterion. I did a search on various books and online but I could not find any approach to solve this problem. Are you aware of any tool? First of all

gurobi - Error code = 10004 Unable to retrieve attribute 'X'

不想你离开。 提交于 2019-12-01 06:04:22
I am getting an error in my c++/gurobi file: Error code = 10004 Unable to retrieve attribute 'X' I read that this might have something to do with labels? But I don't see how there is a problem. It works for some input files, but not for others. So I have created a toy file, t5.txt in attachment. This file does not work, but removing the last column and setting 8 to 7 fixes it. I am puzzled... Below is the output of model.write. Everything seems to make sense, any Ideas what I am doing wrong? Whenever I do a model.write(test.sol), the program stops, so there seems to be something wrong with the

MATLABs 'fminsearch' different from Octave's 'fmincg'

 ̄綄美尐妖づ 提交于 2019-12-01 04:14:20
问题 I am trying to get consistent answers for a simple optimization problem, between two functions in MATLAB and Octave. Here is my code: options = optimset('MaxIter', 500 , 'Display', 'iter', 'MaxFunEvals', 1000); objFunc = @(t) lrCostFunction(t,X,y); [result1] = fminsearch(objFunc, theta, options); [result2]= fmincg (objFunc, theta, options); (Bear in mind, that X, y, and theta are defined earlier and are correct). The problem is the following: When I run the above code in MATLAB with it using

How to do nonlinear complex root finding in Python

為{幸葍}努か 提交于 2019-12-01 04:04:56
I want to do a root search for the following nonlinear equations, I do it in Python but it doesn't work. my code is below from pylab import * import scipy import scipy.optimize def z1(x,y): temp=1+1j+x+2*y; return temp def z2(x,y): temp=-1j-2*x+sqrt(3)*y; return temp def func(x): temp=[z1(x[0],x[1])-1.0/(1-1.0/(z2(x[0],x[1]))),1-2.0/(z2(x[0],x[1])-4.0/z1(x[0],x[1]))] return temp result=scipy.optimize.fsolve(func,[1+1j,1+1j]) print result when I run it, it shows errors: ---> 30 result=scipy.optimize.fsolve(func,[1+1j,1+1j]) C:\Python27\lib\site-packages\scipy\optimize\minpack.py in fsolve(func,

Solving system of nonlinear equations with python

天涯浪子 提交于 2019-12-01 03:39:01
Can I solve a system of nonlinear equations in terms of parameters in python? Is there a example or tutorial? I can do this easily in maple, but the expressions for my particular system are pretty big and copying them over is quite hard. Example: sigma*(y-x) = 0 x*(rho-z)-y = 0 x*y-beta*z = 0 You should get the solutions: [[x = 0, y = 0, z = 0], [x = sqrt(beta*rho-beta), y = sqrt(beta*rho-beta), z = rho-1], [x = -sqrt(beta*rho-beta), y = -sqrt(beta*rho-beta), z = rho-1]] The reason I ask: I have a large system of nonlinear ODEs. I want to solve for the fixed points (this is doable, it's been