GithubHelp home page GithubHelp logo

davecom / swiftsimpleneuralnetwork Goto Github PK

View Code? Open in Web Editor NEW
30.0 5.0 7.0 11.37 MB

A simple multi-layer feed-forward neural network with backpropagation built in Swift.

License: Apache License 2.0

Swift 100.00%
neural-network backpropagation

swiftsimpleneuralnetwork's Introduction

SwiftSimpleNeuralNetwork

A simple multi-layer feed-forward neural network with backpropagation built in Swift.

Philosophy

This teaching project is proclaimed simple for two reasons:

  • The code aims to be simple to understand (even at the expense of performance). I built this project to learn more about implementing neural networks. It does not aim to be state of the art or feature complete, but instead approachable.
  • The type of neural network targetted is very specific - only multi-layer feed-forward backpropagation networks. Why? Because we're keeping it simple,

Contributions to the project will be measured not only by their functional aspects (improved performance, more features) but also by how much they stick to the philosophy.

Installation

The project requires Xcode 10.2 and Swift 5.

Manual

For the present, the best way to try the project out is through the wine and iris Xcode unit tests. Just download or clone the repository and run them from within Xcode.

SPM

You can also install the project's main files (but not the unit tests) through SPM via this repository.

Mac Example App

The example app for macOS that comes with SwiftSimpleNeuralNetwork trains on 60,000 MNIST sample images and then predicts another 10,000 testing images. In my testing it reaches as high as 94% accuracy without much tuning (just many batches of training on the full dataset). This is definitely not state of the art, but for a simple neural network, it's a decent demonstration.

MNIST Example App Screenshot

Unit Tests

A check indicates a test is passing/working.

  • IrisTest.swift uses the classic data set (contained in iris.csv) to classify 150 irises by four attributes.
  • WineTest.swift uses a data set of 178 wines across thirteen attributes (contained in wine.csv) to classify wines by cultivar (three cultivars total). The test trains on the first 150 and then validates itself by classifying the remaining 28.
  • SinTest.swift tries to learn to approximate the sin() function. ~80% of predictions come close to correct values.

Book Chapter

Chapter 7 of Classic Computer Science Problems in Swift is based on this project. It contains it a step-by-step tutorial, explaining how a slightly more primitive version of the project works.

License, Contributions, and Attributions

SwiftSimpleNeuralNetwork is Copyright 2016-2019 David Kopec and licensed under the Apache License 2.0 (see LICENSE). As per the Apache license, contributions are also Apache licensed by default. And contributions are welcome!

The wine and iris datasets in the unit tests are provided curtosy of the UCI Machine Learning Repository which should be cited as:

Lichman, M. (2013). UCI Machine Learning Repository [http://archive.ics.uci.edu/ml]. Irvine, CA: University of California, School of Information and Computer Science.

The MNIST dataset is from LeCun, Cortes, and Burges.

The overall neural network algorithm implemented throughout the project was derived primarily from Chapter 18 of Artificial Intelligence: A Modern Approach (Third Edition) by Stuart Russell and Peter Norvig.

A few small individual utility functions in Functions.swift are from third party sources and cited appropriately in-source.

Future Directions

  • Improved in-source documentation
  • Improved documentation in this README
  • More unit tests
  • More activation functions
  • Utility function to archive (serialize) and recreate (deserialize) trained neural networks
  • Better testing of networks with more than one hidden layer
  • Improved performance

swiftsimpleneuralnetwork's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

swiftsimpleneuralnetwork's Issues

determine angle from image - training images / testing images

I've been dabbling in this space for a couple of weeks. perhaps we can help each other.

I love how your code is very simple and elegant.
I see you haven’t included heavy frameworks and just cherry picked the needed code from Surge.
Keeping things simple.

I would say though - I'm getting some good mileage with EasyImagy (needs carthage) / it can build images by pixel arrays safely. I threw this code together(which is a mash up of other code) which builds out 1000 images / 1000 slopes on them. https://github.com/johndpope/Bresenham-Line/blob/master/Bresenham-Line/CMKViewController%2BNet.swift

working on integrating machine learning stuff slowly.

This question on stack overflow was original thought process for this work
https://stats.stackexchange.com/questions/218407/encoding-angle-data-for-neural-network

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.