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.

sampling
Filter by
Sorted by
Tagged with
38 votes
8 answers
98k views

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 ...
user3525533's user avatar
93 votes
13 answers
75k views

Take n random elements from a List<E>?

How can I take n random elements from an ArrayList<E>? Ideally, I'd like to be able to make successive calls to the take() method to get another x elements, without replacement.
user avatar
22 votes
1 answer
32k views

How to draw waveform of Android's music player? [closed]

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 ...
INeedHelpWithWaveforms's user avatar
5 votes
2 answers
6k views

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 ...
gran_profaci's user avatar
  • 8,269
3 votes
1 answer
2k views

Looping at a constant rate with high precision for signal sampling

I am trying to sample a signal at 10Khz in Python. There is no problem when try to run this code(at 1KHz): import sched, time i = 0 def f(): # sampling function s.enter(0.001, 1, f, ()) ...
Guray Yildirim's user avatar
48 votes
5 answers
108k views

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 ...
WGP's user avatar
  • 738
6 votes
1 answer
2k views

Efficient algorithm for generating unique (non-repeating) random numbers

I want to solve the following problem. I have to sample among an extremely large set, of the order of 10^20 and extracting a sample without repetitions of size about 10%-20%. Given the size of the set,...
Santiago Hernandez Orozco's user avatar
40 votes
1 answer
52k views

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:...
shiva's user avatar
  • 2,543
19 votes
1 answer
13k views

sample random point in triangle [closed]

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 ...
dsg's user avatar
  • 13k
14 votes
4 answers
3k views

Random sampling to give an exact sum

I want to sample 140 numbers between 1000 to 100000 such that the sum of these 140 numbers is around 2 million (2000000): sample(1000:100000,140) such that: sum(sample(1000:100000,140)) = 2000000 ...
Hardik Gupta's user avatar
  • 4,750
4 votes
5 answers
8k views

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 ...
Roland Kofler's user avatar
79 votes
2 answers
28k views

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's user avatar
  • 1,343
14 votes
8 answers
20k views

OpenCV, how to use arrays of points for smoothing and sampling contours?

