Skip to content

Commit

Permalink
Language migrations aids, do not leak logging library
Browse files Browse the repository at this point in the history
  • Loading branch information
rzo1 committed Nov 20, 2023
1 parent 6b1c348 commit d11add0
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 69 deletions.
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,4 @@ public ClassificationCoreException(String message) {
super(message);
}

public ClassificationCoreException(String message, Throwable throwable) {
super(message, throwable);
}

}
2 changes: 1 addition & 1 deletion zlibsvm-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<scope>runtime</scope>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public NativeSvmModelWrapper(SvmConfigurationBuilder svmConfigurationBuilder, in

this(new svm_model());

svmModel.l = (amountOfSupportVectors);
svmModel.nr_class = (numberOfClasses);
svmModel.l = amountOfSupportVectors;
svmModel.nr_class = numberOfClasses;

svmModel.rho = (ArrayUtils.toPrimitive(rhoConstants.toArray(new Double[0])));
svmModel.probA = (ArrayUtils.toPrimitive(probabilityA.toArray(new Double[0])));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static double[] toPrimitive(final Double[] array) {
}
final double[] result = new double[array.length];
for (int i = 0; i < array.length; i++) {
result[i] = array[i].doubleValue();
result[i] = array[i];
}
return result;
}
Expand All @@ -75,7 +75,7 @@ public static int[] toPrimitive(final Integer[] array) {
}
final int[] result = new int[array.length];
for (int i = 0; i < array.length; i++) {
result[i] = array[i].intValue();
result[i] = array[i];
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ public void testInvalidParameters() {
try {
new SvmClassifierImpl(null);
failed = true;
} catch (AssertionError ae) {
} catch (AssertionError ignored) {

} catch (Exception e) {
e.printStackTrace();
fail("caught Exception of type "
+ e.getClass().getName()
+ " instead of an AssertionError. See stacktrace for further information.");
Expand All @@ -92,10 +91,9 @@ public void testInvalidParameters() {
try {
new SvmClassifierImpl(ownModel).classify(null, false);
failed = true;
} catch (AssertionError ae) {
} catch (AssertionError ignored) {

} catch (Exception e) {
e.printStackTrace();
fail("caught Exception of type "
+ e.getClass().getName()
+ " instead of an AssertionError. See stacktrace for further information.");
Expand All @@ -108,10 +106,9 @@ public void testInvalidParameters() {
try {
new SvmClassifierImpl(ownModel).classify(new ArrayList<>(), false);
failed = true;
} catch (AssertionError ae) {
} catch (AssertionError ignored) {

} catch (Exception e) {
e.printStackTrace();
fail("caught Exception of type "
+ e.getClass().getName()
+ " instead of an AssertionError. See stacktrace for further information.");
Expand Down
26 changes: 9 additions & 17 deletions zlibsvm-core/src/test/java/de/hhn/mi/SvmConfigurationTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ public void testBuildConfigurationWithInvalidParameters() {
try {
builder.setDegree(-1);
failed = true;
} catch (AssertionError ae) {
} catch (AssertionError ignored) {

} catch (Exception e) {
e.printStackTrace();
fail("caught Exception of type "
+ e.getClass().getName()
+ " instead of an AssertionError. See stacktrace for further information.");
Expand All @@ -54,10 +53,9 @@ public void testBuildConfigurationWithInvalidParameters() {
try {
builder.setGamma(-1.0d);
failed = true;
} catch (AssertionError ae) {
} catch (AssertionError ignored) {

} catch (Exception e) {
e.printStackTrace();
fail("caught Exception of type "
+ e.getClass().getName()
+ " instead of an AssertionError. See stacktrace for further information.");
Expand All @@ -70,10 +68,9 @@ public void testBuildConfigurationWithInvalidParameters() {
try {
builder.setNu(-1.0d);
failed = true;
} catch (AssertionError ae) {
} catch (AssertionError ignored) {

} catch (Exception e) {
e.printStackTrace();
fail("caught Exception of type "
+ e.getClass().getName()
+ " instead of an AssertionError. See stacktrace for further information.");
Expand All @@ -87,10 +84,9 @@ public void testBuildConfigurationWithInvalidParameters() {
try {
builder.setNu(1.1d);
failed = true;
} catch (AssertionError ae) {
} catch (AssertionError ignored) {

} catch (Exception e) {
e.printStackTrace();
fail("caught Exception of type "
+ e.getClass().getName()
+ " instead of an AssertionError. See stacktrace for further information.");
Expand All @@ -103,7 +99,7 @@ public void testBuildConfigurationWithInvalidParameters() {
try {
builder.setCacheSize(-1);
failed = true;
} catch (AssertionError ae) {
} catch (AssertionError ignored) {

} catch (Exception e) {
e.printStackTrace();
Expand All @@ -119,10 +115,9 @@ public void testBuildConfigurationWithInvalidParameters() {
try {
builder.setCost(0.0d);
failed = true;
} catch (AssertionError ae) {
} catch (AssertionError ignored) {

} catch (Exception e) {
e.printStackTrace();
fail("caught Exception of type "
+ e.getClass().getName()
+ " instead of an AssertionError. See stacktrace for further information.");
Expand All @@ -135,10 +130,9 @@ public void testBuildConfigurationWithInvalidParameters() {
try {
builder.setEpsilon(0.0d);
failed = true;
} catch (AssertionError ae) {
} catch (AssertionError ignored) {

} catch (Exception e) {
e.printStackTrace();
fail("caught Exception of type "
+ e.getClass().getName()
+ " instead of an AssertionError. See stacktrace for further information.");
Expand All @@ -151,10 +145,9 @@ public void testBuildConfigurationWithInvalidParameters() {
try {
builder.setP(-1.0d);
failed = true;
} catch (AssertionError ae) {
} catch (AssertionError ignored) {

} catch (Exception e) {
e.printStackTrace();
fail("caught Exception of type "
+ e.getClass().getName()
+ " instead of an AssertionError. See stacktrace for further information.");
Expand All @@ -167,10 +160,9 @@ public void testBuildConfigurationWithInvalidParameters() {
try {
builder.setCrossValidation(true, 1);
failed = true;
} catch (AssertionError ae) {
} catch (AssertionError ignored) {

} catch (Exception e) {
e.printStackTrace();
fail("caught Exception of type "
+ e.getClass().getName()
+ " instead of an AssertionError. See stacktrace for further information.");
Expand Down
9 changes: 3 additions & 6 deletions zlibsvm-core/src/test/java/de/hhn/mi/SvmTrainingTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ public void testInvalidParameters() {
try {
new SvmTrainerImpl(null, null);
failed = true;
} catch (AssertionError ae) {
} catch (AssertionError ignored) {

} catch (Exception e) {
e.printStackTrace();
fail("caught Exception of type "
+ e.getClass().getName()
+ " instead of an AssertionError. See stacktrace for further information.");
Expand All @@ -80,10 +79,9 @@ public void testInvalidParameters() {
try {
new SvmTrainerImpl(config, MODEL_NAME).train(null);
failed = true;
} catch (AssertionError ae) {
} catch (AssertionError ignored) {

} catch (Exception e) {
e.printStackTrace();
fail("caught Exception of type "
+ e.getClass().getName()
+ " instead of an AssertionError. See stacktrace for further information.");
Expand All @@ -96,10 +94,9 @@ public void testInvalidParameters() {
try {
new SvmTrainerImpl(config, MODEL_NAME).train(new ArrayList<>());
failed = true;
} catch (AssertionError ae) {
} catch (AssertionError ignored) {

} catch (Exception e) {
e.printStackTrace();
fail("caught Exception of type "
+ e.getClass().getName()
+ " instead of an AssertionError. See stacktrace for further information.");
Expand Down
61 changes: 31 additions & 30 deletions zlibsvm-core/src/test/java/tw/edu/ntu/csie/libsvm/svm_train.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -73,34 +73,35 @@ public class svm_train {

private static void exit_with_help() {
System.out.print(
"Usage: svm_train [options] training_set_file [model_file]\n"
+ "options:\n"
+ "-s svm_type : set type of SVM (default 0)\n"
+ " 0 -- C-SVC (multi-class classification)\n"
+ " 1 -- nu-SVC (multi-class classification)\n"
+ " 2 -- one-class SVM\n"
+ " 3 -- epsilon-SVR (regression)\n"
+ " 4 -- nu-SVR (regression)\n"
+ "-t kernel_type : set type of kernel function (default 2)\n"
+ " 0 -- linear: u'*v\n"
+ " 1 -- polynomial: (gamma*u'*v + coef0)^degree\n"
+ " 2 -- radial basis function: exp(-gamma*|u-v|^2)\n"
+ " 3 -- sigmoid: tanh(gamma*u'*v + coef0)\n"
+ " 4 -- precomputed kernel (kernel values in training_set_file)\n"
+ "-d degree : set degree in kernel function (default 3)\n"
+ "-g gamma : set gamma in kernel function (default 1/num_features)\n"
+ "-r coef0 : set coef0 in kernel function (default 0)\n"
+ "-c cost : set the parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1)\n"
+ "-n nu : set the parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)\n"
+ "-p epsilon : set the epsilon in loss function of epsilon-SVR (default 0.1)\n"
+ "-m cachesize : set cache memory size in MB (default 100)\n"
+ "-e epsilon : set tolerance of termination criterion (default 0.001)\n"
+ "-h shrinking : whether to use the shrinking heuristics, 0 or 1 (default 1)\n"
+ "-b probability_estimates : whether to train a SVC or SVR model for probability estimates, " +
"0 or 1 (default 0)\n"
+ "-wi weight : set the parameter C of class i to weight*C, for C-SVC (default 1)\n"
+ "-v n : n-fold cross validation mode\n"
+ "-q : quiet mode (no outputs)\n"
"""
Usage: svm_train [options] training_set_file [model_file]
options:
-s svm_type : set type of SVM (default 0)
0 -- C-SVC (multi-class classification)
1 -- nu-SVC (multi-class classification)
2 -- one-class SVM
3 -- epsilon-SVR (regression)
4 -- nu-SVR (regression)
-t kernel_type : set type of kernel function (default 2)
0 -- linear: u'*v
1 -- polynomial: (gamma*u'*v + coef0)^degree
2 -- radial basis function: exp(-gamma*|u-v|^2)
3 -- sigmoid: tanh(gamma*u'*v + coef0)
4 -- precomputed kernel (kernel values in training_set_file)
-d degree : set degree in kernel function (default 3)
-g gamma : set gamma in kernel function (default 1/num_features)
-r coef0 : set coef0 in kernel function (default 0)
-c cost : set the parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1)
-n nu : set the parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)
-p epsilon : set the epsilon in loss function of epsilon-SVR (default 0.1)
-m cachesize : set cache memory size in MB (default 100)
-e epsilon : set tolerance of termination criterion (default 0.001)
-h shrinking : whether to use the shrinking heuristics, 0 or 1 (default 1)
-b probability_estimates : whether to train a SVC or SVR model for probability estimates, 0 or 1 (default 0)
-wi weight : set the parameter C of class i to weight*C, for C-SVC (default 1)
-v n : n-fold cross validation mode
-q : quiet mode (no outputs)
"""
);
System.exit(1);
}
Expand Down

0 comments on commit d11add0

Please sign in to comment.