Skip to content

Instantly share code, notes, and snippets.

@kris-singh
Created March 18, 2017 23:49
Show Gist options
  • Save kris-singh/22f15954a6c7ceaa153df53881d79879 to your computer and use it in GitHub Desktop.
Save kris-singh/22f15954a6c7ceaa153df53881d79879 to your computer and use it in GitHub Desktop.
FFN<NegativeLogLikelihood<> > model;
model.Add<Linear<> >(trainData.n_rows, hiddenLayerSize);
model.Add<SigmoidLayer<> >();
model.Add<Linear<> >(hiddenLayerSize, outputSize);
model.Add<LogSoftMax<> >();
MomentumUpdate momentumUpdate(0.7);
NoDecay noDecay;
SGD<decltype(model), MomentumUpdate, NoDecay> opt(model, 0.01, maxEpochs * trainData.n_cols,
1e-5 , true, momentumUpdate, noDecay);
model.Train(std::move(trainData), std::move(trainLabels), opt);
MatType predictionTemp;
model.Predict(testData, predictionTemp);
MatType prediction = arma::zeros<MatType>(1, predictionTemp.n_cols);
for (size_t i = 0; i < predictionTemp.n_cols; ++i)
{
prediction(i) = arma::as_scalar(arma::find(
arma::max(predictionTemp.col(i)) == predictionTemp.col(i), 1)) + 1;
}
size_t error = 0;
for (size_t i = 0; i < testData.n_cols; i++)
{
if (int(arma::as_scalar(prediction.col(i))) ==
int(arma::as_scalar(testLabels.col(i))))
{
error++;
}
}
@kris-singh
Copy link
Author

/home/kris/Desktop/GsoC2K17/mlpack/src/mlpack/tests/decay_policies_test.cpp: In instantiation of ‘void DecayLearningRateTest::BuildVanillaNetwork(MatType&, MatType&, MatType&, MatType&, size_t, size_t, size_t, double) [with MatType = arma::Mat; size_t = long unsigned int]’:
/home/kris/Desktop/GsoC2K17/mlpack/src/mlpack/tests/decay_policies_test.cpp:146:67: required from here
/home/kris/Desktop/GsoC2K17/mlpack/src/mlpack/tests/decay_policies_test.cpp:80:3: error: no matching function for call to ‘mlpack::ann::FFN<mlpack::ann::NegativeLogLikelihood<arma::Mat, arma::Mat > >::Train(std::remove_reference<arma::Mat&>::type, std::remove_reference<arma::Mat&>::type, mlpack::optimization::SGD<mlpack::ann::FFN<mlpack::ann::NegativeLogLikelihood<arma::Mat, arma::Mat > >, mlpack::optimization::MomentumUpdate, mlpack::optimization::NoDecay>&)’
model.Train(std::move(trainData), std::move(trainLabels), opt);
^
/home/kris/Desktop/GsoC2K17/mlpack/src/mlpack/tests/decay_policies_test.cpp:80:3: note: candidates are:
In file included from /home/kris/Desktop/GsoC2K17/mlpack/src/mlpack/tests/decay_policies_test.cpp:20:0:
/home/kris/Desktop/GsoC2K17/mlpack/src/mlpack/../mlpack/methods/ann/ffn.hpp:97:8: note: template<template class typedef OptimizerType OptimizerType> void mlpack::ann::FFN<OutputLayerType, InitializationRuleType>::Train(const mat&, const mat&, OptimizerType<mlpack::ann::FFN<OutputLayerType, InitializationRuleType> >&) [with OptimizerType = OptimizerType; OutputLayerType = mlpack::ann::NegativeLogLikelihood<arma::Mat, arma::Mat >; InitializationRuleType = mlpack::ann::RandomInitialization]
void Train(const arma::mat& predictors,
^
/home/kris/Desktop/GsoC2K17/mlpack/src/mlpack/../mlpack/methods/ann/ffn.hpp:97:8: note: template argument deduction/substitution failed:
/home/kris/Desktop/GsoC2K17/mlpack/src/mlpack/tests/decay_policies_test.cpp:80:3: error: wrong number of template arguments (3, should be 1)
model.Train(std::move(trainData), std::move(trainLabels), opt);
^
In file included from /home/kris/Desktop/GsoC2K17/mlpack/src/mlpack/../mlpack/methods/ann/ffn.hpp:301:0,
from /home/kris/Desktop/GsoC2K17/mlpack/src/mlpack/tests/decay_policies_test.cpp:20:
/home/kris/Desktop/GsoC2K17/mlpack/src/mlpack/../mlpack/methods/ann/ffn_impl.hpp:77:35: error: provided for ‘template<class OutputLayerType, class InitializationRuleType> template class OptimizerType’
template<template class OptimizerType>
^
In file included from /home/kris/Desktop/GsoC2K17/mlpack/src/mlpack/tests/decay_policies_test.cpp:20:0:
/home/kris/Desktop/GsoC2K17/mlpack/src/mlpack/../mlpack/methods/ann/ffn.hpp:117:8: note: template<template class typedef OptimizerType OptimizerType> void mlpack::ann::FFN<OutputLayerType, InitializationRuleType>::Train(const mat&, const mat&) [with OptimizerType = OptimizerType; OutputLayerType = mlpack::ann::NegativeLogLikelihood<arma::Mat, arma::Mat >; InitializationRuleType = mlpack::ann::RandomInitialization]
void Train(const arma::mat& predictors, const arma::mat& responses);
^
/home/kris/Desktop/GsoC2K17/mlpack/src/mlpack/../mlpack/methods/ann/ffn.hpp:117:8: note: template argument deduction/substitution failed:
/home/kris/Desktop/GsoC2K17/mlpack/src/mlpack/tests/decay_policies_test.cpp:80:3: note: candidate expects 2 arguments, 3 provided
model.Train(std::move(trainData), std::move(trainLabels), opt);
^
make[3]: *** [src/mlpack/tests/CMakeFiles/mlpack_test.dir/decay_policies_test.cpp.o] Error 1
make[2]: *** [src/mlpack/tests/CMakeFiles/mlpack_test.dir/all] Error 2
make[1]: *** [src/mlpack/tests/CMakeFiles/mlpack_test.dir/rule] Error 2
make: *** [mlpack_test] Error 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment