效果
修改
- 在前端的index.html中添加一个名称
<div class="control ui-activation">
<label for="activations">Activation</label>
<div class="select">
<select id="activations">
<option value="relu">ReLU</option>
<option value="tanh">Tanh</option>
<option value="sigmoid">Sigmoid</option>
<option value="linear">Linear</option>
<option value="SINR">SINR</option>
</select>
</div>
</div>
- 在state中添加激活函数的对应
# state.ts
/** A map between names and activation functions. */
export let activations: {[key: string]: nn.ActivationFunction} = {
"relu": nn.Activations.RELU,
"tanh": nn.Activations.TANH,
"sigmoid": nn.Activations.SIGMOID,
"linear": nn.Activations.LINEAR,
"SINR": nn.Activations.SINR
};
- 添加激活函数的计算方法和导数
export class Activations {
public static TANH: ActivationFunction = {
output: x => (Math as any).tanh(x),
der: x => {
let output = Activations.TANH.output(x);
return 1 - output * output;
}
};
public static RELU: ActivationFunction = {
output: x => Math.max(0, x),
der: x => x <= 0 ? 0 : 1
};
public static SIGMOID: ActivationFunction = {
output: x => 1 / (1 + Math.exp(-x)),
der: x => {
let output = Activations.SIGMOID.output(x);
return output * (1 - output);
}
};
public static LINEAR: ActivationFunction = {
output: x => x,
der: x => 1
};
public static SINR: ActivationFunction = {
output: x => Math.sin(x),
der: x => Math.cos(x)
};
}