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


C++ TFltV::PutAll方法代码示例

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


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

示例1: ConjugGrad

static void ConjugGrad(const TMatrix& Matrix, const TFltV& b, TFltV& x, 
        const int& CGMxIter, const double& RelErr, const TFltV& x0) {

    // prepare start vector
    x.Gen(Matrix.GetCols());
    if (x0.Empty()) { x.PutAll(0.0); }
    else { x = x0; }
    // do the magic
}
开发者ID:Accio,项目名称:snap,代码行数:9,代码来源:mkcca.cpp

示例2: IRLS

void TLogReg::IRLS(const TMatrix& Matrix, TFltV& y, TFltV& bb, 
                   const double& ChangeEps, const int& MaxStep, const int& Verb) {
    IAssert(Matrix.GetCols() == y.Len());

    int M = Matrix.GetRows(), R = Matrix.GetCols(), i;
    if (bb.Len() != M+1) { bb.Gen(M+1); bb.PutAll(0.0); }

    TFltV mu(R), w(R), z(R), delta;

    // adjust y
    for (i = 0; i < R; i++) {
        if (y[i] >= 1.0)
            y[i] = 0.999;
        else if (y[i] <= 0.0)
            y[i] = 0.001;
    }

    //const double eps = 0.01;
    double NewDEV = 0.0, OldDEV = -100.0;
    forever {
        Matrix.MultiplyT(bb, z);
        for (i = 0; i < R; i++) {
            z[i] += bb[M];
            // evaluate current model
            mu[i] = 1/(1 + exp(-z[i]));
            // calculate weights
            w[i] = mu[i] * (1 - mu[i]);
            // calculate adjusted dependent variables
            z[i] += (y[i] - mu[i]) / w[i];
        }
        // get new aproximation for bb
        CG(Matrix, w, z, bb, MaxStep, Verb);
        // calculate deviance (error measurement)
        NewDEV = 0.0;
        for (i = 0; i < R; i++) {
            double yi = y[i], mui = mu[i];
            NewDEV += yi*log(yi / mui) + (1 - yi)*log((1 - yi)/(1 - mui));
        }
        
        if (Verb == 1) printf(" -> %.5f\n", NewDEV);
        else if (Verb > 1) printf("NewDEV = %.5f\n", NewDEV);

        // do we stop?
        if (fabs(NewDEV - OldDEV) < ChangeEps) break;
        OldDEV = NewDEV;
    }
}
开发者ID:Accio,项目名称:snap,代码行数:47,代码来源:logreg.cpp

示例3: CG

///////////////////////////////////////////////////////////////////////
// Fast-Robust-Logistic-Regression
void TLogReg::CG(const TMatrix& Matrix, const TFltV& w, const TFltV& b, 
                 TFltV& x, const int& MaxStep, const int& Verb) { // x == bb, b == z
    int M = x.Len(), R = b.Len(), i;
    TFltV r(M), p(M), q(M), tmp(R);

    x.PutAll(0.0);
    // calculate right side of system
    for (i = 0; i < R; i++) tmp[i] = w[i] * b[i];
    Matrix.Multiply(tmp, r); r[M-1] = TLAMisc::SumVec(tmp);

    double nro, ro, alpha, beta;
    const double eps = 0.000001;

    // conjugate gradient method - CG
    // from "Templates for the soltuion of linear systems" (M == eye)
    ro = nro = TLinAlg::Norm2(r); int StepN=0;
    for (int k = 1; k <= MaxStep && nro > eps && k <= M; k++) {
        if ((Verb > 1) && (k%10 == 0)) printf(".");
        if (k == 1) {
            p = r;
        } else {
            beta = nro / ro;
            for (i = 0; i < M; i++)
                p[i] = r[i] + beta*p[i];
        }

        // q = A*p = (X'*W*X)*p = (Matrix*W*Matrix')*p
        Matrix.MultiplyT(p, tmp);
        for (i = 0; i < R; i++) tmp[i] = (tmp[i] + p[M-1]) * w[i];
        Matrix.Multiply(tmp, q); q[M-1] = TLAMisc::SumVec(tmp);

        // calcualte new x and residual
        alpha = nro / TLinAlg::DotProduct(p, q);
        for (i = 0; i < M; i++) {
            x[i] = x[i] + alpha * p[i];
            r[i] = r[i] - alpha * q[i];
        }

        ro = nro;
        nro = TLinAlg::Norm2(r);
        StepN=k;
    }
    if (Verb > 1) printf("\nnorm(r) = %.5f at k = %d\n", nro, StepN-1);
}
开发者ID:Accio,项目名称:snap,代码行数:46,代码来源:logreg.cpp


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