本文整理汇总了C++中arma::Mat::submat方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat::submat方法的具体用法?C++ Mat::submat怎么用?C++ Mat::submat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arma::Mat
的用法示例。
在下文中一共展示了Mat::submat方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Convolution
static typename std::enable_if<
std::is_same<Border, FullConvolution>::value, void>::type
Convolution(const arma::Mat<eT>& input,
const arma::Mat<eT>& filter,
arma::Mat<eT>& output)
{
// In case of the full convolution outputRows and outputCols doesn't
// represent the true output size when the padLastDim parameter is set,
// instead it's the working size.
const size_t outputRows = input.n_rows + 2 * (filter.n_rows - 1);
size_t outputCols = input.n_cols + 2 * (filter.n_cols - 1);
if (padLastDim)
outputCols++;
// Pad filter and input to the working output shape.
arma::Mat<eT> inputPadded = arma::zeros<arma::Mat<eT> >(outputRows,
outputCols);
inputPadded.submat(filter.n_rows - 1, filter.n_cols - 1,
filter.n_rows - 1 + input.n_rows - 1,
filter.n_cols - 1 + input.n_cols - 1) = input;
arma::Mat<eT> filterPadded = filter;
filterPadded.resize(outputRows, outputCols);
// Perform FFT and IFFT
output = arma::real(ifft2(arma::fft2(inputPadded) % arma::fft2(
filterPadded)));
// Extract the region of interest. We don't need to handle the padLastDim
// parameter in a special way we just cut it out from the output matrix.
output = output.submat(filter.n_rows - 1, filter.n_cols - 1,
2 * (filter.n_rows - 1) + input.n_rows - 1,
2 * (filter.n_cols - 1) + input.n_cols - 1);
}
示例2: GenerateNextReber
/**
* Given a Reber string, return a Reber string with all reachable next symbols.
*
* @param transitions The Reber transistion matrix.
* @param reber The Reber string used to generate all reachable next symbols.
* @param nextReber All reachable next symbols.
*/
void GenerateNextReber(const arma::Mat<char>& transitions,
const std::string& reber, std::string& nextReber)
{
size_t idx = 0;
for (size_t grammer = 1; grammer < reber.length(); grammer++)
{
const int grammerIdx = arma::as_scalar(arma::find(
transitions.row(idx) == reber[grammer], 1, "first"));
idx = arma::as_scalar(transitions.submat(idx, grammerIdx + 2, idx,
grammerIdx + 2)) - '0';
}
nextReber = arma::as_scalar(transitions.submat(idx, 0, idx, 0));
nextReber += arma::as_scalar(transitions.submat(idx, 1, idx, 1));
}
示例3: GenerateReber
/**
* Generate a random Reber grammar.
*
* For more information, see the following thesis.
*
* @code
* @misc{Gers2001,
* author = {Felix Gers},
* title = {Long Short-Term Memory in Recurrent Neural Networks},
* year = {2001}
* }
* @endcode
*
* @param transitions Reber grammar transition matrix.
* @param reber The generated Reber grammar string.
*/
void GenerateReber(const arma::Mat<char>& transitions, std::string& reber)
{
size_t idx = 0;
reber = "B";
do
{
const int grammerIdx = rand() % 2;
reber += arma::as_scalar(transitions.submat(idx, grammerIdx, idx,
grammerIdx));
idx = arma::as_scalar(transitions.submat(idx, grammerIdx + 2, idx,
grammerIdx + 2)) - '0';
} while (idx != 0);
reber = "BPTVVE";
}