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
5
votes
1 answer

Vectorised code for sampling from truncated normal distributions with different intervals

The following code generates a sample of size 100 from trunctated normal distributions with different intervals. Is there any effecient(vectorised) way of doing this? from scipy.stats import truncnorm import numpy as…
Cupitor
  • 11,007
  • 19
  • 65
  • 91
5
votes
2 answers

Efficient way of sampling from indices of a Numpy array?

I'd like to sample from indices of a 2D Numpy array, considering that each index is weighted by the number inside of that array. The way I know it is with numpy.random.choice however that does not return the index but the number itself. Is there any…
Cupitor
  • 11,007
  • 19
  • 65
  • 91
5
votes
2 answers

How do I double the size of a vector in MATLAB with interpolation?

Essentially, if I have the following matrix: [1, 2, 3 ,4, 10] I need to explode it whilst interpolating, as follows: [1, 1.5, 2, 2.5, 3, 3.5, 4, 7, 10]. Essentially, buff it up by filling in the average of the two surrounding values. Say if I…
gran_profaci
  • 8,087
  • 15
  • 66
  • 99
5
votes
4 answers

How to Sample a specific proportion of lines from a big file in R?

I have a huge file of coordinates about 125 million lines. I want to sample these lines to obtain say 1% of all the lines so that I can plot them. Is there a way to do this in R? The file is very simple, it has only 3 columns, and I am only…
Sam
  • 7,922
  • 16
  • 47
  • 62
5
votes
3 answers

Can an Arduino sample audio in microseconds for 1-4 kHz?

I've just hooked up a electret microphone to an Arduino, and I'd like to sample between the ranges of 1 kHz and 4 kHz. I understand this is limited to the machine code and the ADC, so I'm trying to keep the sketch simple. Is it possible to sample…
user2119971
  • 71
  • 2
  • 3
  • 5
5
votes
5 answers

Sample with a max

If I want to sample numbers to create a vector I do: set.seed(123) x <- sample(1:100,200, replace = TRUE) sum(x) # [1] 10228 What if I want to sample 20 random numbers that sum to 100, and then 30 numbers but still sum to 100. This I imagine will…
user1320502
  • 2,510
  • 5
  • 28
  • 46
4
votes
5 answers

Sampling from a discrete probability distribution in C++

I am new to C++ and extremely surprised by the lack of accessible, common probability manipulation tools (i.e. the lack of things in Boost and the standard library). I've done a lot of scientific programming in other languages, but the standard…
ely
  • 74,674
  • 34
  • 147
  • 228
4
votes
2 answers

R sampling to get around randomForest 32 factor limit

I'm trying to work around the randomForest package limit of 32 levels for factors. I have a data set with 100 levels in one of the factor variables. I wrote the following code to see what things would look like using sampling with replacement…
screechOwl
  • 27,310
  • 61
  • 158
  • 267
4
votes
1 answer

How to access samples in an audio file

I'm making an iPhone app which lets the user design an audio filter and test it on some recorded sound. I try to do the following: I create two audio files called "recordeAudio.aiff" and "filteredAudio.aiff" I record sound with the mic and save it…
Michael
  • 41
  • 2
4
votes
1 answer

Why sensor sampling rate become too low when Android phone is still?

I write a simple app to read accelerometer data and I found that sampling rate is too low(even one sample 5 seconds) when I put phone on the table and keep quiet. I set sampling rate as FASTEST it's sampling rate always is high. I want to know why…
MoreFreeze
  • 2,856
  • 3
  • 24
  • 34
4
votes
4 answers

drawing a stratified sample in R

Designing my stratified sample library(survey) design <- svydesign(id=~1,strata=~Category, data=billa, fpc=~fpc) So far so good, but how can I draw now a sample in the same way I was able for simple sampling? set.seed(67359) samplerows <-…
Roland Kofler
  • 1,332
  • 1
  • 16
  • 33
4
votes
2 answers

stratified sampling with priors in python

Context The common scenario of applying stratified sampling is about choosing a random sample that roughly maintains the distribution of the selected variable(s) so that it is representative. Goal: The goal is to create a function to perfrom…
PeCaDe
  • 277
  • 1
  • 8
  • 33
4
votes
4 answers

What is the fastest method of sampling random values from a Gaussian distribution?

The Box-Muller transform, is an elegant and reasonably performant method of sampling random values from a Gaussian distribution. I'm looking for a faster method clearly written and in C#. For reference here's an implementation of the Box-Muller…
redcalx
  • 8,177
  • 4
  • 56
  • 105
4
votes
1 answer

How to randomly pick element from an array with different probabilities in C++

Suppose I have a vector p of some objects. I can pick a uniformly random by simply p[rand() % p.size()]. Now suppose I have another same-sized vector of doubles vector chances. I want to randomly sample from p with each element…
Michael
  • 325
  • 3
  • 14
4
votes
2 answers

Set.seed issue with sample when changing order of values

set.seed(59) mean(sample(c(12,7,5),7,prob = c(.3,.3,.4),replace = T)) [1] 9.571429} set.seed(59) mean(sample(c(5,7,12),7,prob = c(.4,.3,.3),replace = T)) [1] 8.142857 Shouldn't both codes return the same sample mean, why is it different?
Olivia
  • 115
  • 6