Giter Club home page Giter Club logo

nn's Introduction

NN

What is it

This is a basic Neural network (which is heavily unoptimised) This was just a one-month project of mine that I did to get back into the gist of things (I hadn't coded a neural network for about 1 year I think)

Plans for NN

I do plan on GPU optimising this shitbox, and maybe implementing convolution and memory stuff but this will come at some other point as I currently have another project I'm doing ):

Example

Apologies for the horrific code this is not pretty

int main() {
  int dataam = 0;
  string text;
  ifstream CSV("result.csv");
  vector<vector<float>> vals;
  vector<int> trues;
  // reads file and loads the data
  while (getline(CSV, text)) {
  	dataam++;
  	string strfirstval = text.substr(0, text.find(","));
  	float x = stof(strfirstval);
  	text.erase(0, text.find(",") + 1);
  	string strsecondval = text.substr(0, text.find(","));
  	float y = stof(strsecondval);
  	text.erase(0, text.find(",") + 1);
  	string strthirdval = text;
  	float xy = stof(strthirdval);
  	text.erase(0, text.find(",") + 1);
  	string strfourthval = text;
  	float x2 = stof(strfourthval);
  	text.erase(0, text.find(",") + 1);
  	string strfithval = text;
  	float y2 = stof(strfithval);
  	text.erase(0, text.find(",") + 1);
  	string strsixthval = text;
  	float sinx = stof(strsixthval);
  	text.erase(0, text.find(",") + 1);
  	string strseventhval = text;
  	float siny = stof(strseventhval);
  	text.erase(0, text.find(",") + 1);
  	string streighthval = text;
  	int _true = stoi(streighthval);
  	trues.push_back(_true);
  	vals.push_back({ x, y, xy, x2, y2, sinx, siny });
  }
  // normalises data
  vals = Normalise(vals);
  vals.erase(vals.begin());
  vals.erase(vals.begin());
  // changes vectors into arrays so the neural network can use it
  float** inputs = new float* [dataam];
  float** truevals = new float* [dataam];
  for (int i = 0; i < dataam; i++) {
  	inputs[i] = new float[7];
  	for (int t = 0; t < 7; t++) {
  		inputs[i][t] = vals[i][t];
  	}
  	truevals[i] = new float[2]();
  	if (trues[i] == 0) {
  		truevals[i][0] = 1;
  		truevals[i][1] = 0;
  	}
  	else {
  		truevals[i][0] = 0;
  		truevals[i][1] = 1;
  	}
  }
  // creates network
  Layer testlayer1 = Layer(7, 128, LEAKYRELU, 9e-6, 1e-8, 2e-7, 0.9, 0., 1e-7);
  Layer testlayer2 = Layer(128, 128, LEAKYRELU, 9e-6, 1e-8, 2e-7, 0.9, 0., 1e-7, 5e-3);
  Layer testlayer3 = Layer(128, 2, SOFTMAX, 9e-6, 1e-8, 2e-7, 0.9, 0., 1e-7);
  Network testnetwork = Network(new Layer[3]{ testlayer1, testlayer2, testlayer3 }, 3, BCE, ACCURACY);
  float* accuracies = new float[300];
  // trains network and records accuracies
  for (int i = 0; i < 300; i++) {
  	testnetwork.Train(inputs, truevals, 7, 2, dataam, 1000, 1);
  	float acc = testnetwork.Accuracy(inputs, truevals, 7, 2, dataam);
  	accuracies[i] = acc;
  }
  // stores accuracies
  WriteAccuracy(accuracies, 300);
  return 0;
}

nn's People

Contributors

sopho-s avatar

Watchers

 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.