Throw an exception if number of neural net layer sizes & activation types do not match
This commit is contained in:
parent
b2fea97c8f
commit
434c327a9d
2 changed files with 16 additions and 1 deletions
|
|
@ -4,7 +4,7 @@
|
|||
#include <psemek/random/uniform.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace psemek::ml
|
||||
{
|
||||
|
|
@ -15,6 +15,12 @@ namespace psemek::ml
|
|||
char const * what() noexcept;
|
||||
};
|
||||
|
||||
struct wrong_activation_types_count_error
|
||||
: std::runtime_error
|
||||
{
|
||||
wrong_activation_types_count_error(std::size_t expected, std::size_t actual);
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
|
|
@ -98,6 +104,9 @@ namespace psemek::ml
|
|||
{
|
||||
if (layer_sizes_.empty())
|
||||
throw empty_neural_net_error{};
|
||||
|
||||
if (layer_sizes_.size() != activation_types_.size() + 1)
|
||||
throw wrong_activation_types_count_error{layer_sizes_.size() - 1, activation_types_.size()};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include <psemek/ml/neural_net.hpp>
|
||||
|
||||
#include <psemek/util/to_string.hpp>
|
||||
|
||||
namespace psemek::ml
|
||||
{
|
||||
|
||||
|
|
@ -8,6 +10,10 @@ namespace psemek::ml
|
|||
return "neural net must have at least a single layer";
|
||||
}
|
||||
|
||||
wrong_activation_types_count_error::wrong_activation_types_count_error(std::size_t expected, std::size_t actual)
|
||||
: std::runtime_error(util::to_string("wrong number of activation types: expected ", expected, ", got ", actual))
|
||||
{}
|
||||
|
||||
template struct neural_net<float>;
|
||||
template struct neural_net<double>;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue