小编Ric*_*ing的帖子

Param不会改变std :: chi_squared_distribution

根据这个问题的答案,我试图<random>通过使用来改变分布的参数.param().下面是一个玩具示例,我正在尝试这样做.

对于卡方和正态分布,我有一个生成两个值的函数,第二个参数已被更改.param().我多次运行这两个函数并打印出两者的平均结果.正如预期的那样,正常函数产生0和10的平均结果.出乎意料的是,卡方函数产生4和4的平均结果,而不是我对4和3的预期.为什么我对卡方分布的预期有所偏差?

#include <iostream>
#include <random>
#include <vector>

using namespace std;

vector<double> chisqtest(mt19937_64 &gen)
{
  vector<double> res(2);
  chi_squared_distribution<double> chisq_dist(4);
  res[0] = chisq_dist(gen);
  chisq_dist.param(std::chi_squared_distribution<double>::param_type (3));
  res[1] = chisq_dist(gen);
  return res;
}

vector<double> normtest(mt19937_64 &gen)
{
  vector<double> res(2);
  normal_distribution<double> norm_dist(0,1);
  res[0] = norm_dist(gen);
  norm_dist.param(std::normal_distribution<double>::param_type (10,1));
  res[1] = norm_dist(gen);
  return res;
}

int main() {
  unsigned int n = 100000;
  mt19937_64 gen(1);

  vector<double> totals = {0,0}, res(2);
  for(unsigned int i = 0; i < n; …
Run Code Online (Sandbox Code Playgroud)

c++ random chi-squared

6
推荐指数
0
解决办法
94
查看次数

斯卡拉猫州立莫纳德

我有一个类,该类具有一个参数方法,该方法可产生结果并返回与自身类似的对象,但具有更新的状态供以后使用。

例如,下面包含此类的简单示例以及如何使用它:

case class Foo(x: Double) {
  def bar(y: Double): (Foo, Double) = (Foo(x + y), x / (x + y))
}

val res = Vector(1.0,2.0,3.0,4.0).foldLeft((Foo(0), 0.0))((foo, x) => foo._1.bar(x))

res._1.bar(3.0)
Run Code Online (Sandbox Code Playgroud)

我已经看过Cats State monad,并希望我可以使用它避免使状态(“ x”成员)混乱。这里的示例接近我想要的示例但是返回新状态的函数没有任何参数,并且状态不会在类似循环的操作中传递(而是在表达式之间传递)。关于Cats,我是一个完全的新手,但是我是否吠错了树?

scala scala-cats

5
推荐指数
1
解决办法
296
查看次数

标签 统计

c++ ×1

chi-squared ×1

random ×1

scala ×1

scala-cats ×1