Questions tagged [weighted]

questions about problems that use a weight function, e.g. weighted mean, weighted sampling

A weight function is a mathematical device used when performing a sum, integral, or average to give some elements more "weight" or influence on the result than other elements in the same set. The result of this application of a weight function is a weighted sum or weighted average.

Weight functions occur frequently in statistics and analysis, and are closely related to the concept of a measure. Weight functions can be employed in both discrete and continuous settings.

615 questions
11
votes
3 answers

Weighted random sampling in Elasticsearch

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…
dpaluy
  • 3,537
  • 1
  • 28
  • 42
11
votes
4 answers

Select element from array with probability proportional to its value

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…
user2341412
  • 413
  • 2
  • 8
  • 14
10
votes
6 answers

How to weight a list of ranks by a numeric value by individual in R

In R I want to allocate projects to people based on their rank preferences but also their performance. Say I have 5 projects and 3 people. In this case, all three people want project A because it's their top preference but Anna should get it because…
adkane
  • 1,429
  • 14
  • 29
10
votes
4 answers

Weighted win percentage by number of games played

Im looking to create a ranking system for users on a gaming site. The system should be based of a weighted win percentage with the weighted element being the number of games played. For instance: 55 wins and 2 losses = 96% win percentage 1 win and 0…
Dave Chenell
  • 601
  • 1
  • 8
  • 23
10
votes
2 answers

weighted mean in dplyr for multiple columns

I'm trying to calculate the weighted mean for multiple columns using dplyr. at the moment I'm stuck with summarize_each which to me seems to be part of the solution. here's some example code: library(dplyr) f2a <- c(1,0,0,1) f2b <- c(0,0,0,1) f2c <-…
Jan
  • 3,825
  • 3
  • 31
  • 51
9
votes
2 answers

Fastest way to take the weighted sum of the columns of a matrix in R

I need the weighted sum of each column of a matrix. data <- matrix(1:2e7,1e7,2) # warning large number, will eat up >100 megs of memory weights <- 1:1e7/1e5 system.time(colSums(data*weights)) system.time(apply(data,2,function(x)…
Anirban
  • 271
  • 2
  • 8
8
votes
1 answer

How to use weights in a logistic regression

I want to calculate (weighted) logistic regression in Python. The weights were calculated to adjust the distribution of the sample regarding the population. However, the results don´t change if I use weights. import numpy as np import pandas as pd …
Banjo
  • 1,191
  • 1
  • 11
  • 28
8
votes
1 answer

Elasticsearch random selection based on weighting out of 100

I have been running a Rails site for a couple of years and some articles are being pulled from the DB based on a weight field. The data structure is: {name: 'Content Piece 1', weight: 50} {name: 'Content Piece 2', weight: 25} {name: 'Content Piece…
Arthur
  • 1,970
  • 4
  • 18
  • 19
8
votes
2 answers

C++. Weighted std::shuffle

Is there a way to do nice and elegant weighted shuffling using standard library? There is std::discrete_distribution. What I want is something like this: std::vector data { N elements }; std::vector weights { N weights…
Y N
  • 811
  • 1
  • 6
  • 22
7
votes
1 answer

Which algorithm/implementation for weighted similarity between users by their selected, distanced attributes?

Data Structure: User has many Profiles (Limit - no more than one of each profile type per user, no duplicates) Profiles has many Attribute Values (A user can have as many or few attribute values as they like) Attributes belong to a category …
StringsOnFire
  • 2,726
  • 5
  • 28
  • 50
7
votes
1 answer

Weighted sum of variables by groups with data.table

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] #…
djhurio
  • 5,437
  • 4
  • 27
  • 48
6
votes
1 answer

XGBRegressor with weights and base_margin: out of sample validation possible?

I have an old linear model which I wish to improve using XGBoost. I have the predictions from the old model, which I wish to use as a base margin. Also, due to the nature of what I'm modeling, I need to use weights. My old glm is a poisson…
6
votes
2 answers

PostgreSQL - making ts_rank take the ts_vector position as-is or defining a custom ts_rank function

I'm performing weighted search on a series of items in an e-commerce platform. The problem I have is ts_rank is giving me the exact same value for different combinations of words, even if the ts_vector gives different positions for each set of…
5
votes
3 answers

Weighted Shuffle of an Array or Arrays?

What is a good algorithm that shuffles an array or arrays using weights from the nested arrays? Example: $array = array( array("name"=>"John", "rank"=>3), array("name"=>"Bob", "rank"=>1), array("name"=>"Todd", "rank"=>8), …
Jake Wilson
  • 88,616
  • 93
  • 252
  • 370
5
votes
1 answer

Weighted linear regression in R with lm() and svyglm(). Same model, different results

I want to do a linear regression applying survey weights in R studio. I have seen that it is possible to do this with the lm() function, which enables me to specify the weights I want to use. However, it is also possible to do this with the svyglm()…
cholo.trem
  • 314
  • 2
  • 9
1
2
3
40 41