19 lines
542 B
Ruby
19 lines
542 B
Ruby
def trace_hopfield_step(weights, vector)
|
|
n = vector.length
|
|
Array.new(n) { |i| n.times.sum { |j| weights[i][j] * vector[j] } }
|
|
end
|
|
|
|
def hamming_trace(pattern_vectors, input_vec)
|
|
n = input_vec.length
|
|
k = pattern_vectors.length
|
|
dots = pattern_vectors.map { |pv| pv.zip(input_vec).sum { |a, b| a * b } }
|
|
initial = dots.map { |dot| (dot.to_f + n) / 2.0 }
|
|
{
|
|
eps: (0.9 / k).round(6),
|
|
k: k,
|
|
n: n,
|
|
dot_products: dots,
|
|
initial_outputs: initial.map { |v| v.round(2) }
|
|
}
|
|
end
|