Matplotlib 浮点格式问题

问题描述 投票:0回答:1

我在同时使用 Matplotlib 或 PyQtGraph 时从 Python 2 中的文件加载 FANN2 网络时遇到奇怪的行为。我需要实时绘制 FANN 网络的 MSE。我将使用具有交互性的

matplotlib
while True
循环或
Thread
来更新绘图。

创建神经网络并存储到文件:

#!/usr/bin/python2

from fann2 import libfann
import matplotlib.pyplot as plt

PLOT = False

if PLOT:
    plt.show()
    axes = plt.subplot(111)

connection_rate = 1
layers = (10, 5)
activation_f = libfann.SIGMOID_SYMMETRIC_STEPWISE
ann = libfann.neural_net()
ann.create_sparse_array(connection_rate, layers)
ann.randomize_weights(-0.1, 0.1)
ann.save('my_network.ann')

PLOT
标志禁用绘图。输出文件,最后一行:

connections (connected_to_neuron, weight)=(0, -9.04591381549835205078e-02) ...

...
表示省略字符。将
PLOT
更改为
True
后,相应的行如下所示:

connections (connected_to_neuron, weight)=(0, -7,55163878202438354492e-02) ...

这会导致加载保存的网络时出错:

from fann2 import libfann
ann = libfann.neural_net()
ann.create_from_file('my_network.ann')

FANN 错误 4:从配置文件“my_network.ann”读取“connection_rate”时出错。

如何解决这个问题?我应该在 Matplotlib 中更改浮点数格式吗? PyQtGraph 给出相同的结果:

#!/usr/bin/python2

from fann2 import libfann
import pyqtgraph as pg

PLOT = False

if PLOT:
pg.plot([1, 2], [3, 4], pen=None, symbol='o')

connection_rate = 1
layers = (10, 5)
activation_f = libfann.SIGMOID_SYMMETRIC_STEPWISE
ann = libfann.neural_net()
ann.create_sparse_array(connection_rate, layers)
ann.randomize_weights(-0.1, 0.1)
ann.save('my_network.ann')
python matplotlib pyqtgraph fann
1个回答
0
投票

在“my_network.ann”中添加

connection_rate
(以及 FANN2 抱怨的
cascade_min_out_epochs
等设置):

connection_rate = 0.7000 {or whichever you prefer}

当我在加载配置文件时将 libfann 更新为 FANN2 时,我得到:

FANN 错误 3:配置文件版本错误,中止读取配置文件“myfile.net”。分段错误

通过添加 FANN2 抱怨的设置修复了该问题。

© www.soinside.com 2019 - 2024. All rights reserved.