当前位置: 首页>>代码示例>>C++>>正文


C++ ArrayXd::sum方法代码示例

本文整理汇总了C++中ArrayXd::sum方法的典型用法代码示例。如果您正苦于以下问题:C++ ArrayXd::sum方法的具体用法?C++ ArrayXd::sum怎么用?C++ ArrayXd::sum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ArrayXd的用法示例。


在下文中一共展示了ArrayXd::sum方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: compute_grad

Vector4d compute_grad(Vector4d beta, VectorXd x, VectorXd y){
  Vector4d grad;
  ArrayXd tmp;
  ArrayXd pred = model_fun(beta, x);

  assert(x.size()==y.size());

  // beta(0)
  tmp = 1 / (1 + exp(-(x.array()-beta(2))/abs(beta(3))));
  tmp *= pred - y.array();
  grad(0) = tmp.sum() / x.size();

  // beta(1)
  tmp = 1 / (1 + exp(-(x.array()-beta(2))/abs(beta(3))));
  tmp = 1 - tmp;
  tmp *= pred - y.array();
  grad(1) = tmp.sum() / x.size();

  // beta(2)
  tmp = -(beta(0)- beta(1)) * (exp((beta(2)-x.array())/abs(beta(3)))/abs(beta(3))) \
        / (1+exp((beta(2)-x.array())/abs(beta(3)))).pow(2);
  tmp *= pred - y.array();
  grad(2) = tmp.sum() / x.size();

  // beta(3)
  tmp = (beta(0) - beta(1)) * (beta(2)-x.array()).pow(2) * sgn(beta(3)) \
        / (abs(beta(3))*pow(beta(3), 2)*(1+exp((beta(2)-x.array())/abs(beta(3)))).pow(2));
  tmp *= pred - y.array();
  grad(3) = tmp.sum() / x.size();

  return grad;
}
开发者ID:caomw,项目名称:CPBD-sharpness,代码行数:32,代码来源:nlinfit.cpp

示例2: disp

    //@{
    double                   gammaDist::aic     (const ArrayXd& y, const ArrayXd& n, const ArrayXd& mu,
						 const ArrayXd& wt, double dev) const {
	double   nn(wt.sum());
	double disp(dev/nn);
	double   ans(0), invdisp(1./disp);
	for (int i = 0; i < mu.size(); ++i)
	    ans += wt[i] * ::Rf_dgamma(y[i], invdisp, mu[i] * disp, true);
	return -2. * ans + 2.;
    }
开发者ID:L4R,项目名称:lme4,代码行数:10,代码来源:glmFamily.cpp

示例3: logValue

double MeanNormalLikelihood::logValue(RefArrayXd modelParameters)
{
    unsigned long n = observations.size();
    double lambda0;
    double lambda;
    ArrayXd argument;
    ArrayXd predictions;

    predictions.resize(n);
    predictions.setZero();
    model.predict(predictions, modelParameters);
    argument = (observations - predictions);
    argument = argument.square()*weights;

    lambda0 = lgammal(n/2.) - log(2) - (n/2.)*log(Functions::PI) + 0.5*weights.log().sum();
    lambda = lambda0 - (n/2.)*log(argument.sum());

    return lambda;
}
开发者ID:JorisDeRidder,项目名称:DIAMONDS,代码行数:19,代码来源:MeanNormalLikelihood.cpp

示例4: logGaussLikelihood

double Functions::logGaussLikelihood(const RefArrayXd observations, const RefArrayXd predictions, const RefArrayXd uncertainties)
{
    if ((observations.size() != predictions.size()) || (observations.size() != uncertainties.size()))
    {
        cerr << "Array dimensions do not match. Quitting program." << endl;
        exit(EXIT_FAILURE);
    }
    
    ArrayXd delta;
    ArrayXd lambda0;
    ArrayXd lambda;
    
    delta = ((observations - predictions)*(observations - predictions)) / (uncertainties*uncertainties);
    lambda0 = -1.*log(sqrt(2.*PI) * uncertainties);
    lambda = lambda0 -0.5*delta;
    
    return lambda.sum();

}
开发者ID:JorisDeRidder,项目名称:DIAMONDS,代码行数:19,代码来源:Functions.cpp

示例5: wtsum

    //@{
    double         inverseGaussianDist::aic     (const ArrayXd& y, const ArrayXd& n, const ArrayXd& mu,
	const ArrayXd& wt, double dev) const {
	double wtsum(wt.sum());
	return wtsum * (std::log(dev/wtsum * 2. * M_PI) + 1.) + 3. * (y.log() * wt).sum() + 2.;
    }
开发者ID:L4R,项目名称:lme4,代码行数:6,代码来源:glmFamily.cpp


注:本文中的ArrayXd::sum方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。