ParametersFloat.java
2.53 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package is2.parser;
import is2.data.F2SF;
import is2.data.FV;
import is2.data.Instances;
import is2.data.Parse;
import is2.util.DB;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
final public class ParametersFloat extends Parameters {
public float[] parameters;
public float[] total;
public ParametersFloat(int size) {
parameters = new float[size];
total = new float[size];
for(int i = 0; i < parameters.length; i++) {
parameters[i] = 0F;
total[i] = 0F;
}
}
/**
* @param parameters2
*/
public ParametersFloat(float[] p) {
parameters =p;
}
@Override
public void average(double avVal) {
for(int j = 0; j < total.length; j++) {
parameters[j] = total[j]/((float)avVal);
}
total =null;
}
public ParametersFloat average2(double avVal) {
float[] px = new float[this.parameters.length];
for(int j = 0; j < total.length; j++) {
px[j] = total[j]/((float)avVal);
}
ParametersFloat pf = new ParametersFloat(px);
return pf;
}
@Override
public void update(FV act, FV pred, Instances isd, int instc, Parse d, double upd, double e) {
e++;
float lam_dist = getScore(act) - getScore(pred);
float b = (float)e-lam_dist;
FV dist = act.getDistVector(pred);
dist.update(parameters, total, hildreth(dist,b), upd,false);
}
protected double hildreth(FV a, double b) {
double A = a.dotProduct(a);
if (A<=0.0000000000000000001) return 0.0;
return b/A;
}
public float getScore(FV fv) {
if (fv ==null) return 0.0F;
return fv.getScore(parameters,false);
}
@Override
final public void write(DataOutputStream dos) throws IOException{
dos.writeInt(parameters.length);
for(float d : parameters) dos.writeFloat(d);
}
@Override
public void read(DataInputStream dis ) throws IOException{
parameters = new float[dis.readInt()];
int notZero=0;
for(int i=0;i<parameters.length;i++) {
parameters[i]=dis.readFloat();
if (parameters[i]!=0.0F) notZero++;
}
DB.println("read parameters "+parameters.length+" not zero "+notZero);
}
public int countNZ() {
int notZero=0;
for(int i=0;i<parameters.length;i++) {
if (parameters[i]!=0.0F) notZero++;
}
return notZero;
// DB.println("read parameters "+parameters.length+" not zero "+notZero);
}
/* (non-Javadoc)
* @see is2.sp09k99995.Parameters#getFV()
*/
@Override
public F2SF getFV() {
return new F2SF(parameters);
}
/* (non-Javadoc)
* @see is2.sp09k99999.Parameters#size()
*/
@Override
public int size() {
return parameters.length;
}
}