本文整理匯總了Python中pybrain.tools.customxml.NetworkReader.iteritems方法的典型用法代碼示例。如果您正苦於以下問題:Python NetworkReader.iteritems方法的具體用法?Python NetworkReader.iteritems怎麽用?Python NetworkReader.iteritems使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pybrain.tools.customxml.NetworkReader
的用法示例。
在下文中一共展示了NetworkReader.iteritems方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from pybrain.tools.customxml import NetworkReader [as 別名]
# 或者: from pybrain.tools.customxml.NetworkReader import iteritems [as 別名]
def __init__(self, mat, cmap=None, pixelspervalue=20, minvalue=None, maxvalue=None, show=True, block=False):
""" Make a colormap image of a matrix or sequence of Matrix/Connection objects
:key mat: the matrix to be used for the colormap.
:key cmap: the matplotlib colormap (color scale) to use ('hot', 'hot_r', 'gray', 'gray_r', 'hsv', 'prism', pylab.cm.hot, etc)
"""
self.colormaps = []
if isinstance(mat, basestring):
try:
#nn = NetworkReader(mat, newfile=False)
mat = NetworkReader(mat, newfile=False).readFrom(mat)
except:
pass
try: # if isinstance(mat, Trainer):
mat = mat.module
except:
pass
if isinstance(mat, Network):
# connections is a dict with key: value pairs of Layer: Connection (ParameterContainer)
mat = [connection for connection in mat.connections.values() if connection]
# connections = mat.module.connections.values()
# mat = []
# for conlist in connections:
# mat += conlist
try:
mat = [v for (k, v) in mat.iteritems()]
if not any(isinstance(m, (ParameterContainer, Connection)) for m in mat):
raise ValueError("Don't know how to display ColorMaps for a sequence of type {} containing key, values of type {}: {}".format(
type(mat), *[type(m) for m in mat.iteritems().next()]))
except AttributeError:
pass
# from traceback import print_exc
# print_exc()
if isinstance(mat, list):
for m in mat:
if isinstance(m, list):
if len(m) == 1:
m = m[0]
else:
raise ValueError("Don't know how to display a ColorMap for a list containing more than one matrix: {}".format([type(m) for m in mat]))
try:
self.colormaps = [ColorMap(m, cmap=cmap, pixelspervalue=pixelspervalue, minvalue=minvalue, maxvalue=maxvalue) ]
except ValueError:
self.colormaps = [ColorMap(m[0], cmap=cmap, pixelspervalue=pixelspervalue, minvalue=minvalue, maxvalue=maxvalue) ]
else:
self.colormaps = [ColorMap(mat)]
# raise ValueError("Don't know how to display ColorMaps for a sequence of type {}".format(type(mat)))
if show:
self.show(block=block)
示例2: weight_matrices
# 需要導入模塊: from pybrain.tools.customxml import NetworkReader [as 別名]
# 或者: from pybrain.tools.customxml.NetworkReader import iteritems [as 別名]
def weight_matrices(nn):
""" Extract list of weight matrices from a Network, Layer (module), Trainer, Connection or other pybrain object"""
if isinstance(nn, ndarray):
return nn
try:
return weight_matrices(nn.connections)
except:
pass
try:
return weight_matrices(nn.module)
except:
pass
# Network objects are ParameterContainer's too, but won't reshape into a single matrix,
# so this must come after try nn.connections
if isinstance(nn, (ParameterContainer, Connection)):
return reshape(nn.params, (nn.outdim, nn.indim))
if isinstance(nn, basestring):
try:
fn = nn
nn = NetworkReader(fn, newfile=False)
return weight_matrices(nn.readFrom(fn))
except:
pass
# FIXME: what does NetworkReader output? (Module? Layer?) need to handle it's type here
try:
return [weight_matrices(v) for (k, v) in nn.iteritems()]
except:
try:
connections = nn.module.connections.values()
nn = []
for conlist in connections:
nn += conlist
return weight_matrices(nn)
except:
return [weight_matrices(v) for v in nn]