本文整理汇总了C++中arma::mat::tail_cols方法的典型用法代码示例。如果您正苦于以下问题:C++ mat::tail_cols方法的具体用法?C++ mat::tail_cols怎么用?C++ mat::tail_cols使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arma::mat
的用法示例。
在下文中一共展示了mat::tail_cols方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parameters
double LogisticRegressionFunction<MatType>::Evaluate(
const arma::mat& parameters,
const size_t begin,
const size_t batchSize) const
{
// Calculating the regularization term.
const double regularization = lambda *
(batchSize / (2.0 * predictors.n_cols)) *
arma::dot(parameters.tail_cols(parameters.n_elem - 1),
parameters.tail_cols(parameters.n_elem - 1));
// Calculating the hypothesis that has to be passed to the sigmoid function.
const arma::rowvec exponents = parameters(0, 0) +
parameters.tail_cols(parameters.n_elem - 1) *
predictors.cols(begin, begin + batchSize - 1);
// Calculating the sigmoid function values.
const arma::rowvec sigmoid = 1.0 / (1.0 + arma::exp(-exponents));
// Iterating for the given batch size from a given point
double result = 0.0;
for (size_t i = 0; i < batchSize; ++i)
{
if (responses[i + begin] == 1)
result += log(sigmoid[i]);
else
result += log(1.0 - sigmoid[i]);
}
// Invert the result, because it's a minimization.
return -result + regularization;
}
示例2:
void LogisticRegressionFunction<MatType>::Gradient(
const arma::mat& parameters,
arma::mat& gradient) const
{
// Regularization term.
arma::mat regularization;
regularization = lambda * parameters.tail_cols(parameters.n_elem - 1);
const arma::rowvec sigmoids = (1 / (1 + arma::exp(-parameters(0, 0)
- parameters.tail_cols(parameters.n_elem - 1) * predictors)));
gradient.set_size(arma::size(parameters));
gradient[0] = -arma::accu(responses - sigmoids);
gradient.tail_cols(parameters.n_elem - 1) = (sigmoids - responses) *
predictors.t() + regularization;
}