Code Monkey home page Code Monkey logo

layered-neural-network's Introduction

Multi Layered Neural Network Library Built in Java

This is a Multi Layered Neural Network Library made in java for experimental purposes in January-March 2020 which is similar to deeplearning4j wrapper. Let's peek into the "Step Builder" code.

      // MultiLayerConfiguration for Neural Network Structure
final MultiLayerConfiguration config = new MultiLayerConfiguration.Builder()
                .activation(ActivationFunction.LEAKY_RELU)
                .weightInit(WeightInit.XAVIER)
                .optimizationAlgo(OptimizationAlgo.STOCHASTIC_GRADIENT_DESCENT) // Change SGD or GD
                .momentum(0.5)
                .updater(0.001) // learning rate or updater
                .layer(0, new InputLayer.Builder().nIn(2) // InputSize fanIn
                        .build())
                .layer(1, new DenseLayer.Builder().nIn(25) // DenseLayer 
                        .activation(ActivationFunction.LEAKY_RELU)
                        .build())
                .layer(2, new DenseLayer.Builder().nIn(15) // DenseLayer
                        .activation(ActivationFunction.LEAKY_RELU)
                        .build())
                .layer(3, new DenseLayer.Builder().nIn(15) // DenseLayer
                        .activation(ActivationFunction.LEAKY_RELU)
                        .build())
                .layer(4, new OutputLayer.Builder().nOut(1) // OutputSize fanOut
                        .activation(ActivationFunction.LEAKY_RELU)
                        .build())
                .list()
                .maxEpoch(100000)
                .minError(0.01)
                .server(true) // port 8080 for visualizing the network
                .build();
        
        // MultiLayer Network Builder
        MultiLayerNetwork model = new MultiLayerNetwork(config);
        model.init();
        
        // If you want to see the score then this callback will give the result
        ScoreListener listener = new ScoreListener(1000);
        model.addScoreListener(listener);
        
        model.fit(xor); // for training the network

        double[] p1 = model.predict(1, 1); // predict the input values that you have trained

Removed

  • Removed The ScalarNormalization and CSVParser for custom implementation.
  • Removed Gradient Cliping Unstable Performance.

Visualization of Multi Layered Network

Screenshot

Dependency Maven

<!-- For Repository Pulling -->
<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
<!-- For Dependencies -->
<dependencies>
    <dependency>
        <groupId>com.github.zaxxio</groupId>
        <artifactId>layered-neural-network</artifactId>
        <version>v1.0.4</version>
    </dependency>
</dependencies>

Dependency Gradle

allprojects {
    repositories {
        // jcenter or mavenCentral something 
        maven { url 'https://jitpack.io' }
    }
}
dependencies {
    implementation 'com.github.zaxxio:layered-neural-network:v1.0.4'
}

Thank you.

MIT Licence

Copyright 2022 Partha Sutradhar

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

layered-neural-network's People

Contributors

zaxxio avatar

Stargazers

 avatar

Watchers

 avatar

layered-neural-network's Issues

Unrealistic output regardless of data used.

Both this layered implementation and your earlier single layer use similar logic and produce the same output/issues.

Oddly, if you use virtually any number as predict data, the output still shows near 100% (ie: .999998...) regardless. I mean, you can use predict(51, 20) and still get similar results to the 4 XOR sets of numbers used in your example. For example, go ahead and run it with these additional predicts...

    neuralNetwork.predict(5, 4);
    neuralNetwork.predict(33, 56);

result:

  • Input : [5.0, 4.0] Predicted : [0.9994366700726042, 0.9999933662619231]
  • Input : [33.0, 56.0] Predicted : [0.9997702883782552, 0.9999951338556543]

Likewise, changing the input and target data to any nonsensical random values of any lengths (with the network configured to match the shapes) will still produce the most amazing, near 100% prediction values. Either there is a hidden Carnac the Magnificent embedded somewhere in the code, or more likely something overlooked in the implementation.

Comments?

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.