https://github.com/stepfenshawn/tidf
A tiny, simple, stupid but powerful deep-learning framework in c++.
https://github.com/stepfenshawn/tidf
c-plus-plus deep-learning machine-learning
Last synced: about 1 year ago
JSON representation
A tiny, simple, stupid but powerful deep-learning framework in c++.
- Host: GitHub
- URL: https://github.com/stepfenshawn/tidf
- Owner: StepfenShawn
- License: mit
- Created: 2023-03-12T03:11:42.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-16T10:31:20.000Z (about 3 years ago)
- Last Synced: 2025-01-29T08:11:53.215Z (over 1 year ago)
- Topics: c-plus-plus, deep-learning, machine-learning
- Language: C++
- Homepage:
- Size: 60.5 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tidf
A tiny, simple, stupid but powerful deep-learning framework in c++.
# Why Tidf?
* Powerful: `Tidf` provides a Keras-like api.
* Simple and stupid: Support brandcast and made in pure c++11.
* Tiny but fast: The implementation is under 1,000 semicolons.
# Components
### Layers
* Dense Layer (Linear Layer)
### Regularizations
* L1 regularization
* L2 regularization
* Dropout
### Activations
* sigmoid
* relu
* tanh
### Optimizers
* SGD (Stochastic gradient descent)
### Cast Functions
* CrossEntropy
* MSE (L2Loss)
* L1Loss
more to come! :)
# Examples
### Train a 3-Layers neural network
```cpp
#include "../tidf/core.h"
int main() {
_TIDF_INIT_;
NEW_MAT(train_inputs, double,
({{0.0, 0.0, 1.0},
{1.0, 1.0, 1.0},
{1.0, 0.0, 1.0},
{0.0, 1.0, 1.0}}));
NEW_MAT(train_outputs, double,
({{0.0, 1.0, 1.0, 0.0}}));
Net* net = new Net(train_inputs.transpose(), train_outputs);
net->addLayer< 4 >(LayerType::Dense, "sigmoid");
net->addLayer< 4 >(LayerType::Dense, "tanh");
net->addLayer< 1 >(LayerType::Dense, "sigmoid");
net->compile("CrossEntropyLoss", "SGD");
net->fit(100000);
std::cout << net->predict(
MAT( double, ({{1.0}, {1.0}, {1.0}})) ) << std::endl;
return 0;
}
```
Result:
```
Matrix(1 x 1):
0.998889
```
You can also load matrix from `.txt` files:
```cpp
...
Matrix train_inputs = load_mat("train_X.txt");
Matrix train_outputs = load_mat("train_Y.txt");
...
```
### Matrix
`tidf` supports `brandcast` and provides a simple but powerful `API` to make it easier to work with matrices:
```cpp
#include "tidf/core.h"
int main() {
NEW_MAT(m1, double, ({{1, 4, 3}, {1, 2, 3}}));
NEW_MAT(m2, double, ({{1, 2, 3}}));
NEW_MAT(m3, double, ({{2, 3, 4}}));
std::cout << m1.dot(m2.transpose()) << std::endl;
std::cout << m2 * 2.0 + m3 << std::endl;
std::cout << m2.apply([](double x) -> double {return x * 10.0;}) << std::endl;
std::cout << m2.join(m3) << std::endl;
std::cout << m1.row(1).sum() << std::endl;
return 0;
}
```
# License
MIT License
Copyright (c) 2023 Stepfen Shawn