forked from bwaldvogel/liblinear-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParameter.java
More file actions
100 lines (81 loc) · 2.73 KB
/
Parameter.java
File metadata and controls
100 lines (81 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package liblinear;
import static liblinear.Linear.copyOf;
public final class Parameter {
double C;
/** stopping criteria */
double eps;
SolverType solverType;
double[] weight = null;
int[] weightLabel = null;
public Parameter( SolverType solverType, double C, double eps ) {
setSolverType(solverType);
setC(C);
setEps(eps);
}
/**
* <p>nr_weight, weight_label, and weight are used to change the penalty
* for some classes (If the weight for a class is not changed, it is
* set to 1). This is useful for training classifier using unbalanced
* input data or with asymmetric misclassification cost.</p>
*
* <p>Each weight[i] corresponds to weight_label[i], meaning that
* the penalty of class weight_label[i] is scaled by a factor of weight[i].</p>
*
* <p>If you do not want to change penalty for any of the classes,
* just set nr_weight to 0.</p>
*/
public void setWeights(double[] weights, int[] weightLabels) {
if (weights == null) throw new IllegalArgumentException("'weight' must not be null");
if (weightLabels == null || weightLabels.length != weights.length)
throw new IllegalArgumentException("'weightLabels' must have same length as 'weight'");
this.weightLabel = copyOf(weightLabels, weightLabels.length);
this.weight = copyOf(weights, weights.length);
}
/**
* @see #setWeights(double[], int[])
*/
public double[] getWeights() {
return copyOf(weight, weight.length);
}
/**
* @see #setWeights(double[], int[])
*/
public int[] getWeightLabels() {
return copyOf(weightLabel, weightLabel.length);
}
/**
* the number of weights
* @see #setWeights(double[], int[])
*/
public int getNumWeights() {
if (weight == null) return 0;
return weight.length;
}
/**
* C is the cost of constraints violation. (we usually use 1 to 1000)
*/
public void setC(double C) {
if (C <= 0) throw new IllegalArgumentException("C must not be <= 0");
this.C = C;
}
public double getC() {
return C;
}
/**
* eps is the stopping criterion. (we usually use 0.01).
*/
public void setEps(double eps) {
if (eps <= 0) throw new IllegalArgumentException("eps must not be <= 0");
this.eps = eps;
}
public double getEps() {
return eps;
}
public void setSolverType(SolverType solverType) {
if (solverType == null) throw new IllegalArgumentException("solver type must not be null");
this.solverType = solverType;
}
public SolverType getSolverType() {
return solverType;
}
}