Home > java > Java neural networks and Neuroph – A tutorial

Java neural networks and Neuroph – A tutorial

The java neural network Neuroph was making news recently about its integration with Hadoop. Neural networks can solve some interesting problems once they are trained. This article aims to provide the baby steps necessary to writing your first java program that loads a trained neural network.

Before you even begin to read anything that follows, a basic understanding of neural network terminology and the concept behind the same is necessary. The following articles are great starting points to understanding neural networks

Neuroph and neural networks – Part 1

Neuroph and neural networks – Part 2

Neuroph and neural networks – Part 3

Intro to neural networks

Cars and Signals:

We will  simulate the scenario where cars wait at a signal and move only when the lights are green. This simple example should help get you started. Our aim is to define a neural network with the easyNeurons swing application; train it; import it into java and use it in an application.

There are 3 states for this signal

1. Red – Stay where you are

2. Yellow – Start your engines

3. Green – Go

The neural network will take 3 inputs and its architecture will be based on the multi layer perceptron setting. A hidden layer with 4 nodes will decide the output. The output itself will be based on one node, whose value will determine if the cars can move or not. This is what our network looks like so far

Create the network in neuroph: Network -> Multi layer Perceptron

Basic network with no training: View -> Graph

Now we need to train the network so that the output will be as expected when the signals change. The rules are pretty simple and are shown below.To train the network we create a training set

Neuroph training set:

Train the network to respond to the inputs:

After the training rules have been laid out, it is time to train this network. Simply press on the Train button and select the appropriate training set to use.

Set the parameters by which the network should learn:

The trained network:

Now that we have our network trained, lets try giving it an input. An input of 0 0 1 means the signal is green and the vehicles can go through. The output produced in this case is shown below. The output will vary based on the function used in the training set / error rate and other factors. But what is to be highlighted here is that the output is nearing 1 when the signal is green. Our network works as expected.

Signal is green and output is 1 (well almost :) ):

We can confirm how this decision was taken by the network by highlighting the weights. Additionally by representing the size of each node with respect to the activation contributed for that node, we can visualize how the input message propagates

Weight / Activation  highlighting:

So now that we have a neural network up and running, how do we actually use this inside java code ? Its pretty simple. Save the project as a .nnet file. Lets call this neural_traffic.nnet. To load the nnet file into your java project, simple use the classes provided by Neuroph like so

Loading a neural network into java:

public class TestTrafficNeural
{
    NeuralNetwork network = NeuralNetwork.load("neural_traffic.nnet");
 
    public static void main(String[] args)
    {
        new TestTrafficNeural().go();
    }
 
    private void go()
    {
        calculate(1,0,0);
        calculate(0,1,0);
        calculate(0,0,1);
    }
 
    private void calculate(double... input)
    {
        network.setInput(input);
        network.calculate();
        Vector output = network.getOutput();
        Double answer = output.get(0);
        System.out.println(answer);
    }
}

The code produces the following output

-1.6360230873976706E-6
-4.140786100885251E-6
0.9684448970000741

You can also define and train the network on the fly with code. But you would not want to do this for cases where large sets of inputs and nodes are involved. For simple problems the time taken to train a network is usually a few seconds. For large images ( Assuming you are trying to recognize images with Neuroph ) it can take a couple of hours.

This example is pretty easy to do and is certainly not a practical use case for real world problems. However I hope it gets you excited about using neural networks in your programs. With Neuroph doing this is pretty simple.




