weighted

Insertion of weighted point with info in CGAL regular triangulation

為{幸葍}努か 提交于 2019-12-04 19:31:32
I'm facing a problem that I hope some others have faced before because I can't find a way out ! I have a regular triangulation in CGAL in which I wish to insert some weighted points with info std::pair<myweightpoint, myinfo> one by one and to get the handle to the vertex ( Vertex_handle ) once it is inserted ! The thing is that there is no such function. It exists several functions to insert : Vertex_handle Regular_triangulation::insert ( const Weighted_point & p ) ; That returns a Vertex_handle which is cool but does not take weighted points WITH INFO which is very important for me and what I

How can I get a weighted random pick from Python's Counter class?

∥☆過路亽.° 提交于 2019-12-04 17:17:46
问题 I have a program where I'm keeping track of the success of various things using collections.Counter — each success of a thing increments the corresponding counter: import collections scoreboard = collections.Counter() if test(thing): scoreboard[thing]+ = 1 Then, for future tests, I want to skew towards things which have generated the most success. Counter.elements() seemed ideal for this, since it returns the elements (in arbitrary order) repeated a number of times equal to the count. So I

“weighted” regression in R

爷,独闯天下 提交于 2019-12-03 17:33:41
问题 I have created a script like the one below to do something I called as "weighted" regression: library(plyr) set.seed(100) temp.df <- data.frame(uid=1:200, bp=sample(x=c(100:200),size=200,replace=TRUE), age=sample(x=c(30:65),size=200,replace=TRUE), weight=sample(c(1:10),size=200,replace=TRUE), stringsAsFactors=FALSE) temp.df.expand <- ddply(temp.df, c("uid"), function(df) { data.frame(bp=rep(df[,"bp"],df[,"weight"]), age=rep(df[,"age"],df[,"weight"]), stringsAsFactors=FALSE)}) temp.df.lm <- lm

Select element from array with probability proportional to its value

≡放荡痞女 提交于 2019-12-03 13:29:42
问题 I have an array of doubles and I want to select a value from it with the probability of each value being selected being inversely proportional to its value. For example: arr[0] = 100 arr[1] = 200 In this example, element 0 would have a 66% of being selected and element 1 a 33% chance. I am having difficulty coding this. What I have done so far is to calculate the total value of the array (the example would be 300), then I've played around with inversing the numbers before calculating them as

Frequency tables with weighted data in R

馋奶兔 提交于 2019-12-03 11:40:23
I need to calculate the frequency of individuals by age and marital status so normally I'd use: table(age, marital_status) However each individual has a different weight after the sampling of the data. How do I incorporate this into my frequency table? You can use function svytable from package survey , or wtd.table from rgrs . EDIT : rgrs is now called questionr : df <- data.frame(var = c("A", "A", "B", "B"), wt = c(30, 10, 20, 40)) library(questionr) wtd.table(x = df$var, weights = df$wt) # A B # 40 60 That's also possible with dplyr : library(dplyr) count(x = df, var, wt = wt) # # A tibble:

How can I get a weighted random pick from Python's Counter class?

一个人想着一个人 提交于 2019-12-03 11:10:43
I have a program where I'm keeping track of the success of various things using collections.Counter — each success of a thing increments the corresponding counter: import collections scoreboard = collections.Counter() if test(thing): scoreboard[thing]+ = 1 Then, for future tests, I want to skew towards things which have generated the most success. Counter.elements() seemed ideal for this, since it returns the elements (in arbitrary order) repeated a number of times equal to the count. So I figured I could just do: import random nextthing=random.choice(scoreboard.elements()) But no, that raises

Select element from array with probability proportional to its value

拈花ヽ惹草 提交于 2019-12-03 02:55:30
I have an array of doubles and I want to select a value from it with the probability of each value being selected being inversely proportional to its value. For example: arr[0] = 100 arr[1] = 200 In this example, element 0 would have a 66% of being selected and element 1 a 33% chance. I am having difficulty coding this. What I have done so far is to calculate the total value of the array (the example would be 300), then I've played around with inversing the numbers before calculating them as a percentage of the total. I can't get anything to work. In the end I desire: new randomNumber for(int

Python: Weighted coefficient of variation

穿精又带淫゛_ 提交于 2019-12-01 13:12:46
How can I calculate the weighted coefficient of variation (CV) over a NumPy array in Python? It's okay to use any popular third-party Python package for this purpose. I can calculate the CV using scipy.stats.variation , but it's not weighted. import numpy as np from scipy.stats import variation arr = np.arange(-5, 5) weights = np.arange(9, -1, -1) # Same size as arr cv = abs(variation(arr)) # Isn't weighted This can be done using the statsmodels.stats.weightstats.DescrStatsW class in the statsmodels package for calculating weighted statistics . from statsmodels.stats.weightstats import

Python: Weighted coefficient of variation

独自空忆成欢 提交于 2019-12-01 11:19:53
问题 How can I calculate the weighted coefficient of variation (CV) over a NumPy array in Python? It's okay to use any popular third-party Python package for this purpose. I can calculate the CV using scipy.stats.variation, but it's not weighted. import numpy as np from scipy.stats import variation arr = np.arange(-5, 5) weights = np.arange(9, -1, -1) # Same size as arr cv = abs(variation(arr)) # Isn't weighted 回答1: This can be done using the statsmodels.stats.weightstats.DescrStatsW class in the

Weighted sum of variables by groups with data.table

試著忘記壹切 提交于 2019-12-01 06:01:22
I am looking for a solution to compute weighted sum of some variables by groups with data.table. I hope the example is clear enough. require(data.table) dt <- data.table(matrix(1:200, nrow = 10)) dt[, gr := c(rep(1,5), rep(2,5))] dt[, w := 2] # Error: object 'w' not found dt[, lapply(.SD, function(x) sum(x * w)), .SDcols = paste0("V", 1:4)] # Error: object 'w' not found dt[, lapply(.SD * w, sum), .SDcols = paste0("V", 1:4)] # This works with out groups dt[, lapply(.SD, function(x) sum(x * dt$w)), .SDcols = paste0("V", 1:4)] # It does not work by groups dt[, lapply(.SD, function(x) sum(x * dt$w