Adaptive Resonance Theory

Java implementation of Adaptive Resonance Theory (ART) algorithms such as ART, ARTMAP, FuzzyART

License

License

MIT
Categories

Categories

Java Languages
GroupId

GroupId

com.github.chen0040
ArtifactId

ArtifactId

java-adaptive-resonance-theory
Last Version

Last Version

1.0.6
Release Date

Release Date

Type

Type

jar
Description

Description

Adaptive Resonance Theory
Java implementation of Adaptive Resonance Theory (ART) algorithms such as ART, ARTMAP, FuzzyART
Project URL

Project URL

https://github.com/chen0040/java-adaptive-resonance-theory
Source Code Management

Source Code Management

https://github.com/chen0040/java-adaptive-resonance-theory

Download java-adaptive-resonance-theory

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.chen0040/java-adaptive-resonance-theory/ -->
<dependency>
    <groupId>com.github.chen0040</groupId>
    <artifactId>java-adaptive-resonance-theory</artifactId>
    <version>1.0.6</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.chen0040/java-adaptive-resonance-theory/
implementation 'com.github.chen0040:java-adaptive-resonance-theory:1.0.6'
// https://jarcasting.com/artifacts/com.github.chen0040/java-adaptive-resonance-theory/
implementation ("com.github.chen0040:java-adaptive-resonance-theory:1.0.6")
'com.github.chen0040:java-adaptive-resonance-theory:jar:1.0.6'
<dependency org="com.github.chen0040" name="java-adaptive-resonance-theory" rev="1.0.6">
  <artifact name="java-adaptive-resonance-theory" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.chen0040', module='java-adaptive-resonance-theory', version='1.0.6')
)
libraryDependencies += "com.github.chen0040" % "java-adaptive-resonance-theory" % "1.0.6"
[com.github.chen0040/java-adaptive-resonance-theory "1.0.6"]

Dependencies

compile (3)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.20
org.slf4j : slf4j-log4j12 jar 1.7.20
com.github.chen0040 : java-data-frame jar 1.0.9

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.16.6

test (11)

Group / Artifact Type Version
org.testng : testng jar 6.9.10
org.hamcrest : hamcrest-core jar 1.3
org.hamcrest : hamcrest-library jar 1.3
org.assertj : assertj-core jar 3.5.2
org.powermock : powermock-core jar 1.6.5
org.powermock : powermock-api-mockito jar 1.6.5
org.powermock : powermock-module-junit4 jar 1.6.5
org.powermock : powermock-module-testng jar 1.6.5
org.mockito : mockito-core jar 2.0.2-beta
org.mockito : mockito-all jar 2.0.2-beta
com.github.chen0040 : java-data-image jar 1.0.2

Project Modules

There are no modules declared in this project.

java-adaptive-resonance-theory

Package provides java implementation of algorithms in the field of adaptive resonance theory (ART)

Build Status Coverage Status

Install

Add the following dependency to your POM file:

<dependency>
  <groupId>com.github.chen0040</groupId>
  <artifactId>java-adaptive-resonance-theory</artifactId>
  <version>1.0.6</version>
</dependency>

Features

Algorithms included:

  • ART1
  • FuzzyART
  • ARTMAP

Applications included:

  • Clustering (FuzzyART, ART1)
  • Multi-class Classification (ARTMAP)
  • Reinforcement Learning (FuzzyART)

Usage

Multi-class Classification using ARTMAP

To create and train a ARTMAP classifier:

ARTMAPClassifier classifier = new ARTMAPClassifier();
clasifier.fit(trainingData);

The "trainingData" is a data frame which holds data rows with labeled output (Please refers to this link to find out how to store data into a data frame)

To predict using the trained ARTMAP classifier:

String predicted_label = classifier.transform(dataRow);

The detail on how to use this can be found in the unit testing codes. Below is a complete sample codes of classifying on the libsvm-formatted heart-scale data:

InputStream inputStream = new FileInputStream("heart_scale");
DataFrame dataFrame = DataQuery.libsvm().from(inputStream).build();

// as the dataFrame obtained thus far has numeric output instead of labeled categorical output, the code below performs the categorical output conversion
dataFrame.unlock();
for(int i=0; i < dataFrame.rowCount(); ++i){
 DataRow row = dataFrame.row(i);
 row.setCategoricalTargetCell("category-label", "" + row.target());
}
dataFrame.lock();

double alpha = 9.89;
double beta = 0.3;
double rho = 0.01;
classifier.setAlpha(alpha);
classifier.setBeta(beta);
classifier.setRho0(rho);

