Exemple #1
0
void Functions::modeProfileSinc(RefArrayXd predictions, const RefArrayXd covariates, 
                               const double centroid, const double height, const double resolution)
{
    ArrayXd sincFunctionArgument = Functions::PI*(covariates - centroid)/resolution;
    ArrayXd sincFunction = sincFunctionArgument.sin() / sincFunctionArgument;


    // Multiply the profile by the height in the PSD

    predictions = height*sincFunction.square();
}
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;
}
Exemple #3
0
MatrixXd NumInt::GuassQaudrature(const int& N, double& a, double& b) {

    int N0=N-1;
    const int N1 = N0+1;
    const int N2 = N0+2;

    VectorXd xu;
    xu.setLinSpaced(N1,-1.0,1.0);


    // Legendre-Gauss-Vandermonde Matrix
    //Matrix<double,N1,N2> L = Matrix<double,N1,N2>::Zero();
    MatrixXd L(N1,N2);
    L = MatrixXd::Zero(N1,N2);

    // Derivative of Legendre-Gauss-Vandermonde Matrix
    //Matrix<double,N1,1> Lp = Matrix<double,N1,1>::Zero();
    VectorXd Lp(N1);
    Lp = VectorXd::Zero(N1);


    VectorXd dum;
    dum.setLinSpaced(N1,0.0,N0);
    ArrayXd y;
    y = cos((2*dum.array()+1)*M_PI/(2*N0+2))+(0.27/N1)*sin(M_PI*xu.array()*N0/N2);

    double deps = std::numeric_limits<double>::epsilon();

    //Initial Guess
    //Array<double,N1,1> y0 = Array<double,N1,1>::Constant(2);
    ArrayXd y0 = ArrayXd::Constant(N1,2);

    while ((y-y0).abs().matrix().maxCoeff() > deps) {


        // L.col(0) = Matrix<double,N1,1>::Constant(1);
        L.col(0) = VectorXd::Constant(N1,1);
        //Lp = Matrix<double,N1,1>::Zero();
        Lp = VectorXd::Zero(N1);

        L.col(1) = y;

        for (int k=1; k!=N1; k++)
        {
            L.col(k+1) = ((2*k+1)*L.col(k).cwiseProduct(y.matrix())-k*L.col(k-1))/(k+1);
        }

        Lp = (N2)*(L.col(N0)-L.col(N1).cwiseProduct(y.matrix())).cwiseQuotient((1-y.square()).matrix());


        y0 = y;
        y = y0-(L.col(N1).cwiseQuotient(Lp)).array();
    }

    // Gauss Points
    //Matrix<double,N1,1> z = ((a*(1-y)+b*(1+y))/2).matrix();
    VectorXd z(N1);
    z = ((a*(1-y)+b*(1+y))/2).matrix();

    // Gauss Weights
    //Matrix<double,N1,1> w;
    VectorXd w(N1);
    w = (b-a)/(((1-y.square()).matrix()).cwiseProduct(Lp.cwiseProduct(Lp))).array()*pow((double)N2/N1,2);

    // Store
    //Matrix<double,N1,2> zw;
    Matrix<double,Dynamic,Dynamic> zw(N1,2);
    zw.col(0)=z;
    zw.col(1)=w;

    return zw;
}
Exemple #4
0
    const ArrayXd negativeBinomialDist::variance(const ArrayXd &mu) const {
	return mu + mu.square()/d_theta;
    }
Exemple #5
0
    const ArrayXd  inverseGaussianDist::devResid(const ArrayXd& y, const ArrayXd& mu, const ArrayXd& wt) const {
	return wt * ((y - mu).square())/(y * mu.square());
    }
Exemple #6
0
 const ArrayXd            gammaDist::variance(const ArrayXd& mu) const {return mu.square();}
Exemple #7
0
    /** @brief Gaussian profile
     *
     *  $f(x) = a exp(\frac{-(x-b)^2}{2 c^2})$
     */
    inline VectorXcd
    Gaussian(const int N, const int b, const double c, const double a = 1){
	ArrayXd dx = ArrayXd::LinSpaced(N, 0, N-1) - b;
	VectorXd f = (- dx.square() / (2*c*c)).exp() * a;
	return f.cast<std::complex<double>>();	
    }