Questions tagged [performance-tuning]
Questions on optimizing Mathematica code for higher performance. This may mean faster execution, lower memory usage or both. Not to be confused with mathematical optimization.
3,012
questions
0
votes
0
answers
69
views
Fastest way of removing outliers from a data set which depends on a variable
Suppose we have the following code:
...
7
votes
3
answers
671
views
NSolve uses all CPU resources
Is it default setting of NSolve that it uses all my four cores of CPU?
Be aware that the following code made my computer non-respondent for about 18 seconds till it ...
0
votes
1
answer
76
views
Speeding up NMaximize for an optimisation problem in thousands of variables
I am trying to find the set of parameters that maximize the log-likelihood $f(\mathbf{x}) = \ln P(G|\mathbf{x})$ in an graph-based optimisation problem.
I have an expression of the form $f(\mathbf{x}) ...
0
votes
1
answer
60
views
Expression evaluates numerically inside of Plot but not inside NIntegrate
I have a function that I want to integrate:
...
2
votes
1
answer
74
views
Faster evaluation of matrix operation
I am working on a code to simulate spins under certain condition. The code runs but takes abnormally long time. earlier I asked similar question but this is more complex and fails the earlier ...
3
votes
2
answers
252
views
Problem with illustrating pathways
This is slightly different from this and this question. We are focusing on an illustration of all pathways from a specific sample.
Suppose we have the following sample:
$$\small{\mathcal{S}=\left\{(-1....
0
votes
1
answer
81
views
Help defining all pathways of a sample from the same start-point
This is slightly different from this question. We are focusing on finding all pathways of a sample rather than partitions of equal area:
Suppose we have the following sample:
$$\small{\mathcal{S}=\...
4
votes
4
answers
457
views
How to raise a vector to powers contained in a vector, change the list into a product, and do this for all the lines of a matrix, efficiently?
I want to raise the first vector var to the powers in a second vector, and then multiply the list, when the second vector runs over all lines of a matrix ...
3
votes
1
answer
279
views
Faster simulation of two spins
I am working on a code to simulate two spins under a certain condition. I have tried to optimize the code as much as I can, however this code is not so fast yet, taking long time to evaluate, but I ...
1
vote
1
answer
100
views
Nested For runs really slow
Consider this simple code:
M = 400;
AbsoluteTiming[For[x = 1, x <= M, x++,
For[y = 1, y <= M, y++,
For[z = 1, z <= M, z++,
i = 1]]]]
Above code ...
0
votes
0
answers
35
views
How can I speed up this ParallelMap operation? [duplicate]
Is there a quick way to do this?
ParallelMap[Position[gather, #] &, elements]
where gather has around 9 million elements, ...
4
votes
1
answer
93
views
Best way to implement the "plus-distribution" for very long expressions?
I'm at my wits end here. Is there an efficient way to implement the following distribution into MMA:
$$\int_0^y dx \frac{f(x)-f(y)}{y-x}$$
where $f/1-x$ can be analytically integrated. The difficulty ...
0
votes
1
answer
66
views
Optimize while loop with several conditions
I am trying to generate several random numbers according to some conditions, but the way I have it implemented, it won't run.
The conditions are:
...
6
votes
2
answers
163
views
Techniques for NIntegrate on a 3D surface region
I'm looking for ways to speed up NIntegrate[] on a region. My application involves a humongous expression obtained from diagonalizing a 3x3 matrix (see Lattice ...
1
vote
2
answers
73
views
Speed up definite integral of 1/x^(n/2)
I'm a bit buffled by how terribly slow this is:
...
2
votes
0
answers
46
views
Dot product between chosen indices for high-rank tensors
I am doing computations with multilinear maps and representing them with tensors. For example, I have an operator $O : V_1 \otimes V_2 \to W$, where $\dim(V_1) = \dim(V_2) = 5$ and $\dim(W)=3$ that I ...
0
votes
0
answers
32
views
Parallelization with Do and ParallelSubmit
I have quite a large expression that I need to integrate. My ansatz was to Expand the expression (easiest case results in ~5.5 million terms) and parallelize the ...
4
votes
2
answers
236
views
Speed up finite element method solver with small features
I post a question on making mesh for small features. @user21 gave a useful suggestion which resolves the small features. To improve the mesh, I have also tried to increase the resolution near the ...
2
votes
1
answer
84
views
Internal`MRealToString Gives Scientific Output From Large Inputs. How To Stop This?
The undocumented Internal`MRealToString works just fine for reals up to 999999. For anything over it outputs scientific notation. I don't need scientific, I need simple decimal.
...
0
votes
0
answers
30
views
SmoothKernelDistribution only uses 1 core
I have a huge amount of datasets, each containing many elements, and trying to convert it to PDF using SmoothKernelDistribution. I see that applying it to 1 dataset ...
1
vote
3
answers
107
views
Optimizing a function definition
I am using the following function to calculate A358497 as defined by OEIS:
...
1
vote
0
answers
94
views
Way to run the script faster
I have a mathematica code, which is running fine, but it takes long time to evaluate.I have already modified the code with compilation and vectorization as you can see from my code.
May be its a ...
3
votes
2
answers
310
views
Problem computing a limit
I have the following function in Mathematica:
$\frac{x! \sum _{i=1}^j (-i+j+1) S_{j+1}^{(-i+j+2)} x^{-i+j+1}}{(x-j)! \left((1-x)_j\right){}^2}$
Defined as:
...
5
votes
3
answers
439
views
How to optimize performance with DeleteDuplicates?
Does anyone know how to improve this for speed performance? The code works fine, but DeleteDuplicates makes it really slow for large lists.
...
1
vote
1
answer
438
views
Use of Compile[] to optimize the code to run faster
I am working on a code that takes long time to evaluate, So I come to know that use of Compile[] function can speed up significantly. Here is my original code.
...
0
votes
0
answers
71
views
How to speed up this code? (related to list manipulation)
This code is a program for generating a 2D roughness surface. There is no problem when the image size (m * n) is small (e.g., 50 * 50), but when it gets larger (e.g., 500 * 500), errors occur and the ...
0
votes
0
answers
59
views
Module with two conditions isn't correct
I am trying to divide a country into rectangles in order to integrate over these simpler regions. From a previous post, I am able to use quadtree to divide the country into many small rectangles, over ...
0
votes
0
answers
82
views
Can this loop / code be optimized to find more items in the sequence?
I am looking at the code snippet for OEIS A067075.
Do[k = 1; While[Plus @@ IntegerDigits[k^3] != n^3, k++]; Print[k], {n, 1, 6}]
It does okay for the first ...
0
votes
0
answers
79
views
Efficient construction of Hermitian block matrix
I need to construct large Hermitian matrices $H$, which can be built out of blocks. The matrix $H$ is of total size $Lx\times Ly$, with blocks of size $Ly$. For $Lx=5,\,Ly=3$ and $L=2$ (which is the ...
2
votes
1
answer
35
views
Table with preset variable is slower than table with explicit number
Why it takes ages to evaluate the second table compared to the first one?
The tables are same except that first uses explicit constant 667 while the second one uses ...
2
votes
1
answer
306
views
Approximating country by rectangles
Say I have a list of coordinates (these form the border of a country) called testpolycoords that is about 400 points long. I want to use a quadtree to divide the ...
0
votes
0
answers
51
views
Qualitative question: can the code matching the given patterns be made significantly faster if being written in pure C?
I made some code in Mathematica that I compiled in C. It involves operations such as looping inside While, custom random sampling from particular distributions, and ...
0
votes
0
answers
30
views
AbsArgPlot for List (Parallel Computation)
Basically, I have a very complicated function that I'd like to draw using AbsArgPlot. I thought it could speed up if I first use ...
0
votes
0
answers
110
views
Solving set of Gaussian integrals, integrating over an implicitly defined function that depends on the values of the integrals
I have the following NExpectations and the Implicit Function
...
0
votes
0
answers
39
views
Solving a system of NExpectations over an implicit function, repeated evaluations to converge to a fixed point(?)
I have the following NExpectations,
...
1
vote
1
answer
197
views
Parallelization with compile gives an error
I have this uncompiled code with MMA14, win10,64
...
1
vote
0
answers
76
views
Dot product of every pair of rows of a matrix
I have some code to get the cosine of the angle between vectors given by every pair of rows in a large rectangular matrix,
...
1
vote
0
answers
59
views
Replacement rule runs for a long time [duplicate]
I have a simple expression that reads (some expression in b) q^(8/3):
...
2
votes
0
answers
90
views
How to push the performance of this compiled function
I have the function optvals solving for two variables. For the given example of variables, I need the program to run atmost in a millisecond.
The main part of the ...
1
vote
1
answer
90
views
How to speed up generating and filtering large lists of numbers?
I have the following code where I brute force search for two variables.
list gives a list of 3 dimensional vectors, say {x,y,z}. ...
3
votes
1
answer
132
views
Code for sampling and quantizing a signal running too slow
Below is the code for sampling a sine wave and quantizing it with negative feedback. It is running very slowly unless we reduce the sampling size ns.
...
4
votes
1
answer
125
views
Strategy to speed up two polygons (or region) intersection
Basically, I want to compare the overlap between two polygons (or regions).
First, I have a reference particle ring that can form a simple polygon, but this type of ring is very thin and long, and its ...
0
votes
0
answers
33
views
Getting better answers by smaller working precision?
I have the following code
...
1
vote
0
answers
59
views
Why is SymmetrizedArray taking so much memory?
The context is: I take the tensor product of 2 totally symmetric tensors of rank 8, in 2 dimensions(in this case there are only 9 independent components):
...
1
vote
2
answers
115
views
Plotting with piecewise is slow
This drives me crazy. Why producing the first plot is so slow?
It is exactly same as the second plot except that the colors are not the same.
(The same slow it is with ...
0
votes
0
answers
83
views
Can I reduce execution time of these NDSolve precision runs?
I'm working on an NDSolve project with high precision but the integration takes a lot of time and wondering if there's a quicker way to integrate the DEs ...
0
votes
1
answer
80
views
Optimization for NSolve
I am trying to solve the system of n equations numerically. Basically, I am solving saddle point equations for eigenvalues of hermitean matrices and trying to reproduce Wigner's semicircle law:
...
2
votes
1
answer
109
views
Fast sampling from Fermi-Dirac distribution under specific conditions
This question is a continuation of the following one.
Let us assume a Fermi-Dirac (FD) distribution (times $p^{2}$):
...
2
votes
1
answer
96
views
Speeding up the nested NIntegration consisted of `Exp' and `Bessel' functions
I got stuck with optimizing the nested numerical integration of function with a high number of Bessel functions (first and second kinds) summed and several exponents. I will appreciate any suggestions ...
1
vote
1
answer
96
views
Most efficient way of defining the following sets for every step $n$
For each $n\in\mathbb{N}$, how do we compute sets $A_n$ and $B_n$ below:
Let $A_1=[0,2/3)$. Let $B_1=(2/3,1]$.
If $A_n$ is a union of intervals, then for each interval cut out the
middle $1/2^{n+1}$ ...