classifier.fit(dataFrame);

for(int i = 0; i < dataFrame.rowCount(); ++i){
  DataRow tuple = dataFrame.row(i);
  String predicted_label = classifier.transform(tuple);
  System.out.println("predicted: "+predicted_label+"\tactual: "+tuple.categoricalTarget());
}

Spatial Segmentation (Clustering) using ART1

The following sample code shows how to do clustering using ART1:

DataQuery.DataFrameQueryBuilder schema = DataQuery.blank()
      .newInput("c1")
      .newInput("c2")
      .newOutput("designed")
      .end();

Sampler.DataSampleBuilder negativeSampler = new Sampler()
      .forColumn("c1").generate((name, index) -> randn() * 0.3 + (index % 2 == 0 ? 2 : 4))
      .forColumn("c2").generate((name, index) -> randn() * 0.3 + (index % 2 == 0 ? 2 : 4))
      .forColumn("designed").generate((name, index) -> 0.0)
      .end();

Sampler.DataSampleBuilder positiveSampler = new Sampler()
      .forColumn("c1").generate((name, index) -> rand(-4, -2))
      .forColumn("c2").generate((name, index) -> rand(-2, -4))
      .forColumn("designed").generate((name, index) -> 1.0)
      .end();

DataFrame data = schema.build();

data = negativeSampler.sample(data, 200);
data = positiveSampler.sample(data, 200);

System.out.println(data.head(10));

ART1Clustering algorithm = new ART1Clustering();

DataFrame learnedData = algorithm.fitAndTransform(data);

for(int i = 0; i < learnedData.rowCount(); ++i){
 DataRow tuple = learnedData.row(i);
 String clusterId = tuple.getCategoricalTargetCell("cluster");
 System.out.println("learned: " + clusterId +"\tknown: "+tuple.target());
}

Image Segmentation (Clustering) using FuzzyART

The following sample code shows how to use FuzzyART to perform image segmentation:

BufferedImage img= ImageIO.read(FileUtils.getResource("1.jpg"));

DataFrame dataFrame = ImageDataFrameFactory.dataFrame(img);

FuzzyARTClustering cluster = new FuzzyARTClustering();

DataFrame learnedData = cluster.fitAndTransform(dataFrame);

for(int i=0; i <learnedData.rowCount(); ++i) {
 ImageDataRow row = (ImageDataRow)learnedData.row(i);
 int x = row.getPixelX();
 int y = row.getPixelY();
 String clusterId = row.getCategoricalTargetCell("cluster");
 System.out.println("cluster id for pixel (" + x + "," + y + ") is " + clusterId);
}

The segmented image can be generated using the trained KMeans from above as illustrated by the following sample code:

List<Integer> classColors = new ArrayList<Integer>();
for(int i=0; i < 5; ++i){
 for(int j=0; j < 5; ++j){
    classColors.add(ImageDataFrameFactory.get_rgb(255, rand.nextInt(255), rand.nextInt(255), rand.nextInt(255)));
 }
}

BufferedImage segmented_image = new BufferedImage(img.getWidth(), img.getHeight(), img.getType());
for(int x=0; x < img.getWidth(); x++)
{
 for(int y=0; y < img.getHeight(); y++)
 {
    int rgb = img.getRGB(x, y);

    DataRow tuple = ImageDataFrameFactory.getPixelTuple(x, y, rgb);

    int clusterIndex = cluster.transform(tuple);

    rgb = classColors.get(clusterIndex % classColors.size());

    segmented_image.setRGB(x, y, rgb);
 }
}

Reinforcement Learning

There is also an example of reinforcement learning (TD-learning using Q-Learning and SARSA) based on FuzzyART. It is known as "FALCON A Fusion Architecture for Learning Cognition and Navigation", and the sample codes can be found in the src/test/java/com/github/chen0040/art/falcon/simulation/minefield The reinforcement learning objective is to navigate a tank (the agent) to a target flag in a mine field, sensors are available to the tank when making decision to turn and move forward, immediate reward and delayed rewards were given to the tank during the Q-Learning and SARSA reinforcement learning process. To launch the reinforcement learning, right-click MineFieldSimulatorGUI.java and select "Run in main()" in the IntelliJ editor popup menu (or something similar in eclipse or other editors), in the GUI launched, select "File->Start Simulation" (slow training mode) or "File->Start Simulation (No GUI)" (fast training mode)

Versions

Version
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1