Exemplo n.º 1
0
/*
  Computes covariance using the renormalization above and adds it to
  an existing matrix.
*/
void MultinomialCovariance(double alpha,
                           const gsl_vector* v,
                           gsl_matrix* m) {
  double scale = gsl_blas_dsum(v);
  gsl_blas_dger(-alpha / scale, v, v, m);
  gsl_vector_view diag = gsl_matrix_diagonal(m);
  gsl_blas_daxpy(alpha, v, &diag.vector);
}
Exemplo n.º 2
0
/*
  This function takes as input a multinomial parameter vector and
  computes the "total" variance, i.e., the sum of the diagonal of the
  covariance matrix.

  If the multinomial parameter is unnormalized, then the variance of
  the normalized multinomial vector will be computed and then
  multiplied by the scale of the vector.
 */
double MultinomialTotalVariance(const gsl_vector* v) {
  double scale = gsl_blas_dsum(v);
  double variance = 0.0;
  for (size_t ii = 0; ii < v->size; ++ii) {
    double val = gsl_vector_get(v, ii) / scale;
    variance += val * (1. - val);
  }
  return variance * scale;
}
Exemplo n.º 3
0
double normalize(gsl_vector* v) {
  double sum = gsl_blas_dsum(v);
  gsl_blas_dscal(1 / sum, v);
  return sum;
}
Exemplo n.º 4
0
double Synset::emission_sum(int lang) const {
  return gsl_blas_dsum(emission_prior_[lang].get());
}
Exemplo n.º 5
0
double Synset::choice_sum() const {
  return gsl_blas_dsum(choice_prior_.get());
}
Exemplo n.º 6
0
double Synset::transition_sum() const {
  return gsl_blas_dsum(transition_prior_.get());
}