-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexampleScene.ts
More file actions
143 lines (135 loc) · 4.67 KB
/
exampleScene.ts
File metadata and controls
143 lines (135 loc) · 4.67 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
138
139
140
141
142
143
namespace micro_ml {
import Screen = user_interface_base.Screen
import Scene = user_interface_base.Scene
import AppInterface = user_interface_base.AppInterface
import font = user_interface_base.font
/**
* Use a Scene instead of a CursorScene when you want to
* control display-shield button behaviour yourself.
*/
export class ExampleScene extends Scene {
// layerDims = Buffer.fromArray([30, 16, 2]);
// afe = Buffer.fromArray([ActivationFunctionEnum.Sigmoid, ActivationFunctionEnum.SoftMax]);
// epochs = 50
// learningRate = 0.015
// trainTestSplit = 0.5
// training = false
// accuracy: number = null
// trainTime: number = null
constructor(app: AppInterface) {
super(app)
}
// This is called when the Scene 'becomes active'.
// This happens when the scene ahead is popped, or this is the first one pushed.
activate() {
super.activate()
// const layer_dims = Buffer.fromArray([2, 3, 2]);
// const afe = Buffer.fromArray([ActivationFunctionEnum.Sigmoid, ActivationFunctionEnum.SoftMax]);
//
// construct_nn(layer_dims, afe, DatasetEnum.XOR, 1.0);
// construct_nn(this.layerDims, this.afe, DatasetEnum.ACCEL, this.trainTestSplit);
// train_nn(this.epochs, this.learningRate, false);
//
// // Setup display-shield buttons yourself
// control.onEvent(
// ControllerButtonEvent.Pressed,
// controller.A.id,
// () => {
// // this.app.pushScene(new ExampleMicroGUIScene(this.app))
//
// const startTime = control.millis();
// this.training = true;
// this.accuracy = test_nn(true) * 100;
// this.trainTime = control.millis() - startTime
// }
// )
//
// control.onEvent(
// ControllerButtonEvent.Pressed,
// controller.B.id,
// () => {
// this.app.popScene()
// }
// )
}
draw() {
Screen.fillRect(
Screen.LEFT_EDGE,
Screen.TOP_EDGE,
Screen.WIDTH,
Screen.HEIGHT,
6 // Light blue in the default palette
)
// let layers = "";
// for (let i = 0; i < this.layerDims.length; i++) {
// layers += this.layerDims.getNumber(NumberFormat.UInt8LE, i).toString() + (i === this.layerDims.length - 1 ? "" : "->");
// }
//
// let afes = "";
// for (let i = 0; i < this.afe.length; i++) {
// switch (this.afe.getNumber(NumberFormat.UInt8LE, i)) {
// case ActivationFunctionEnum.ReLU: {afes += "ReLU "; break;}
// case ActivationFunctionEnum.Sigmoid: {afes += "Sigmoid "; break;}
// case ActivationFunctionEnum.Tanh: {afes += "Tanh "; break;}
// case ActivationFunctionEnum.SoftMax: {afes += "SoftMax "; break;}
// default: afes += "Unknown AF ";
// }
// afes += (i === this.afe.length - 1 ? "" : "->");
// }
//
// const modelInfo: string[] = [
// "Model architecture:",
// layers,
// "Activation functions:",
// afes,
// "Epochs: " + this.epochs,
// "Learning rate: " + this.learningRate,
// "Train-test split: " + (this.trainTestSplit * 100) + "%"
// ];
//
// modelInfo.forEach((line, index) => {
// Screen.print(
// line,
// -line.length * font.charWidth >> 1,
// -55 + index * (font.charHeight + 1),
// 15 // Black in the default palette
// )
// })
//
// if (!this.training) {
// const txt1 = "Press A to start training"
// Screen.print(
// txt1,
// -txt1.length * font.charWidth >> 1,
// 30,
// 15 // Black in the default palette
// )
// } else if (this.accuracy === null || this.trainTime === null) {
// const txt1 = "model is training..."
// Screen.print(
// txt1,
// -txt1.length * font.charWidth >> 1,
// 30,
// 15 // Black in the default palette
// )
// } else {
// const trainTimeSec = (this.trainTime / 1000).toString().slice(0, 4)
// const info = [
// "Trained in " + trainTimeSec + " seconds\n",
// "Model accuracy is " + this.accuracy.toString().slice(0, 4) + "%"
// ]
//
// info.forEach((line, index) => {
// Screen.print(
// line,
// -line.length * font.charWidth >> 1,
// 30 + (index * (font.charHeight + 1)),
// 15 // Black in the default palette
// )
// })
//
// }
super.draw()
}
}
}