Friday, March 13, 2015

RCaller 2.5 is available for downloading

We are happy to announce that our 'easy to use' Java library for calling R from Java is available for downloading by now on. Developers access the compiled jar file in site


 https://github.com/jbytecode/rcaller/releases/tag/2.5


This release does not extend the main functionality of the library but now there are some handy functions for performing some calculations and later development of the library.



What is new:

* Official document bibtex added to cite RCaller in any projects or papers

* RealMatrix class is implemented. Matrix operations are performed in more 'java-ish style'

* RService is implemented for developing wrapper functions


Where to start?

* Read the web page on RCaller http://mhsatman.com/tag/rcaller/
* Read blog entries in http://stdioe.blogspot.com.tr/search/label/rcaller
* Have a look at the source tree in https://github.com/jbytecode/rcaller
* Download the library in  https://github.com/jbytecode/rcaller/releases/tag/2.5

Have a nice try!


Migration of RCaller and Fuzuli Projects to GitHub

Since Google announced that they are shutting down the code hosting service 'Google code' in which our two projects RCaller and Fuzuli Programming Language are hosted.

We migrated our projects into the popular code hosting site GitHub.

Source code of these projects will no longer be committed in Google code site. Please check the new repositories.

GitHub pages are listed below:





RCaller:

https://github.com/jbytecode/rcaller




Fuzuli Project:

https://github.com/jbytecode/fuzuli



Thursday, March 12, 2015

Android Device Information Tool Application

Hello! I would like to share an Android application that can be used as a tool.

The application provides information about software of your Android device. You can find out:

-Device name
-Device ID
-Android version
-Device product
-Device manufacturer
-Device brand
-Device version
-Device host
-Device model
-Device user
-Device hardware
-Device radio version
-Device serial number
-Device finger print

If you need informations given above, you can download it from this URL.

Android Device Info App!

Monday, March 9, 2015

Nearest-Neighbor Clustering using RCaller - A library for Calling R from Java

RCaller is a software for calling R from Java. A blog post includes the latest version of downloadable jar and documentation here. The latest news can always be traced using the RCaller label in Practical Code Solutions blog.

A blog post on performing a k-means clustering analysis using RCaller is also available at this link.

In the code below, two double arrays, x and y, are created in Java side. These variables are then passed to R. In R side, distance matrix d is calculated. The R function hclust performs the main calculations. Finally, calculated heights of clustering tree and a dendrogram plot are returned to Java. The source code, output text and the returned plot are presented here:




package kmeansrcaller;

import java.io.File;
import rcaller.RCaller;
import rcaller.RCode;

public class SingleLinkageClustering {

    public static void main(String[] args) {
        RCaller caller = new RCaller();
        RCode code = new RCode();
        File dendrogram = null;

        double[] x = new double[]{1, 2, 3, 4, 5, 10, 20, 30, 40, 50};
        double[] y = new double[]{2, 4, 6, 8, 10, 20, 40, 60, 80, 100};

        code.addDoubleArray("x", x);
        code.addDoubleArray("y", y);

        code.addRCode("d <- dist(cbind(x,y))");
        code.addRCode("h&<- hclust(d, method=\"single\")");

        try {
            dendrogram = code.startPlot();
            code.addRCode("plot(h)");
            code.endPlot();
        } catch (Exception e) {
            System.out.println("Plot Error: " + e.toString());
        }

        caller.setRCode(code);

        caller.setRscriptExecutable("/usr/bin/Rscript");

        caller.runAndReturnResult("h");
        System.out.println(caller.getParser().getNames());

        if (dendrogram != null) {
            code.showPlot(dendrogram);
        }

        double[] heights = caller.getParser().getAsDoubleArray("height");
        for (int i = 0; i < heights.length; i++) {
            System.out.println("Height " + i + " = " + heights[i]);
        }
    }
}




The output is 

[merge, height, order, method, call, dist_method]
Height 0 = 2.23606797749979
Height 1 = 2.23606797749979
Height 2 = 2.23606797749979
Height 3 = 2.23606797749979
Height 4 = 11.1803398874989
Height 5 = 22.3606797749979
Height 6 = 22.3606797749979
Height 7 = 22.3606797749979
Height 8 = 22.3606797749979



The screen shot of the plotted graphics is here:



Have a nice read!


Saturday, March 7, 2015

K-means clustering with RCaller - A library for calling R from Java

Here is an example of RCaller, a library for calling R from Java.

In the code below, we create two variables x and y. K-means clustering function kmeans is applied on the data matrix that consists of x and y. The result is then reported in Java.






package kmeansrcaller;

import rcaller.RCaller;
import rcaller.RCode;

public class KMeansRCaller {

    public static void main(String[] args) {
        RCaller caller = new RCaller();
        RCode code = new RCode();

        double[] x = new double[]{1, 2, 3, 4, 5, 10, 20, 30, 40, 50};
        double[] y = new double[]{2, 4, 6, 8, 10, 20, 40, 60, 80, 100};

        code.addDoubleArray("x", x);
        code.addDoubleArray("y", y);

        code.addRCode("result <- kmeans(cbind(x,y), 2)");

        caller.setRCode(code);

        caller.setRscriptExecutable("/usr/bin/Rscript");

        caller.runAndReturnResult("result");
        System.out.println(caller.getParser().getNames());

        int[] clusters = caller.getParser().getAsIntArray("cluster");
        double[][] centers = caller.getParser().getAsDoubleMatrix("centers");
        double[] totalSumOfSquares = caller.getParser().getAsDoubleArray("totss");
        // RCaller automatically replaces dots with underlines in variable names
        // So the parameter tot.withinss is accessible as tot_withinss
        double[] totalWithinSumOfSquares = caller.getParser().getAsDoubleArray("tot_withinss");
        double[] totalBetweenSumOfSquares = caller.getParser().getAsDoubleArray("betweenss");

        for (int i = 0; i < clusters.length; i++) {
            System.out.println("Observation " + i + " is in cluster " + clusters[i]);
        }

        System.out.println("Cluster Centers:");
        for (int i = 0; i < centers.length; i++) {
            for (int j = 0; j < centers[0].length; j++) {
                System.out.print(centers[i][j] + " ");
            }
            System.out.println();
        }

        System.out.println("Total Within Sum of Squares: " + totalWithinSumOfSquares[0]);
        System.out.println("Total Between Sum of Squares: " + totalBetweenSumOfSquares[0]);
        System.out.println("Total Sum of Squares: " + totalSumOfSquares[0]);
    }

}



The output is



[cluster, centers, totss, withinss, tot_withinss, betweenss, size, iter, ifault]
Observation 0 is in cluster 2
Observation 1 is in cluster 2
Observation 2 is in cluster 2
Observation 3 is in cluster 2
Observation 4 is in cluster 2
Observation 5 is in cluster 2
Observation 6 is in cluster 2
Observation 7 is in cluster 1
Observation 8 is in cluster 1
Observation 9 is in cluster 1
Cluster Centers:
40.0 6.42857142857143 
80.0 12.8571428571429 
Total Within Sum of Squares: 2328.57142857143
Total Between Sum of Squares: 11833.9285714286
Total Sum of Squares: 14162.5



Have a nice read!