Example #1
0
rowvec dF2du(unsigned row, irowvec causes, const DataPairs &data, const gmat &sigma, vec u){

  // Attaining variance covariance matrix etc. (conditional on u)
  vmat cond_sig = sigma(causes);
  vec cond_mean = cond_sig.proj*u;

  rowvec alp = data.alpha_get(row, causes);
  rowvec gam = data.gamma_get(row, causes);
  colvec alpgam = alp.t() - gam.t();

  double cdf = pn(alpgam, cond_mean, cond_sig.vcov);

  vec ll = sqrt(diagvec(cond_sig.vcov));
  mat Lambda = diagmat(ll);
  mat iLambda = diagmat(1/ll);
  mat R = iLambda*cond_sig.vcov*iLambda;
  mat LR = Lambda*R;
  double r = R(0,1);

  vec ytilde = iLambda*(alpgam - cond_mean);
  vecmat D = Dbvn(ytilde(0),ytilde(1),r);
  mat M = -LR*D.V;

  vec dcdfdu = trans(cond_sig.proj)*cond_sig.inv*M;

  rowvec dF2du_1 = data.dpiduMarg_get(row, causes(0), 0)*data.piMarg_get(row, causes(1), 1)*cdf ;
  rowvec dF2du_2 = data.dpiduMarg_get(row, causes(1), 1)*data.piMarg_get(row, causes(0), 0)*cdf;
  vec dF2du_3 = data.piMarg_get(row, causes(0), 0)*data.piMarg_get(row, causes(1), 1)*dcdfdu;

  rowvec dF2du = dF2du_1 + dF2du_2 + dF2du_3.t();
  return(dF2du);
};
Example #2
0
arma::rowvec bs_optim_calc(const arma::vec& theta,
                           const std::vector<std::string>& desc, const arma::field<arma::vec>& objdesc, 
                           std::string model_type, const arma::vec& scales, const arma::mat& omega, unsigned int N,
                           double obj_value, double alpha,
                           std::string compute_v, 
                           unsigned int K, unsigned int H, unsigned int G, 
                           bool robust, double eff){
  
  arma::field<arma::mat> bso = opt_n_gof_bootstrapper(theta,
                                                      desc, objdesc,
                                                      scales, model_type, 
                                                      N, robust, eff, alpha,
                                                      H);
  arma::mat cov_nu_nu_theta = bso(0);
  
  arma::mat bs_obj_values = bso(1);
  
  
  double optimism = 2*sum(diagvec(cov_nu_nu_theta * omega));
  
  
  arma::rowvec temp(4);
  
  temp(0) = obj_value;
  
  temp(1) = optimism;
  
  temp(2) = obj_value + optimism;
  
  temp(3) = arma::as_scalar(bootstrap_gof_test(obj_value, bs_obj_values, alpha, false).row(0));
  
  return temp;
}
      void expectedArmaDiagvec() {
        if(_colInd >= _genMat.n_cols) {
          return;
        }

        cout << "- Compute expectedArmaDiagvec() ... ";
        save<double>("Arma.diagvecSuper", diagvec(_genMat, _colInd));
        cout << "done." << endl;
      }
Example #4
0
//' @title Generate the Confidence Interval for Theta Estimates
//' @description Create an Asymptotic CI for the Theta Estimates.
//' @param theta A \code{vec} containing the estimates
//' @param A A \code{mat} that is the first derivative matrix.
//' @param v_hat A \code{mat} that is the bootstrapped V matrix
//' @param omega A \code{mat} that is the inverse of the diagonal V matrix.
//' @param alpha A \code{double} that contains the confidence level.
//' @return A \code{mat} that has the first column 
//' @backref src/inference.cpp
//' @backref src/inference.h
//' @keywords internal
// [[Rcpp::export]]
arma::mat theta_ci(const arma::vec& theta,
                   const arma::mat& A, 
                   const arma::mat& v_hat, const arma::mat& omega, double alpha){

  arma::mat psi = calculate_psi_matrix(A, v_hat, omega);
  
  arma::vec se = sqrt(diagvec(psi));

  return format_ci(theta, se, alpha);
}
Example #5
0
rowvec Connectome::clusteringCoeff(const mat &W)
{
    /*
    The weighted clustering coefficient is the average "intensity" of
    triangles around a node.
       Input:      NW,     weighted undirected connection matrix
       Output:     C,      clustering coefficient vector
    Reference: Onnela et al. (2005) Phys Rev E 71:065103
    */
    rowvec K = degree(W);
    mat t = arma::pow(W,(1.0/3.0));
    rowvec cyc3 = conv_to<rowvec>::from(diagvec(t*t*t));
    K(find(cyc3 == 0)).fill(datum::inf);
    return cyc3/(K%(K-1));
}
Example #6
0
double Connectome::transitivity(const mat &W)
{
    /*
    Transitivity is the ratio of 'triangles to triplets' in the network.
    (A classical version of the clustering coefficient).

        Input:      W       weighted undirected connection matrix
        Output:     T       transitivity scalar

    Reference: Onnela et al. (2005) Phys Rev E 71:065103
    */
    rowvec K = degree(W);
    mat t = arma::pow(W,(1.0/3.0));
    vec cyc3 = diagvec(t*t*t);
    return accu(cyc3)/sum(K%(K-1));
}
Example #7
0
AD::SXMatrix CasadiSystem::gauss_likelihood(const AD::SXMatrix& v) {
	mat Sf = chol(this->R);
	mat Sf_inv = inv(Sf);

	int r_size = this->R.n_cols;

	float C = pow(2*M_PI, r_size/2)*prod(diagvec(Sf));

	AD::SXMatrix Sf_inv_casadi(r_size,r_size);
	for(int i=0; i < r_size; ++i) {
		for(int j=0; j < r_size; ++j) {
			Sf_inv_casadi(i,j) = Sf_inv(i,j);
		}
	}

	AD::SXMatrix M = mul(Sf_inv_casadi, v);

	AD::SXMatrix E_exp_sum = exp(-0.5*mul(trans(M),M));
	AD::SXMatrix w = E_exp_sum / C; // no need to normalize here because normalized later on anyways

	return w;
}