-
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.
Merge pull request #11 from C-Text/feature/neural_network
Close #9
- Loading branch information
Showing
19 changed files
with
770 additions
and
36 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
cmake_minimum_required(VERSION 3.17) | ||
project(CText C) | ||
|
||
set(CMAKE_C_STANDARD 99) | ||
|
||
add_executable( | ||
CText src/main.c | ||
src/neuralnetwork/neuron.c src/neuralnetwork/neuron.h | ||
src/neuralnetwork/function.c src/neuralnetwork/function.h | ||
src/neuralnetwork/layer.c src/neuralnetwork/layer.h | ||
src/util.c src/util.h | ||
) | ||
|
||
add_executable( | ||
CText-tests src/test/main.c | ||
src/neuralnetwork/neuron.c src/neuralnetwork/neuron.h | ||
src/neuralnetwork/function.c src/neuralnetwork/function.h | ||
src/neuralnetwork/layer.c src/neuralnetwork/layer.h | ||
src/util.c src/util.h | ||
src/test/test.c src/test/test.h | ||
src/test/test_method.c src/test/test_method.h | ||
) | ||
|
||
target_link_libraries(CText m) | ||
target_link_libraries(CText-tests m) | ||
|
||
if ( CMAKE_COMPILER_IS_GNUCC ) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wshadow -Wdouble-promotion -Wformat=2 -Wformat-truncation -Wformat-overflow -Wundef -fno-common -Wconversion") | ||
endif() | ||
if ( MSVC ) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") | ||
endif() |
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,22 +1,33 @@ | ||
CText | ||
====== CText ====== | ||
|
||
This is a school project. | ||
= Clone = | ||
|
||
Depandencies : | ||
git clone https://github.com/C-Text/CText.git | ||
|
||
= Dependencies = | ||
|
||
gcc | ||
cmake | ||
make | ||
|
||
= Build = | ||
cmake . | ||
make | ||
|
||
Prepare the project : | ||
= Launch = | ||
./CText | ||
./CText-tests | ||
|
||
= Contribute = | ||
|
||
git clone git@github.com:C-Text/CText.git | ||
git clone https://github.com/C-Text/CText.git | ||
git flow init | ||
|
||
|
||
Create a new feature : | ||
= Create a new feature = | ||
|
||
git flow feature start <my_feature> | ||
|
||
|
||
Finish a feature : | ||
= Finish a feature = | ||
Open a Pull Request -> base: develop, compare: feature/<my_feature> |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "neuralnetwork/layer.h" | ||
#include <stdio.h> | ||
|
||
void prints(layer *l1, layer *l2) { | ||
lprint(l1, true); | ||
printf("\n"); | ||
lprint(l2, true); | ||
printf("\n"); | ||
} | ||
|
||
void test(int ** arr) { | ||
for (int i = 0; i < 5; ++i) { | ||
printf("%d", arr[i][i]); | ||
} | ||
} | ||
|
||
int main(void) { | ||
const unsigned int EPOCHS = 100; | ||
// XOR table | ||
double inputs[4][2] = { | ||
{0.0, 0.0}, | ||
{0.0, 1.0}, | ||
{1.0, 0}, | ||
{1.0, 1.0} | ||
}; | ||
double outputs[4] = {0.0, 1.0, 1.0, 0.0}; | ||
// Creating layers | ||
layer l = create_layer(2, 1); | ||
layer l2 = create_layer(1, 1); | ||
|
||
// Input | ||
feed(&l, inputs[1]); | ||
printf("================== INPUT ==================\n"); | ||
prints(&l,&l2); | ||
|
||
// Activate the layer | ||
activate(&l); | ||
printf("================== ACTIV ==================\n"); | ||
prints(&l,&l2); | ||
|
||
//Feed forward | ||
feedforward(&l,&l2); | ||
printf("================== FEEDF ==================\n"); | ||
prints(&l,&l2); | ||
|
||
double out = sum(&l2, 0); | ||
printf("OUTPUT: %lf", out); | ||
|
||
return 0; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "function.h" | ||
#include "../util.h" | ||
#include <math.h> | ||
|
||
/** | ||
* Softmax activation. | ||
* | ||
* @date 25/10/2020 | ||
* @version 0.0.1 | ||
* @author Vinetos | ||
* @package network | ||
* | ||
* This method activates the given input array using the softmax | ||
* classification method. | ||
* | ||
* @warning This method modify the given array. | ||
* | ||
* @throw error when size < 0. | ||
* @param inputs the arrays of values to activate. | ||
* @param size the size of the array | ||
* | ||
*/ | ||
void softmax(double *inputs, size_t size) { | ||
if (size == 0) | ||
return; | ||
|
||
double m = find_min(inputs, size); | ||
|
||
double sum = 0.0; | ||
for (size_t i = 0; i < size; ++i) | ||
sum += exp(inputs[i] - m); | ||
|
||
double constant = m + log(sum); | ||
for (size_t i = 0; i < size; ++i) | ||
inputs[i] = exp(inputs[i] - constant); | ||
} | ||
|
||
/** | ||
* Mean squared error. | ||
* | ||
* @date 25/10/2020 | ||
* @version 0.0.1 | ||
* @author Vinetos | ||
* @package network | ||
* | ||
* This method calculate the mean squared error between the input and the | ||
* expected output. | ||
* | ||
* @param input The activated value of the neuron | ||
* @param expected The expected value | ||
* | ||
* @return the mean squared error value. | ||
*/ | ||
double mse(double input, double expected) { | ||
double diff = expected - input; | ||
return diff * diff; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#ifndef CTEXT_SRC_NEURALNETWORK_FUNCTION_H_ | ||
#define CTEXT_SRC_NEURALNETWORK_FUNCTION_H_ | ||
|
||
#include <stdlib.h> | ||
|
||
/** | ||
* Softmax activation. | ||
* | ||
* @date 25/10/2020 | ||
* @version 0.0.1 | ||
* @author Vinetos | ||
* @package network | ||
* | ||
* This method activates the given input array using the softmax | ||
* classification method. | ||
* | ||
* @warning This method modify the given array. | ||
* | ||
* @throw error when size < 0. | ||
* @param inputs the arrays of values to activate. | ||
* @param size the size of the array | ||
* | ||
*/ | ||
void softmax(double *inputs, size_t size); | ||
|
||
/** | ||
* Mean squared error. | ||
* | ||
* @date 25/10/2020 | ||
* @version 0.0.1 | ||
* @author Vinetos | ||
* @package network | ||
* | ||
* This method calculate the mean squared error between the input and the | ||
* expected output. | ||
* | ||
* @param input The activated value of the neuron | ||
* @param expected The expected value | ||
* | ||
* @return the mean squared error value. | ||
*/ | ||
double mse(double input, double expected); | ||
|
||
#endif //CTEXT_SRC_NEURALNETWORK_FUNCTION_H_ |
Oops, something went wrong.