Questions tagged [sampling]

In signal processing, sampling is the reduction of a continuous signal to a discrete signal. In statistics, sampling is the selection of a subset of individuals from within a statistical population to estimate characteristics of the whole population.

This tag should be used for questions related to programming solutions related to sampling.

Sampling can be done for functions varying in space, time, or any other dimension, and similar results are obtained in two or more dimensions. More information in Wikipedia - sampling (signal processing).

For statistical sampling, see Wikipedia - sampling (statistics) for more.

1593 questions
91
votes
12 answers

Take n random elements from a List?

How can I take n random elements from an ArrayList? Ideally, I'd like to be able to make successive calls to the take() method to get another x elements, without replacement.
user568866
75
votes
2 answers

What does replacement mean in numpy.random.choice?

Here explains the function numpy.random.choice. However, I am confused about the third parameter replace. What is it? And in which case will it be useful? Thanks!
wking
  • 1,293
  • 1
  • 16
  • 27
58
votes
8 answers

Algorithms for determining the key of an audio sample

I am interested in determining the musical key of an audio sample. How would (or could) an algorithm go about trying to approximate the key of a musical audio sample? Antares Autotune and Melodyne are two pieces of software that do this sort of…
Alex
  • 4,844
  • 7
  • 44
  • 58
55
votes
1 answer

Abysmal OpenCL ImageSampling performance vs OpenGL TextureSampling

I've recently ported my volumeraycaster from OpenGL to OpenCL, which decreased the raycaster's performance by about 90 percent. I tracked the performance decrease to the OpenCL's imagesampling functions, which are much slower than the respective…
user1449137
  • 651
  • 5
  • 3
45
votes
5 answers

Random Sample of a subset of a dataframe in Pandas

I have a pandas DataFrame with 100,000 rows and want to split it into 100 sections with 1000 rows in each of them. How do I draw a random sample of certain size (e.g. 50 rows) of just one of the 100 sections? The df is already ordered such that the…
WGP
  • 708
  • 2
  • 7
  • 18
40
votes
12 answers

How to generate a random 4 digit number not starting with 0 and having unique digits?

This works almost fine but the number starts with 0 sometimes: import random numbers = random.sample(range(10), 4) print(''.join(map(str, numbers))) I've found a lot of examples but none of them guarantee that the sequence won't start with 0.
Menon A.
  • 580
  • 1
  • 4
  • 12
40
votes
1 answer

What are chunks, samples and frames when using pyaudio

After going through the documentation of pyaudio and reading some other articles on the web, I am confused if my understanding is correct. This is the code for audio recording found on pyaudio's site: import pyaudio import wave CHUNK = 1024 FORMAT…
shiva
  • 2,535
  • 2
  • 18
  • 32
37
votes
8 answers

Stratified random sampling from data frame

I have a data frame in the format: head(subset) # ants 0 1 1 0 1 # age 1 2 2 1 3 # lc 1 1 0 1 0 I need to create new data frame with random samples according to age and lc. For example I want 30 samples from age:1 and lc:1, 30 samples from…
user3525533
  • 405
  • 1
  • 5
  • 7
27
votes
3 answers

FloatingPointError from PyMC in sampling from a Dirichlet distribution

After being unsuccessful in using decorators to define the stochastic object of the "logarithm of an exponential random variable", I decided to manually write the code for this new distribution using pymc.stochastic_from_dist. The model that I am…
Cupitor
  • 11,007
  • 19
  • 65
  • 91
22
votes
1 answer

How to draw waveform of Android's music player?

one of the default live wallpapers that came with my phone was a wallpaper that displayed the wave form of music playing in the background in real time. I was wondering how one could go about doing this. It seems I should somehow access the…
22
votes
3 answers

Use R to Randomly Assign of Participants to Treatments on a Daily Basis

The Problem: I am attempting to use R to generate a random study design where half of the participants are randomly assigned to "Treatement 1" and the other half are assigned to "Treatment 2". However, because half of the subjects are male and half…
Wu Wei
  • 380
  • 1
  • 11
19
votes
1 answer

sample random point in triangle

Suppose you have an arbitrary triangle with vertices A, B, and C. This paper (section 4.2) says that you can generate a random point, P, uniformly from within triangle ABC by the following convex combination of the vertices: P = (1 - sqrt(r1)) * A +…
dsg
  • 12,924
  • 21
  • 67
  • 111
17
votes
2 answers

Is there an algorithm for weighted reservoir sampling?

Is there an algorithm for how to perform reservoir sampling when the points in the data stream have associated weights?
Budhapest
  • 601
  • 1
  • 5
  • 12
16
votes
5 answers

Random Sampling from Mongo

I have a mongo collection with documents. There is one field in every document which is 0 OR 1. I need to random sample 1000 records from the database and count the number of documents who have that field as 1. I need to do this sampling 1000 times.…
Aditya Singh
  • 822
  • 3
  • 15
  • 25
15
votes
3 answers

How to do a random stratified sampling with Python (Not a train/test split)?

I am looking for the best way to do a random stratified sampling like survey and polls. I don't want to do a sklearn.model_selection.StratifiedShuffleSplit since I am not doing a supervised learning and I have no target. I just want to create random…
asl
  • 471
  • 2
  • 4
  • 13
1
2 3
99 100