Dropout Layer
Implemented rng::uniform and rng::binomial for single values, vectors and matrices. implemeted dropout layers and tested it. Also fixed the validation code. Before it used y one place, now it uses y_test as it should.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "random/engine.h"
|
||||
|
||||
#include <random>
|
||||
//#include <type_traits>
|
||||
|
||||
#include "utils/matrix.h"
|
||||
#include "utils/vector.h"
|
||||
|
||||
namespace rng::detail {
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline T binomial_serial(const uint64_t trials, const double probability) {
|
||||
std::binomial_distribution<int> dist(trials, probability);
|
||||
|
||||
return static_cast<T>(dist(rng::engine()));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
utils::Vector<T> binomial_serial(const uint64_t size, const uint64_t trials, const double probability){
|
||||
utils::Vector<T> v(size);
|
||||
for (uint64_t i = 0; i < size; ++i){
|
||||
v[i] = binomial_serial<T>(trials, probability);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
utils::Matrix<T> binomial_serial(const uint64_t rows, const uint64_t cols, const uint64_t trials, const double probability){
|
||||
utils::Matrix<T> A(rows, cols);
|
||||
for (uint64_t i = 0; i < rows; ++i){
|
||||
for (uint64_t j = 0; j < cols; ++j){
|
||||
A(i,j) = binomial_serial<T>(trials, probability);
|
||||
}
|
||||
}
|
||||
return A;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include "random/engine.h"
|
||||
|
||||
#include <random>
|
||||
//#include <type_traits>
|
||||
|
||||
#include "utils/matrix.h"
|
||||
#include "utils/vector.h"
|
||||
|
||||
namespace rng::detail {
|
||||
|
||||
//
|
||||
// Base functions int
|
||||
//
|
||||
template <typename T>
|
||||
typename std::enable_if<std::is_integral<T>::value, T>::type
|
||||
uniform_serial(const T low, const T high) {
|
||||
std::uniform_int_distribution<T> dist(low, high);
|
||||
return dist(rng::engine());
|
||||
}
|
||||
|
||||
//
|
||||
// Base functions float
|
||||
//
|
||||
template <typename T>
|
||||
typename std::enable_if<std::is_floating_point<T>::value, T>::type
|
||||
uniform_serial(const T low, const T high) {
|
||||
std::uniform_real_distribution<T> dist(low, high);
|
||||
return dist(rng::engine());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
utils::Vector<T> uniform_serial(const uint64_t size, const T low, const T high){
|
||||
utils::Vector<T> v(size);
|
||||
for (uint64_t i = 0; i < size; ++i){
|
||||
v[i] = uniform_serial(low, high);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
utils::Matrix<T> uniform_serial(const uint64_t rows, const uint64_t cols, const T low, const T high){
|
||||
utils::Matrix<T> A(rows, cols);
|
||||
for (uint64_t i = 0; i < rows; ++i){
|
||||
for (uint64_t j = 0; j < cols; ++j){
|
||||
A(i,j) = uniform_serial(low, high);
|
||||
}
|
||||
}
|
||||
return A;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user