GithubHelp home page GithubHelp logo

rubbaboy / simpleneuralnetwork Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jlmd/simpleneuralnetwork

0.0 3.0 0.0 232 KB

Simple neural network implementation in Java

License: Apache License 2.0

Java 100.00%

simpleneuralnetwork's Introduction

Simple neural network

Simple neural network is a Java project that allow users to easily create a asynchronous simple neural network.

This project can be used to predict a output based on a initial learning.

Features

  • Callback with a result entity
  • Number of neurons customizable
  • Read data from external files
  • Simple predictor usage

Usage

This is a simple usage with default configuration:

  1. First of all, load input and output data. You can read it from external text file:

float[][] x = DataUtils.readInputsFromFile("data/x.txt"); int[] t = DataUtils.readOutputsFromFile("data/t.txt"); 2. Instantiate new NeuralNetwork and create a new callback to receive response: java NeuralNetwork neuralNetwork = new NeuralNetwork(x, t, new INeuralNetworkCallback() { @Override public void success(Result result) { }

        @Override
        public void failure(Error error) {
        }
    });
```
  1. Predict a value using Result entity from success response:

    @Override
    public void success(Result result) {
        float[] valueToPredict = new float[] {-1.2f, 0.796f};
        System.out.println("Predicted result: " + result.predictValue(valueToPredict));
    }
  2. Finally, run learning of neural network:

neuralNetwork.startLearning(); ```

Full example:

        float[][] x = DataUtils.readInputsFromFile("data/x.txt");
        int[] t = DataUtils.readOutputsFromFile("data/t.txt");

        NeuralNetwork neuralNetwork = new NeuralNetwork(x, t, new INeuralNetworkCallback() {
            @Override
            public void success(Result result) {
                float[] valueToPredict = new float[] {-0.205f, 0.780f};
                System.out.println("Success percentage: " + result.getSuccessPercentage());
                System.out.println("Predicted result: " + result.predictValue(valueToPredict));
            }

            @Override
            public void failure(Error error) {
                System.out.println("Error: " + error.getDescription());
            }
        });

        neuralNetwork.startLearning();

Output:

Success percentage: 88.4
Predicted result: 1

You can customize some values as the number of neurons, bucle iterations limit, transfer function and result parser.

Example

This project has a example with real data that contains a list of 250 patients with two results of a analysis as inputs and 0 or 1 (depending if the has a disease or not) as output:

         Inputs                         Output
------------------------        --------------------
 Result 1       Result 2                Disease
 -----------------------        --------------------
-0.5982         0.9870                     1     
-0.2019         0.6210                     1
 0.1797         0.4518                     0
-0.0982         0.5876                     1
  ...             ...                     ...

Using this data in neural network, this project is able to predict the output (disease result) of a patient that isn't in the data list with a minimum percentage of success of 88%.

License

Copyright 2014 José Luis Martín

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

simpleneuralnetwork's People

Contributors

jlmd avatar

Watchers

James Cloos avatar Adam Yarris 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.