Skip to content
Permalink
Browse files

Merge remote-tracking branch 'upstream/master'

  • Loading branch information...
jeffpasternack committed Dec 18, 2018
2 parents 8ad179f + 0195dce commit e3df9bb96afa8f768ec3a8850e05091faef82476
@@ -8,5 +8,9 @@
!.travis.yml

build/
out/
classes/
data/

*.ipr
*.iws
@@ -11,3 +11,7 @@ matrix:
jdk: openjdk8
- os: linux
jdk: oraclejdk9
- os: linux
jdk: openjdk10
- os: linux
jdk: openjdk11
@@ -1,5 +1,5 @@

Copyright (c) 2007-2017 The LIBLINEAR Project.
Copyright (c) 2007-2018 The LIBLINEAR Project.
All rights reserved.

Redistribution and use in source and binary forms, with or without
@@ -1,9 +1,8 @@
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'nexus'
apply plugin: 'org.standardout.versioneye'
apply plugin: 'com.bmuschko.nexus'

version = '2.11'
group = "de.bwaldvogel"
version = '2.21'

sourceCompatibility = 1.7
targetCompatibility = 1.7
@@ -22,30 +21,29 @@ jar {
}
}

// https://github.com/bmuschko/gradle-nexus-plugin
buildscript {
repositories {
jcenter()
}

dependencies {
classpath 'org.gradle.api.plugins:gradle-nexus-plugin:0.7.1'
classpath 'org.standardout:gradle-versioneye-plugin:1.2.0'
classpath 'com.bmuschko:gradle-nexus-plugin:2.3.1'
}
}

ext {
junitVersion = '4.12'
assertjVersion = '2.6.0'
assertjVersion = '2.9.1'
powermockVersion = '1.6.5'
equalsverifierVersion = '2.5.2'
}

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

@@ -74,26 +72,24 @@ modifyPom {
}

nexus {
attachSources = true
attachTests = false
attachJavadoc = true
sign = true
}

repositories {
mavenCentral()
}

