标签: variance

了解代表逆向有用性

所以我有一个委托定义为:

public delegate void MyDelegate<T>(T myParameter);
Run Code Online (Sandbox Code Playgroud)

Resharper建议我应该T如下逆变:

public delegate void MyDelegate<in T>(T myParameter);
Run Code Online (Sandbox Code Playgroud)

现在,我很难理解这有什么用处?我知道它阻止我制作T一个返回类型,但T除此之外,通过制作逆变会得到什么有用的约束?也就是说,当需要将委托与实例一起使用时,我可以创建哪些实例

public delegate void MyDelegate<T>(T myParameter);
Run Code Online (Sandbox Code Playgroud)

我无法创造

public delegate void MyDelegate<in T>(T myParameter);
Run Code Online (Sandbox Code Playgroud)

c# generics delegates variance

8
推荐指数
1
解决办法
1683
查看次数

如何从R中的princomp获得"方差比例"向量

这应该是非常基本的,我希望有人可以帮助我.我通过以下调用运行了主成分分析:

pca <- princomp(....)
summary(pca)
Run Code Online (Sandbox Code Playgroud)

摘要pca返回此描述:

                          PC1    PC2     PC3
Standard deviation     2.8788 2.7862  2.1845
Proportion of Variance 0.1977 0.1549 0.07831
Run Code Online (Sandbox Code Playgroud)

查看显示每台PC解释的差异的第二行.如何从变量pca以编程方式从我的脚本中提取此向量.我做了足够的搜索,找不到答案.

r variance pca princomp

8
推荐指数
2
解决办法
7249
查看次数

如何突出显示ggplot的差异?

我不明白我应该如何提出这个问题所以我使用这种方法.

我有一个纬度 - 经度数据集.下面张贴的图片是我想要制作的图片.这是我的数据集:

Latitude    Longitude
21.06941667 71.07952778
21.06941667 71.07952778
21.06666667 71.08158333
21.07186111 71.08688889
21.08625    71.07083333
21.08719444 71.07286111
21.08580556 71.07686111
21.07894444 71.08225
....
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我使用geom_path()来查找路径.现在,如图所示.我已经突出了我想要做的路径周围的白色差异.这就是我计算方差的方法:

var.latitude <- var(Data$Latitude)
var.longitude <- var(Data$Longitude)
Run Code Online (Sandbox Code Playgroud)

我使用geom_errorbar()标记了点的方差:

geom_errorbar(aes(x=Latitude,y=Longitude, ymin=Longitude-var.longitude, ymax=Longitude+var.longitude),width=0.001)+
geom_errorbarh(aes(xmin=Latitude-var.latitude,xmax=Latitude+var.latitude),height=0.001)
Run Code Online (Sandbox Code Playgroud)

谁能告诉我如何突出白色区域?

r variance ggplot2

8
推荐指数
1
解决办法
683
查看次数

在 R 调查包中对单独的 PSU 使用“调整”选项:为什么当其他层中的数据发生变化时,单个 PSU 层方差不会发生变化?

