Hot answers tagged

6

You could use Region functionality (for simpler regions), e.g. rw[pt_, s_, n_, reg_] := Module[{ch = {{0, 0}, {1, 0}, {-1, 0}, {0, 1}, {0, -1}}, np, st}, st = RandomChoice[ch, n]; FoldList[If[RegionMember[reg, #1 + s #2], #1 + s #2, #1] &, pt, st] ] an[p_, step_, num_, regn_] := With[{pnts = rw[p, step, num, regn]}, ListAnimate[ ...


6

There seems to be a bug in version 10.1 that has been fixed in 10.3. You can always try writing your own random number generator. Here is a simple acceptance rejection method based on generalized Gaussian distributions as discussed here. Here I use a very naive envelope, a uniform distribution over {mu - s*sd, mu + s*sd} where mu is the mean of your ...


6

The following two expressions are equivalent. Table[RandomReal[], {10^8}]; // AbsoluteTiming {7.99593, Null} RandomReal[1., 10^8]; // AbsoluteTiming {1.20604, Null} The second expression shows the advantage of RandomReal over Random. Edit Another consideration is the generator used. For example, when the Mersenne twister is specified, there is not ...


5

If you want two lists to have the same Total, then you need to scale one of them by the right amount. The trick is to pick which one to scale so that both of the lists are within $U(0,1)$ n=2000; lists = RandomReal[1, {n, 2}] // Transpose; lists = lists (Min[Total /@ lists]/Total@# & /@ lists); Now you verify that they are both from the right ...


4

Use Normal to get the lists out of a TemporalData object Normal[td] returns a list containing time-value pairs for each path. s = {2, 1, 6, 5, 7, 4}; s2 = {22, 12, 62, 52, 72, 42}; t = {1, 2, 5, 10, 12, 15}; td = TemporalData[{s, s2}, {t}]; Normal@td (* {{{1, 2}, {2, 1}, {5, 6}, {10, 5}, {12, 7}, {15, 4}}, {{1, 22}, {2, 12}, {5, 62}, {10, 52}, ...


3

The bug appears to be fixed in the latest version of Mathematica (10.3.1), as confirmed by @JasonB and @Szabolcs.


2

Here are solutions to both boundary protocols. They are built on the same basic framework -- mainly the function that generates the moves for the walker is what differs between the two. There is a little adjustment in the way the lines and walker point is drawn because of discontinuities in the path generated by the wrap-arround protocol, Path clips at the ...


2

A possible solution: RandomBipartiteGraph[m_, n_, e_] := Graph[Range[m + n], RandomSample[Flatten@Table[i <-> j, {i, m}, {j, m + 1, m + n}], e]] But I wonder if I can do it with some of Mathematica built-in graph generator functions? Also, this is very slow if $m$ or $n$ are large. I am generating the list of all posible edges, which is a big ...


2

I have version 10.0.2, so i can't test this, but i think it works! n = 5; sum = RandomVariate[UniformSumDistribution[n]]; RandomPoint[RegionIntersection[Simplex[DiagonalMatrix[ConstantArray[sum, n]]], Cuboid[ConstantArray[0, n], ConstantArray[1, n]]], 2] Edit: If RandomPoint performs better when using ImplicitRegion, this ...


2

You can just multiply the random numbers by a windowing function that does go to zero in the way you want. One choice is a super-Gaussian, it's like a smooth version of a square windowing function (with n=6 below, but you can choose other values Plot[Exp[-(x/120)^6], {x, -210, 210}, PlotRange -> {0, 1}] Here is the initial data, bounds = 200; width ...


2

I have previously used the following two helper functions to generate the format of covariance and correlation matrices: covariancematrix[n_] := Table[ σ[i] σ[j] ρ[i, j]^(1 - KroneckerDelta[i, j]), {i, 1, n, 1}, {j, 1, n, 1} ] /. {ρ[i_, j_] :> ρ[j, i] /; i > j} correlationmatrix[n_] := Table[ σ[i] σ[j] ρ[i, j]^(1 - KroneckerDelta[i, ...


2

Edit TemporalData is one of those functions that accepts property names as arguments for extracting the information it holds. Please read the documentation for TemporalData where will find a list of such properties and examples of their use. Using example data taken from the documentation s = {2, 1, 6, 5, 7, 4}; s2 = {22, 12, 62, 52, 72, 42}; t = {1, 2, ...


1

Here is my fast entry: randomBipartiteGraph[m_, n_, e_] := Module[{edges, mat}, edges = ConstantArray[1, e] ~Join~ ConstantArray[0, m*n - e]; mat = Partition[RandomSample[edges], m]; AdjacencyGraph@ArrayFlatten[ {{0, Transpose[mat]}, {mat, 0}} ] ] Graph[randomBipartiteGraph[10, 20, 80], GraphLayout -> "BipartiteEmbedding"] Here ...


1

In a simplified 1D version my idea may look as follows. Here are two lists of the amplitudes, that I limited by 10 terms: lst1 = RandomReal[{-1, 1}, 10]; lst2 = RandomReal[{-1, 1}, 10]; Here are the arbitrary functions defined as the Fourier-polynomials with the above amplitudes: y1[x_] := Sum[lst1[[i]]*Sin[x*i], {i, 1, Length[lst1]}] y2[x_] := ...


1

bounds = 200; f[{x_, y_}] := CDF[GammaDistribution[4, 2], 15 Rescale[ Min@Outer[Abs[Subtract@##] &, {x, y}, {bounds, -bounds}], {0, bounds}, {0, 10}]]/2 // N func = Interpolation@Flatten[Table[{{x, y}, RandomReal[{-#, +#}] &@ f[{x, y}]}, {x, -bounds, +bounds}, {y, -bounds, +bounds}], 1]; DensityPlot[func[x, y], ...



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