task wrapper(type: Wrapper) {
gradleVersion = '4.4'
distributionType = "ALL"
wrapper {
gradleVersion = "4.10.2"
distributionType = Wrapper.DistributionType.ALL
}

dependencies {
testCompile group: 'junit', name: 'junit', version: junitVersion
testCompile group: 'org.assertj', name: 'assertj-core', version: assertjVersion
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: powermockVersion
testCompile group: 'org.powermock', name: 'powermock-api-mockito', version: powermockVersion
testCompile group: 'nl.jqno.equalsverifier', name: 'equalsverifier', version: equalsverifierVersion
}

// vim: set ts=4 sw=4 et:

This file was deleted.

Oops, something went wrong.
Binary file not shown.
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
File renamed without changes.
@@ -8,11 +8,11 @@
*
* <em>This code is borrowed from Sun's JDK 1.6.0.07</em>
*/
public static void reversedMergesort(double[] a) {
static void reversedMergesort(double[] a) {
reversedMergesort(a, 0, a.length);
}

private static void reversedMergesort(double x[], int off, int len) {
private static void reversedMergesort(double[] x, int off, int len) {
// Insertion sort on smallest arrays
if (len < 7) {
for (int i = off; i < len + off; i++)
@@ -66,7 +66,7 @@ private static void reversedMergesort(double x[], int off, int len) {
/**
* Swaps x[a] with x[b].
*/
private static void swap(double x[], int a, int b) {
private static void swap(double[] x, int a, int b) {
double t = x[a];
x[a] = x[b];
x[b] = t;
@@ -75,15 +75,15 @@ private static void swap(double x[], int a, int b) {
/**
* Swaps x[a .. (a+n-1)] with x[b .. (b+n-1)].
*/
private static void vecswap(double x[], int a, int b, int n) {
private static void vecswap(double[] x, int a, int b, int n) {
for (int i = 0; i < n; i++, a++, b++)
swap(x, a, b);
}

/**
* Returns the index of the median of the three indexed doubles.
*/
private static int med3(double x[], int a, int b, int c) {
private static int med3(double[] x, int a, int b, int c) {
return (x[a] < x[b] ? (x[b] < x[c] ? b : x[a] < x[c] ? c : a) : (x[b] > x[c] ? b : x[a] > x[c] ? c : a));
}

@@ -6,13 +6,12 @@
private final double[] _array;
private int _offset;


public void setOffset(int offset) {
void setOffset(int offset) {
if (offset < 0 || offset >= _array.length) throw new IllegalArgumentException("offset must be between 0 and the length of the array");
_offset = offset;
}

public DoubleArrayPointer(final double[] array, final int offset) {
DoubleArrayPointer(final double[] array, final int offset) {
_array = array;
setOffset(offset);
}
@@ -6,7 +6,7 @@
public double value;

public FeatureNode(final int index, final double value) {
if (index < 0) throw new IllegalArgumentException("index must be >= 0");
if (index <= 0) throw new IllegalArgumentException("index must be > 0");
this.index = index;
this.value = value;
}
@@ -11,6 +11,6 @@

int get_nr_variable();

void get_diagH(double[] M);
void get_diag_preconditioner(double[] M);

}
@@ -6,13 +6,12 @@
private final int[] _array;
private int _offset;


public void setOffset(int offset) {
void setOffset(int offset) {
if (offset < 0 || offset >= _array.length) throw new IllegalArgumentException("offset must be between 0 and the length of the array");
_offset = offset;
}

public IntArrayPointer(final int[] array, final int offset) {
IntArrayPointer(final int[] array, final int offset) {
_array = array;
setOffset(offset);
}
@@ -105,7 +105,7 @@ protected void Xv(double[] v, double[] Xv) {
}

@Override
public void get_diagH(double[] M) {
public void get_diag_preconditioner(double[] M) {
int w_size = get_nr_variable();
Feature[][] x = prob.x;

@@ -195,7 +195,7 @@ private void get_diagH_loop(int start, int endExclusive, double[] m) {
}

@Override
public void get_diagH(final double[] M) {
public void get_diag_preconditioner(final double[] M) {
int l = prob.l;
int w_size = get_nr_variable();

@@ -23,16 +23,16 @@
/**
* <h2>Java port of <a href="http://www.csie.ntu.edu.tw/~cjlin/liblinear/">liblinear</a></h2>
*
* <p>The usage should be pretty similar to the C version of <tt>liblinear</tt>.</p>
* <p>Please consider reading the <tt>README</tt> file of <tt>liblinear</tt>.</p>
* <p>The usage should be pretty similar to the C version of liblinear.</p>
* <p>Please consider reading the README file of liblinear.</p>
*
* <p><em>The port was done by Benedikt Waldvogel (mail at bwaldvogel.de)</em></p>
*
* @version 2.11
* @version 2.21
*/
public class Linear {

static final int VERSION = 211;
static final int VERSION = 221;

static final Charset FILE_CHARSET = StandardCharsets.ISO_8859_1;

@@ -578,18 +578,18 @@ public static void saveModel(Writer modelOutput, Model model) throws IOException
}

printf(formatter, "nr_feature %d\n", nr_feature);
printf(formatter, "bias %.16g\n", model.bias);
printf(formatter, "bias %.17g\n", model.bias);

printf(formatter, "w\n");
for (int i = 0; i < w_size; i++) {
for (int j = 0; j < nr_w; j++) {
double value = model.w[i * nr_w + j];

/** this optimization is the reason for {@link Model#equals(double[], double[])} */
/* this optimization is the reason for {@link Model#equals(double[], double[])} */
if (value == 0.0) {
printf(formatter, "%d ", 0);
} else {
printf(formatter, "%.16g ", value);
printf(formatter, "%.17g ", value);
}
}
printf(formatter, "\n");
@@ -994,7 +994,7 @@ else if (Gn > H * beta[i])
*
* @since 1.7
*/
private static void solve_l2r_lr_dual(Problem prob, double w[], double eps, double Cp, double Cn, int max_iter) {
private static void solve_l2r_lr_dual(Problem prob, double[] w, double eps, double Cp, double Cn, int max_iter) {
int l = prob.l;
int w_size = prob.n;
int i, s, iter = 0;
@@ -114,7 +114,7 @@ static void doPredict(BufferedReader reader, Writer writer, Model model) throws
printf(out, "\n");
} else {
predict_label = Linear.predict(model, nodes);
printf(out, "%g\n", predict_label);
printf(out, "%.17g\n", predict_label);
}

if (predict_label == target_label) {
@@ -122,19 +122,19 @@ private void exit_with_help() {
}


Problem getProblem() {
public Problem getProblem() {
return prob;
}

double getBias() {
public double getBias() {
return bias;
}

Parameter getParameter() {
public Parameter getParameter() {
return param;
}

void parse_command_line(String argv[]) {
public void parse_command_line(String argv[]) {
int i;

// eps: see setting below
@@ -15,7 +15,7 @@
private final int max_iter;
private final double eps_cg;

public Tron(Function fun_obj, double eps, int max_iter, double eps_cg) {
Tron(Function fun_obj, double eps, int max_iter, double eps_cg) {
this.fun_obj = fun_obj;
this.eps = eps;
this.max_iter = max_iter;
@@ -56,16 +56,15 @@ void tron(double[] w) {
if (gnorm <= eps * gnorm0)
search = 0;

iter = 1;
fun_obj.get_diag_preconditioner(M);
for (i = 0; i < n; i++)
M[i] = (1 - alpha_pcg) + alpha_pcg * M[i];
delta = Math.sqrt(uTMv(n, g, M, g));

double[] w_new = new double[n];
AtomicBoolean reach_boundary = new AtomicBoolean();
boolean delta_adjusted = false;
while (iter <= max_iter && search != 0) {
fun_obj.get_diagH(M);
for (i = 0; i < n; i++)
M[i] = (1 - alpha_pcg) + alpha_pcg * M[i];
if (iter == 1)
delta = Math.sqrt(uTMv(n, g, M, g));
cg_iter = trpcg(delta, g, M, s, r, reach_boundary);

System.arraycopy(w, 0, w_new, 0, n);
@@ -80,8 +79,10 @@ void tron(double[] w) {

// On the first iteration, adjust the initial step bound.
sMnorm = Math.sqrt(uTMv(n, s, M, s));
if (iter == 1)
if (iter == 1 && !delta_adjusted) {
delta = Math.min(delta, sMnorm);
delta_adjusted = true;
}

// Compute prediction alpha*sMnorm of the step.
if (fnew - f - gs <= 0)
@@ -112,6 +113,9 @@ else if (actred < eta2 * prered)
System.arraycopy(w_new, 0, w, 0, n);
f = fnew;
fun_obj.grad(w, g);
fun_obj.get_diag_preconditioner(M);
for (i = 0; i < n; i++)
M[i] = (1 - alpha_pcg) + alpha_pcg * M[i];

gnorm = euclideanNorm(g);
if (gnorm <= eps * gnorm0)
@@ -206,7 +210,7 @@ private int trpcg(double delta, double[] g, double[] M, double[] s, double[] r,
*
* @since 1.8
*/
private static void daxpy(double constant, double vector1[], double vector2[]) {
private static void daxpy(double constant, double[] vector1, double[] vector2) {
if (constant == 0) return;

assert vector1.length == vector2.length;
@@ -220,7 +224,7 @@ private static void daxpy(double constant, double vector1[], double vector2[]) {
*
* @since 1.8
*/
private static double dot(double vector1[], double vector2[]) {
private static double dot(double[] vector1, double[] vector2) {

double product = 0;
assert vector1.length == vector2.length;
Oops, something went wrong.

0 comments on commit e3df9bb

Please sign in to comment.
You can’t perform that action at this time.