https://github.com/theolepage/prophecy
A tiny deep neural network framework developed from scratch in C++ and CUDA.
https://github.com/theolepage/prophecy
cpp cpp17 machine-learning machine-learning-framework machine-learning-from-scratch ml-framework neural-network
Last synced: about 1 month ago
JSON representation
A tiny deep neural network framework developed from scratch in C++ and CUDA.
- Host: GitHub
- URL: https://github.com/theolepage/prophecy
- Owner: theolepage
- Created: 2020-03-20T18:14:23.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-02-18T10:07:48.000Z (over 4 years ago)
- Last Synced: 2025-07-21T06:12:20.233Z (4 months ago)
- Topics: cpp, cpp17, machine-learning, machine-learning-framework, machine-learning-from-scratch, ml-framework, neural-network
- Language: C++
- Homepage:
- Size: 141 KB
- Stars: 11
- Watchers: 0
- Forks: 2
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# prophecy
Check this out Google.
## Usage
```cpp
#include
#include
#include "model/model.hh"
#include "layer_implem/dense_layer.hh"
using model_type = float;
using training_set = std::vector>;
static auto get_xor(unsigned a, unsigned b)
{
auto mx = Matrix(2, 1);
mx(0, 0) = a;
mx(1, 0) = b;
auto my = Matrix(1, 1);
my(0, 0) = a^b;
return std::make_pair(mx, my);
}
static void create_dataset(
training_set& x_train,
training_set& y_train)
{
auto a = get_xor(0, 0);
x_train.emplace_back(a.first);
y_train.emplace_back(a.second);
auto b = get_xor(0, 1);
x_train.emplace_back(b.first);
y_train.emplace_back(b.second);
auto c = get_xor(1, 0);
x_train.emplace_back(c.first);
y_train.emplace_back(c.second);
auto d = get_xor(1, 1);
x_train.emplace_back(d.first);
y_train.emplace_back(d.second);
}
int main(void)
{
Model model = Model();
SigmoidActivationFunction s = SigmoidActivationFunction();
// Create model
model.add(new InputLayer(2));
model.add(new DenseLayer(2, s));
model.add(new DenseLayer(1, s));
// Create dataset
auto x_train = training_set();
auto y_train = training_set();
create_dataset(x_train, y_train);
// Train model
model.compile(0.1);
model.train(x_train, y_train, 10000, 1);
// Test the model
for (size_t i = 0; i < x_train.size(); i++)
{
auto x = x_train.at(i);
auto x_t = x.transpose();
auto y = model.predict(x);
std::cout << "Input: " << x_t;
std::cout << "Output: " << y << std::endl;
}
return 0;
}
```
## To-Do
Refer to [this page](https://github.com/theolepage/prophecy/projects/1).