mean

Parallel.For() with Interlocked.CompareExchange(): poorer performance and slightly different results to serial version

懵懂的女人 提交于 2019-12-18 09:39:10
问题 I experimented with calculating the mean of a list using Parallel.For() . I decided against it as it is about four times slower than a simple serial version. Yet I am intrigued by the fact that it does not yield exactly the same result as the serial one and I thought it would be instructive to learn why. My code is: public static double Mean(this IList<double> list) { double sum = 0.0; Parallel.For(0, list.Count, i => { double initialSum; double incrementedSum; SpinWait spinWait = new

Calculating Mean of arrays with different lengths

时光毁灭记忆、已成空白 提交于 2019-12-18 05:46:07
问题 Is it possible to calculate the mean of multiple arrays, when they may have different lengths? I am using numpy. So let's say I have: numpy.array([[1, 2, 3, 4, 8], [3, 4, 5, 6, 0]]) numpy.array([[5, 6, 7, 8, 7, 8], [7, 8, 9, 10, 11, 12]]) numpy.array([[1, 2, 3, 4], [5, 6, 7, 8]]) Now I want to calculate the mean, but ignoring elements that are 'missing' (Naturally, I can not just append zeros as this would mess up the mean) Is there a way to do this without iterating through the arrays? PS.

Confusion about (Mean) Average Precision

我怕爱的太早我们不能终老 提交于 2019-12-18 04:57:06
问题 In this question I asked clarifications about the precision-recall curve. In particular, I asked if we have to consider a fixed number of rankings to draw the curve or we can reasonably choose ourselves. According to the answer, the second one is correct. However now I have a big doubt about the Average Precision (AP) value: AP is used to estimate numerically how good is our algorithm given a certain query. Mean Average Precision (MAP) is average precision on multiple queries. My doubt is: if

Dealing with NAs when calculating mean (summarize_each) on group_by

六眼飞鱼酱① 提交于 2019-12-18 04:44:08
问题 I have a data frame md: md <- data.frame(x = c(3,5,4,5,3,5), y = c(5,5,5,4,4,1), z = c(1,3,4,3,5,5), device1 = c("c","a","a","b","c","c"), device2 = c("B","A","A","A","B","B")) md[2,3] <- NA md[4,1] <- NA md I want to calculate means by device1 / device2 combinations using dplyr: library(dplyr) md %>% group_by(device1, device2) %>% summarise_each(funs(mean)) However, I am getting some NAs. I want the NAs to be ignored (na.rm = TRUE) - I tried, but the function doesn't want to accept this

Find and replace missing values with row mean

那年仲夏 提交于 2019-12-18 04:12:50
问题 I have a data frame with NAs and I want to replace the NAs with row means c1 = c(1,2,3,NA) c2 = c(3,1,NA,3) c3 = c(2,1,3,1) df = data.frame(c1,c2,c3) > df c1 c2 c3 1 1 3 2 2 2 1 1 3 3 NA 3 4 NA 3 1 so that > df c1 c2 c3 1 1 3 2 2 2 1 1 3 3 3 3 4 2 3 1 回答1: Very similar to @baptiste's answer > ind <- which(is.na(df), arr.ind=TRUE) > df[ind] <- rowMeans(df, na.rm = TRUE)[ind[,1]] 回答2: I think this works, df[which(is.na(df), arr.ind=TRUE)] <- rowMeans(df[!complete.cases(df), ], na.rm=TRUE) 回答3:

Caching the mean of a Vector in R

旧时模样 提交于 2019-12-17 18:44:44
问题 I am learning R and came across some code as part of the practice assignment. makeVector <- function(x = numeric()) { m <- NULL set <- function(y) { x <<- y m <<- NULL } get <- function() x setmean <- function(mean) m <<- mean getmean <- function() m list(set = set, get = get, setmean = setmean, getmean = getmean) } The documentation says: The function, makeVector creates a special "vector", which is really a list containing a function to set the value of the vector get the value of the

Calculating weighted mean and standard deviation

跟風遠走 提交于 2019-12-17 18:22:22
问题 I have a time series x_0 ... x_t . I would like to compute the exponentially weighted variance of the data. That is: V = SUM{w_i*(x_i - x_bar)^2, i=1 to T} where SUM{w_i} = 1 and x_bar=SUM{w_i*x_i} ref: http://en.wikipedia.org/wiki/Weighted_mean#Weighted_sample_variance The goal is to basically weight observations that are further back in time less. This is very simple to implement but I would like to use as much built in funcitonality as possible. Does anyone know what this corresponds to in

Mean of a column in a data frame, given the column's name

断了今生、忘了曾经 提交于 2019-12-17 10:33:39
问题 I'm inside a big function I have to write. In the last part I have to calculate the mean of a column in a data frame. The name of the column I am operating on is given as an argument to the function. 回答1: I think you're asking how to compute the mean of a variable in a data frame, given the name of the column. There are two typical approaches to doing this, one indexing with [[ and the other indexing with [ : data(iris) mean(iris[["Petal.Length"]]) # [1] 3.758 mean(iris[,"Petal.Length"]) # [1

统计词汇

人走茶凉 提交于 2019-12-16 15:03:03
统计术语 TAG: 教育理论 A acceptance region  接受区域 adjusted  校正的 allocation  配置、布局 alternative hypothesis  备择假设 * analysis of variance  方差分析 * analysis of covariance  协方差分析 ANOCOVA  =Analysis of covariance * ANOVA  =Analysis of variance arithmetic mean  算术平均值 association  关联性 * assumed mean  假定平均值 * asymmetric distribution  非对称分布 autoregressive  自回归(的) averages  平均量 B bar chart  条线图 Bartlett\'s test  巴特利特检验 * Bayes, -ian  贝叶斯的、贝叶斯 beta function  贝塔函数 between  (间)内 bias  偏倚 biased question  有偏质问 * binomial distribution  二项分布 binomial theorem  二项定理 bioassay  生物鉴定法 bivariate normal distribution  二元正态分布

How to convert zeros into NaN and then take mean afterwards

寵の児 提交于 2019-12-14 04:12:47
问题 I have one big 5D matrix and I want to split the matrix in 10 parts containing 57 rows and 92 columns and then take the means of each matrix (10 matrices) while ignoring zeros. I am trying this one example. While applying the second loop, Undefined function M_ii error is showing in Matlab. val = zeros(57,92,1,1,10); % Create N matrices N = 10; for i = 1:N eval(sprintf('M_%d = val(:,:,1,1,%d);', i, i)); end for i = 1:10 M_i(M_i==0)=NaN; Mean_1=mean(M_i); mean_1=mean(Mean_1,2); end 回答1: You