我有来自分层简单随机抽样设计的调查数据,其中某些层仅包含单个抽样单位(即使层总体规模可能>1)。这些在 R 调查包 ( http://r-survey.r-forge.r-project.org/survey/exmample-lonely.html )中被称为“孤独 PSU” 。处理这种情况有多种选择,我感兴趣的是“调整”选项。

的文档options(survey.lonely.psu="adjust")指出

“单个 PSU 层的数据以样本总平均值为中心,而不是层平均值。”

在尝试此选项时,我预计如果更改另一个层中的数据,我的单 PSU 层的方差将会改变,但事实并非如此。这是一个小例子:

library(survey)
options(survey.lonely.psu="adjust")

# sample 1
dat1 <- data.frame(N = c(3, 3, 2), h = c(1, 1, 2), y = c(2, 6, 15))
survey1 <- svydesign(~1, fpc = ~N, strata = ~h, data = dat1)
svyby(~y, by = ~h, design = survey1, FUN = svytotal)
Run Code Online (Sandbox Code Playgroud)

在结果中,请注意层 2(即单 PSU 层)的标准误差:

  h  y        se
1 1 12  3.464102
2 2 30 21.213203
Run Code Online (Sandbox Code Playgroud)

现在,如果我像这样更改层 1 中的数据 …

r survey variance

8
推荐指数
1
解决办法
3549
查看次数

计算C++中的标准差和方差

所以我发布了几次,以前我的问题很模糊

我本周开始使用C++,并且做了一个小项目

所以我试图计算标准偏差和方差

我的代码加载一个100个整数的文件,并将它们放入一个数组,计算它们,计算平均值,总和,var和sd

但我的方差有点麻烦

我不断得到一个巨大的数字 - 我感觉它与它的计算有关

我的意思和总和还可以

任何帮助或提示?

注意:

sd&mean calcs

干杯,

插口

 using namespace std;
    int main()

{

int n = 0;
int Array[100];
float mean;
float var;
float sd;
string line;
float numPoints;

ifstream myfile(“numbers.txt");

if (myfile.is_open())

{
    while (!myfile.eof())

    {
        getline(myfile, line);

        stringstream convert(line);

        if (!(convert >> Array[n]))

        {
            Array[n] = 0;
        }
        cout << Array[n] << endl;

        n++;

    }

    myfile.close();

    numPoints = n;

}
else cout<< "Error loading file" <<endl;

int sum = accumulate(begin(Array), end(Array), 0, …
Run Code Online (Sandbox Code Playgroud)

c++ arrays average variance standard-deviation

8
推荐指数
2
解决办法
3万
查看次数

Scala类型成员差异

考虑这个简短的片段:

trait Table[+A] {
  type RowType = Seq[A]
}
Run Code Online (Sandbox Code Playgroud)

Scala 2.11.7编译器给出以下错误:

covariant type A occurs in invariant position in type Seq[A] of type RowType
Run Code Online (Sandbox Code Playgroud)

为什么被A认为处于不变的位置,Seq[A]Seq它本身被定义为trait Seq[+A]

另外,如果我们忽略错误,您能否提供一个用例来说明此类型定义可能存在的问题?

scala variance higher-kinded-types

8
推荐指数
1
解决办法
354
查看次数

计算图像方差背后的理论是什么?

我试图通过使用LaplacianFilter来计算图像的模糊度.

根据这篇文章:https://www.pyimagesearch.com/2015/09/07/blur-detection-with-opencv/我必须计算输出图像的方差.问题是我从概念上不了解如何计算图像的方差.

每个像素对于每个颜色通道都有4个值,因此我可以计算每个通道的方差,但是我通过计算方差 - 协方差矩阵获得4个值,甚至16个,但根据OpenCV示例,它们只有1个数字.

在计算该数字之后,他们只是使用阈值来进行二元判定,无论图像是否模糊.

PS.我绝不是这方面的专家,因此我的陈述毫无意义.如果是这样,请很高兴编辑问题.

opencv pixel blurry variance computer-vision

8
推荐指数
2
解决办法
2811
查看次数

我可以用TraversableLike.map的类似物来"pimp my library"吗?它具有很好的变体类型?

假设我要像功能添加map到斯卡拉List,沿着线的东西list mapmap f,其功能适用f于每个元素list的两倍.(一个更严重的例子可能是实现并行或分布式地图,但我不想被那个方向的细节分心.)

我的第一种方法是

object MapMap {
    implicit def createFancyList[A](list: List[A]) = new Object {
        def mapmap(f: A => A): List[A] = { list map { a: A => f(f(a)) } }
    }
}
Run Code Online (Sandbox Code Playgroud)

现在这很好用

scala> import MapMap._
import MapMap._

scala> List(1,2,3) mapmap { _ + 1 }
res1: List[Int] = List(3, 4, 5)
Run Code Online (Sandbox Code Playgroud)

当然除了这只是为ListS,而且也没有理由我们不应该想这对任何工作Traverseable,具有map功能,例如SetS或Stream秒.所以第二次尝试看起来像

object MapMap2 {
    implicit def …
Run Code Online (Sandbox Code Playgroud)

scala variance implicit-conversion scala-collections

7
推荐指数
2
解决办法
705
查看次数

K表示当肘部曲线是平滑曲线时找到肘部

我试图使用以下代码绘制k的肘部:

load CSDmat %mydata
for k = 2:20
    opts = statset('MaxIter', 500, 'Display', 'off');
    [IDX1,C1,sumd1,D1] = kmeans(CSDmat,k,'Replicates',5,'options',opts,'distance','correlation');% kmeans matlab
    [yy,ii] = min(D1');      %% assign points to nearest center

    distort = 0;
    distort_across = 0;
    clear clusts;
    for nn=1:k
        I = find(ii==nn);       %% indices of points in cluster nn
        J = find(ii~=nn);       %% indices of points not in cluster nn
        clusts{nn} = I;         %% save into clusts cell array
        if (length(I)>0)
            mu(nn,:) = mean(CSDmat(I,:));               %% update mean
            %% Compute within class …
Run Code Online (Sandbox Code Playgroud)

matlab cluster-analysis variance k-means

7
推荐指数
1
解决办法
4364
查看次数

朴素贝叶斯:培训的每个特征的内部差异必须是积极的

试图适应朴素贝叶斯时:

    training_data = sample; % 
    target_class = K8;
 # train model
 nb = NaiveBayes.fit(training_data, target_class);

 # prediction
 y = nb.predict(cluster3);
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

??? Error using ==> NaiveBayes.fit>gaussianFit at 535
The within-class variance in each feature of TRAINING
must be positive. The within-class variance in feature
2 5 6 in class normal. are not positive.

Error in ==> NaiveBayes.fit at 498
            obj = gaussianFit(obj, training, gindex);
Run Code Online (Sandbox Code Playgroud)

任何人都可以阐明这一点以及如何解决它?请注意,我在这里阅读了类似的帖子,但我不知道该怎么办?似乎它试图基于列而不是行来拟合,类方差应该基于属于特定类的每一行的概率.如果我删除那些列然后它可以工作,但显然这不是我想要做的.

matlab classification bayesian variance naivebayes

7
推荐指数
1
解决办法
6207
查看次数