5 votes
Accepted

How to optimize an approximated matrix multiplication?

This is a linear least squares problem if you just look at it the right way. Write $$ B = (I-aX)^{-1}, $$ then $X = \frac{1}{a}(I-B^{-1})$ and $$ (I-aX)^{-1}XA = B\frac{1}{a}(I-B^{-1})A = \frac{1}{...
Wolfgang Bangerth's user avatar
4 votes

How to sample points in hyperbolic space?

I'm in the middle of doing this for myself. I think the most appropriate analogue to the Gaussian would be the heat kernel in hyperbolic space. Fortunately, this has been figured out before: https://...
xue2sheng1's user avatar
4 votes
Accepted

Uniform dots distribution in a sphere

To generate a specified number of random points in a 3D ball, one possibility is to use rejection sampling to have an initial point distribution, then improve the sampling with Lloyd relaxation. ...
BrunoLevy's user avatar
  • 2,315
3 votes
Accepted

Different questions about "Inverse Physics problems"

As I understand, your ultimate goal is to solve an inverse problem (i.e., infer some parameters from given data / observations). To this end, you want to apply Bayesian Inference, which relates the ...
cos_theta's user avatar
  • 451
3 votes

Generating Random Orthogonal Matrices in C++

I've seen in your comment that you want a uniform sampling. With the Eigen library, you can uniformly generate at random a unit quaternion: ...
Stéphane Laurent's user avatar
3 votes

Estimate information entropy through Monte Carlo sampling

If I understand what information you have available, what you want is not possible: the information available to you is not enough to determine the entropy. It's not even enough to approximate the ...
D.W.'s user avatar
  • 400
2 votes

Why are Hamiltonian dynamics used in MCMC?

I'm a little late to reply but I found this review to be really informative. One particularly nice feature of Hamiltonian flows is that they preserve volume in phase space. If we take an infinitesimal ...
Daniel Shapero's user avatar
2 votes
Accepted

How to choose a good distribution for visualizing phase changes in the nature of the roots of a quadratic equation

Because the polynomial $ax^2+bx+c$ and $x^2+\frac{b}{a}x + \frac{c}{a}$ have the exact same roots, let's first simplify the problem by only considering the roots of the equation $$ x^2+b'x + c' = 0 $...
Wolfgang Bangerth's user avatar
2 votes

Estimate information entropy through Monte Carlo sampling

For the second part of your question (estimation of entropy difference between distributions) you may be able to use the identity $$F = \langle E \rangle - T S,$$ where $\langle E \rangle$ is the ...
Juan M. Bello-Rivas's user avatar
2 votes

Rotate a vector by a randomly oriented angle

If you want to use a single random number, you first need to find "a" solution (one vector w that meets the criterion), then rotate that vector about $\mathbf{v}$ by a randomly generated angle. We ...
Floris's user avatar
  • 243
2 votes

Is there a better way to do run time analysis than this?

Welcome to SE SciComp. First of all, I would suggest using Jupyter so that you have access to IPython and its nice timing magics (see %time and %timeit magic function). These magics take into account ...
GertVdE's user avatar
  • 6,179
2 votes
Accepted

Testing Wiener process splitting in adaptive-step SDE integrators

I discuss the method you describe in more detail in this paper (Rackauckas and Nie 2017) as RSwM2. In that paper I am ever so slightly able to detect that it's sometimes doing something wrong, but ...
Chris Rackauckas's user avatar
2 votes

Generating Random Orthogonal Matrices in C++

The example you cited appears to be generating random Householder vectors and multiplying them out using backwards accumulation. Another simple thing to do would be to generate a random matrix $\...
rchilton1980's user avatar
  • 4,862
2 votes
Accepted

How is the D value being updated at simple RRT algorithm?

I don't think $D$ is updated at all. It is just a temporary value for $D_{exp}$ times uniform random value in [0,1]. As a general remark, RRT means Rapidly-exploring Random Tree. Hence, the algorithm ...
Frederik Heber's user avatar
2 votes

How to plot random points in 3 dimensions in order to calculate volume of a torus through Monte Carlo integration

You don't need to plot a torus to calculate its volume. Moreover you can analytically compute the volume integral and it's even on wikipedia. With Monte Carlo you can use rejection sampling to figure ...
lightxbulb's user avatar
  • 2,122
2 votes
Accepted

Grid walk vs. uniform random weights for bounded grid

Not every method that seems reasonable leads to an algorithm that is competitive. In your case, if you want to draw uniform random numbers from $[0,1]^2$, you could use a method that is based on ...
Wolfgang Bangerth's user avatar
2 votes
Accepted

Changing randomly a unit vector

What you’re seeing is a basic acceptance-rejection method. $\Delta S$ generated in that way will be uniform in the ball of radius $\Delta S_{\text{max}}$ centered at the origin. Added I imagine you're ...
A rural reader's user avatar
1 vote
Accepted

Random access (quasi-?)random sequence

There's a paper by Gruenschloss about enumerating Sobol points falling within some elementary intervals: https://github.com/lgruen/sample-enum This is used in pbrt with the global sampler in order to ...
1 vote

How to sample points uniformly over a region of the unit sphere

So if I correctly understand, you know how to sample in the "vertical" cone, and you ask how to rotate? Here is some pseudo-code to get the unit quaternion representing a rotation sending a ...
Stéphane Laurent's user avatar
1 vote

Optimization on MCMC codes

The Julia probabilistic programming libraries like Turing.jl work on abstract array types and use the Julia automatic differentiation tooling, so if you write your model as something that uses CUDA.jl ...
Chris Rackauckas's user avatar
1 vote

Generating Random Orthogonal Matrices in C++

If $X$ is a $(n \times m)$-matrix whose entries are independently generated values from the standard normal distribution, then $X(X^{\top}X)^{-\frac12}$ is a uniformly generated random orthogonal ...
Stéphane Laurent's user avatar
1 vote

Monte Carlo - Random Walk Simulation - polyfit the log log data points?

If I understood the first image correctly, you should do a linear fit with $\ln(N)$ being the independent variable and, presumably, $\ln(d)$ the dependent variable. Furthermore, it seems to me that ...
Ertxiem - reinstate Monica's user avatar
1 vote

Uniform dots distribution in a sphere

There is a nice document: M. Deserno, "How to generate equidistributed points on the surface of a sphere" which basically summarizes the two easiest methods to generate a distribution of points on a ...
Anton Menshov's user avatar
  • 8,672
1 vote

Sampling simulation steps logarithmically

If you want your sampling over the (a,b) interval to appear uniform when viewed on a log-log scale, linearly interpolate the logarithms: ...
rchilton1980's user avatar
  • 4,862
1 vote

Rotate a vector by a randomly oriented angle

Find a vector $\vec a$ such that $\vec v \times \vec a \ne 0$. Define $\hat x = (\vec v\,\times \vec a)/||\vec v \times \vec a||$. By construction, $\hat x$ is a unit vector and is orthogonal to $\vec ...
David Hammen's user avatar
1 vote

How to choose a good distribution for visualizing phase changes in the nature of the roots of a quadratic equation

Well, for the visualization of the discrete and real/imaginary character of the roots, you can simply do a 3D plot of $$ \frac{-b\pm \sqrt{b^2-4ac}}{2a} $$ against $a$, $b$, and $c$. This will give ...
Silmathoron's user avatar
1 vote
Accepted

(numpy/scipy) Build a random vector given mean vector and covariance matrix

If random vector $X$ has variance $S$, then $LX$ has variance $LSL^\top$. So generate whatever random variables with mean 0 and identity covariance matrix, then transform it $LX+\mu$, where $\mu$ is ...
jf328's user avatar
  • 482

Only top scored, non community-wiki answers of a minimum length are eligible