gpt4 book ai didi

java - encog java 导出网络权重

转载 作者:行者123 更新时间:2023-11-30 08:38:46 24 4
gpt4 key购买 nike

我正在使用 encog 完成一些大学作业,我想导出网络中所有连接及其相关权重的列表。

我看到了 dumpWeights() 函数,它是 BasicMLNetwork 类的一部分(我使用 Java),但这只为我提供了权重,没有有关连接。

有谁知道实现这一目标的好方法吗?

提前致谢比德斯基

最佳答案

是的,使用BasicNetwork.getWeight。您可以循环所有层和神经元。只需指定您想要在其之间分配权重的两个神经元即可。其名称如下:

/**
* Get the weight between the two layers.
* @param fromLayer The from layer.
* @param fromNeuron The from neuron.
* @param toNeuron The to neuron.
* @return The weight value.
*/
public double getWeight(final int fromLayer,
final int fromNeuron,
final int toNeuron) {

我刚刚向 Encog 的 BasicNetwork 类添加了以下函数来转储权重和结构。它将出现在下一个 Encog 版本 (3.4) 中,它已经在 GitHub 上。现在,这是代码,这是一个关于如何从 Encog 中提取权重的不错的教程:

    public String dumpWeightsVerbose() {
final StringBuilder result = new StringBuilder();

for (int layer = 0; layer < this.getLayerCount() - 1; layer++) {
int bias = 0;
if (this.isLayerBiased(layer)) {
bias = 1;
}

for (int fromIdx = 0; fromIdx < this.getLayerNeuronCount(layer)
+ bias; fromIdx++) {
for (int toIdx = 0; toIdx < this.getLayerNeuronCount(layer + 1); toIdx++) {
String type1 = "", type2 = "";

if (layer == 0) {
type1 = "I";
type2 = "H" + (layer) + ",";
} else {
type1 = "H" + (layer - 1) + ",";
if (layer == (this.getLayerCount() - 2)) {
type2 = "O";
} else {
type2 = "H" + (layer) + ",";
}
}

if( bias ==1 && (fromIdx == this.getLayerNeuronCount(layer))) {
type1 = "bias";
} else {
type1 = type1 + fromIdx;
}

result.append(type1 + "-->" + type2 + toIdx
+ " : " + this.getWeight(layer, fromIdx, toIdx)
+ "\n");
}
}
}

return result.toString();
}

关于java - encog java 导出网络权重,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29670601/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com