Permalink
Browse files

"Hard fork" from parent project: change package name, update deployme…

…nt logic, supplement README.
  • Loading branch information...
jeffpasternack committed Dec 19, 2018
1 parent e3df9bb commit 2267a30aadb08352c5922216219d62c0b7a06083
Showing with 163 additions and 131 deletions.
  1. +18 −3 README.md
  2. +70 −47 build.gradle
  3. +1 −1 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/ArraySorter.java
  4. +1 −1 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/DoubleArrayPointer.java
  5. +1 −1 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/Feature.java
  6. +1 −1 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/FeatureNode.java
  7. +1 −1 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/Function.java
  8. +1 −1 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/IntArrayPointer.java
  9. +1 −1 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/InvalidInputDataException.java
  10. +1 −1 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/L2R_L2_SvcFunction.java
  11. +1 −1 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/L2R_L2_SvrFunction.java
  12. +1 −1 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/L2R_LrFunction.java
  13. +1 −1 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/LLThreadPool.java
  14. +1 −1 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/Linear.java
  15. +2 −2 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/Model.java
  16. +2 −2 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/Parameter.java
  17. +1 −1 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/ParameterSearchResult.java
  18. +16 −19 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/Predict.java
  19. +1 −1 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/Problem.java
  20. +4 −4 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/SolverMCSVM_CS.java
  21. +1 −1 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/SolverType.java
  22. +1 −1 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/SparseOperator.java
  23. +13 −16 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/Train.java
  24. +7 −7 src/main/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/Tron.java
  25. +1 −1 src/test/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/ArrayPointerTest.java
  26. +3 −3 src/test/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/ArraySorterTest.java
  27. +1 −1 src/test/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/FeatureNodeTest.java
  28. +3 −3 src/test/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/LinearTest.java
  29. +1 −1 src/test/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/ParameterTest.java
  30. +1 −1 src/test/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/PredictTest.java
  31. +1 −1 src/test/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/SolverTypeTest.java
  32. +1 −1 src/test/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/SparseOperatorTest.java
  33. +1 −1 src/test/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/TestUtils.java
  34. +2 −2 src/test/java/{de/bwaldvogel → com/jeffreypasternack}/liblinear/TrainTest.java
