def newhop(target, transf=None, max_init=10, delta=0):
"""
Create a Hopfield recurrent network
:Parameters:
target: array like (l x net.co)
train target patterns
transf: func (default HardLims)
Activation function
max_init: int (default 10)
Maximum of recurrent iterations
delta: float (default 0)
Minimum difference between 2 outputs for stop recurrent cycle
:Returns:
net: Net
:Example:
>>> net = newhem([[-1, -1, -1], [1, -1, 1]])
>>> output = net.sim([[-1, 1, -1], [1, -1, 1]])
"""
target = np.asfarray(target)
assert target.ndim == 2
ci = len(target[0])
if transf is None:
transf = trans.HardLims()
l = layer.Reccurent(ci, ci, transf, max_init, delta)
w = l.np['w']
b = l.np['b']
# init weight
for i in range(ci):
for j in range(ci):
if i == j:
w[i, j] = 0.0
else:
w[i, j] = np.sum(target[:, i] * target[:, j]) / ci
b[i] = 0.0
l.initf = None
minmax = transf.out_minmax if hasattr(transf, 'out_minmax') else [-1, 1]
net = Net([minmax] * ci, ci, [l], [[-1], [0]], None, None)
return net
评论列表
文章目录