# Questions tagged [optimization]

19565 questions

1

votes

0

answer

54

Views

### How to find extremums of function in R and determine their type?

Consider some function like f(x,y) = x^2+y^2 .
Question: Is there some simple way to find its extremums and determine their type (e.g. max/min...) ?
I see the long way:
Take partial derivates and using nleqslv R-package find the solutions to the equations f_x=0, f_y = 0.
Then calculate Hessian a...

1

votes

1

answer

217

Views

### Optimise a function with two parameters and constraints in R using solnp function?

I have the following function and would like to optimise parameters x and y in order to maximise the output. I am trying to do that using optimise.
EDIT
Thanks to the comments here I am able to optimise using Rsolnp::solnp.
But now I get error when I add upper and lower bounds.
See example below
Oje...

1

votes

0

answer

56

Views

### Find sub sequence with max sum in an array such that sum of any interval is greater than the sum of end elements in linear time

Given an array of n strictly positive elements, it is expected to find a sub sequence [a b c ...](where a, b and c are indexes) of the array such that sum of elements in the range [a+1 b-1] is greater than array[a]+array[b]. In case of the first index selected, array[a] must be greater than sum of a...

1

votes

1

answer

131

Views

### STM32 VCP driver - pointer becomes invalid only with optimization

I am working on an embedded project with the STM32F405 microcontroller, and have some really confusing behavior. I am porting an existing (working) project from the STM32F1 to the STM32F4, but I have added ST's standard peripheral library USB stack for VCP.
If I compile the program with -O0 optimiz...

1

votes

1

answer

50

Views

### Maximum sum of straight line lengths in a convex polygon with constraints

This is a follow up to a question I asked previously. But here is the full question:
Consider two convex polygons A and B. Polygon B lies completely inside polygon A. There are two lines with different slopes (both fixed slopes), such that they have one common end point on or inside B and their othe...

1

votes

0

answer

170

Views

### Setting up a linear optimizer with an “or” constraint

I have a big linear optimizer I'm running and need some help setting up the constraints to get what I want. It's hard for me to express it in words exactly (hence the vague post-title), so I've written an example, details:
Select a total of 5 items, maximizing value and keeping the cost under 5k.
Ea...

1

votes

0

answer

31

Views

1

votes

0

answer

851

Views

### scipy.optimize with SLSQP. 'Singular matrix C in LSQ subproblem'

