Skip to content

Commit 7c133b3

Browse files
committed
temp location for Weka DJL example
1 parent 236bab4 commit 7c133b3

File tree

3 files changed

+161
-0
lines changed

3 files changed

+161
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import weka.classifiers.AbstractClassifier
17+
import weka.classifiers.Evaluation
18+
import weka.core.Instances
19+
import weka.core.Utils
20+
import weka.core.WekaPackageManager
21+
import weka.core.converters.ArffLoader
22+
23+
WekaPackageManager.loadPackages(true)
24+
25+
def tabnet = getClass().classLoader.getResource('tabnet.groovy').file
26+
def source = getClass().classLoader.getResource('bolts.arff').file as File
27+
def loader = new ArffLoader(file: source)
28+
def data = loader.dataSet
29+
data.classIndex = data.numAttributes() - 1
30+
31+
def options = Utils.splitOptions(/-network "weka.classifiers.djl.networkgenerator.GroovyGenerator -G $tabnet"/)
32+
def classifier = Utils.forName(AbstractClassifier, 'weka.classifiers.djl.DJLRegressor', options)
33+
34+
def rand = new Random(0)
35+
def randData = new Instances(data)
36+
randData.randomize(rand)
37+
randData.stratify(3)
38+
def train = randData.trainCV(3, 0)
39+
def test = randData.testCV(3, 0)
40+
41+
classifier.buildClassifier(train)
42+
def eval = new Evaluation(test)
43+
eval.evaluateModel(classifier, test)
44+
println eval.toSummaryString()
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
% Data from StatLib (ftp stat.cmu.edu/datasets)
2+
%
3+
% SUMMARY:
4+
%
5+
% Data from an experiment on the affects of machine adjustments on
6+
% the time to count bolts. Data appear as the STATS (Issue 10) Challenge.
7+
%
8+
% DATA:
9+
%
10+
% Submitted by W. Robert Stephenson, Iowa State University
11+
12+
%
13+
% A manufacturer of automotive accessories provides hardware, e.g. nuts,
14+
% bolts, washers and screws, to fasten the accessory to the car or truck.
15+
% Hardware is counted and packaged automatically. Specifically, bolts
16+
% are dumped into a large metal dish. A plate that forms the bottom of
17+
% the dish rotates counterclockwise. This rotation forces bolts to the
18+
% outside of the dish and up along a narrow ledge. Due to the vibration
19+
% of the dish caused by the spinning bottom plate, some bolts fall off
20+
% the ledge and back into the dish. The ledge spirals up to a point
21+
% where the bolts are allowed to drop into a pan on a conveyor belt.
22+
% As a bolt drops, it passes by an electronic eye that counts it. When
23+
% the electronic counter reaches the preset number of bolts, the
24+
% rotation is stopped and the conveyor belt is moved forward.
25+
%
26+
% There are several adjustments on the machine that affect its operation.
27+
% These include; a speed setting that controls the speed of rotation
28+
% (SPEED1) of the plate at the bottom of the dish, a total number of
29+
% bolts (TOTAL) to be counted, a second speed setting (SPEED2) that is
30+
% used to change the speed of rotation (usually slowing it down) for the
31+
% last few bolts, the number of bolts to be counted at this second speed
32+
% (NUMBER2), and the sensitivity of the electronic eye (SENS). The
33+
% sensitivity setting is to insure that the correct number of bolts are
34+
% counted. Too few bolts packaged causes customer complaints. Too many
35+
% bolts packaged increases costs. For each run conducted in this
36+
% experiment the correct number of bolts was counted. From an
37+
% engineering standpoint if the correct number of bolts is counted, the
38+
% sensitivity should not affect the time to count bolts. The measured
39+
% response is the time (TIME), in seconds, it takes to count the desired
40+
% number of bolts. In order to put times on a equal footing the
41+
% response to be analyzed is the time to count 20 bolts (T20BOLT).
42+
% Below are the data for 40 combinations of settings. RUN is the order
43+
% in which the data were collected.
44+
%
45+
% Analyze the data. What adjustments have the greatest effect on the
46+
% time to count 20 bolts? How would you adjust the machine to get
47+
% the shortest time to count 20 bolts? Are there any unusual features
48+
% to the data?
49+
%
50+
% The data description and data may be freely used for non-commercial
51+
% purposes and can be freely distributed. Copyright remains with the
52+
% author and STATS Magazine.
53+
%
54+
55+
@relation bolts
56+
57+
@attribute RUN integer
58+
@attribute SPEED1 integer
59+
@attribute TOTAL integer
60+
@attribute SPEED2 integer
61+
@attribute NUMBER2 integer
62+
@attribute SENS integer
63+
@attribute TIME real
64+
@attribute T20BOLT real
65+
66+
@data
67+
25, 2, 10, 1.5, 0, 6, 5.70, 11.40
68+
24, 2, 10, 1.5, 0, 10, 17.56, 35.12
69+
30, 2, 10, 1.5, 2, 6, 11.28, 22.56
70+
2, 2, 10, 1.5, 2, 10, 8.39, 16.78
71+
40, 2, 10, 2.5, 0, 6, 16.67, 33.34
72+
37, 2, 10, 2.5, 0, 10, 12.04, 24.08
73+
16, 2, 10, 2.5, 2, 6, 9.22, 18.44
74+
22, 2, 10, 2.5, 2, 10, 3.94, 7.88
75+
33, 2, 30, 1.5, 0, 6, 27.02, 18.01
76+
17, 2, 30, 1.5, 0, 10, 19.46, 12.97
77+
28, 2, 30, 1.5, 2, 6, 18.54, 12.36
78+
27, 2, 30, 1.5, 2, 10, 25.70, 17.13
79+
14, 2, 30, 2.5, 0, 6, 19.02, 12.68
80+
13, 2, 30, 2.5, 0, 10, 22.39, 14.93
81+
4, 2, 30, 2.5, 2, 6, 23.85, 15.90
82+
21, 2, 30, 2.5, 2, 10, 30.12, 20.08
83+
23, 6, 10, 1.5, 0, 6, 13.42, 26.84
84+
35, 6, 10, 1.5, 0, 10, 34.26, 68.52
85+
19, 6, 10, 1.5, 2, 6, 39.74, 79.48
86+
34, 6, 10, 1.5, 2, 10, 10.60, 21.20
87+
31, 6, 10, 2.5, 0, 6, 28.89, 57.78
88+
9, 6, 10, 2.5, 0, 10, 35.61, 71.22
89+
38, 6, 10, 2.5, 2, 6, 17.20, 34.40
90+
15, 6, 10, 2.5, 2, 10, 6.00, 12.00
91+
39, 6, 30, 1.5, 0, 6, 129.45, 86.30
92+
8, 6, 30, 1.5, 0, 0, 107.38, 71.59
93+
26, 6, 30, 1.5, 2, 6, 111.66, 74.44
94+
11, 6, 30, 1.5, 2, 0, 109.10, 72.73
95+
6, 6, 30, 2.5, 0, 6, 100.43, 66.95
96+
20, 6, 30, 2.5, 0, 0, 109.28, 72.85
97+
10, 6, 30, 2.5, 2, 6, 106.46, 70.97
98+
32, 6, 30, 2.5, 2, 0, 134.01, 89.34
99+
1, 4, 20, 2.0, 1, 8, 10.78, 10.78
100+
3, 4, 20, 2.0, 1, 8, 9.39, 9.39
101+
5, 4, 20, 2.0, 1, 8, 9.84, 9.84
102+
7, 4, 20, 2.0, 1, 8, 13.94, 13.94
103+
12, 4, 20, 2.0, 1, 8, 12.33, 12.33
104+
18, 4, 20, 2.0, 1, 8, 7.32, 7.32
105+
29, 4, 20, 2.0, 1, 8, 7.91, 7.91
106+
36, 4, 20, 2.0, 1, 8, 15.58, 15.58
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import ai.djl.basicdataset.tabular.TabularDataset
2+
import ai.djl.nn.Block
3+
import ai.djl.zero.Performance
4+
import weka.classifiers.djl.networkgenerator.NetworkGenerator
5+
import weka.classifiers.djl.networkgenerator.TabularRegressionGenerator
6+
7+
class TabNetGenerator implements NetworkGenerator {
8+
Block generate(TabularDataset dataset) {
9+
new TabularRegressionGenerator(performance: Performance.FAST).generate(dataset)
10+
}
11+
}

0 commit comments

Comments
 (0)