效果





修改
- 在前端的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)
};
}
在前端HTML中添加了一个用于选择神经网络激活函数的下拉菜单,包括ReLU、Tanh、Sigmoid、Linear和SINR。在状态管理文件中定义了这些激活函数的映射,并提供了它们的计算方法及导数实现。

被折叠的 条评论
为什么被折叠?



