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()
    private void calculate(double... input)
        Vector output = network.getOutput();
        Double answer = output.get(0);

The code produces the following output


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. February 10th, 2015 at 15:29 | #1

    Why viewers still make use of to read news papers when in this technological world everything is accessible
    on web?

  2. February 11th, 2015 at 15:42 | #2

    Good article! We are linking to this particularly great
    content on our website. Keep up the good writing.

  3. February 11th, 2015 at 22:37 | #3

    Can I simply say what a comfort to discover someone who actually knows what they are discussing on the internet.

    You actually realize how to bring an issue to light and make it important.
    More people should read this and understand this side of the story.
    I was surprised that you aren’t more popular since you surely have the gift.

  4. February 12th, 2015 at 09:33 | #4

    I feel this is among the such a lot vital information for me.
    And i’m satisfied studying your article. However wanna statement on few
    normal issues, The site taste is ideal, the articles is truly nice : D.
    Just right job, cheers

  5. February 12th, 2015 at 12:34 | #5

    Hello Dear, are you genuinely visiting this web site daily,
    if so afterward you will definitely take fastidious knowledge.

  6. February 12th, 2015 at 13:43 | #6

    This is exactly why lack of attic insulation always causes the hot air to ascend
    from the house and get directly away through the roof.

  7. February 13th, 2015 at 09:46 | #7

    I am now 22 and I am an avid blogger, writer and internet enthusiast.
    The negative points about this option however are that the clips tend to make it short-circuit, but this has been resolved and any faulty Kindles have been replaced and repaired long ago. , “I could not obtain that website that posts the profitable lottery quantities, so I just Googled it.

  8. February 13th, 2015 at 13:08 | #8

    Hello there, You have done a great job. I’ll certainly digg it and personally suggest to my
    friends. I am confident they’ll be benefited from this site.

  9. February 14th, 2015 at 09:40 | #9

    Aw, this was an exceptionally good post. Finding the time and actual effort to make
    a great article… but what can I say… I put things off a whole lot and never manage to
    get nearly anything done.

  10. February 14th, 2015 at 21:59 | #10

    ” The official audio video of the second song debuted on You – Tube the day before the Victoria’s Secret show. The feel of jewellery you use shows your frame of mind towards existence. It is appropriate, regardless of the setting, for your Christmas party attire to be one step dressier than your normal office wear.

  11. February 15th, 2015 at 09:04 | #11

    Je ne pouvais pas ne pouvait pas résister . Parfaitement écrite !

  12. February 15th, 2015 at 13:59 | #12

    I know this web page offers quality depending articles or
    reviews and other data, is there any other site which offers such stuff in quality?

  13. February 16th, 2015 at 00:09 | #13

    Hello, after reading this amazing post i am too
    delighted to share my familiarity here with friends.

  14. February 16th, 2015 at 04:05 | #14

    My partner and I absolutely love your blog and find a lot of your post’s to be
    precisely what I’m looking for. can you offer guest writers to write content available for you?
    I wouldn’t mind publishing a post or elaborating
    on a lot of the subjects you write concerning here.
    Again, awesome blog!

  15. February 19th, 2015 at 13:23 | #15

    In the current economic climate everyone is worried about their
    budget. The takeover of the jewellery industry by the machine made ornaments, had led to the fall in the charm of the artisan crafted jewellery in the past few years.
    So, no matter if it is any occasion, go for diamond jewelry and
    let her know how much you love and value her.
    This deep burgundy and reddish colour readily captures attention of each
    eye and jewel appears amazing in white gold. You can also try bending
    your precious metals and stones. Or semi-precious bracelets that have made
    from beautiful handmade glass beads in every colour for you to think of.
    is far more interesting than sterling silver studs and
    plain chains. The brides in Maharashtra wear dark green Paithni
    saris, matched with green glass bangles and gold bangles, which really look amazing.
    I would not want any money I spend on diamonds to go to the
    wrong people and there does look like a lot of inappropriate dealings with
    regard to Africa’s diamonds. As it is known to all,women love jewellery very much
    and love flaunting it.

  16. February 28th, 2015 at 05:30 | #16

    Location, Location, Find Alan Cooper Estate Agents in Location is an estate agency built on the values of trust, local
    knowledge and experience.

  17. March 2nd, 2015 at 02:31 | #17

    Very soon this web site will be famous amid all blog users, due to it’s good articles

  18. March 3rd, 2015 at 15:59 | #18

    Hi, I do believe this iss a great site. I stumbledupon it ;
    ) I will revisit yet again since i have saved as a
    favorite it. Monry and freedom is the best way
    to change, may you be rich and continue tto guide others.

  19. March 5th, 2015 at 13:35 | #19

    And, as you again probably know, Arsene Wenger has again refused, partially, to heed my advice,
    advances, pleas, begs, howlers, screams, errr. Don’t worry though, with some practice and the right guidance you can improve
    your skills. Twelve teams representing their countries were sent to compete.

  20. March 5th, 2015 at 16:15 | #20

    If you would like tto grow your experience only ksep visiting tnis web site and be updated
    with the latest news posted here.

  21. May 2nd, 2015 at 06:55 | #21

    I love your blog.. very nice colors & theme. Did you create this website yourself? Plz reply back as I’m looking to create my own blog and would like to know wheere u got this from. thanks

  22. June 14th, 2015 at 17:39 | #22

    I do feel great having found your post. I would like to thank you for sharing it.

  23. June 18th, 2015 at 20:49 | #23

    We can fix the issue by disconnecting the power from
    the wireless router for about 10 seconds and then reconnecting the ability cable.

  24. July 10th, 2015 at 02:14 | #24

    Thank you for writing this. The whole read has been eye opening.Many thanks.

  25. July 15th, 2015 at 18:17 | #25

    Good day I am so grateful I found your web site, I really found you by accident, while I was searching on Yahoo for something else, Anyhow I am here now and would just like to say kudos for a remarkable post and a all round interesting blog (I also love the theme/design), I don’t have time to look over it all at the minute but I have saved it and also added in your RSS feeds, so when I have time I will be back to read much more, Please do keep up the awesome work.|

  26. July 17th, 2015 at 17:41 | #26

    At this time I am ready to do my breakfast, when having my breakfast coming over again to read other news.|

  27. July 17th, 2015 at 18:41 | #27

    Whats up very nice site!! Man .. Excellent .. Superb .. I will bookmark your website and take the feeds also? I’m satisfied to seek out a lot of useful information right here within the publish, we need work out more techniques on this regard, thank you for sharing. . . . . .|

  28. July 23rd, 2015 at 18:01 | #28

    Going in the evening company’s surfaces:. Start Saving: In case you
    complete this, you will be saving cash in no time.

  29. August 6th, 2015 at 20:34 | #29

    Denver internet site style was targeted on maximizing house for one-way links so
    that consumers could pile on the linking group additions weekly,
    even daily. Which just one of these approaches is the most successful when it
    comes to search motor internet marketing. Social media permits organizations to interact
    with their clients, offering a confront driving
    the firm.

  30. August 10th, 2015 at 08:39 | #30

    Nice post. I used to be checking constantly this weblog and I am inspired!
    Extremely useful info specifically the ultimate section :
    ) I care for such information a lot. I was seeking
    this certain information for a very long time. Thank you and good luck.

  31. August 23rd, 2015 at 10:00 | #31

    When choosing full figured lingerie, it’s advisable to evaluate your figure
    type. In fact, you will get creative using the naughtiest of words so much so that you’ll be setting
    the stage to get a fun time together with your partner.
    hide physical imperfections including blemishes, bruises, scars,
    hair, or varicose veins.

  32. August 26th, 2015 at 11:55 | #32

    What’s up to every one, it’s genuinely a
    nice for me to visit this site, it contains helpful Information.

  33. August 26th, 2015 at 22:22 | #33

    Nice info, i enjoyed your site

  34. September 14th, 2015 at 21:49 | #34

    At this time it sounds like BlogEngine is the top blogging platform available right now.
    (from what I’ve read) Is that what you are using
    on your blog?

  35. September 15th, 2015 at 13:52 | #35

    Wonderful goods from you, man. I’ve understand your stuff previous to and you are just too excellent.
    I really like what you have acquired here, really like
    what you are saying and the way in which you say it. You make
    it entertaining and you still care for to keep it sensible.

    I can’t wait to read far more from you. This is really a great web site.

  36. October 12th, 2015 at 03:16 | #36

    Hello. remarkable job. I did not anticipate this. This is a splendid story. Thanks!

  37. October 26th, 2015 at 11:40 | #37

    The most trusted and the most high priced route will be decide
    on a skilled oral whitening method. As experts in her subject with the
    means to access modern hi-tech instruments and electronics they might be probably going to get you
    the best benefits. Dentists also provide accessibility
    extra targeted prescription peroxide solutions.
    Luckily they are almost certainly going to have the option to discover from your medical studies if something can create damage to your smile.

    There was a sensible optional though – trays rather than strip.
    Aquafresh White Trays (approximately $37) permit
    you to just put on these trays in your throat
    for 45 moments every single day during the period of three
    days to gather benefits. In this technique you are going to get the benefits
    of the ceaseless get in touch with over a period of moments without the presense of irritation of pieces.
    The only problem is that occasionally the gel can leak right out the holder.

    To learn a lot more about zoom teeth whitening visit our page: teeth whitening kit

    Initially, you should know of those that in order to avoid.

    These could be the over-the-counter gels and light/heat remedies within the dentist.
    We should accomplish the gels initially. Non-prescription ties
    in grab a long time to focus. It may take about fourteen days to ensure you to definitely attain the level
    of whitening you want. Even if you’re definitely not
    pressed for time, exactly why is it possible you hold off whenever possible posses leads to a substantially reduced span of time?
    Furthermore, most people grumble that they are just not helpful and happened to be upset employing the effects.

    Subsequent, we will speak about the laser therapy illumination treatment options that you can get at a dentist’s
    company. Most clients claim serious serious pain and susceptibility following the technique, also to the stage
    they’ve trouble eating food. Although beam mild remedies are efficient, sometimes it is way too
    successful. Some clients get eerie-looking, unnaturally white teeth.
    They whine they are often teased regarding their smiles are as well blinding.
    Lastly, this technique is fairly costly. The whole lot can run up to $600,
    instead of most people have enough money to expend a lot
    of money on their looks.

    Not commonly correct! Professional Teeth Whitening product or service retailers
    primarily use peroxide or Carbamide oxide being the ingredients in their
    enamel whitener gels. The inorganic peroxide (HO) happens to
    be a bleaching representative which converts into drinking water (HO)
    and produces an Oxygen molecule (O) in the act with the compound impulse.
    Both liquids and air are standard, safer pieces of our daily
    physical lives.

    The air contaminants infiltrate the harsh area of your own dental (despite the reality they come smooth, they
    truly are microscopically coarse, rod like crystal components) and dislodge discoloration fibers.
    I like to clarify this by imagining the television commercials which reveal just how a clothes washing powder with oxygen lifts stain because of your clothes.

    Acidic goods can take out tooth enamel from your own tooth
    enamel. Check for teeth bleaching services and products using peroxide that will be pH equal, indicating they have got no, or reduced
    acidity values. Adding acidity into viewpoint,
    you should know that day-to-day 100% juice was demonstrated in lab research to soften (and perhaps deteriorate) dental tooth
    enamel by many folks circumstances more than a seasoned hydrogen peroxide relying dental whitening gel could,
    if employed effectively.

  38. November 2nd, 2015 at 04:33 | #38

    Good day I am so happy I foun yoyr weblog, I really found you by error, while I was looking on Digg for something else,
    Nonetheless I am here now and would just like tto say
    kudos for a marvelous post and a all rouhnd entertaining blog (I also love the theme/design),
    I don’t have time to read it all at the minute but I have book-marked it and also included your RSS feeds, so when I have time I will bbe back to read more,
    Please do keep up the excellent jo.

Comment pages
1 2 3 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