Wednesday, 17 February 2016

Two-Dimensional Bayesian Network Classifier

I posted a simple time series pattern recognition ten days ago, and I didn't  expect readers may come, download and test it. I'm happy it happened and since some of them have asked to prepare something to show the result, here I put a server and client application to let you send your training and test data to the server and it displays the result.

The server side name is BNTSC1 it is for "Bayesian Network Time Series Classifier" but since it can be used for any two-dimensional data, I preferred to put that as the title of the post. You can download the server and client side from the following link:

Download server and client applications from here ...

And the online version of the tool is here:

Online Bayesian Network Time Series Classifier

Server side
The server side is a simple Java servlet application, containing two individual servlets. the "Home" class is a servlet which reads the sent data and displays them on the screen and the "Data" servlet which you can config the classifier and send training or test data to it.

The core of the server is "SimpleTimeSeries" class I used it before in my previous post. It is documented nearly well, and the rest of the "Home" servlet is nothing but reading updated data and pass them to JSP file.

Both servlets are "extends" of a "RootServlet" just because I wanted to let them both have access to "TimeSeriesAnalysis1" and "DataStorage" which are analysis wrapper over "SimpleTimeSeries" and simple storage. I've used "DataStorage" class because I didn't see any reason to use any database or text file to store data. If you just take a look at the code you'll find it easy to understand.

Client side
It just consists of two classes "ClassifierInterface" and "Test". The first is a wrapper for Java's "HttpURLConnection" class to send requests to a server. The "ClassifierInterface" has three public methods to set parameters of the classifier, send training data and send test data. If you call them correctly you can see the results in server side.

The whole thing "Test" class does, has three step:

1- Setting the parameters by calling "setParameters()" method.
2- A loop to send training data by calling "train()".
3- A loop to send test data by calling "test()".

Just note running the client application shows nothing notably to you. It just sends data to the server, you can see the result on server by updating the graph.

How test works
Upload the war file in your application server or run the server's source codes on your IDE, at this time don't change the application's context. You have to see an empty coordinate system. Now on the client application go to the "getTimeSeriesTrainingValue()" method and make sure you have chosen the "getLine()" training data. "getLine()" generates a line shape pattern of data, there are some more training data generator functions like "getSinusoidalWave()",  "getSquareWave()" and "getSquareBox()".

The second loop sends randomly 1440 pair of (time, value) to the server and if server found them in the class of the trained network, shows them in green otherwise in red. Look at the following.

Classifying a line trend.

Click on the picture above and see how the classifier distinguishes the points around the trained data (in gray) and shows them in green. Now if you change the training data generator to "getSquareWave()" and run the test, it shows you the followings.


Classifying a square wave.

As you see it works perfect, for "getSinusoidalWave()" and "getSquareBox()" you have the followings:

Classifying a sinusoidal wave.

There is no limit for the training data; the classifier learns any available pattern in the training set, look at this one.

Classifying a box.

Download the applications and test them, let me know if there is anything wrong. Feel free to ask may about them (the contact me form on the right side column).

No comments:

Post a Comment