Skip to content

Commit 540d123

Browse files
committed
added softmax, starting to build first neural network
1 parent d1b3e21 commit 540d123

12 files changed

Lines changed: 85 additions & 26 deletions

File tree

build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ cd build
77
cmake ..
88
make
99
./src/tensor_sann_main
10+
./src/tensor_sann_model_main

include/TensorSANN/activations/Softmax.hpp

Whitespace-only changes.

include/TensorSANN/core/NeuralNetwork.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ class NeuralNetwork{
1919

2020
void set_loss_func(std::shared_ptr<LossFunction> lossfunc);
2121

22-
Tensor forward();
22+
// Tensor forward();
2323

24-
Tensor backward();
24+
// Tensor backward();
2525

26-
void train();
26+
// void train();
2727

28-
float validate();
28+
// float validate();
2929

3030

3131
protected:
32-
std::vector<Layer> layers;
33-
std::shared_ptr<LossFunction> lossFunction; // Loss function
34-
std::shared_ptr<Optimizer> optimizer;
32+
std::vector<Layer> layers_;
33+
std::shared_ptr<LossFunction> lossFunction_; // Loss function
34+
std::shared_ptr<Optimizer> optimizer_;
3535

3636
};
3737

include/TensorSANN/optimizers/Optimizer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace TensorSANN{
99
class Optimizer{
1010
public:
1111
virtual ~Optimizer() = default;
12-
virtual bool update(Layer & layer);
12+
virtual bool update(Layer & layer) = 0;
1313
};
1414

1515
}// namespace TensorSANN

include/TensorSANN/optimizers/SGD.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ namespace TensorSANN{
1010
// class SGD {
1111
class SGD : Optimizer{
1212
public:
13-
~SGD() = default;
14-
13+
1514
SGD(float learning_rate);
1615

1716
bool update(Layer & layer);

src/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ add_subdirectory(optimizers)
99

1010
# Main executable that links all libraries
1111
add_executable(tensor_sann_main main.cpp)
12+
add_executable(tensor_sann_model_main model_main.cpp)
1213

1314
target_link_libraries(tensor_sann_main
1415
activations
@@ -18,3 +19,12 @@ target_link_libraries(tensor_sann_main
1819
optimizers
1920
# loss
2021
)
22+
23+
target_link_libraries(tensor_sann_model_main
24+
activations
25+
core
26+
layers
27+
utils
28+
optimizers
29+
# loss
30+
)

src/activations/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
add_library(activations STATIC
22
ReLU.cpp
3+
Softmax.cpp
34
)
45

56
# Include the directory for headers

src/activations/Softmax.cpp

Whitespace-only changes.

src/core/NeuralNetwork.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "TensorSANN/core/NeuralNetwork.hpp"
2+
#include "TensorSANN/layers/Layer.hpp"
3+
4+
5+
namespace TensorSANN{
6+
7+
void NeuralNetwork::add_layer(Layer &layer){
8+
// layers_.push_back(layer); TODO this is borken
9+
}
10+
11+
void NeuralNetwork::set_optimzer(std::shared_ptr<Optimizer> optimzer){
12+
optimizer_ = optimzer;
13+
14+
}
15+
16+
void NeuralNetwork::set_loss_func(std::shared_ptr<LossFunction> lossfunc){
17+
lossFunction_ = lossfunc;
18+
}
19+
20+
}

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
int main() {
99
std::cout << "Hello world!" << std::endl;
10-
// TensorSANN::SGD optimizer = TensorSANN::SGD(0.01f);
10+
TensorSANN::SGD optimizer = TensorSANN::SGD(0.01f);
1111

1212
std::vector<size_t> shape1 = {2, 3}; // 2x3 tensor
1313
TensorSANN::Tensor tensor_1(shape1);

0 commit comments

Comments
 (0)