Skip to main content

Questions tagged [sampling]

Filter by
Sorted by
Tagged with
3 votes
4 answers
214 views

Selecting elements from sublists (with removal) subject to constraints on the sublist choice

My problem is a little difficult to explain so I'll exhibit with a couple of examples. Given the following nested list - {{5,13},{5,11},{23}} - imagine the sublists are urns with balls numbered with ...
ngc5139's user avatar
  • 307
0 votes
2 answers
180 views

Sampling irrational numbers [closed]

I'm sorry that my unclear statement has caused some misunderstanding. This edit was just to stop misunderstanding, Keep Closed. I don't know if there is another software with a better fit for this ...
babyK's user avatar
  • 459
0 votes
0 answers
21 views

Simulating data from a piecewise pdf occasionally returns an error [duplicate]

In the following code, I generate data from a piecewise PDF. Usually, I get a sample size of ns, but sometimes I get an error message: Error: RandomVariate::unsdst:...
M. Mo's user avatar
  • 9
0 votes
0 answers
92 views

How to find a fit for the following data?

Consider the following function: ...
John Taylor's user avatar
  • 5,963
2 votes
1 answer
121 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}$): ...
John Taylor's user avatar
  • 5,963
1 vote
1 answer
133 views

How to quickly sample from the following distributions

Consider the following distributions: ...
John Taylor's user avatar
  • 5,963
1 vote
1 answer
100 views

How to compile the following code (sampling from a distribution)?

Consider the following code: ...
John Taylor's user avatar
  • 5,963
0 votes
0 answers
61 views

How to quickly sample points according to the given distribution?

Consider the following points sampler: ...
John Taylor's user avatar
  • 5,963
0 votes
1 answer
84 views

Resampling the points with a constraint [closed]

I have a list of npts elements energies obeying some arbitrary distribution. By performing some operation many times, it would ...
John Taylor's user avatar
  • 5,963
2 votes
0 answers
62 views

Why RandomSample fails and how to fix this?

Consider the following sampling: weights = 10^RandomReal[{-13, Log10[35]}, 499500]; vals = Range[Length[weights]]; randomvals = RandomSample[weights -> vals]; ...
John Taylor's user avatar
  • 5,963
0 votes
1 answer
84 views

How to select non-repeating pair of numbers?

Consider the following combinations of integers comb, where the integers range from 1 to n ...
John Taylor's user avatar
  • 5,963
0 votes
0 answers
130 views

How to quickly generate the values satisfying the given condition?

Consider some domains in variables th, z and some condition cond defining the domain of a ...
John Taylor's user avatar
  • 5,963
4 votes
1 answer
235 views

How to quickly sample points from the given PDF data?

