1 package liblinear;
2
3 import static liblinear.Linear.copyOf;
4
5
6 public final class Parameter {
7
8 double C;
9
10
11 double eps;
12
13 SolverType solverType;
14
15 double[] weight = null;
16
17 int[] weightLabel = null;
18
19 public Parameter( SolverType solverType, double C, double eps ) {
20 setSolverType(solverType);
21 setC(C);
22 setEps(eps);
23 }
24
25
26
27
28
29
30
31
32
33
34
35
36
37 public void setWeights(double[] weights, int[] weightLabels) {
38 if (weights == null) throw new IllegalArgumentException("'weight' must not be null");
39 if (weightLabels == null || weightLabels.length != weights.length)
40 throw new IllegalArgumentException("'weightLabels' must have same length as 'weight'");
41 this.weightLabel = copyOf(weightLabels, weightLabels.length);
42 this.weight = copyOf(weights, weights.length);
43 }
44
45
46
47
48 public double[] getWeights() {
49 return copyOf(weight, weight.length);
50 }
51
52
53
54
55 public int[] getWeightLabels() {
56 return copyOf(weightLabel, weightLabel.length);
57 }
58
59
60
61
62
63 public int getNumWeights() {
64 if (weight == null) return 0;
65 return weight.length;
66 }
67
68
69
70
71 public void setC(double C) {
72 if (C <= 0) throw new IllegalArgumentException("C must not be <= 0");
73 this.C = C;
74 }
75
76 public double getC() {
77 return C;
78 }
79
80
81
82
83 public void setEps(double eps) {
84 if (eps <= 0) throw new IllegalArgumentException("eps must not be <= 0");
85 this.eps = eps;
86 }
87
88 public double getEps() {
89 return eps;
90 }
91
92 public void setSolverType(SolverType solverType) {
93 if (solverType == null) throw new IllegalArgumentException("solver type must not be null");
94 this.solverType = solverType;
95 }
96
97 public SolverType getSolverType() {
98 return solverType;
99 }
100 }