-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInitializer.java
183 lines (89 loc) · 3.31 KB
/
Initializer.java
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
iimport java.io.FileReader;
import java.util.HashSet;
import java.util.Set;
import weka.core.Instances;
public class Initializer{
public double[][] local_sgd;
public static Set<Double> ClassSet = new HashSet<Double>();
// public String[] classArray= new String[3];
private static final String PAR_PATH = "resourcepath";
/** used to generate unique IDs */
private static long counter = -1;
// the weight matrix
public double[][] wtVec;
public int num_class; // total no. of classes
public int num_Att;
public static int c;
public int count = 0;
private long ID; // The ID
public int max_class = 10;
protected double lambda = 0.01;
/** Learning rate */
protected double alpha = 0.02;
private String resourcepath;
public Instances traindataset; // The training dataset
private long nextID()
{
return counter++;
}
public void setID(long nextID)
{
ID = nextID;
}
public long getID() {
return ID;
}
public Initialzer()
{
resourcepath = (String) Configuration.getString(prefix + "." + PAR_PATH);
// N= Configuration.getInt(prefix + "."+PAR_SIZE);
System.out.println("Data is saved in: " + resourcepath + "\n"); //
setID(nextID());
// read the data into node
try {
String traindataset = resourcepath + "/" + "weather_dataset_"
+ ".arff";
// Instances data= traindataset.getDataSet();
FileReader reader = new FileReader(traindataset);
Instances data = new Instances(reader);
// printing the number of attributes
num_Att = data.numAttributes() - 1;
System.out.println("Number of Attributes" + " " + num_Att + "\n");
// total number of instances
int num_Instance = data.numInstances();
System.out.println("Number of instances "+ " " + num_Instance + "\n");
// set the last attribute to be the class attribute
int label = data.numAttributes();
data.setClassIndex(label - 1);
// System.out.println("\n"+label);
int N = data.numInstances(); // data size at each node
for (int i = 0; i < N; i++) // Adding unique classes to Hashset {
double y = data.instance(i).value(label - 1);
// System.out.println("\n"+y);
ClassSet.add(y);
}
// Initialize the weight vector dxc dimension where d is the num ber
// of attributes and c is the total number of classes
wtVec = new double[num_Att][max_class];
for (int j = 0; j < num_Att; j++)
{
for (int k = 0; k < max_class; k++)
{
wtVec[j][k] = 1;
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static int write_class_size()
{
c = ClassSet.size();
// System.out.println("\n"+ClassSet.size());
return c;
}
}
Contact GitHub API Training Shop Blog About
© 2017 GitHub, Inc. Terms Privacy Security Status Help