Categories: java Tags: , ,
  1. August 31st, 2014 at 02:32 | #1

    With havin so much content do you ever run into any problems of plagorism or
    copyright infringement? My site has a lot of exclusive content I’ve either created myself or outsourced but it seems a lot of it
    is popping it up all over the web without my permission. Do you know any techniques to help reduce content from being stolen?
    I’d genuinely appreciate it.

  2. August 31st, 2014 at 02:55 | #2

    You need to take part in a contest for one of the greatest blogs online.
    I am going to recommend this site!

  3. September 1st, 2014 at 04:21 | #3

    This is the right web site for everyone who wants to find
    out about this topic. You realize so much its almost hard to
    argue with you (not that I personally would want to…HaHa).
    You definitely put a fresh spin on a topic which has been written about for years.
    Excellent stuff, just great!

  4. September 1st, 2014 at 18:10 | #4

    great publish, very informative. I wonder why the opposite specialists of this sector don’t understand this.
    You should continue your writing. I’m confident, you have a great readers’ base already!

  5. September 3rd, 2014 at 03:04 | #5

    Hello my loved one! I want to say that this article is amazing, nice written and include almost all important infos.

    I’d like to see extra posts like this .

  6. September 8th, 2014 at 08:41 | #6

    These tiny components can damage easily if a large amount of current passes through them.
    They also sustain enough space between the elements
    to allow warm dissipation. Imagine how it feels when all of you in the same state
    wear the Real Madrid football kit to represent your love
    and support for the team, while the team is playing its game.

  7. September 8th, 2014 at 15:52 | #7

    Your style is unique in comparison to other people I have read stuff from.
    Thank you for posting when you’ve got the opportunity, Guess I’ll just book mark
    this site.

  8. September 9th, 2014 at 08:40 | #8

    I’m really enjoying the theme/design of your blog.

    Do you ever run into any browser compatibility problems?

    A small number of my blog readers have complained about my website not operating correctly in Explorer but looks great in Firefox.
    Do you have any ideas to help fix this issue?

  9. September 10th, 2014 at 01:40 | #9

    Hmm it seems like your site ate my first comment (it
    was super long) so I guess I’ll just sum it up what I had written and say, I’m
    thoroughly enjoying your blog. I too am an aspiring blog writer but I’m still new to the whole thing.

    Do you have any points for novice blog writers?
    I’d definitely appreciate it.

  10. September 10th, 2014 at 02:58 | #10

    There are several operating systems that a user can use, such as Linux, Macintosh, UNIX and Windows.

    Research is something that will take up a lot
    of your time and energy. Dedicated hosting offers most of the resources in a server but is normally had at a top
    quality price.

  11. September 12th, 2014 at 20:48 | #11

    Write more, thats all I have to say. Literally, itt seems as though you relied on the vidro to make your point.
    You clearly know what youre talking about, why waswte youur intelligence on just
    posting videos to yoiur blog when you could be giving us something enlightening to
    read?

  12. September 14th, 2014 at 02:28 | #12

    Nice post. I learn something totally new and challenging on websites I stumbleupon every day.
    It’s always interesting to read content from other writers and practice a little something
    from other web sites.

  13. September 21st, 2014 at 03:08 | #13

    Hello there, just became aware off your blog through
    Google, and found that it’s truly informative.

    I’m gonna watch out for brussels. I’ll applreciate if
    you continue this in future. Numerous peopl will be benefited
    from your writing. Cheers!

  14. September 21st, 2014 at 04:11 | #14

    绉併伅鎰熼姌銈掑彈銇戙€佺銇█銈忋仾銇戙倢銇般仾銈夈仾銇勩€?

  15. September 21st, 2014 at 11:25 | #15

    This site definitely has all the info I needed concerning this subject and didn’t know who to ask.

  16. September 24th, 2014 at 15:28 | #16

    Aquí para poder ver solo perros, acá para poder ver solo gatos,
    y acá casos especiales.

  17. September 29th, 2014 at 18:46 | #17

    Terrific post however I was wanting to know if you could write a litte more on this
    subject? I’d be very grateful if you could elaborate a
    little bit more. Appreciate it!

  18. October 1st, 2014 at 06:11 | #18

    It’s really a great and useful piece of information. I am satisfied that you simply shared this helpful information with
    us. Please keep us informed like this. Thanks for sharing.

  19. October 6th, 2014 at 10:21 | #19

    Very good blog! Do you have any helpful hints for aspiring writers?
    I’m planning to start my own website soon but I’m a little lost on everything.
    Would you propose starting with a free platform like WordPress
    or go for a paid option? There are so many choices out there
    that I’m totally overwhelmed .. Any suggestions?
    Bless you!

  20. October 7th, 2014 at 01:27 | #20

    Smoking affects the potency levels in men and many times it has
    been noted that smokers are generally impotent. A head gasket failure
    results in a leak, which in turn produces white smoke.

    When your home or business establishment has been affected by fire or its aggregate damages like soot,
    smoke and fire retardants, it is best to consult or hire a professional smoke odor
    removal company to assist you in effectively handling the problem.

  21. October 7th, 2014 at 04:59 | #21

    Il y a des occasions où le jeu en ligne devient difficile,
    et vous pouvez aller de l’avant peu importe ce que vous faites.

  22. October 8th, 2014 at 22:59 | #22

    This is a great tip particularly to those fresh to the blogosphere.
    Simple but very precise info… Appreciate your sharing this
    one. A must read post!

  23. October 10th, 2014 at 09:17 | #23

    obviously like your web site but you need to test the spelling on quite
    a few of your posts. Several of them are rife with
    spelling problems and I find it very troublesome to tell the truth nevertheless I’ll certainly come back again.

  24. October 10th, 2014 at 19:21 | #24

    I’m amazed, I have to admit. Seldom do I encounter a blog that’s
    equally educative and amusing, and let me tell you, you have hit the nail on the head.

    The problem is something too few men and women are speaking intelligently about.
    I’m very happy I found this in my hunt for something
    concerning this.

  25. October 11th, 2014 at 07:39 | #25

    WOW just what I was searching for. Came here by searching for canada auto
    insurance quote

  26. October 12th, 2014 at 03:25 | #26

    Mianowicie detektor ustawiany szykach nagłych. Sporządzenie mobilizacja
    alarmowa, że własny sam punkt. Przedpotopowo układany, takich jakże
    na pyroelemencie. Pilnują jeszcze na tenże sławny porządek trafień krewniackich,
    będzie najtrafniejszy przylega się na wiki egzystuje
    niewdzięczna. Do m2 natomiast emitorów uczona a wyłączenie nowych wbiec.

  27. October 12th, 2014 at 17:33 | #27

    If your overall goal is to work with the home repair service provider with the lowest bid,
    the quality of the job will likely be compromised and
    you may have to work with a different furniture adjustment team to fix the damage.
    The selection under this category includes a variety of styles and popular brands.
    Once purchasing such refined furniture there is little chance that you will ever
    want to part with it, being almost definitely one of the most cherished bedroom suites material, it adds both
    a bold and beautiful appearance to the space.

  28. October 13th, 2014 at 00:27 | #28

    Google is also facing “intense competition” in all of its associated industries – Most of the
    issues Google is facing have to do with competitors innovating technology at a faster rate than
    Google is. Get Latest Updates on Mobile Phone
    Deals,mobile phone shop, Free Gifts with Phones, mobile phones,
    cheap mobile phones, online phone shop & Coming
    Soon Mobile Phones. It all started when I was searching online about QR Codes, I was curious because I keep seeing more and more popping up online.

  29. October 15th, 2014 at 11:59 | #29

    Choice of material for making conservatory furniture would
    depend on a lot on factors like the customer’s budget and the ambience of the house.
    Contemporary furniture encompasses all current furniture
    designs that are bold and geometric, or, flowing and romantic.
    Check online for a broad selection of contemporary furniture websites and update your home today.

  30. October 15th, 2014 at 23:31 | #30

    Pretty component of content. I simply stumbled upon your
    blog and in accession capital to say that I get in fact loved account
    your blog posts. Anyway I’ll be subscribing to your feeds and even I
    fulfillment you get right of entry to persistently quickly.

  31. October 16th, 2014 at 16:09 | #31

    Wij zijn 3 jaar klant geweest bij Juresta Nederland bv.
    Wij hebben veel klachten over Juresta, ze werpen veel hindernissen op als ze moeten incasseren. Juresta kwam meestal bij ons zeuren dat het een niet haalbare incasso was en dat wij Juresta moesten betalen. Als
    we dan toch wilden doorzetten lieten ze de incasso zaak versloffen. Een ander probleem was
    dat Juresta wil dat voordat ze iets aan hun klant
    uitkeren dat die klant allemaal fax formulieren verstuurt.

    En ze lieten het ons niet weten als er geld op de rekening bij Juresta binnenkwam.
    Wij adviseren iedereen een ander incassobureau te zoeken, wij zijn nu bij een ander bureau zeer tevreden.

  32. October 17th, 2014 at 17:26 | #32

    Pretty! This has been an extremely wonderful post. Thank you for supplying this info.

  33. October 23rd, 2014 at 05:47 | #33

    Unquestionably imagine that that you stated. Your favourte reason appeared to be at the internet the simplest
    thing to tazke into accout of. I say to you,
    I definitely get irked even as people think about concerns that they juust
    do not realize about. You controlled to hit the nail upon the top as neatly as outlined out tthe whole thing with no need side effect , other folks can take a
    signal. Will probably be again too get more.
    Thanbk you

  34. October 31st, 2014 at 22:41 | #34

    The backend part of your company supports these profit centers.
    Then consider yourself one of the few, true internet marketers.

    To report stolen email addresses at Yahoo, click
    Yahoo.

  35. November 7th, 2014 at 13:33 | #35

    Jistě ѕі Sesnamku také oblíbítе, vaše láska
    a nový vztah se třeba skrývá mezi našimi profily. Chatovací místnosti lzze využívat
    zdarma, taak ѕi tuto nabídku nna dobrodružství a free sex nenechte proklouznout mezi prsty.
    Zdarma se zkuste zapojit ɗo našiϲh sexy chatu, а když budete chtít svuj sedy objev kontakttovat ɑ
    zažít sex v Liberci, stante se clenem ɑ napištе mu.

  36. November 14th, 2014 at 05:19 | #36

    Bidding wars for properties in some parts of the country drove up the appraised values of
    all nearby properties, creating a ripple effect throughout the fabric of the nation’s entire housing market.
    To qualify for a reverse mortgage the applicant must be 62 years of age or older.
    Combined with the regular interest that accrues on the loan balance, the up front costs can make
    this an extremely expensive way to borrow.

  37. November 16th, 2014 at 05:09 | #37

    For hottest news you have to pay a quick visit world wide web
    and on web I found this web page as a most excellent site for
    most recent updates.

  38. November 20th, 2014 at 00:08 | #38

    One thing I’ve noticed is there are plenty of misguided beliefs regarding the financial institutions intentions any time talking
    about foreclosed. One misconception in particular is the fact the bank prefers to have your house.
    Your banker wants your cash, not the house.
    They want the amount of money they loaned you with interest.
    Averting the bank will only draw any foreclosed realization.
    Thanks for your post.

  39. November 20th, 2014 at 18:04 | #39

    Excellent blog right here! Additionally your site lots up fast!
    What host are you the usage of? Can I am getting your associate
    link for your host? I desire my web site loaded up as quickly as yours lol

  40. December 2nd, 2014 at 05:29 | #40

    Pretty! This has been an incredibly wonderful post.
    Thanks for providing this info.

  41. December 15th, 2014 at 02:08 | #41

    Wonderful goods from you, man. I have understand your stuff previous to and you are just extremely excellent.
    I actually like what you have acquired here, certainly like what you are stating and the way in which you say it.

    You make it entertaining and you still care for to keep it wise.
    I cant wait to read much more from you. This is really a great website.

Comment pages
1 2 650
  1. April 27th, 2010 at 05:17 | #1
  2. September 4th, 2014 at 00:59 | #2
  3. September 23rd, 2014 at 23:09 | #3