本文整理汇总了C++中tensor_type::col方法的典型用法代码示例。如果您正苦于以下问题:C++ tensor_type::col方法的具体用法?C++ tensor_type::col怎么用?C++ tensor_type::col使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensor_type
的用法示例。
在下文中一共展示了tensor_type::col方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: backward
void Min::backward(const tensor_type& data_input, const tensor_type& gradient_output)
{
gradient_input.resizeLike(data_input);
gradient_input.setZero();
if (dimension) {
for (int row = 0; row != data_input.rows(); ++ row)
gradient_input.row(row)[indices[row]] = gradient_output.col(0)[row];
} else {
for (int col = 0; col != data_input.cols(); ++ col)
gradient_input.col(col)[indices[col]] = gradient_output.col(0)[col];
}
}
示例2: forward
void SoftMax::forward(const tensor_type& data_input)
{
// use of redux for computing logsum...
const double infty = - std::numeric_limits<double>::infinity();
double logsum = infty;
for (difference_type i = 0; i != data_input.rows(); ++ i) {
const double value = data_input.col(0)[i];
if (logsum == infty)
logsum = value;
else if (value > infty) {
if (logsum >= value)
logsum = logsum + utils::mathop::log1p(std::exp(value - logsum));
else
logsum = value + utils::mathop::log1p(std::exp(logsum - value));
}
}
data_output = (data_input.array() - logsum).exp();
}
示例3: forward
void Min::forward(const tensor_type& data_input)
{
if (dimension) {
// select row and compute column-min
data_output.resize(data_input.rows(), 1);
indices.resize(data_input.rows());
for (size_type row = 0; row != data_input.rows(); ++ row) {
int col_min = 0;
data_output.col(0)[row] = data_input.row(row).minCoeff(&col_min);
indices[row] = col_min;
}
} else {
// select column and compute row-min!
data_output.resize(data_input.cols(), 1);
indices.resize(data_input.cols());
for (size_type col = 0; col != data_input.cols(); ++ col) {
int row_min = 0;
data_output.col(0)[col] = data_input.col(col).minCoeff(&row_min);
indices[col] = row_min;
}
}
}