sampling

Oversampling functionality in Tensorflow dataset API

别来无恙 提交于 2019-11-30 04:22:22
问题 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 specific classes during dataset parsing i.e. online generation. I've seen the implementation for rejection_resample function, however this removes samples instead of duplicating them and its slows down batch generation (when target distribution is much different then initial one). The thing I would

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

寵の児 提交于 2019-11-30 03:52:40
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 image: Ultimately, I want To smooth a sequence of points using different kernels. To resize the sequence using different types of interpolations. After smoothing, I hope to have a result like : I also considered drawing my contour in a cv::Mat , filtering the Mat (using blur or morphological operations) and re-finding the contours, but is slow and suboptimal. So, ideally, I could do the job using

What are chunks, samples and frames when using pyaudio

天涯浪子 提交于 2019-11-29 21:54:44
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 = pyaudio.paInt16 CHANNELS = 2 RATE = 44100 RECORD_SECONDS = 5 WAVE_OUTPUT_FILENAME = "output.wav" p = pyaudio.PyAudio() stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK) print("* recording") frames = [] for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)): data = stream.read(CHUNK) frames.append(data)

How to get sound data sample value in c#

心已入冬 提交于 2019-11-29 15:41:59
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 get audio data sample values using Naudio library or wmp library? I am getting the sample values in this way: byte[] data = File.ReadAllBytes(File_textBox.Text); var samples=new int[data.Length]; int x = 0; for (int i = 44; i <data.Length; i += 2) { samples[x] = BitConverter.ToInt16(data, i); x++; } But I am getting negative values more like (-326260). so is this right or wrong? I mean can a sample

Interpolation/subsampling of 3D data in python without VTK

删除回忆录丶 提交于 2019-11-29 15:36:59
问题 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 centers of the grid cells and a 3D numpy array with the corresponding shape with a value for each cell center) and I want to interpolate (or you may call it subsample) this entire array to a subsampled array (e.g. size factor of 5) with linear interpolation. All the approaches I've seen this far involve

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

末鹿安然 提交于 2019-11-29 15:20:50
问题 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 socket. Hopefully code that uses one of Apple's frameworks (Audio Queues). Documentation is not very clear, and what I need is very basic. 回答1: Try the AudioQueue Framework for this. You mainly have to perform 3 steps: setup an audio format how to sample the incoming analog audio start a new recording

What does replacement mean in numpy.random.choice?

匆匆过客 提交于 2019-11-28 18:09:30
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! It controls whether the sample is returned to the sample pool. If you want only unique samples then this should be false. You can use it when you want sample some elements from a list, and meanwhile you want the elements no repeat , then you can set the " replace=False ". eg. from numpy import random as rd ary = list(range(10)) # usage In[18]: rd.choice(ary, size=8, replace=False) Out[18]: array([0, 5, 9, 8, 2, 1, 6, 3]) # no

drawing a stratified sample in R

主宰稳场 提交于 2019-11-28 10:26:52
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 <- sort(sample(x=1:N, size=n.pre$n)) If you have a stratified design, then I believe you can sample randomly within each stratum. Here is a short algorithm to do proportional sampling in each stratum, using ddply : library(plyr) set.seed(1) dat <- data.frame( id = 1:100, Category = sample(LETTERS[1:3], 100, replace=TRUE, prob=c(0.2, 0.3, 0.5)) ) sampleOne <-

sample random point in triangle [closed]

一笑奈何 提交于 2019-11-28 07:39:33
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 + (sqrt(r1) * (1 - r2)) * B + (sqrt(r1) * r2) * C where r1 and r2 are uniformly drawn from [0, 1] , and sqrt is the square root function. How do you justify that the sampled points that are uniformly distributed within triangle ABC ? EDIT As pointed out in a comment on the mathoverflow question , Graphical Gems discusses this algorithm . You have

Looping at a constant rate with high precision for signal sampling

旧时模样 提交于 2019-11-28 02:20:56
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, ()) global i i += 1 if i == 1000: i = 0 print "one second" s = sched.scheduler(time.time, time.sleep) s.enter(0.001, 1, f, ()) s.run() When I try to make the time less, it starts to exceed one second(in my computer, 1.66s at 10e-6). It it possible to run a sampling function at a specific frequency in Python? ivan_pozdeev You didn't account for the code's overhead. Each iteration, this error adds up and skews the