Skip to content

Commit

Permalink
Issue 5: Upgrade to version 3.0 of libsvm
Browse files Browse the repository at this point in the history
  • Loading branch information
jnioche committed Feb 9, 2011
1 parent c988557 commit 8ce078a
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 2,988 deletions.
3 changes: 2 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
1.4.1-SNAPSHOT
- updated to liblinear 1.7
- upgraded lisvm 3.0 + rely on external lib instead of modified code
- upgraded liblinear 1.7
- can specify weighting schemes per field
- added TestWeightingSchemes
- can remap the attribute numbers before generating the vector file
Expand Down
Binary file added lib/libsvm-3.0.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions libLinear.copyright.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

Copyright (c) 2007-2008 The LIBLINEAR Project.
Copyright (c) 2007-2010 The LIBLINEAR Project.
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -29,3 +28,4 @@ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

2 changes: 1 addition & 1 deletion libSVM.copyright.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2000-2006 Chih-Chung Chang and Chih-Jen Lin
Copyright (c) 2000-2010 Chih-Chung Chang and Chih-Jen Lin
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import libsvm.svm_node;
import libsvm.svm_parameter;
import libsvm.svm_problem;
import libsvm.svm_problem_impl;

import com.digitalpebble.classification.Document;
import com.digitalpebble.classification.Learner;
Expand Down Expand Up @@ -94,12 +93,6 @@ public void internal_learn() throws Exception {
} else {
model = svm.svm_train(prob, param);
svm.svm_save_model(model_file_name, model);
// dump linear weights in lexicon
try {
double[] weights = model.getLinearWeights();
this.lexicon.setLinearWeight(weights);
} catch (Exception e) {
}
}
}

Expand Down Expand Up @@ -221,12 +214,15 @@ private void read_problem(File learningFile) throws IOException {
max_index = Math.max(max_index, x[m - 1].index);
vx.addElement(x);
}
prob = new svm_problem_impl(vy.size());
for (int i = 0; i < prob.size(); i++)
prob.setNodes(i, (svm_node[]) vx.elementAt(i));
for (int i = 0; i < prob.size(); i++) {
prob = new svm_problem();
prob.l=vy.size();
prob.y = new double[prob.l];
prob.x = new svm_node[prob.l][];
for (int i = 0; i < prob.l; i++)
prob.x[i]= (svm_node[]) vx.elementAt(i);
for (int i = 0; i < prob.l; i++) {
double labell = Double.parseDouble((String) vy.elementAt(i));
prob.setLabel(i, labell);
prob.y[i]= labell;
}
if (param.gamma == 0)
param.gamma = 1.0 / max_index;
Expand All @@ -246,13 +242,13 @@ private void do_cross_validation() {
int total_correct = 0;
double total_error = 0;
double sumv = 0, sumy = 0, sumvv = 0, sumyy = 0, sumvy = 0;
double size = prob.size();
double[] target = new double[prob.size()];
double size = prob.l;
double[] target = new double[prob.l];
svm.svm_cross_validation(prob, param, this.nfold, target);
if (param.svm_type == svm_parameter.EPSILON_SVR
|| param.svm_type == svm_parameter.NU_SVR) {
for (i = 0; i < prob.size(); i++) {
double y = prob.getLabel(i);
for (i = 0; i < prob.l; i++) {
double y = prob.y[i];
double v = target[i];
total_error += (v - y) * (v - y);
sumv += v;
Expand All @@ -274,7 +270,7 @@ private void do_cross_validation() {
int numclasses = lexicon.getLabelNum();
double[][] confMatrix = new double[numclasses][numclasses];
for (i = 0; i < size; i++) {
double expected = prob.getLabel(i);
double expected = prob.y[i];
if (target[i] == expected)
++total_correct;
confMatrix[(int) target[i]][(int) expected]++;
Expand Down Expand Up @@ -328,13 +324,13 @@ private void do_cross_validation() {
Map<Integer, String> inverted = lexicon.getInvertedIndex();
for (i = 0; i < size; i++) {
StringBuffer sb = new StringBuffer();
double expected = prob.getLabel(i);
double expected = prob.y[i];
if (target[i] == expected)
continue;
sb.append("expected: ").append(lexicon.getLabel((int) expected))
.append("\tfound:").append(
lexicon.getLabel((int) target[i]));
svm_node[] nodes = prob.getNodes(i);
svm_node[] nodes = prob.x[i];
for (svm_node node : nodes) {
String attLabel = inverted.get(new Integer(node.index));
if (attLabel == null)
Expand Down
Loading

0 comments on commit 8ce078a

Please sign in to comment.