本文整理汇总了C++中arma::colvec::at方法的典型用法代码示例。如果您正苦于以下问题:C++ colvec::at方法的具体用法?C++ colvec::at怎么用?C++ colvec::at使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arma::colvec
的用法示例。
在下文中一共展示了colvec::at方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CheckDerivativeCorrect
void CheckDerivativeCorrect(const arma::colvec input, const arma::colvec target)
{
// Test the calculation of the derivatives using a single value as input.
for (size_t i = 0; i < target.n_elem; i++)
{
BOOST_REQUIRE_CLOSE(ActivationFunction::deriv(input.at(i)),
target.at(i), 1e-3);
}
// Test the calculation of the derivatives using the entire vector as input.
arma::colvec derivatives;
ActivationFunction::deriv(input, derivatives);
for (size_t i = 0; i < derivatives.n_elem; i++)
{
BOOST_REQUIRE_CLOSE(derivatives.at(i), target.at(i), 1e-3);
}
}
示例2: CheckActivationCorrect
void CheckActivationCorrect(const arma::colvec input, const arma::colvec target)
{
// Test the activation function using a single value as input.
for (size_t i = 0; i < target.n_elem; i++)
{
BOOST_REQUIRE_CLOSE(ActivationFunction::fn(input.at(i)),
target.at(i), 1e-3);
}
// Test the activation function using the entire vector as input.
arma::colvec activations;
ActivationFunction::fn(input, activations);
for (size_t i = 0; i < activations.n_elem; i++)
{
BOOST_REQUIRE_CLOSE(activations.at(i), target.at(i), 1e-3);
}
}
示例3: CheckInverseCorrect
void CheckInverseCorrect(const arma::colvec input)
{
// Test the calculation of the inverse using a single value as input.
for (size_t i = 0; i < input.n_elem; i++)
{
BOOST_REQUIRE_CLOSE(ActivationFunction::inv(ActivationFunction::fn(
input.at(i))), input.at(i), 1e-3);
}
// Test the calculation of the inverse using the entire vector as input.
arma::colvec activations;
ActivationFunction::fn(input, activations);
ActivationFunction::inv(activations, activations);
for (size_t i = 0; i < input.n_elem; i++)
{
BOOST_REQUIRE_CLOSE(activations.at(i), input.at(i), 1e-3);
}
}
示例4: CheckPReLUActivationCorrect
/*
* Implementation of the PReLU activation function test. The function
* is implemented as PReLU layer in the file perametric_relu.hpp
*
* @param input Input data used for evaluating the PReLU activation
* function.
* @param target Target data used to evaluate the PReLU activation.
*/
void CheckPReLUActivationCorrect(const arma::colvec input,
const arma::colvec target)
{
PReLU<> prelu;
// Test the activation function using the entire vector as input.
arma::colvec activations;
prelu.Forward(std::move(input), std::move(activations));
for (size_t i = 0; i < activations.n_elem; i++)
{
BOOST_REQUIRE_CLOSE(activations.at(i), target.at(i), 1e-3);
}
}
示例5: CheckPReLUDerivativeCorrect
/*
* Implementation of the PReLU activation function derivative test.
* The function is implemented as PReLU layer in the file
* perametric_relu.hpp
*
* @param input Input data used for evaluating the PReLU activation
* function.
* @param target Target data used to evaluate the PReLU activation.
*/
void CheckPReLUDerivativeCorrect(const arma::colvec input,
const arma::colvec target)
{
PReLU<> prelu;
// Test the calculation of the derivatives using the entire vector as input.
arma::colvec derivatives;
// This error vector will be set to 1 to get the derivatives.
arma::colvec error = arma::ones<arma::colvec>(input.n_elem);
prelu.Backward(std::move(input), std::move(error), std::move(derivatives));
for (size_t i = 0; i < derivatives.n_elem; i++)
{
BOOST_REQUIRE_CLOSE(derivatives.at(i), target.at(i), 1e-3);
}
}
示例6: edges_coords
//' Compute ego/alter edge coordinates considering alter's size and aspect ratio
//'
//' Given a graph, vertices' positions and sizes, calculates the absolute positions
//' of the endpoints of the edges considering the plot's aspect ratio.
//'
//' @param graph A square matrix of size \eqn{n}. Adjacency matrix.
//' @param toa Integer vector of size \eqn{n}. Times of adoption.
//' @param x Numeric vector of size \eqn{n}. x-coordinta of vertices.
//' @param y Numeric vector of size \eqn{n}. y-coordinta of vertices.
//' @param vertex_cex Numeric vector of size \eqn{n}. Vertices' sizes in terms
//' of the x-axis (see \code{\link{symbols}}).
//' @param undirected Logical scalar. Whether the graph is undirected or not.
//' @param no_contemporary Logical scalar. Whether to return (compute) edges'
//' coordiantes for vertices with the same time of adoption (see details).
//' @param dev Numeric vector of size 2. Height and width of the device (see details).
//' @param ran Numeric vector of size 2. Range of the x and y axis (see details).
//' @param curved Logical vector.
//' @return A numeric matrix of size \eqn{m\times 5}{m * 5} with the following
//' columns:
//' \item{x0, y0}{Edge origin}
//' \item{x1, y1}{Edge target}
//' \item{alpha}{Relative angle between \code{(x0,y0)} and \code{(x1,y1)} in terms
//' of radians}
//' With \eqn{m} as the number of resulting edges.
//' @details
//'
//' In order to make the plot's visualization more appealing, this function provides
//' a straight forward way of computing the tips of the edges considering the
//' aspect ratio of the axes range. In particular, the following corrections are
//' made at the moment of calculating the egdes coords:
//'
//' \itemize{
//' \item{Instead of using the actual distance between ego and alter, a relative
//' one is calculated as follows
//' \deqn{d'=\left[(x_0-x_1)^2 + (y_0' - y_1')^2\right]^\frac{1}{2}}{d'=sqrt[(x0-x1)^2 + (y0'-y1')^2]}
//' where \eqn{%
//' y_i'=y_i\times\frac{\max x - \min x}{\max y - \min y} }{%
//' yi' = yi * [max(x) - min(x)]/[max(y) - min(y)]}
//' }
//' \item{Then, for the relative elevation angle, \code{alpha}, the relative distance \eqn{d'}
//' is used, \eqn{\alpha'=\arccos\left( (x_0 - x_1)/d' \right)}{\alpha' = acos[ (x0 - x1)/d' ]}}
//' \item{Finally, the edge's endpoint's (alter) coordinates are computed as follows: %
//' \deqn{%
//' x_1' = x_1 + \cos(\alpha')\times v_1}{%
//' x1' = x1 + cos(\alpha') * v1
//' }
//' \deqn{%
//' y_1' = y_1 -+ \sin(\alpha')\times v_1 \times\frac{\max y - \min y}{\max x - \min x} }{%
//' y1' = y1 -+ sin(\alpha')*[max(y) - min(y)]/[max(x) - min(x)]
//' }
//' Where \eqn{v_1}{v1} is alter's size in terms of the x-axis, and the sign of
//' the second term in \eqn{y_1'}{y1'} is negative iff \eqn{y_0 < y_1}{y0<y1}.
//' }
//' }
//'
//' The same process (with sign inverted) is applied to the edge starting piont.
//' The resulting values, \eqn{x_1',y_1'}{x1',y1'} can be used with the function
//' \code{\link{arrows}}. This is the workhorse function used in \code{\link{plot_threshold}}.
//'
//' The \code{dev} argument provides a reference to rescale the plot accordingly
//' to the device, and former, considering the size of the margins as well (this
//' can be easily fetched via \code{par("pin")}, plot area in inches).
//'
//' On the other hand, \code{ran} provides a reference for the adjustment
//' according to the range of the data, this is \code{range(x)[2] - range(x)[1]}
//' and \code{range(y)[2] - range(y)[1]} respectively.
//'
//' @keywords misc dplot
//' @examples
//' # --------------------------------------------------------------------------
//' data(medInnovationsDiffNet)
//' library(sna)
//'
//' # Computing coordinates
//' set.seed(79)
//' coords <- sna::gplot(as.matrix(medInnovationsDiffNet$graph[[1]]))
//'
//' # Getting edge coordinates
//' vcex <- rep(1.5, nnodes(medInnovationsDiffNet))
//' ecoords <- edges_coords(
//' medInnovationsDiffNet$graph[[1]],
//' diffnet.toa(medInnovationsDiffNet),
//' x = coords[,1], y = coords[,2],
//' vertex_cex = vcex,
//' dev = par("pin")
//' )
//'
//' ecoords <- as.data.frame(ecoords)
//'
//' # Plotting
//' symbols(coords[,1], coords[,2], circles=vcex,
//' inches=FALSE, xaxs="i", yaxs="i")
//'
//' with(ecoords, arrows(x0,y0,x1,y1, length=.1))
//' @export
// [[Rcpp::export]]
NumericMatrix edges_coords(
const arma::sp_mat & graph,
const arma::colvec & toa,
const arma::colvec & x,
//.........这里部分代码省略.........