-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScaler.java
More file actions
44 lines (41 loc) · 808 Bytes
/
Copy pathScaler.java
File metadata and controls
44 lines (41 loc) · 808 Bytes
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
public class Scaler {
public double max =Double.NEGATIVE_INFINITY;
public double min =Double.POSITIVE_INFINITY;
Attributes attributes;
Scaler(Attributes att)
{
this.attributes = att;
}
public Scaler() {
// TODO Auto-generated constructor stub
}
public Example scale(Example e,int index)
{
if(e.get(index)<min)
{
e.set(index, 0.0);
return e;
}
if(e.get(index)>max)
{
e.set(index, 1.0);
return e;
}
e.set(index,e.get(index)-min/(max-min));
return e;
}
public Examples scale(Examples es, int index)
{
for(int j=0;j<es.size();j++)
{
if(es.get(j).get(index)>max)
max = es.get(j).get(index);
else if(es.get(j).get(index)<min)
min = es.get(j).get(index);
}
//scale for each example
for(int j=0;j<es.size();j++)
es.set(j,scale(es.get(j),index));
return es;
}
}