Consider some data (distr.dat). It is a tabulated PDF: x, y, z, PDF[x,y,z], where x is some parameter (and the integral of ...
John Taylor's user avatar
  • 5,963
1 vote
1 answer
169 views

Pick random value based on list of probabilities

I'm pretty sure this must have been asked before, but I can not find the duplicate. Given a list of values with their probabilities ...
infinitezero's user avatar
  • 1,451
2 votes
2 answers
196 views

How to sample from a `MultinormalDistribution` with a positive semidefinite covariance matrix?

I'm trying to sample from a Gaussian process (GP) following these tutorials: https://peterroelants.github.io/posts/gaussian-process-tutorial/#Sampling-from-prior https://stephens999.github.io/...
ForceBru's user avatar
  • 165
2 votes
3 answers
138 views

Generating random samples from normal distributions with parameters coming from a list

...
nutan's user avatar
  • 107
0 votes
2 answers
46 views

Cannot use RandomSample to get a sample bigger than the original [closed]

I have a sample of 300 elements and I need a random vector of size 100000 which consists of random repetitions of the elements of the 300-element sample I have tried the following ...
slow_learner's user avatar
4 votes
1 answer
74 views

Speeding up RandomVariate with custom probability distribution

I have the defined a custom distribution, which is a Gaussian where the exponent can be any real n greater than 0 (set to actually be >0.5 in use), i.e. ...
Xyive's user avatar
  • 115
6 votes
4 answers
899 views

Finding the periodicity (or wavelength) in approximately periodic data irregularly sampled

I have irregularly sampled data that looks as in the picture. Is there a function in Mathematica that allows me to find an approximate or average period or wavelength? I know beforehand that the data ...
EGME's user avatar
  • 647
0 votes
1 answer
84 views

Is there a difference between generating and loading data?

EDIT-1 This is a minimal example where an error occurs after 44538 samples generated in d1 upon importing as d2. Note that if <...
slow_learner's user avatar
4 votes
2 answers
225 views

Is there a way to generate a data-driven Monte Carlo sample from a histogram?

I have a vector with 50 elements. These are values of a random variable. I have represented the data as Histogram[RandomVariable1Histogram]. However, I need to ...
slow_learner's user avatar
4 votes
1 answer
158 views

Reverse engineer visualizations to compactly extract underlying data

TL;DR How to implement in mathematica a tool such as WebPlotDigitizer by Ankit Rohatgi which would allow us to trace automatically curves from either (randomly ordered) data or imported images. ...
chris's user avatar
  • 23.1k
4 votes
2 answers
235 views

Smart under-sampling of a large list of data points

I have dielectric functions of materials as lists of value pairs {{x1, y1}, {x2, y2}, ...} and unfortunately some of them are quite long, which is a bother in ...
Hexacyanoferrat's user avatar
1 vote
0 answers
61 views

putting condition on do loop

...
tabi_k's user avatar
  • 157
1 vote
1 answer
69 views

Select a subsequence of a sequence according to tosses of a biased coin

I have a sequence, from which I would like to select a subsequence, each term of the original sequence being included in the subsequence with probability $p$, independently of the other terms. That is,...
Simon's user avatar
  • 1,445
1 vote
2 answers
258 views

Evaluate function at "good" points used by Plot in numerical problems

Plot function with option Mesh->All shows how mathematica evaluates function to make it most optimal for plotting. I'd like to evaluate some physical function in ...
Kater Tatianow's user avatar
0 votes
2 answers
82 views

How to get a list of exponentially distributed points sampled in a range

I want to get 256 points exponentially sampled in a range, and then get its histogram. If I plot PDF, I get the following: ...
tabi_k's user avatar
  • 157
3 votes
4 answers
351 views

Sampling Implicit functions

Consider an implicit function like f ...
lineage's user avatar
  • 1,184
2 votes
1 answer
145 views

How to extract colors from ColorsNear?

Is there any way to get a discrete list of samples from the ColorsNear function? I have tried ...
skyfire's user avatar
  • 477
0 votes
1 answer
183 views

Sampling two integer lists of given sizes from a distribution that have equal sums

(This question emerged from discussions in this post.) Context and code sample: I am trying to figure out if there is a way to generate two $a$ and $b,$ comprised of $n_a$ and $n_b$ integers which ...
user avatar
1 vote
2 answers
78 views

Sampling an inequality over multi-dimensional space

Let's say I have two functions $f(x,y,z), g(x,y,z)$. I would like to know the probability that $f(x,y,z) < g(x,y,z)$ over some defined, numerical ranges of $x, y, z$. Any thoughts on how to do it ...
John Smith's user avatar
8 votes
2 answers
350 views

Plot, sampling, and why it does not display for some ranges

The following gives an empty plot on V12 under Windows 10: ...
Nasser's user avatar
  • 150k
5 votes
2 answers
515 views

Why does plot not show where Piecewise function is not zero?

From my user point view this looks like bug. But I am not an expert. f[x_?NumericQ]:=Piecewise[{{1,x==1},{0,True}}]; Plot[f[x],{x,0,1}] Does not show ...
Nasser's user avatar
  • 150k
1 vote
1 answer
195 views

Random sampling of a discrete distribution in NetGraph

Within a NetGraph I would like to use the output of a softmax layer, interpreted as a probability distribution, to sample a "next token". Since this is done inside an RNN structure, I cannot do this ...
Steven Hutt's user avatar
1 vote
2 answers
361 views

Multiple unique random samples?

I'm trying to produce $n$ random samples from a list, but not all samples, and I'd like the samples to not repeat in the same execution of the command. If I'm not mistaken, something like ...
Pedro Sobota's user avatar
2 votes
4 answers
819 views

How to generate a matrix with certain conditions

I want to generate a $n \times n$ matrix. I want the diagonal entries to be all 0 I want a random choice of matrix elements with 0 or 1. The probability of having a 1 as a matrix element is $1/m$ and ...
tiffany's user avatar
  • 21
0 votes
1 answer
247 views

How do I extract data points from an audio plot at a constant spaced time interval?

AudioPlot[Audio[File["Downloads/1_mp3.wav"]]] data = Cases[AudioPlot[Audio[File["Downloads/1_mp3.wav"]]], Line[x_] :> x, Infinity] This code can extract data ...
qy_x's user avatar
  • 3
1 vote
2 answers
195 views

Sampling data from numerical values of density distribution of nucleons

How could i sample my data which follows distribution if i have only numerical values of density distribution as an example data attached as in picture I tried but do not know how to do it. The data:...
user43830's user avatar
  • 101
0 votes
1 answer
59 views

ProbabilityDistribution fails for square root

I would like to sampling data from a distribution Sqrt[x^2 + y^2]. I used the code as follows: ...
ZHANG Juenjie 's user avatar
0 votes
1 answer
120 views

Speeding up Module

I am working on the Ising 2D model in Mathematica and this is currently my Metropolis sampling function: ...
Lera's user avatar
  • 11
4 votes
2 answers
187 views

Filtering data with timestamps

How to apply filter to data that was sampled in certain moments of time? Examples from documentation deal only with uniformly sampled data: ...
Vsevolod A.'s user avatar
0 votes
3 answers
142 views

Sample the data with equal step size

I have the data below. I would like to sample with equal step size. For simplicity lets try unit step size. Here is the desired result. Find the first time exceed the unit time step, and take lower ...
OkkesDulgerci's user avatar
5 votes
2 answers
240 views

Random sample of big big numbers

Consider the following piece of code: m = 2; n = 6; samplesize = 1000; totalsize = 2^(n^m); numbersample = 2 RandomSample[Range[totalsize/2], samplesize]; With ...
Filburt's user avatar
  • 588
5 votes
3 answers
407 views

Sample over a matrix

Assume I have a matrix. ...
OkkesDulgerci's user avatar
2 votes
1 answer
89 views

Looking for an estimator for non-linear statistics

Goal We sample $n$ individuals with replacement and measure their trait values $x_i$ for all individual $i$. The variable $x$ is bounded [0,1]. Let $\mu$ be the ...
Remi.b's user avatar
  • 1,155
0 votes
0 answers
89 views

Problems with sampling

Let $t\ge 0$ and let $f_{s}(t)$ be the sampled version of $f(t)$. If $$f(t)=\begin{cases}\int_{0}^{t}\exp\left(-\frac{1}{1-s^{2}}\right)\,ds,&|s|<1, \\ 0,&\text{otherwise}.\end{cases}$$ I ...
Jason Born's user avatar
26 votes
4 answers
3k views

How to sample points randomly below a curve? [duplicate]

How can I randomly select 1000 points uniformly from the shaded area below the plotted curve? Plot[1/π Cos[θ]^2, {θ, 0, 2 π}, Filling -> Bottom]
ZHANG Juenjie 's user avatar
5 votes
2 answers
331 views

Generate multiple integer variables with constant sum

I have asked similar question three day ago[The old question]. it was incorrectly marked as duplicated. This time I make this question more general and closer to reality. I want to build a model of N ...
yanfyon's user avatar
  • 604
39 votes
4 answers
2k views

How to implement the sample-point process like the built-ins of Mathematica?

Consider this: pts = {{0, 0}, {1, 1}, {2, -1}, {3, 0}, {4, -2}, {5, 1}}; f = BSplineFunction[pts] I can use ParametricPlot to ...
xyz's user avatar
  • 655
7 votes
1 answer
384 views

Draw from a given list according to empirical distribution

I have two lists, where each time I have age-income vectors. Given the distribution of age in the first list, I would like to draw a sample with the similar distribution of age from the second list (...
Kass's user avatar
  • 671