-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
109 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
#pragma once | ||
|
||
#include <iostream> | ||
|
||
using std::string; | ||
|
||
namespace Utils { | ||
unsigned int get_random_pos(unsigned int max_range, unsigned int factor); | ||
double random(int start, int end); | ||
bool passed_debounce_time(int last_tick); | ||
void append_to_file(string filename, string data); | ||
void create_file(string filename, string data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,81 @@ | ||
#include "machine.h" | ||
#include "layer.h" | ||
#include "weights.h" | ||
#include <stdexcept> | ||
#include <vector> | ||
|
||
using Layers::Layer; | ||
using NNWeights::Weights; | ||
using std::vector; | ||
using std::string; | ||
using std::invalid_argument; | ||
|
||
namespace Machine { | ||
vector<Layer*>* layers; | ||
vector<Weights*>* weights; | ||
unsigned int total_layers; | ||
|
||
void NN::add_layer(unsigned int size){ | ||
layers->push_back(new Layer(size)); | ||
this->total_layers++; | ||
this->NN::add_weight(); | ||
} | ||
|
||
void NN::add_layer(Layer* layer){ | ||
layers->push_back(layer); | ||
this->total_layers++; | ||
} | ||
this->NN::add_weight(); | ||
} | ||
|
||
void NN::add_weight(){ | ||
if(this->total_layers <= 1) | ||
return; | ||
|
||
unsigned int first_layer_size = layers->at(this->total_layers-2)->get_size(); | ||
unsigned int second_layer_size = layers->at(this->total_layers-1)->get_size(); | ||
this->weights->push_back(new Weights(first_layer_size, second_layer_size)); | ||
this->total_weights++; | ||
} | ||
|
||
vector<Layer*>* NN::get_layers(){ | ||
return this->layers; | ||
} | ||
|
||
void NN::save_weights(string filename){ | ||
for(Weights* weight: (*this->weights)) | ||
weight->save_weights(filename); | ||
} | ||
|
||
Layer* NN::get_layer(unsigned int i){ | ||
if(this->total_layers == 0 || i > this->total_layers-1) | ||
throw invalid_argument("invalid layer position"); | ||
|
||
return this->layers->at(i); | ||
} | ||
|
||
Weights* NN::get_weight(unsigned int i){ | ||
if(this->total_weights == 0 || i > this->total_weights-1) | ||
throw invalid_argument("invalid weights position"); | ||
return this->weights->at(i); | ||
} | ||
|
||
vector<Weights*>* NN::get_weights(){ | ||
return this->weights; | ||
} | ||
|
||
|
||
unsigned int NN::get_total_layers(){ | ||
return this->total_layers; | ||
} | ||
|
||
unsigned int NN::get_total_weights(){ | ||
return this->total_weights; | ||
} | ||
|
||
NN::~NN(){ | ||
for(Layer *layer: (*this->layers)) | ||
delete layer; | ||
for(Weights *weight: (*this->weights)) | ||
delete weight; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters