本文整理汇总了C++中arma::Cube::slice方法的典型用法代码示例。如果您正苦于以下问题:C++ Cube::slice方法的具体用法?C++ Cube::slice怎么用?C++ Cube::slice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arma::Cube
的用法示例。
在下文中一共展示了Cube::slice方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Optimize
void Optimize(arma::Cube<eT>& weights,
arma::Cube<eT>& gradient,
arma::Cube<eT>& momWeights)
{
for (size_t s = 0; s < weights.n_slices; s++)
Optimize(weights.slice(s), gradient.slice(s), momWeights.slice(s));
}
示例2: Gradient
void Gradient(arma::Cube<eT>& gradient)
{
gradient = arma::zeros<arma::Cube<eT> >(weights.n_rows, weights.n_cols,
weights.n_slices);
for (size_t outputmap = 0; outputmap < outputLayer.OutputMaps(); outputmap++)
{
for (size_t inputmap = 0, s = outputmap; inputmap < inputLayer.OutputMaps();
inputmap++, s += OutputLayer().OutputMaps())
{
arma::Cube<eT> inputSlices = inputLayer.InputActivation().slices(
inputmap * inputLayer.LayerSlices(), (inputmap + 1) *
inputLayer.LayerSlices() - 1);
arma::Cube<eT> deltaSlices = outputLayer.Delta().slices(
outputmap * inputLayer.LayerSlices(),
(outputmap + 1) * inputLayer.LayerSlices() - 1);
arma::Cube<eT> output;
GradientConvolutionRule::Convolution(inputSlices, deltaSlices, output);
for (size_t i = 0; i < output.n_slices; i++)
gradient.slice(s) += output.slice(i);
gradient.slice(s) /= inputLayer.LayerSlices();
}
}
}
示例3: Rotate180
void Rotate180(const arma::Cube<eT>& input, arma::Cube<eT>& output)
{
output = arma::Cube<eT>(input.n_rows, input.n_cols, input.n_slices);
// * left-right flip, up-down flip */
for (size_t s = 0; s < output.n_slices; s++)
output.slice(s) = arma::fliplr(arma::flipud(input.slice(s)));
}
示例4: Forward
void Forward(const arma::Cube<eT>& input, arma::Cube<eT>& output)
{
output = arma::zeros<arma::Cube<eT> >(input.n_rows / kSize,
input.n_cols / kSize, input.n_slices);
for (size_t s = 0; s < input.n_slices; s++)
Pooling(input.slice(s), output.slice(s));
}
示例5: Optimize
void Optimize(arma::Cube<eT>& weights,
arma::Cube<eT>& gradient,
arma::Cube<eT>& meanSquaredGradient,
arma::Cube<eT>& meanSquaredGradientDx)
{
for (size_t s = 0; s < weights.n_slices; s++)
{
Optimize(weights.slice(s), gradient.slice(s), meanSquaredGradient.slice(s),
meanSquaredGradientDx.slice(s));
}
}
示例6: Optimize
void Optimize(arma::Cube<eT>& weights,
arma::Cube<eT>& gradient,
arma::Cube<eT>& mean,
arma::Cube<eT>& variance)
{
for (size_t s = 0; s < weights.n_slices; s++)
{
Optimize(weights.slice(s), gradient.slice(s), mean.slice(s),
variance.slice(s));
}
}
示例7: Backward
void Backward(const arma::Cube<eT>& /* unused */,
const arma::Cube<eT>& gy,
arma::Cube<eT>& g)
{
g = arma::zeros<arma::Cube<eT> >(inputParameter.n_rows,
inputParameter.n_cols, inputParameter.n_slices);
for (size_t s = 0; s < gy.n_slices; s++)
{
Unpooling(inputParameter.slice(s), gy.slice(s), g.slice(s));
}
}
示例8: FeedBackward
void FeedBackward(const arma::Cube<eT>& error)
{
for (size_t s = 0; s < error.n_slices; s++)
{
Unpooling(inputLayer.InputActivation().slice(s), error.slice(s),
delta.slice(s));
}
}
示例9: Forward
void Forward(const arma::Cube<eT>& input, arma::Cube<eT>& output)
{
output = input;
for (size_t s = 0; s < input.n_slices; s++)
{
output.slice(s) += weights(s) * bias;
}
}
示例10: Gradient
void Gradient(const arma::Cube<eT>& d, InputDataType& g)
{
g = arma::Mat<eT>(weights.n_rows, weights.n_cols);
for (size_t s = 0; s < d.n_slices; s++)
{
g(s) = arma::accu(d.slice(s)) * bias;
}
}
示例11: Convolution
static void Convolution(const arma::Cube<eT>& input,
const arma::Mat<eT>& filter,
arma::Cube<eT>& output)
{
arma::Mat<eT> convOutput;
SVDConvolution<BorderMode>::Convolution(input.slice(0), filter, convOutput);
output = arma::Cube<eT>(convOutput.n_rows, convOutput.n_cols,
input.n_slices);
output.slice(0) = convOutput;
for (size_t i = 1; i < input.n_slices; i++)
{
SVDConvolution<BorderMode>::Convolution(input.slice(i), filter,
convOutput);
output.slice(i) = convOutput;
}
}
示例12: TestArmadilloSerialization
void TestArmadilloSerialization(arma::Cube<CubeType>& x)
{
// First save it.
std::ofstream ofs("test", std::ios::binary);
OArchiveType o(ofs);
bool success = true;
try
{
o << BOOST_SERIALIZATION_NVP(x);
}
catch (boost::archive::archive_exception& e)
{
success = false;
}
BOOST_REQUIRE_EQUAL(success, true);
ofs.close();
// Now load it.
arma::Cube<CubeType> orig(x);
success = true;
std::ifstream ifs("test", std::ios::binary);
IArchiveType i(ifs);
try
{
i >> BOOST_SERIALIZATION_NVP(x);
}
catch (boost::archive::archive_exception& e)
{
success = false;
}
BOOST_REQUIRE_EQUAL(success, true);
BOOST_REQUIRE_EQUAL(x.n_rows, orig.n_rows);
BOOST_REQUIRE_EQUAL(x.n_cols, orig.n_cols);
BOOST_REQUIRE_EQUAL(x.n_elem_slice, orig.n_elem_slice);
BOOST_REQUIRE_EQUAL(x.n_slices, orig.n_slices);
BOOST_REQUIRE_EQUAL(x.n_elem, orig.n_elem);
for(size_t slice = 0; slice != x.n_slices; ++slice){
auto const &orig_slice = orig.slice(slice);
auto const &x_slice = x.slice(slice);
for (size_t i = 0; i < x.n_cols; ++i){
for (size_t j = 0; j < x.n_rows; ++j){
if (double(orig_slice(j, i)) == 0.0)
BOOST_REQUIRE_SMALL(double(x_slice(j, i)), 1e-8);
else
BOOST_REQUIRE_CLOSE(double(orig_slice(j, i)), double(x_slice(j, i)), 1e-8);
}
}
}
remove("test");
}
示例13: Forward
void Forward(const arma::Cube<eT>& input, arma::Cube<eT>& output)
{
const size_t wConv = ConvOutSize(input.n_rows, wfilter, xStride, wPad);
const size_t hConv = ConvOutSize(input.n_cols, hfilter, yStride, hPad);
output = arma::zeros<arma::Cube<eT> >(wConv, hConv, outMaps);
for (size_t outMap = 0, outMapIdx = 0; outMap < outMaps; outMap++)
{
for (size_t inMap = 0; inMap < inMaps; inMap++, outMapIdx++)
{
arma::Mat<eT> convOutput;
ForwardConvolutionRule::Convolution(input.slice(inMap),
weights.slice(outMap), convOutput);
output.slice(outMap) += convOutput;
}
}
}
示例14: Initialize
void Initialize(arma::Cube<eT>& W,
const size_t rows,
const size_t cols,
const size_t slices)
{
W = arma::Cube<eT>(rows, cols, slices);
for (size_t i = 0; i < slices; i++)
Initialize(W.slice(i), rows, cols);
}
示例15: geometry
void
NumericalTestTrialIntegrator<BasisFunctionType, ResultType, GeometryFactory>::
integrate(const std::vector<int> &elementIndices,
const Shapeset<BasisFunctionType> &testShapeset,
const Shapeset<BasisFunctionType> &trialShapeset,
arma::Cube<ResultType> &result) const {
const size_t pointCount = m_localQuadPoints.n_cols;
const size_t elementCount = elementIndices.size();
if (pointCount == 0 || elementCount == 0)
return;
// TODO: in the (pathological) case that pointCount == 0 but
// elementCount != 0, set elements of result to 0.
// Evaluate constants
const int testDofCount = testShapeset.size();
const int trialDofCount = trialShapeset.size();
BasisData<BasisFunctionType> testBasisData, trialBasisData;
GeometricalData<CoordinateType> geomData;
size_t testBasisDeps = 0, trialBasisDeps = 0;
size_t geomDeps = 0; // INTEGRATION_ELEMENTS;
m_testTransformations.addDependencies(testBasisDeps, geomDeps);
m_trialTransformations.addDependencies(trialBasisDeps, geomDeps);
m_integral.addGeometricalDependencies(geomDeps);
typedef typename GeometryFactory::Geometry Geometry;
std::unique_ptr<Geometry> geometry(m_geometryFactory.make());
CollectionOf3dArrays<BasisFunctionType> testValues, trialValues;
result.set_size(testDofCount, trialDofCount, elementCount);
testShapeset.evaluate(testBasisDeps, m_localQuadPoints, ALL_DOFS,
testBasisData);
trialShapeset.evaluate(trialBasisDeps, m_localQuadPoints, ALL_DOFS,
trialBasisData);
// Iterate over the elements
for (size_t e = 0; e < elementCount; ++e) {
const int elementIndex = elementIndices[e];
m_rawGeometry.setupGeometry(elementIndex, *geometry);
geometry->getData(geomDeps, m_localQuadPoints, geomData);
if (geomDeps & DOMAIN_INDEX)
geomData.domainIndex = m_rawGeometry.domainIndex(elementIndex);
m_testTransformations.evaluate(testBasisData, geomData, testValues);
m_trialTransformations.evaluate(trialBasisData, geomData, trialValues);
m_integral.evaluate(geomData, testValues, trialValues, m_quadWeights,
result.slice(e));
}
}