I have a problem to get my head around smoothing and sampling contours in OpenCV (C++ API). Lets say I have got sequence of points retrieved from cv::findContours (for instance applied on this this ...
Quentin Geissmann's user avatar
13 votes
1 answer
40k views

Taking a disproportionate sample from a dataset in R

If I have a large dataset in R, how can I take random sample of the data taking into consideration the distribution of the original data, particularly if the data are skewed and only 1% belong to a ...
simplyme's user avatar
  • 221
13 votes
4 answers
30k views

Stratified splitting of pandas dataframe into training, validation and test set

The following extremely simplified DataFrame represents a much larger DataFrame containing medical diagnoses: medicalData = pd.DataFrame({'diagnosis':['positive','positive','negative','negative','...
Oblomov's user avatar
  • 9,263
7 votes
1 answer
2k views

How to repeat 1000 times this random walk simulation in R?

I'm simulating a one-dimensional and symmetric random walk procedure: y[t] = y[t-1] + epsilon[t] where white noise is denoted by epsilon[t] ~ N(0,1) in time period t. There is no drift in this ...
Übel Yildmar's user avatar
6 votes
2 answers
2k views

Randomly selecting values from an existing matrix after adding a vector (in R)

Thank you so much for your help in advance! I am trying to modify an existing matrix such that, when a new line is added to the matrix, it removes values from the preexisting matrix. For example, I ...
Laura's user avatar
  • 689
2 votes
2 answers
1k views

accurate sampling in c++

I want to sample values I get from a gpio 4000 times per second, currently I do something like that: std::vector<int> sample_a_chunk(unsigned int rate, unsigned int block_size_in_seconds) { ...
Marinos K's user avatar
  • 1,799
2 votes
1 answer
3k views

How to get sound data sample value in c#

I need to get the sample values of sound data of a WAV file so that by using those sample values i need to get the amplitude values of that sound data in every second. Important: Is there any way to ...
azeem's user avatar
  • 103
58 votes
8 answers
23k views

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 ...
Alex's user avatar
  • 4,884
12 votes
4 answers
7k views

Oversampling functionality in Tensorflow dataset API

I would like to ask if current API of datasets allows for implementation of oversampling algorithm? I deal with highly imbalanced class problem. I was thinking that it would be nice to oversample ...
K Kolasinski's user avatar
8 votes
1 answer
3k views

Pandas: Sampling from a DataFrame according to a target distribution

I have a Pandas DataFrame containing a dataset D of instances drawn from a distribution x. x may be a uniform for example. Now, I want to draw n samples from D, sampled according to some new ...
meow's user avatar
  • 975
7 votes
2 answers
17k views

Why set.seed() affects sample() in R

I always thought set.seed() only makes random variable generators (e.g., rnorm) to generate a unique sequence for any specific set of input values. However, I'm wondering, why when we set the set.seed(...
rnorouzian's user avatar
  • 7,457
6 votes
2 answers
3k views

AudioRecord object not initializing in a project

When I am trying to record an audio through my Nexus 5 using following code record = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat....
Kabir's user avatar
  • 1,469
6 votes
6 answers
4k views

How do I call CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer?

I'm trying to figure out how to call this AVFoundation function in Swift. I've spent a ton of time fiddling with declarations and syntax, and got this far. The compiler is mostly happy, but I'm left ...
nhgrif's user avatar
  • 61.7k
6 votes
2 answers
4k views

Simulate samples from a joint cumulative distribution function?

I have a joint density function for two independent variables X and Y. And I now want to sample new x,y from this distribution. What I believe I have to do is to find the joint cumulative ...
Groot's user avatar
  • 14.1k
5 votes
5 answers
1k views

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 ...
user1320502's user avatar
  • 2,530
4 votes
2 answers
11k views

Interpolation/subsampling of 3D data in python without VTK

What I want to do is rather simple but I havent found a straightforward approach thus far: I have a 3D rectilinear grid with float values (therefore 3 coordinate axes -1D numpy arrays- for the ...
somada141's user avatar
  • 1,274
4 votes
1 answer
5k views

How to play a sound with a given sample rate in Java?

I was wondering if there is a library or something to play a sound on a given sample rate (20–20,000 Hz). Actually, I found something but I'm not understanding how I can make it work!
user3538081's user avatar
4 votes
5 answers
5k views

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 ...
ely's user avatar
  • 76k
4 votes
2 answers
6k views

Simplest way to capture raw audio from audio input for real time processing on a mac

What is the simplest way to capture audio from the built in audio input and be able to read the raw sampled values (as in a .wav) in real time as they come in when requested, like reading from a ...
user497804's user avatar
3 votes
1 answer
1k views

Controlling sampling for crossvalidation in the caret R package

I have the following problem. In a data set from N subjects I have several samples per subject. I want to train a model on the data set, but I would like to make sure that in each resampling, in the ...
January's user avatar
  • 16.7k
3 votes
1 answer
6k views

Change the playback rate of a track in real time on Android

I would like to know if somebody knows a library to changing the playback rate of a track in real time. My idea is to load a track and change its playback rate to half or double. Firstly, I tried with ...
ahmontero's user avatar
  • 351
3 votes
2 answers
3k views

Sampling small data frame from a big dataframe

I am trying to sample a data frame from a given data frame such that there are enough samples from each of the levels of a variable. This can be achieved by separating the data frame by the levels and ...
Stat-R's user avatar
  • 5,160
2 votes
2 answers
4k views

Stratified sampling - not enough observations

What I would like to achieve is get a 10% sample from each group (which is a combination of 2 factors - recency and frequency category). So far I have thought about package sampling and function ...
Radim Sevcik's user avatar
2 votes
1 answer
311 views

MATLAB: Comparing 2 arrays with different lengths

I have two arrays with different lengths (due to different sampling rates) that I need to compare. I'd like to downsample the larger array to match the smaller one in length, however the factor is not ...
Bensa's user avatar
  • 139
1 vote
2 answers
639 views

CV and under sampling on a test fold

I am a bit lost on building a ML classifier with imbalanced data (80:20). The dataset has 30 columns; the target is Label. I want to predict the major class. I am trying to reproduce the following ...
Math's user avatar
  • 231
1 vote
1 answer
2k views

Monte Carlo integration using importance sampling given a proposal function

Given a Laplace Distribution proposal: g(x) = 1/2*e^(-|x|) and sample size n = 1000, I want to Conduct the Monte Carlo (MC) integration for estimating θ: via importance sampling. Eventually I want ...
Chris95's user avatar
  • 75
1 vote
3 answers
6k views

Android SENSOR_DELAY_FASTEST isn't fast enough

I'm using the sensors to balance a robot, but SENSOR_DELAY_FASTEST only provides a 10Hz sampling rate, which is simply not fast enough. Is there a way of sampling even faster? Is there a way of ...
Hamish's user avatar
  • 13
1 vote
1 answer
4k views

Stratified sample when some strata are too small

I need to draw a stratified sample with n observation in each stratum, but some strata have fewer observations than n. If a stratum has too few observations (say, k<n observations), I want to ...
Dr. Beeblebrox's user avatar
0 votes
1 answer
842 views

Update values of a matrix variable in tensorflow, advanced indexing

I would like to create a function that for every line of a given data X, is applying the softmax function only for some sampled classes, lets say 2, out of K total classes. In simple python the code ...
Cfis Yoi's user avatar
  • 241
40 votes
12 answers
20k views

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 ...
Menon A.'s user avatar
  • 580
17 votes
2 answers
7k views

Is there an algorithm for weighted reservoir sampling? [closed]

Is there an algorithm for how to perform reservoir sampling when the points in the data stream have associated weights?
Budhapest's user avatar
  • 601
17 votes
5 answers
19k views

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 ...
Aditya Singh's user avatar
15 votes
6 answers
8k views

How to keep a random subset of a stream of data?

I have a stream of events flowing through my servers. It is not feasible for me to store all of them, but I would like to periodically be able to process some of them in aggregate. So, I want to ...
twk's user avatar
  • 17.1k
14 votes
1 answer
6k views

Efficiently picking a random element from a chained hash table?

Just for practice (and not as a homework assignment) I have been trying to solve this problem (CLRS, 3rd edition, exercise 11.2-6): Suppose we have stored n keys in a hash table of size m, with ...
Bicheng.Cao's user avatar
14 votes
6 answers
16k views

Select cells randomly from NumPy array - without replacement

I'm writing some modelling routines in NumPy that need to select cells randomly from a NumPy array and do some processing on them. All cells must be selected without replacement (as in, once a cell ...
robintw's user avatar
  • 28.1k
13 votes
4 answers
5k views

Profiling a (possibly I/O-bound) process to reduce latency

I want to improve the performance of a specific method inside a larger application. The goal is improving latency (wall-clock time spent in a specific function), not (neccessarily) system load. ...
Arnout Engelen's user avatar
11 votes
2 answers
8k views

Profilers Instrumenting Vs Sampling

I am doing a study to between profilers mainly instrumenting and sampling. I have came up with the following info: sampling: stop the execution of program, take PC and thus deduce were the program is ...
Syntax_Error's user avatar
  • 6,092
10 votes
2 answers
16k views

Android: startRecording() called on an uninitialized AudioRecord when SAMPLERATE set to 44100

I get an error, when I set the sampling rate to 44100 for the AudioRecord object. When it's 22050 it works fine. 02-16 10:45:45.099 24021-24021/com.vlad.jackcomms E/AudioRecord﹕ frameCount 1024 < ...
user3333414's user avatar