mathematical-optimization

Recalculate an average value

若如初见. 提交于 2019-12-25 14:17:27
问题 In my Java application I need to recalculate an average value based on the following data: I know current avg value - avgValue I know that avgValue is an average value for list of 12 values - count . Based on this information how to recalculate avgValue when a new value is added to this list of previous 12 values. What is the new avgValue for list of 13 values - count + 1 ? 回答1: Current Sum = avgValue * 12 New sum = current Sum + New value New average = New sum / 13 回答2: If you want to make

Recalculate an average value

萝らか妹 提交于 2019-12-25 14:17:11
问题 In my Java application I need to recalculate an average value based on the following data: I know current avg value - avgValue I know that avgValue is an average value for list of 12 values - count . Based on this information how to recalculate avgValue when a new value is added to this list of previous 12 values. What is the new avgValue for list of 13 values - count + 1 ? 回答1: Current Sum = avgValue * 12 New sum = current Sum + New value New average = New sum / 13 回答2: If you want to make

R portfolio analytics chart.EfficientFrontier function

我只是一个虾纸丫 提交于 2019-12-25 07:49:30
问题 I am trying to use the chart.EfficientFrontier function in the portfolioanalytics package in R to chart an efficient frontier object that I have created but it keeps failing. Basically I am trying to find a frontier that will minimize annaulized standard deviation. Eventually once I get this working I would also like to maximize annualized return. Firstly I created an annualized standard deviation function using this code pasd <- function(R, weights){ as.numeric(StdDev(R=R, weights=weights)

Can the genetic-algorithm in Matlab pass a second return value from the fitness-function to the constraints?

不问归期 提交于 2019-12-25 04:29:11
问题 I am simulating a batch evaporator in Matlab. The genetic algorithm varies several starting variables x (such as size, max. mass of working fluid, the overall number of evaporators used ...) and the goal is to maximize the efficiency. So my function evaporator(x) returns the negative efficiency which is minimized by the algorithm. Besides the efficiency, there are several other values calculated. One is the duration of the simulated cycle (NOT the runtime of the calculation itself!). As a

Java library for multidimensionial continuous optimization

一世执手 提交于 2019-12-25 03:58:38
问题 I need Java library that performs gradient descent (preferred) or other multidimensional continuous optimization methods. Specifically, I need it to find logit regression coefficients. Does anyone knows such a lib? 回答1: I suggest you try Weka - it's a package for Data Mining and Machine Learning. For example, logistic regression is in this class. 来源: https://stackoverflow.com/questions/8296197/java-library-for-multidimensionial-continuous-optimization

Mathematica Not Saving Variable

被刻印的时光 ゝ 提交于 2019-12-25 03:48:51
问题 I try to perform this nested loop but it is not working. It's not saving the result in each stage. But if I replace listInitial with Print[ ] I observer that all changes are made. Any suggestions?? For[b = 1, b < 4, b = b + 1, For[a = 1, a < 4, a = a + 1, For[x = 1, x < 4, x = x + 1, For[z = 1, z < 4, z = z + 1, listInitial = If[Random[] > psurvival, ReplacePart[ InitialMatrix[3, 3, 3, 3], {b, a, x, z} -> InitialMatrix[3, 3, 3, 3][[b]][[a]][[x]][[z]] - 1], InitialMatrix[3, 3, 3, 3], {b, a, x,

Calculate the number of hours in a given timeframe between two datetimes

匆匆过客 提交于 2019-12-25 02:20:00
问题 I have a booking system where users can book a room at any time, and for any number of continuous days. The booking is charged depending on the number of minutes the room is in use. In the booking system, the start and end time is represented by two timestamps. e.g. start_time = 1397124000 end_time = 1397129400 From this I can calculate the number of seconds booked, and therefore calculate a charge. The problem I have is that I'd like to calculate a 50% discount on any bookings made out of

How to apply conditional constraints to Python Pulp function

冷暖自知 提交于 2019-12-24 23:37:13
问题 I'm setting up a linear optimization using Pulp in Python. I would like to set up a conditional constrain to the problem. Like, I want to Maximize the profit of a factory. For the cost of the material, the first 1000 units cost $5 each, any more unit cost $3. For example, if the factory order 1100 units, total cost will be 1000*5+100*3. I have a list of material: material_list , a dictionary of benchmark for the materials: benchmark_dic={material_a: 1000, material_b:2000 ....} , a dictionary

How to get “first-order optimality” with python script

社会主义新天地 提交于 2019-12-24 18:56:36
问题 I curious about how to get "first-order optimality" value using python script. For optimatization python has many module like scipy.optimize and openopt. But I confused how to use that module to get first-order optimality This is sample matlab script to get first-order optimality [x,resnorm,residual,exitflag,output,lambda]= lsqcurvefit(func,x0,xdata,tdata); foo = output.firstorderopt %get first-order optimality value this is some of foo reference from mathworks here Thanks for your attention,

scipy.optimize.fmin_cg: "'Desired error not necessarily achieved due to precision loss.'

醉酒当歌 提交于 2019-12-24 14:28:32
问题 I am using scipy.optimize.fmin_cg to minimize a function. The function takes various data sets and the fmin_cg returns good values for a lot of the data sets, except for the first 3 which fail: DATASET: 0 Warning: Desired error not necessarily achieved due to precision loss. Current function value: 2.988730 Iterations: 1 Function evaluations: 32 Gradient evaluations: 5 [ 500.00011672 -0.63965932] DATASET: 1 Warning: Desired error not necessarily achieved due to precision loss. Current