I'm trying to minimize a dot product of 2 vectors but it doesn't work and I have no idea why. Can someone please help me?
I have a matrix c of this form:
c = [[c11, c12, c13, c14, c15],
[c21, c22, c23, c24, c25]]
I want to get a matrix p of this form:
p = [[p11, p12, p13, p14, p15],
[p21, p22, p2...

1

votes

0

answer

94

Views

### Matlab fmincon increasing function value

I'm using Matlab's fmincon function for optimization, but experience the function value increases instead of decreases, even though all of my constraint functions at all iterates are satisfied.
My optimization problem consist of a (smooth and continuous) cost function with two design variables to b...

1

votes

0

answer

54

Views

### How to add minimum up time constraint for a home load into a Mixed Integer Linear Programming in matlab?

I have written the code for the operation of the appliances for a minimum up time in a MILP problem in MATLAB.
The code I have written is based on the lines of the 'optimal operation of thermal plants' tutorial video for MILP problem.Following is the link to it -
https://in.mathworks.com/videos/mixe...

1

votes

0

answer

364

Views

### High consumer lag on Kafka Stream app that uses persistent key value store

I am not getting as much throughput as I would think I should with my this Streams app that uses a state store and my consumer lag is going way up. I'm wondering if there are any obvious configs that I could tweak or anything that could help optimize my throughput.
In my main I have this for proper...

1

votes

1

answer

273

Views

### scipy.optimize.minimize, travelling salesman with integer programming

import numpy as np;
import math;
import random;
from scipy.optimize import minimize;
def matrixmult (A, B):
rows_A = len(A)
cols_A = len(A[0])
rows_B = len(B)
cols_B = len(B[0])
Z = [[0 for row in range(rows_B)] for col in range(cols_A)]
for i in range(cols_A):
for j in range(rows_A):
#for k in rang...

1

votes

1

answer

191

Views

### Faster way to calculate modulo when you have a previous answer?

I have a large number of modulo calculations to perform. The basic calculation is as follows:
const uint64_t start; // Some 'large' number that does NOT change
uint32_t prime[bigNumber]; // Precalculated sequential prime numbers (generated on the fly from a bit compaction storage method for...

1

votes

0

answer

232

Views

### How to create custom graphs for dask dataframes?

I'm trying to paralelize some operations to be done on a Dask Dataframe but I'm not completely understanding the best way to do it.
For example, I'm reading a dask dataframe from parquet and I want to add one unit to the first column by one and two to the second column:
import dask.dataframe as dd
d...

1

votes

0

answer

73

Views

### Integration and false convergence of optimization in R

I am trying to find MLEs of three positive parameters a, mu and theta, and then the value of a function, saying f1.
f1

1

votes

0

answer

137

Views

### Subroutine reordering, reducing TLB misses

Let's say I have an algorithm which would optimize subroutine ordering, in hopes to reduce TLB misses.
How would one be able actually to reorder subroutines at run-time in gcc compiler? So far I presume that it would be possible to write a gcc plugin for this. How ever I have no idea how to actually...

1

votes

1

answer

57

Views

### Generating function derivative as Python callable function

I was reading this question and I was trying to do the same, but I want the function to have a single parameter say x. And that parameter is an array of 'values' to be filled by an optimization solver. For instance:
def f(x):
return x[0]**2 + 3*x[1]
That function will refer to: f(x)=x^2 + 3y, meanin...

1

votes

0

answer

231

Views

### Slow serialization in django rest framework

I'm trying to figure out why django rest framework's ModelSerializer is so slow. I'm aware of the problem with N+1 queries, it's not the case. I have a super simple model that has only numbers and strings. Profiling shows that my code spends most of the time inside Serializer::to_representation() me...

1

votes

0

answer

46

Views

### Error in maxLik function

I am trying to compare two distributions by using Likelihood ratio test. I used the maxLik function to obtain mles of both of null and alternative distributions. I want to use BFGSR method because it gives better estimates.
library('maxLik')
library('flexsurv')
n=20
den1=1000
mpar=3
omepar=5
spar=3...

1

votes

0

answer

335

Views

### Response Surface Modeling and Optimization in Python: Analogous to rsm in R?

I wonder, if there are modules in Python that support Design of Experiments, Response Surface Modeling and Optimization. R has a number of libraries, such as rsm which helps you define a Design and then evolve it given outcomes to approach closer the optimum using the Response Surface Modeling appr...

1

votes

2

answer

95

Views

### Rectangle Intersection. print message for empty intersection

I have four coordinates: x,y,width=w,height=h and I have two rectangles with the following coordinates:
r1.x=2,r1.y=3,r1.w=5,r1.h=6;
r2.x=0, r2.y=7,r2.w=-4,r4.h=2
How you can observe this intersection is empty.
what I did until now it was:
rectangle intersection (rectangle r1, rectangle r2){
r1.x=...

1

votes

0

answer

35

Views

### PostgreSQL slow running query

The following SQL query used to execute in a few seconds, but it suddenly started to take a long time to execute. I've already done a few improvements on the older query, but I still think it can be sped up:
SELECT COUNT(*) AS count_all, flows.user_id AS flows_user_id, events.metadata->? AS events_m...

1

votes

1

answer

356

Views

### Non-Linear/Linear Programming in python

I have optimization that goes like this :
Maximize (x1*a1 + x2*a2+...+xn * an)
such that :
any j, (xj*aj)/sum(all xi*ai) = 0.15
any three j, (xj*aj)/sum(all xi*ai) >= 0.07
any j 1

1

votes

0

answer

91

Views

### Fog of War on android devices in Unity

I've wrote the code according to this tutorial.
It is the code:
public GameObject fogOfWarPlane;
public LayerMask fogLayer;
public float radius = 5f;
private float radiusSqr { get { return radius * radius; } }
private Transform target;
private Mesh mesh;
private Vector3[] vertices;
private Color[] c...

1

votes

0

answer

48

Views

### Optimise R loop with data table passed into a recursive function

I'm trying to run a simulation which would run n_tests for n_products for n_years to estimate an increase in demand and subsequent increase in stored pallets (linear relation between demand and stored products assumed). To make things a bit spicier, the demand comes from 2 separate regions (A and B)...

1

votes

0

answer

43

Views

### SQL - How to equally assigned records to Skil matrix table using stored procedure

I want to use a stored procedure for assigning records to each person.
These are my tables:
tblTransaction:
ID Owner Country Region Vendor Description
----------------------------------------------------------------
1 NULL Country1 Region1 Vendor2
4 NULL Country1 R...

1

votes

0

answer

39

Views

### Python Tkinter mainloop increases processing time in multithread application

In my application, I have a process which runs on another thread, takes a few seconds to complete and only needs to be done once. I also have a loading window which would let users know that the application is still running and let them cancel the process. This loading window calls a function every...

1

votes

0

answer

162

Views

### Multiple visits of cities in TSP

Which subtour-elimination-constraint in TSP (travelling salesman problem) will allow multiple visits of each city on the route?
In my version of TSP, each city (except the departing warehouse) is allowed to be visited multiple times but the subtour elimination constraint does not allow it. When I re...

1

votes

0

answer

93

Views

### PROLOG code to find cheapest combination of all possible combinations

Complete newbie in PROLOG here. I am provided with a list of parts to implement a hypothetical computational system:
%partName(name, type, number, required_types, size, price)
part(a-1, a, 1, 2*b, 0.5, 60 )
part(a-2, a, 2, 3*b, 1.0, 25 )
part(b-1, b, 1, 2*c, 0.5, 25 )
part(b-2, b, 2, -, 1, 45 )
part...

1

votes

0

answer

44

Views

### Adding further properties to a function: timing and iteration improvement

I have a function written in python which does two procedures:
Preprocessing: read in data from an array and compute some values that I will later need to prevent repeated computation
Iterate and compute a 'summary' of the data at every stage and use this to solve an optimisation problem.
The code i...

1

votes

1

answer

308

Views

### Using a vector of constraints to a scipy.optimize function

I want to do constrained optimisation using a vector of constraints using the scipy.optimize library. In particular, I am supplying a vector of 3d coordinates r0 of N points -- hence a matrix of size N x 3 -- as input to the function. The coordinates are Cartesian, and I wish to freeze out all y dep...

1

votes

0

answer

323

Views

### How to optimize Firestore read/write operation

I try to make Stock monitoring app where users can make Alert when price change.
I have Stock document where I fetch from 3rd party API periodically.
Upon Stock update I fetch all Alert which meet condition and notify users with Firebase messaging.
Here is my models.
/stocks/{stockId}
id: String
pri...

1

votes

0

answer

95

Views

### Understanding Time and Space Complexity of Networkx function in python with relation to system configuration

I am trying to find all the cycles in my data using networkx.simple_cycles() function in python. As written in networkx documentation 'This is a non-recursive, iterator/generator version of Johnson’s algorithm'. Johnson's algorithm has a time complexity of: ((nodes+edges)*(cycles+1)) and space com...

1

votes

1

answer

61

Views

### This is the query I am trying to run in neo4j but it takes too long to run:

I am trying to run this query using Neo4j but it takes too long (more than 30 min, for almost 2500 nodes and 1.8 million relationships) to run:
Match (a:Art)-[r1]->(b:Art)
with collect({start:a.url,end:b.url,score:r1.ed_sc}) as row1
MATCH (a:Art)-[r1]->(b:Art)-[r2]->(c:Art)
Where a.urlc.url
with r...

1

votes

0

answer

34

Views

### optimization algorithm for grouping sets of numbers

There is N subsets of natural numbers between 1 and K (sample set: {2,9,32}). Number of items/numbers in each set varies, but it cannot exceed K. 50% of subsets are 1- or 2-element sets. The distribution can be visualised as
number of elem.|frequency
1 #########################
2 ##############
3 #...

1

votes

2

answer

30

Views

### which one is more important : optimize database size or make less process

in my laravel project i have many users who have ads and each ad have some keywords : users->ads->keywords (with 3 tables in database)
state 1 : make this with just 2 relation between users/ads and ads/keywords
in this case when i want to access all keywords of a user i should first get that user ad...

1

votes

0

answer

39

Views

### After INSERT/UPDATE Trigger affecting inserted rows

Background:
I've a table in a MS SQL database which lists a company and associated supplier and their effective from and to dates. There should only ever be one supplier active per company at one time.
The table structure is as follows;
_sRID DataAreaID Supplier ApplicableFrom Applic...

1

votes

0

answer

25

Views

### What parts of the computation graph does Tensorflow optimize?

I have the following situation: I have a model X that is shared between three more models A, B, C and training samples belong to one of the models A, B, C.
Depending on the model a training sample belongs to, I multiply the individual loss either with 0 (doesn't belong to it) or 1 (belongs to it) an...

1

votes

0

answer

102

Views

### Creating interaction dummy variables for lpSolve constraint

I have a linear programming model I'm trying to optimize, and need some help setting up the constraints to get what I want. High-level: I want to choose items only if their 'type' doesn't 'conflict' with another item's specific 'type'. Explaining in more depth via example:
Select a total of 6 items,...

1

votes

0

answer

87

Views

### How to optimize a lsqnonlin function, which I have already tried to optimize adding different options but still gives the same result?

I have a set of parameters that I want to have them returned as result of the non-linear optimization through, the function lsqnonlin. The code is for an inverse problem, which gives a set of ThermoMechanical parameters in function of the displacement of a metallic bar. The problem, is that the opti...