mathematical-optimization

scipy.optimize.minimize keep track of objective function

送分小仙女□ 提交于 2019-12-08 05:26:41
问题 I'm working with scipy.optimize.minimize , and I'm optimizing 3 parameters with a function like this def foo(A, x, y, z): test = my_function(A[0], A[1], A[2], x, y, z) return test In this answer I found some insight: How to display progress of scipy.optimize function? So I came up with this function: def callbackF(Xi, x, y, z) global Nfeval print '{0:4d} {1: 3.6f} {2: 3.6f} {3: 3.6f} {4: 3.6f}'.format(Nfeval, Xi[0], Xi[1], Xi[2], foo(Xi, x, y, z)) Nfeval += 1 So my code will look like this

Optimizing working scheduling MiniZinc code - constraint programming

◇◆丶佛笑我妖孽 提交于 2019-12-08 02:53:46
问题 Please can you help optimize this working MiniZinc code: Task: There is a conference which has 6x time slots. There are 3 speakers attending the conference who are each available at certain slots. Each speaker will present for a predetermined number of slots. Objective: Produce the schedule that has the earliest finish of speakers. Example: Speakers A, B & C. Talk durations = [1, 2, 1] Speaker availability: +---+------+------+------+ | | Sp.A | Sp.B | Sp.C | +---+------+------+------+ | 1 | |

Minimizing functions with large gradients using `scipy.optimize.minimize`

余生颓废 提交于 2019-12-08 02:20:13
问题 I need to optimize a scalar function in a high-dimensional space. The function varies quickly with changing arguments such that the (absolute value of) gradients are large. The optimizers in scipy.optimize.minimize fail because the minimization procedure takes steps that are too large. The following code illustrates the problem using a simple quadratic function. from scipy.optimize import minimize def objective(x, scalar=1): """ Quadratic objective function with optional scalar. """ # Report

constrained optimization in R setting up constraints

帅比萌擦擦* 提交于 2019-12-08 01:37:00
问题 I have been trying to solve a constrained optimization problem in R using constrOptim() (my first time) but am struggling to set up the constraints for my problem. The problem is pretty straight forward and i can set up the function ok but am a bit at a loss about passing the constraints in. e.g. problem i've defined is (am going to start with N fixed at 1000 say so i just want to solve for X ultimately i'd like to choose both N and X that max profit): so i can set up the function as: fun <-

R: (How) can the nlm function be used for optimization with multiple variables

萝らか妹 提交于 2019-12-08 00:21:00
问题 Can the nlm function be used for optimization with multiple variables? How would that work? For instance: I want to find x and y so that f(x,y) is minimized. How would the nlm function work? something like that?: nlm(f,c(0.1,0.1)) 回答1: Make a function that receives a vector: f <- function(X) { x <- X[1] y <- X[2] (x-3.14)^2 + (y-6.28)^2 } nlm(f,c(0.1,0.1)) 来源: https://stackoverflow.com/questions/40620277/r-how-can-the-nlm-function-be-used-for-optimization-with-multiple-variables

curve fitting with a known function numpy

≡放荡痞女 提交于 2019-12-07 19:30:24
问题 I have a x and y one-dimension numpy array and I would like to reproduce y with a known function to obtain "beta". Here is the code I am using: import numpy as np import matplotlib.pyplot as plt from scipy.optimize import curve_fit y = array([ 0.04022493, 0.04287536, 0.03983657, 0.0393201 , 0.03810298, 0.0363814 , 0.0331144 , 0.03074823, 0.02795767, 0.02413816, 0.02180802, 0.01861309, 0.01632699, 0.01368056, 0.01124232, 0.01005323, 0.00867196, 0.00940864, 0.00961282, 0.00892419, 0.01048963, 0

Fox-Goat-Cabbage Transportation

纵然是瞬间 提交于 2019-12-07 18:30:03
问题 My question is about an old transportation problem -- carrying three items across a river with a boat only capable of tranferring one item at a time. A constraint is certain items cannot be left together, such as the cabbage with the goat, wolf with the goat etc. This problem should be solveable using Integer programming, or another optimization approach. The cost function is all items being on the other side of the river, and the trips required to get there could be the output from Simplex (

Minimize function in adjacent items of an array

荒凉一梦 提交于 2019-12-07 15:06:53
问题 I have an array ( arr ) of elements, and a function ( f ) that takes 2 elements and returns a number. I need a permutation of the array, such that f(arr[i], arr[i+1]) is as little as possible for each i in arr . (and it should loop, ie. it should also minimize f(arr[arr.length - 1], arr[0]) ) Also, f works sort of like a distance, so f(a,b) == f(b,a) I don't need the optimum solution if it's too inefficient, but one that works reasonable well and is fast since I need to calculate them pretty

scipy.optimize.minimize (COBYLA and SLSQP) ignores constraints initiated within for loop

大城市里の小女人 提交于 2019-12-07 12:46:14
问题 I'm using scipy.optimize.minimize to solve a complex reservoir optimization model (SQSLP and COBYLA as the problem is constrained by both bounds and constraint equations). There is one decision variable per day (storage), and releases from the reservoir are calculated as a function of change in storage, within the objective function. Penalties based on releases and storage penalties are then applied with the goal of minimizing penalties (the objective function is a summation of all penalties)

Rsolnp: In cbind(temp, funv) : number of rows of result is not a multiple of vector length (arg 1)

无人久伴 提交于 2019-12-07 11:12:32
问题 I'm new to stackoverflow and searched a lot, but couldn't find an answer to my question. I'm trying to minimise the problem bellow with the optimisation package Rsolnp. Although the solver gives me a solution, every time I run the code I get the following warning message: Warning messages: 1: In cbind(temp, funv) : number of rows of result is not a multiple of vector length (arg 1) Furthermore, the solution is completely different from the solutions I get with ipop and solve.QP. Their