forked from liquidcarrot/carrot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NoiseLayer.ts
58 lines (52 loc) 路 1.47 KB
/
NoiseLayer.ts
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
import { ActivationType, Identitiy } from "activations";
import { Layer } from "../Layer";
import { NoiseNode } from "../../nodes/NoiseNode";
import { ConnectionType } from "../../../enums/ConnectionType";
/**
* Noise layer
*/
export class NoiseLayer extends Layer {
constructor(
outputSize: number,
options: {
/**
* The activation type for the output nodes of this layer.
*/
activation?: ActivationType;
/**
* The mean value for gaussian noise
*/
mean?: number;
/**
* The standard deviation for gaussian noise
*/
deviation?: number;
} = {}
) {
super(outputSize);
const activation: ActivationType = options.activation ?? Identitiy;
for (let i = 0; i < outputSize; i++) {
this.inputNodes.add(new NoiseNode(options).setActivationType(activation));
}
this.outputNodes = this.inputNodes;
this.nodes.push(...Array.from(this.inputNodes));
}
/**
* Gets the default connection type for a incoming connection to this layer.
*
* @returns the default incoming connection
*/
public getDefaultIncomingConnectionType(): ConnectionType {
return ConnectionType.ONE_TO_ONE;
}
/**
* Checks if a given connection type is allowed on this layer.
*
* @param type the type to check
*
* @return Is this connection type allowed?
*/
public connectionTypeisAllowed(type: ConnectionType): boolean {
return type === ConnectionType.ONE_TO_ONE;
}
}