-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeatureVector.java
More file actions
89 lines (65 loc) · 1.36 KB
/
FeatureVector.java
File metadata and controls
89 lines (65 loc) · 1.36 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
import java.io.Serializable;
public class FeatureVector implements Serializable, Cloneable {
/**
*
*/
private static final long serialVersionUID = 1L;
private int[] keys;
private double[] values;
private int size;
private int pos;
//private ArrayList<Integer> list;
public FeatureVector(int size) {
this.keys = new int[size];
this.values = new double[size];
// this.list = new ArrayList<Integer>();
this.size = size;
this.pos = 0;
}
public void add(int index, double value) {
keys[getPos()] = index;
values[getPos()] = value;
setPos(getPos() + 1);
}
public double get(int index) {
double result = -1;
for (int i = 0; i < size; i++) {
if (keys[i] == index) {
result = values[i];
break;
}
}
return result;
}
public int[] getKeys() {
return keys;
}
public void setKeys(int[] keys) {
this.keys = keys;
}
public double[] getValues() {
return values;
}
public void setValues(double[] values) {
this.values = values;
}
public void setSpecificValuetoValues(int index, double value) {
this.values[index] = value;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public int getPos() {
return pos;
}
public void setPos(int pos) {
this.pos = pos;
}
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}