sampling

Sampling from discrete probability distribution from first principles

家住魔仙堡 提交于 2019-12-12 18:33:17
问题 I have a set S={a1,a2,a3,a4,a5,......,an}. The probability with which each of the element is selected is {p1,p2,p3,p4,p5,...,pn} respectively (where ofcourse p1+p2+p3+p4+p5+....+pn=1}. I want to simulate an experiment which does that. However I wish to do that without any libraries (i.e from first principles) I'm using the following method: 1) I map the elements on the real number line as follows X(a1)=1; X(a2)=2; X(a3)=3; X(a4)=4; X(a5)=5;....,X(an)=n 2) Then I calculate the cumulative

Efficiently sample from arbitrary multivariate function

半世苍凉 提交于 2019-12-12 13:18:29
问题 I would like to sample from an arbitrary function in Python. In Fast arbitrary distribution random sampling it was stated that one could use inverse transform sampling and in Pythonic way to select list elements with different probability it was mentioned that one should use inverse cumulative distribution function. As far as I undestand those methods only work the univariate case. My function is multivariate though and too complex that any of the suggestions in https://stackoverflow.com/a

Sampling from a texture which is also a render target

回眸只為那壹抹淺笑 提交于 2019-12-12 11:41:02
问题 I know this technically isn't supported (and as far as I can tell it's undefined behavior) but is it really a fatally horrible thing to sample from a texture which is also being written to? I ask because I need to read from a depth texture which I also need to write to, if I can't do this it means I will have to copy the depth texture and if it isn't that big of a deal I don't see the harm in simply copying it? Thanks for any help! 回答1: Yes, it's fatal and triggers undefined behaviour. Just

Logarithmic sampling

三世轮回 提交于 2019-12-12 10:18:57
问题 I am working with values between [minValue,maxValue] and I want to create a vector of values in between this range. But I want more values near to the minValue. Example: min = 1 max = 100 vector = [1,1.1,1.5,2,3,5,10,15,30,50,100]; Something like that. The goal is to be more accurate around the minimum. Is that possible to implement that? 回答1: You can start with by generating numbers from 0 to 1 with constant step (for example 0.1). Then power them with some exponent - the bigger exponent,

Quickly sampling large number of rows from large dataframes in python

霸气de小男生 提交于 2019-12-12 03:44:40
问题 I have a very large dataframe (about 1.1M rows) and I am trying to sample it. I have a list of indexes (about 70,000 indexes) that I want to select from the entire dataframe. This is what Ive tried so far but all these methods are taking way too much time: Method 1 - Using pandas : sample = pandas.read_csv("data.csv", index_col = 0).reset_index() sample = sample[sample['Id'].isin(sample_index_array)] Method 2 : I tried to write all the sampled lines to another csv. f = open("data.csv",'r')

Android realtime audio acquisition - losing some samples?

痞子三分冷 提交于 2019-12-12 02:34:23
问题 I wrote this class, to acquire audio data. I want to use the audio input to sample realtime RF signals. I sample @ 44kHz, and I expect to know the elapsed time by measuring the total acquired samples, knowing the sample frequency. I don't know why I found a delta time between elapsed time measured by system.nanoTime and acquired samples divided by frequency. Why this delta of about 170ms changing each time I start/stop acquisition? Am I losing samples from acquired signal? Basically, what I

Randomly Assign Integers in R within groups without replacement

懵懂的女人 提交于 2019-12-12 01:18:13
问题 I am running an experiment with two experiments: experiment_1 and experiment_2. Each experiment has 5 different treatments (i.e. 1, 2, 3, 4, 5). We are trying to randomly assign the treatments within groups. We would like to do this via sampling without replacement iteratively within each group. We want to do this to insure that we get as a balanced a sample as possible in the treatment (e.g. we don't want to end up with 4 subjects in group 1 getting assigned to treatment 2 and no one getting

Improve performance calculating a random sample matching specific conditions in pandas

只愿长相守 提交于 2019-12-11 15:57:58
问题 For some dataset group_1 I need to iterate over all rows k times for robustness and find a matching random sample of another data frame group_2 according to some criteria expressed as data frame columns. Unfortunately, this is fairly slow. How can I improve performance? The bottleneck is the apply -ed function, i.e. randomMatchingCondition . import tqdm import numpy as np import pandas as pd from tqdm import tqdm tqdm.pandas() seed = 47 np.random.seed(seed) ###################################

Grouping rows from an R dataframe together when randomly assigning to training/testing datasets

只谈情不闲聊 提交于 2019-12-11 10:34:07
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 4 years ago . I have a dataframe that consists of blocks of X rows, each corresponding to a single individual (where X can be different for each individual). I'd like to randomly distribute these individuals into train, test and validation samples but so far I haven't been able to get the syntax correct to ensure that each of a user's X rows are always collected into the same subsample. For

How to write the remaining data frame in R after randomly subseting the data

淺唱寂寞╮ 提交于 2019-12-11 10:00:11
问题 I took a random sample from a data frame. But I don't know how to get the remaining data frame. df <- data.frame(x=rep(1:3,each=2),y=6:1,z=letters[1:6]) #select 3 random rows df[sample(nrow(df),3)] What I want is to get the remaining data frame with the other 3 rows. 回答1: sample sets a random seed each time you run it, thus if you want to reproduce its results you will either need to set.seed or save its results in a variable. Addressing your question, you simply need to add - before your