random-sample

Weighted random sampling in Elasticsearch

爷,独闯天下 提交于 2020-01-09 19:30:52
问题 I need to obtain a random sample from an ElasticSearch index, i.e. to issue a query that retrieves some documents from a given index with weighted probability Wj/ΣWi (where Wj is a weight of row j and Wj/ΣWi is a sum of weights of all documents in this query). Currently, I have the following query: GET products/_search?pretty=true {"size":5, "query": { "function_score": { "query": { "bool":{ "must": { "term": {"category_id": "5df3ab90-6e93-0133-7197-04383561729e"} } } }, "functions": [{

Weighted random sampling in Elasticsearch

北慕城南 提交于 2020-01-09 19:29:59
问题 I need to obtain a random sample from an ElasticSearch index, i.e. to issue a query that retrieves some documents from a given index with weighted probability Wj/ΣWi (where Wj is a weight of row j and Wj/ΣWi is a sum of weights of all documents in this query). Currently, I have the following query: GET products/_search?pretty=true {"size":5, "query": { "function_score": { "query": { "bool":{ "must": { "term": {"category_id": "5df3ab90-6e93-0133-7197-04383561729e"} } } }, "functions": [{

How to generate random vector from specific user defined range?

馋奶兔 提交于 2020-01-07 05:56:11
问题 I want to generate the random vector containing the number from the user defined range. For example: numbers = [1 2 4 10] The random vector should always consist of these numbers. Eg. rand_num= [1 1 2 10 5 2 10] Thanks. 回答1: Let numbers = [1 2 4 10]; %// population to sample from N = 5; %// how many samples to take You can use randsample (Statistics Toolbox): rand_num = randsample(numbers, N, true); %// "true" means sample with replacement or randi (standard function): rand_num = numbers

How to Shuffle & Echo 5 Random Elements from a String?

痞子三分冷 提交于 2020-01-07 03:21:08
问题 a question about getting three random words out of a big string of say 200 words: $trans = __("water paradise, chicken wing, banana beach, tree trunk")?> // $trans becomes "water paradijs, kippenvleugel, bananen strand, boom tak" // elements are separated by comma's and a space Now imagine I want to get 5 random elements from that $trans string and echo that . How can I do that? Code is welcome! Please keep this syntax in your answer: $trans = the original string $shufl = selective shuffle of

Latin Hypercube Sampling from a normal distribution (Python)

…衆ロ難τιáo~ 提交于 2020-01-05 07:14:11
问题 How to generate 10 random numbers from normal distribution using latin hypercube sampling technique in python 2.7? The range of the random number should be 5 to 14. I tried following import random from random import randint iter = 10 segSize = 1 / iter for i in range(iter): segMin = i * segSize point = segMin+ (random.normalvariate(7.5,1)*segSize) pointValue = (point * (14 - 5)) + 4 print point print pointValue Thanks 回答1: Try this: def rand: import random from random import randint iter = 10

Latin Hypercube Sampling from a normal distribution (Python)

佐手、 提交于 2020-01-05 07:14:09
问题 How to generate 10 random numbers from normal distribution using latin hypercube sampling technique in python 2.7? The range of the random number should be 5 to 14. I tried following import random from random import randint iter = 10 segSize = 1 / iter for i in range(iter): segMin = i * segSize point = segMin+ (random.normalvariate(7.5,1)*segSize) pointValue = (point * (14 - 5)) + 4 print point print pointValue Thanks 回答1: Try this: def rand: import random from random import randint iter = 10

Sample() in R returning non-random sample after population vector length > 13. Why? [duplicate]

拈花ヽ惹草 提交于 2019-12-29 09:26:13
问题 This question already has answers here : Histogram of uniform distribution not plotted correctly in R (3 answers) Closed 4 years ago . The following code will return a perfectly sound sample: b <- sample(c(0,1,2,3,4,5,6,7,8,9,10,11,12), 100000, replace=TRUE) hist(b) Increasing the number for elements by 1 to 14 will result into this: b <- sample(c(0,1,2,3,4,5,6,7,8,9,10,11,12,13), 100000, replace=TRUE) hist(b) That's clearly not correct. Zero occurs more often that it should. Is there a

Randomly split data by criterion into training and testing data set using R

送分小仙女□ 提交于 2019-12-29 08:12:39
问题 Gidday, I'm looking for a way to randomly split a data frame (e.g. 90/10 split) for testing and training of a model keeping a certain grouping criteria. Imagine I have a data frame like this: > test[1:20,] companycode year expenses 1 C1 1 8.47720 2 C1 2 8.45250 3 C1 3 8.46280 4 C2 1 14828.90603 5 C3 1 665.21565 6 C3 2 290.66596 7 C3 3 865.56265 8 C3 4 6785.03586 9 C3 5 312.02617 10 C3 6 760.48740 11 C3 7 1155.76758 12 C4 1 4565.78313 13 C4 2 3340.36540 14 C4 3 2656.73030 15 C4 4 1079.46098 16

Randomly split data by criterion into training and testing data set using R

扶醉桌前 提交于 2019-12-29 08:12:00
问题 Gidday, I'm looking for a way to randomly split a data frame (e.g. 90/10 split) for testing and training of a model keeping a certain grouping criteria. Imagine I have a data frame like this: > test[1:20,] companycode year expenses 1 C1 1 8.47720 2 C1 2 8.45250 3 C1 3 8.46280 4 C2 1 14828.90603 5 C3 1 665.21565 6 C3 2 290.66596 7 C3 3 865.56265 8 C3 4 6785.03586 9 C3 5 312.02617 10 C3 6 760.48740 11 C3 7 1155.76758 12 C4 1 4565.78313 13 C4 2 3340.36540 14 C4 3 2656.73030 15 C4 4 1079.46098 16

How to generate random numbers with no repeat javascript

强颜欢笑 提交于 2019-12-28 07:12:25
问题 I am using the following code which generates random number between 0 to Totalfriends, I would like to get the random numbers but they should not be repeated. Any idea how? This is the code I am using FB.getLoginStatus(function(response) { var profilePicsDiv = document.getElementById('profile_pics'); FB.api({ method: 'friends.get' }, function(result) { // var result =resultF.data; // console.log(result); var user_ids="" ; var totalFriends = result.length; // console.log(totalFriends); var