This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
addHiddenLayer.js
93 lines (92 loc) · 2.88 KB
/
addHiddenLayer.js
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
/**
* @module Dann
* @submodule Create
*/
/**
* Add a Hidden Neuron Layer to a Dann neural network.
* @method addHiddenLayer
* @param {Number} size Layer size, the number of neurons in the layer.
* @param {String} [act] Takes a string of the activation function's name. If left empty, the activation function will be set to 'sigmoid' by default. See available activation functions below.
* <table>
* <thead>
* <tr>
* <th>Name</th>
* <th>Desmos</th>
* </tr>
* </thead>
* <tbody>
* <tr>
* <td>Sigmoid</td>
* <td><a target="_blank" href="https://www.desmos.com/calculator/so8eiigug4">See graph</a></td>
* </tr>
* <tr>
* <td>leakyReLU</td>
* <td><a target="_blank" href="https://www.desmos.com/calculator/pxqqqxd3tz">See graph</a></td>
* </tr>
* <tr>
* <td>reLU</td>
* <td><a target="_blank" href="https://www.desmos.com/calculator/jdb8dfof6x">See graph</a></td>
* </tr>
* <tr>
* <td>siLU</td>
* <td><a target="_blank" href="https://www.desmos.com/calculator/f4nhtck5dr">See graph</a></td>
* </tr>
* <tr>
* <td>tanH</td>
* <td><a target="_blank" href="https://www.desmos.com/calculator/eai4bialus">See graph</a></td>
* </tr>
* <tr>
* <td>binary</td>
* <td><a target="_blank" href="https://www.desmos.com/calculator/zq8s1ixyp8">See graph</a></td>
* </tr>
* <tr>
* <td>softsign</td>
* <td><a target="_blank" href="https://www.desmos.com/calculator/vmuhohc3da">See graph</a></td>
* </tr>
* <tr>
* <td>sinc</td>
* <td><a target="_blank" href="https://www.desmos.com/calculator/6u4ioz8lhs">See graph</a></td>
* </tr>
* <tr>
* <td>softplus</td>
* <td><a target="_blank" href="https://www.desmos.com/calculator/aegpfcyniu">See graph</a></td>
* </tr>
* </tbody>
* </table>
* <a href="./Add.html#method_activation"><p>See how to add more </p></a>
* @example
* <code>
* const nn = new Dann(10, 2);
* //Add a layer
* nn.addHiddenLayer(8, 'sigmoid');
* //console log
* console.log('Added first hidden layer: ');
* nn.log({struct:true});
* //Add a layer
* nn.addHiddenLayer(4, 'tanH');
* //console log
* console.log('Added a second hidden layer: ');
* nn.log({struct:true});
* </code>
*/
Dann.prototype.addHiddenLayer = function addHiddenLayer(size, act) {
if (act !== undefined) {
const lowerCaseAct = act.toLocaleLowerCase();
if (activations[lowerCaseAct] === undefined) {
if (typeof act === 'string') {
DannError.error(
"'" +
act +
"' is not a valid activation function, as a result, the activation function was set to 'sigmoid'.",
'Dann.prototype.addHiddenLayer'
);
}
act = 'sigmoid';
}
} else {
act = 'sigmoid';
}
this.arch.splice(this.arch.length - 1, 0, size);
let layer = new Layer('hidden', size, act);
this.Layers.splice(this.Layers.length - 1, 0, layer);
};