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


C++ MatrixXi::colwise方法代码示例

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


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

示例1: calculate_from_confusion_matrix

void FScore::calculate_from_confusion_matrix(const MatrixXi &cmat) {
    // Sometimes a class is never predicted, leading to a sum that is 0.
    // When dividing later, there can be a nan. Avoid setting the value to 1.
    // Setting to 1 is correct because the value to divide will be 0.
    VectorXi sums = cmat.colwise().sum().unaryExpr(std::ptr_fun(avoid_zero));
    recall_ = cmat.cast<double>().diagonal().array() / sums.cast<double>().array();
    sums = cmat.rowwise().sum().unaryExpr(std::ptr_fun(avoid_zero));
    precision_ = cmat.cast<double>().diagonal().array() / sums.cast<double>().array();

    // Apply the same fix to the sum of the recall and precision arrays.
    VectorXd s = (recall_ + precision_).unaryExpr(std::ptr_fun(avoid_zero_double));
    fscore_ = 2 * recall_.array() * precision_.array() / s.array();
}
开发者ID:javang,项目名称:mlearning,代码行数:13,代码来源:fscore.cpp

示例2: nominal_gini_gain

double nominal_gini_gain(const VectorXi &values, const VectorXi &classes) {
  MatrixXi T = get_cross_table(values, classes);
  // total_per_value(k) is the number of times that value k appears
  MatrixXi total_per_value = T.rowwise().sum(); 
  VectorXd probability_of_value = total_per_value.cast<double>() /values.rows();
  // Fraction of each class  per value
  MatrixXd fractions_yx = divide_colwise( T.cast<double>(),
                                          total_per_value.cast<double>());
  // Gini impurity for each value: sum fractions^2 over the rows
  VectorXd G = fractions_yx.array().square().rowwise().sum();
  double total_gini =  1 - probability_of_value.transpose() * G;
  VectorXi counts = T.colwise().sum();
  double gain = gini(counts.cast<double>()) - total_gini;
  return gain;
}
开发者ID:javang,项目名称:mlearning,代码行数:15,代码来源:information_gain.cpp

示例3: nominal_entropy_gain

double nominal_entropy_gain(const VectorXi &values, const VectorXi &classes) {
  MatrixXi T = get_cross_table(values, classes);
  MatrixXi total_per_value = T.rowwise().sum(); 
  VectorXd probability_of_value = total_per_value.cast<double>() /values.rows();
  MatrixXd fractions_yx = divide_colwise( T.cast<double>(),
                                          total_per_value.cast<double>());
  double epsilon = std::numeric_limits<double>::epsilon();
  double invlog = 1 / std::log(2);
  MatrixXd H = (- invlog) * fractions_yx.array() * 
                             (fractions_yx.array() + epsilon).log().array();
  double total_entropy = probability_of_value.transpose() * H.rowwise().sum();
  VectorXi counts = T.colwise().sum();
  double gain = entropy(counts.cast<double>()) - total_entropy;
  return gain;
}
开发者ID:javang,项目名称:mlearning,代码行数:15,代码来源:information_gain.cpp

示例4: main

int main(int, char**)
{
  cout.precision(3);
  MatrixXi m = MatrixXi::Random(3,4);
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the rowwise reverse of m:" << endl << m.rowwise().reverse() << endl;
cout << "Here is the colwise reverse of m:" << endl << m.colwise().reverse() << endl;

cout << "Here is the coefficient (1,0) in the rowise reverse of m:" << endl
<< m.rowwise().reverse()(1,0) << endl;
cout << "Let us overwrite this coefficient with the value 4." << endl;
//m.colwise().reverse()(1,0) = 4;
cout << "Now the matrix m is:" << endl << m << endl;

  return 0;
}
开发者ID:AlperenAydin,项目名称:TP_MATH,代码行数:16,代码来源:compile_Vectorwise_reverse.cpp


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