@@ -1,6 +1,21 @@
[![Build Status](https://travis-ci.org/bwaldvogel/liblinear-java.png?branch=master)](https://travis-ci.org/bwaldvogel/liblinear-java)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/de.bwaldvogel/liblinear/badge.svg)](http://maven-badges.herokuapp.com/maven-central/de.bwaldvogel/liblinear)
[![BSD 3-Clause License](https://img.shields.io/github/license/bwaldvogel/liblinear-java.svg)](https://opensource.org/licenses/BSD-3-Clause)
[![Build Status](https://api.travis-ci.org/jeffpasternack/liblinear-java.svg?branch=master)](https://api.travis-ci.org/jeffpasternack/liblinear-java.svg?branch=master)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.jeffreypasternack/liblinear/badge.svg)](http://maven-badges.herokuapp.com/maven-central/com.jeffreypasternack/liblinear/)
[![BSD 3-Clause License](https://img.shields.io/github/license/jeffpasternack/liblinear-java.svg)](https://opensource.org/licenses/BSD-3-Clause)

This is a fork of the Java port of LIBLINEAR, adding multithreading for logistic regression with L2 regularization (L2_LR). In informal testing on a MacBook using 4 threads, a wall clock speedup of ~2.4x was observed in a problem with 100K examples in 5 dimensions.

The multithreading strategy is:
1. Break up lists of examples into "chunks", small subsets of the examples
2. Process each chunk independently via the thread pool, accumulating results (e.g. the partial gradients) into a thread-local array where applicable
3. When each thread completes, it acquires a lock and adds the thread-local array into a global accumulator array.

Key changes from the original port:
- Added threadCount param and associated command-line argument. This argument is ignored unless L2_LR solver is used.
- Added the LLThreadPool class, a wrapper around a ThreadPoolExecutor with accompanying helper classes.
- Changed the package from de.bwaldvogel.liblinear to com.jeffreypasternack.liblinear; this is to avoid conflicts when (possibly transitively) depending on both the original and multithreaded libraries.

Original README
---

This is the Java version of LIBLINEAR.

@@ -1,7 +1,11 @@
apply plugin: 'java'
apply plugin: 'com.bmuschko.nexus'
apply plugin: 'idea'
apply plugin: 'java-library'

group = "de.bwaldvogel"
apply plugin: 'maven'
apply plugin: 'signing'

archivesBaseName = "liblinear"
group = "com.jeffreypasternack"
version = '2.21'

sourceCompatibility = 1.7
@@ -11,8 +15,8 @@ compileJava.options.encoding = 'UTF-8'

ext {
title = 'liblinear'
description = 'Java port of Liblinear'
url = 'https://www.github.com/bwaldvogel/liblinear'
description = 'Java port of Liblinear with Multithreaded Training'
url = 'https://github.com/jeffpasternack/liblinear-java'
}

jar {
@@ -25,10 +29,6 @@ buildscript {
repositories {
jcenter()
}

dependencies {
classpath 'com.bmuschko:gradle-nexus-plugin:2.3.1'
}
}

ext {
@@ -38,43 +38,6 @@ ext {
equalsverifierVersion = '2.5.2'
}

modifyPom {
project {
groupId 'de.bwaldvogel'
artifactId 'liblinear'
name title
description 'Java port of Liblinear'
url url
inceptionYear '2008'

scm {
url 'git@github.com:bwaldvogel/liblinear.git'
connection 'scm:git:git@github.com:bwaldvogel/liblinear.git'
developerConnection 'scm:git:git@github.com:bwaldvogel/liblinear.git'
}

licenses {
license {
name 'The BSD License'
url 'http://www.opensource.org/licenses/bsd-license.php'
distribution 'repo'
}
}

developers {
developer {
id 'bwaldvogel'
name 'Benedikt Waldvogel'
email 'mail@bwaldvogel.de'
}
}
}
}

nexus {
sign = true
}

repositories {
mavenCentral()
}
@@ -92,4 +55,64 @@ dependencies {
testCompile group: 'nl.jqno.equalsverifier', name: 'equalsverifier', version: equalsverifierVersion
}

// vim: set ts=4 sw=4 et:
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}

task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}

artifacts {
archives javadocJar, sourcesJar
}

signing {
sign configurations.archives
}

uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}

snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}

pom.project {
name 'liblinear'
packaging 'jar'

description 'Java port of Liblinear with Multithreaded Training'
url 'https://github.com/jeffpasternack/liblinear-java'

scm {
connection 'scm:git@github.com:jeffreypasternack/liblinear-java.git'
developerConnection 'scm:git@github.com:jeffreypasternack/liblinear-java.git'
url 'scm:git@github.com:jeffreypasternack/liblinear-java.git'
}

licenses {
license {
name 'The BSD License'
url 'http://www.opensource.org/licenses/bsd-license.php'
}
}

developers {
developer {
id 'jeffpasternack'
name 'Jeff Pasternack'
}
}
}
}
}
}
@@ -1,4 +1,4 @@
package de.bwaldvogel.liblinear;
package com.jeffreypasternack.liblinear;


final class ArraySorter {
@@ -1,4 +1,4 @@
package de.bwaldvogel.liblinear;
package com.jeffreypasternack.liblinear;


final class DoubleArrayPointer {
@@ -1,4 +1,4 @@
package de.bwaldvogel.liblinear;
package com.jeffreypasternack.liblinear;

/**
* @since 1.9
@@ -1,4 +1,4 @@
package de.bwaldvogel.liblinear;
package com.jeffreypasternack.liblinear;

public class FeatureNode implements Feature {

@@ -1,4 +1,4 @@
package de.bwaldvogel.liblinear;
package com.jeffreypasternack.liblinear;

// origin: tron.h
interface Function {
@@ -1,4 +1,4 @@
package de.bwaldvogel.liblinear;
package com.jeffreypasternack.liblinear;


final class IntArrayPointer {
@@ -1,4 +1,4 @@
package de.bwaldvogel.liblinear;
package com.jeffreypasternack.liblinear;


public class InvalidInputDataException extends Exception {
@@ -1,4 +1,4 @@
package de.bwaldvogel.liblinear;
package com.jeffreypasternack.liblinear;

class L2R_L2_SvcFunction implements Function {

@@ -1,4 +1,4 @@
package de.bwaldvogel.liblinear;
package com.jeffreypasternack.liblinear;

/**
* @since 1.91
@@ -1,4 +1,4 @@
package de.bwaldvogel.liblinear;
package com.jeffreypasternack.liblinear;

class L2R_LrFunction implements Function {

@@ -1,4 +1,4 @@
package de.bwaldvogel.liblinear;
package com.jeffreypasternack.liblinear;

import java.util.Arrays;
import java.util.concurrent.ExecutionException;
@@ -1,4 +1,4 @@
package de.bwaldvogel.liblinear;
package com.jeffreypasternack.liblinear;

import java.io.BufferedReader;
import java.io.BufferedWriter;
@@ -1,6 +1,6 @@
package de.bwaldvogel.liblinear;
package com.jeffreypasternack.liblinear;

import static de.bwaldvogel.liblinear.Linear.copyOf;
import static com.jeffreypasternack.liblinear.Linear.copyOf;

import java.io.File;
import java.io.IOException;
@@ -1,6 +1,6 @@
package de.bwaldvogel.liblinear;
package com.jeffreypasternack.liblinear;

import static de.bwaldvogel.liblinear.Linear.copyOf;
import static com.jeffreypasternack.liblinear.Linear.copyOf;


public final class Parameter {
@@ -1,4 +1,4 @@
package de.bwaldvogel.liblinear;
package com.jeffreypasternack.liblinear;

public class ParameterSearchResult {

@@ -1,9 +1,6 @@
package de.bwaldvogel.liblinear;
package com.jeffreypasternack.liblinear;

import static de.bwaldvogel.liblinear.Linear.atof;
import static de.bwaldvogel.liblinear.Linear.atoi;
import static de.bwaldvogel.liblinear.Linear.printf;
import static de.bwaldvogel.liblinear.Linear.info;
import static com.jeffreypasternack.liblinear.Linear.info;

import java.io.BufferedReader;
import java.io.BufferedWriter;
@@ -56,10 +53,10 @@ static void doPredict(BufferedReader reader, Writer writer, Model model) throws
int[] labels = model.getLabels();
prob_estimates = new double[nr_class];

printf(out, "labels");
Linear.printf(out, "labels");
for (int j = 0; j < nr_class; j++)
printf(out, " %d", labels[j]);
printf(out, "\n");
Linear.printf(out, " %d", labels[j]);
Linear.printf(out, "\n");
}


@@ -70,7 +67,7 @@ static void doPredict(BufferedReader reader, Writer writer, Model model) throws
double target_label;
try {
String label = st.nextToken();
target_label = atof(label);
target_label = Linear.atof(label);
} catch (NoSuchElementException e) {
throw new RuntimeException("Wrong input format at line " + (total + 1), e);
}
@@ -82,8 +79,8 @@ static void doPredict(BufferedReader reader, Writer writer, Model model) throws
}

try {
int idx = atoi(split[0]);
double val = atof(split[1]);
int idx = Linear.atoi(split[0]);
double val = Linear.atof(split[1]);

// feature indices larger than those in training are not used
if (idx <= nr_feature) {
@@ -108,13 +105,13 @@ static void doPredict(BufferedReader reader, Writer writer, Model model) throws
if (flag_predict_probability) {
assert prob_estimates != null;
predict_label = Linear.predictProbability(model, nodes, prob_estimates);
printf(out, "%g", predict_label);
Linear.printf(out, "%g", predict_label);
for (int j = 0; j < model.nr_class; j++)
printf(out, " %g", prob_estimates[j]);
printf(out, "\n");
Linear.printf(out, " %g", prob_estimates[j]);
Linear.printf(out, "\n");
} else {
predict_label = Linear.predict(model, nodes);
printf(out, "%.17g\n", predict_label);
Linear.printf(out, "%.17g\n", predict_label);
}

if (predict_label == target_label) {
@@ -132,11 +129,11 @@ static void doPredict(BufferedReader reader, Writer writer, Model model) throws

if (model.solverType.isSupportVectorRegression()) //
{
info("Mean squared error = %g (regression)%n", error / total);
info("Squared correlation coefficient = %g (regression)%n", //
Linear.info("Mean squared error = %g (regression)%n", error / total);
Linear.info("Squared correlation coefficient = %g (regression)%n", //
((total * sumpt - sump * sumt) * (total * sumpt - sump * sumt)) / ((total * sumpp - sump * sump) * (total * sumtt - sumt * sumt)));
} else {
info("Accuracy = %g%% (%d/%d)%n", (double)correct / total * 100, correct, total);
Linear.info("Accuracy = %g%% (%d/%d)%n", (double)correct / total * 100, correct, total);
}
}

@@ -158,7 +155,7 @@ public static void main(String[] argv) throws IOException {
switch (argv[i - 1].charAt(1)) {
case 'b':
try {
flag_predict_probability = (atoi(argv[i]) != 0);
flag_predict_probability = (Linear.atoi(argv[i]) != 0);
} catch (NumberFormatException e) {
exit_with_help();
}
@@ -1,4 +1,4 @@
package de.bwaldvogel.liblinear;
package com.jeffreypasternack.liblinear;

import java.io.File;
import java.io.IOException;
@@ -1,8 +1,8 @@
package de.bwaldvogel.liblinear;
package com.jeffreypasternack.liblinear;

import static de.bwaldvogel.liblinear.Linear.copyOf;
import static de.bwaldvogel.liblinear.Linear.info;
import static de.bwaldvogel.liblinear.Linear.swap;
import static com.jeffreypasternack.liblinear.Linear.copyOf;
import static com.jeffreypasternack.liblinear.Linear.info;
import static com.jeffreypasternack.liblinear.Linear.swap;


/**
@@ -1,4 +1,4 @@
package de.bwaldvogel.liblinear;
package com.jeffreypasternack.liblinear;

import java.util.HashMap;
import java.util.Map;
@@ -1,4 +1,4 @@
package de.bwaldvogel.liblinear;
package com.jeffreypasternack.liblinear;

class SparseOperator {

Oops, something went wrong.

0 comments on commit 2267a30

Please sign in to comment.