sampling

Random sampling to give an exact sum

时光怂恿深爱的人放手 提交于 2019-12-01 03:32:11
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 Any pointers how I can achieve this? There exist an algorithm for generating such random numbers. Originally created for MATLAB , there is an R implementation of it: Surrogate::RandVec Citation from MATLAB script comment: % This generates an n by m array x, each of whose m columns % contains n random values lying in the interval [a,b], but % subject to the condition that their sum be equal to s. The %

AudioRecord object not initializing in a project

元气小坏坏 提交于 2019-12-01 02:27:14
问题 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.ENCODING_PCM_8BIT, BYTE_OF_SAMPLE * bufferSampleSize); record.startRecording(); Then I am getting following exceptions in logcat: E/AudioRecord: AudioFlinger could not create record track, status: -1 E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1. E/android

accurate sampling in c++

…衆ロ難τιáo~ 提交于 2019-12-01 00:30:01
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) { std::vector<std::int> data; constexpr unsigned int times = rate * block_size_in_seconds; constexpr unsigned int delay = 1000000 / rate; // microseconds for (int j=0; j<times; j++) { data.emplace_back(/* read the value from the gpio */); std::this_thread::sleep_for(std::chrono::microseconds(delay)); } return data; } yet according to the reference sleep_for is guaranteed to wait for at least the specified

Random sampling to give an exact sum

大城市里の小女人 提交于 2019-11-30 23:53:03
问题 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 Any pointers how I can achieve this? 回答1: There exist an algorithm for generating such random numbers. Originally created for MATLAB, there is an R implementation of it: Surrogate::RandVec Citation from MATLAB script comment: % This generates an n by m array x, each of whose m columns % contains n

Sampling from a discrete probability distribution in C++

最后都变了- 提交于 2019-11-30 22:44:38
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 and/or ubiquitious third party add-ons always include a full range of probability tools. A friend billed up Boost to be the equivalent ubiquitous add-on for C++, but as I read the Boost documentation, even it seems to have a dearth of what I would consider extremely elementary built-ins. I cannot find a built in that takes some sort of array of discrete

Oversampling functionality in Tensorflow dataset API

旧街凉风 提交于 2019-11-30 20:21:27
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 like to achieve is: to take an example, look at its class probability decide if duplicate it or not.

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

怎甘沉沦 提交于 2019-11-30 19:14:35
问题 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! 回答1: Here's complete example not requiring any external library : import javax.sound.sampled.*; public class SoundUtils { public static float SAMPLE_RATE = 8000f; public static void tone(int hz, int msecs) throws LineUnavailableException { tone(hz, msecs, 1.0); } public static void tone(int hz, int msecs, double

Sampling from a discrete probability distribution in C++

自古美人都是妖i 提交于 2019-11-30 17:40:09
问题 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 and/or ubiquitious third party add-ons always include a full range of probability tools. A friend billed up Boost to be the equivalent ubiquitous add-on for C++, but as I read the Boost documentation, even it seems to have a dearth of what I would

Android SENSOR_DELAY_FASTEST isn't fast enough

南楼画角 提交于 2019-11-30 16:40:16
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 polling the sensors rather than waiting for a SensorEvent ? Is there a way of sampling even faster? SENSOR_DELAY_FASTEST is a 0ms delay. You cannot have negative time, at least as far as physicists have determined. Hence, there is no "faster" delay than SENSOR_DELAY_FASTEST . Use Traceview to determine where your time is being taken up. It is possible that it is your code that is slowing down your

Algorithms for determining the key of an audio sample

烂漫一生 提交于 2019-11-30 10:14:08
问题 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 thing. Can anyone give a bit of a layman's explanation about how this would work? To mathematically deduce the key of a song by analysing the frequency spectrum for chord progressions etc. This topic interests me a lot! Edit - brilliant sources and a