Code Monkey home page Code Monkey logo

ai's Introduction

Usage

first off start by including the library with #include <NeuralNetwork/NeuralNetwork.hpp> AI::NeuralNetwork provides tow constructors, one for a precomputed weight map and one for creating a neural network from scratch

With the source

make sure to compile NeuralNetwork.cpp and link the object with the project

With the shared library

Linux

! make sure you installed the library

  • at linking time include -lNeuralNetwork

Windows

! make sure you compiled the library

  • copy the dll file to the binary location
  • at linking time include -lNeuralNetwork

Documentation

  • AI::NeuralNetwork::NeuralNetwork(const std::vector<int>& blueprint, std::function<long double(long double)> f, df, long doube alpha, eta)

    • takes the blueprint of the neural net, blueprint gives the class the requiered information about how many neurons are per layer and the number of layers (given by blueprint.size())
      [...]
      std::vector<int> blueprint = {2, 10, 15, 4};
      AI::NeuralNetwork nn(blueprint);
      the example above creates a NN that has 2 neurons in the input layer, 2 hidden layers, one having 10 neurons and the second 15, and the output layer having 4 neurons.
    • generates the weights based on a clever tehnique called Xavier's algorithm
    • takes the activation function and its derivative, f and df -- default is the linear function
    • takes tow arguments: alpha, the momentum for backpropagation, and eta, the learing rate -- default is 0.8 and 0.0001
  • AI::NeuralNetwork::FeedInData(const std::vector<double>& data)

    • takes the input data in the form of an array, (data.size() must be equal to blueprint[0])
  • AI::NeuralNetwork::getData(std::vector<double>& data)

    • calculates the output of the NN
      ! AI::NeuralNetwork::FeedInData(...) calculates the output, AI::NeuralNetwork::getData(...) only copies the output of it into data
  • AI::NeuralNetwork::Backpropagation(const std::vector<double>& outputData)

    • applies backpropagation over the NN to train it, it take as a parameter the correct output of the training set and retweakes the weights accordingly to minimise the error
  • AI::NeuralNetwork::NeuralNetwork(const std::string& file, ...)

    • provinding the filepath to the already computed weight-map, is loads in into the neural net
    • takes the activation function and its derivatie -- default is the linear function
    • it remembers the learing rate and momentum, its not requiered to pass as an argument

examples

find them in the ./test directory

more about activation function

the library dedicates a namespace inside AI:: for some popular activation functions, and their derivatives
some of them are: sigmoid, hiperbolic tangent, rectifed linear unit (ReLU), parameter rectified linear unit (PReLU) (and its parameter, as default beeing 0.01), linear, binary step

about PReLU, the parameter can be modified by modifing the AI::functions::PReLU_argument variable

Compiling the program from source

Linux

requiered: a c++ compiler
optionaly: gnu make

Using the Makefile

head to ./link/:

  • building: make build
  • installing: make install
  • uninstalling make uninstall

Using bash commands

head to the root directory (./AI/)

  • building:
g++ ./NeuralNetwork/NeuralNetwork.cpp -o NeuralNetwork.o -fpic -O3 -Wall -c \
g++ NeuralNetwork.o -o NeuralNetwork.so.1 -shared \
  • installing: sudo cp NeuralNetwork.so.1 /lib/
  • uninstalling: sudo rm /lib/NeuralNetwork.so.*

Windows

requiered: a c++ compiler

you can use the makefile if you have g++ installed thru msys2 but its eazy to compile it form source with inline commands as the library is self sustained and dosen't have any dependecies.

happy coding !

ai's People

Contributors

c-0-s-m-1-n avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.