Code Monkey home page Code Monkey logo

gcrfs_library's Introduction

GCRFs Library

Java library for Gaussian Conditional Random Fields (GCRF) supports training and testing of GCRF methods on random generated datasets and real datasets.

Methods

Library supports two GCRF methods:

  • Standard GCRF (GCRF) - structured regression model that incorporates the outputs of unstructured predictors (based on the given attributes values) and the correlation between output variables in order to achieve a higher prediction accuracy
  • Directed GCRF (DirGCRF) - method extends the GCRF method by considering asymmetric similarity

Use

Download gcrfs.jar from http://gcrfs-tool.com/ and provide a reference to GCRFs Library jar file in your project.

Also, provide references to following jar:

In Eclipse: right click on the project, then Build Path > Configure Build Path > Add JARs or Add External JARs, and choose jars In NetBeans: right click on the project, then Properties > Libraries > Add JAR/Folder, and choose jars

See the GCRFs Library documentation for more.

Quickstart tutorial

Dataset

Required data:

  • s - similarity matrix (double[][])
  • r - outputs of unstructured predictor (double[])
  • y - expected outputs (double[])

Dataset from .txt files:

double[] r = ArrayReader.readArray("data/r.txt");
double[] y = ArrayReader.readArray("data/y.txt");
double[][] s = GraphReader.readGraph("data/s.txt", y.length);
Dataset dataset = new Dataset(s, r, y);

Required format for .txt file with similarity matrix:

  • Format: from node, to node, weight
  • Each edge should be in a separate line.
  • Nodes are represented by ordinal numbers (numbers, from 1 to the number of nodes).

Required format for .txt files with outputs of unstructured predictor and expected outputs:

  • Each output should be in a separate line.
  • Output should be number.
  • Order of outputs should be consistent with ordinal numbers of nodes in the file with similarity matrix.

Random generated dataset:

double[][] s = GraphGenerator.generateDirectedGraph(200);
double[] r = ArrayGenerator.generateArray(200, 5);

The generated S and R should be used to calculate the actual value of output y for each node, in accordance to the method calculation rules, so y method from specific Calculations class should be used:

CalculationsDirGCRF c = new CalculationsDirGCRF(s, r);
double[] y = c.y(1, 2, 0.05);
Dataset dataset = new Dataset(s, r, y);

Method

Use class of specific method that integrates learning algorithm and calculation rules:

// parameters for learning algorithm
double alpha = 1;
double beta = 1;
double lr = 0.0001;
int maxIter = 100;
Parameters p = new Parameters(alpha, beta, maxIter, lr);
		
DirGCRF method = new DirGCRF(p, dataset);
		
double[] predictedOutputs = method.predictOutputs();
for (int i = 0; i < predictedOutputs.length; i++) {
	System.out.println(predictedOutputs[i]);
}
		
System.out.println("R^2 Train: " + method.rSquared());

The new method is trained and it should be tested:

double[] yTest = ArrayReader.readArray("data/yTest.txt");
double[] rTest = ArrayReader.readArray("data/rTest.txt");
double[][] sTest = GraphReader.readGraph("data/sTest.txt", y.length);

double[] predictedOutputsTest = g1.predictOutputsForTest(sTest, rTest);
for (int i = 0; i < predictedOutputsTest.length; i++) {
	System.out.println(predictedOutputsTest[i]);
}
System.out.println("R^2 Test: " + g1.rSquaredForTest(predictedOutputsTest, yTest));

Another way is to Use Basic class and specify learning algorithm and calculation rules:

// parameters for learning algorithm
double alpha = 1;
double beta = 1;
double lr = 0.0001;
int maxIter = 100;
Parameters p = new Parameters(alpha, beta, maxIter, lr);
		
// calculation rules
CalculationsDirGCRF c = new CalculationsDirGCRF(s, r);
		
// learning algorithm
GradientAscent g = new GradientAscent(p, c, y, false, null);
		
Basic method = new Basic(g, c, dataset);
		
double[] predictedOutputs = method.predictOutputs();
for (int i = 0; i < predictedOutputs.length; i++) {
	System.out.println(predictedOutputs[i]);
}
		
System.out.println("R^2 Train: " + method.rSquared());

Class diagram

Basic classes presented at the class diagram provide a general structure and logic components that are common for GCRF based methods.

Full list of packages, classes and methods can be found in GCRFs Library GCRFs Library API documentation.

diagram

How to extend?

Library can be easily extended with new GCRF based methods.

Difference between various GCRF methods is reflected in the calculation rules, so first step is to extend the CalculationsGCRF class and to override methods that implement specific calculations.

Second step is to pass object of the new class for calculations to the Basic class, or to override it.

Also, it is possible add new learning algorithm by implementing LearningRule interface.

gcrfs_library's People

Contributors

vujicictijana avatar

Watchers

 avatar

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.