New answers tagged

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 ...


7

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 ...


0

Let $U,V\sim U\left(0,\,1\right)$ be two iid standard uniform random variables. Sample $n$ times from $U$ and denote the sum by $s_{x} := \sum_{k=1}^{n} u_{k}$. Note that this sum $s_{1}$ has the Irwin–Hall distribution, which is defined to be the sum of iid standard uniform random variables. I understand your question in the following way: You are asking ...


0

Here is an approach to produce a good approximation. Brute force generate lots of distributions until we achieve the desired total: target = Total@RandomReal[1, {1000}] 511.315 set2 = NestWhile[ Append[ Rest@#, RandomReal[1]] &, RandomReal[1, {1000}], Abs[Total[#] - target] > .0001 &]; Total@set2 511.315 % - target ...


0

Someone can maybe implement the following idea: It is enough to be able to produce a list of $n$ random numbers in range $[0,1]$ with total sum $s$, where the random numbers are chosen in some uniform (fair) fashion. Note that picking a random vector in $C=[0,1]^n$ is the same as sampling a hypercube. We can intersect this hypercube with the plane ...


6

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 ...


3

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


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 ...


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], ...


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, ...


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}, ...


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 ...


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 ...



Top 50 recent answers are included