Add initial implementation of Hopfield and Hamming networks with web interface
- Create Dockerfile and entrypoint script for application setup - Implement pattern loading from Excel and weight caching - Develop core functions for Hopfield and Hamming networks - Add Sinatra web server for user interaction - Create HTML interface for displaying patterns and results - Include necessary gems in Gemfile and lockfile - Add .dockerignore and .gitignore files
This commit is contained in:
+29
@@ -0,0 +1,29 @@
|
||||
def hamming_layer(pattern_vectors, input_vec)
|
||||
n = input_vec.length
|
||||
pattern_vectors.map do |pv|
|
||||
dot = pv.zip(input_vec).sum { |a, b| a * b }
|
||||
(dot.to_f + n) / 2.0
|
||||
end
|
||||
end
|
||||
|
||||
def maxnet_step(outputs, eps)
|
||||
outputs.map.with_index do |val, i|
|
||||
inhibition = eps * outputs.each_with_index.sum { |v, j| j == i ? 0.0 : v }
|
||||
[val - inhibition, 0.0].max
|
||||
end
|
||||
end
|
||||
|
||||
MAX_MAXNET_ITER = 500
|
||||
|
||||
def recall_hamming(pattern_vectors, input_vec)
|
||||
eps = 0.9 / pattern_vectors.length
|
||||
|
||||
outputs = hamming_layer(pattern_vectors, input_vec)
|
||||
MAX_MAXNET_ITER.times do
|
||||
next_out = maxnet_step(outputs, eps)
|
||||
return next_out.each_with_index.max_by { |v, _| v }[1] if next_out.count { |v| v > 0 } <= 1
|
||||
outputs = next_out
|
||||
end
|
||||
|
||||
outputs.each_with_index.max_by { |v, _| v }[1]
|
||||
end
|
||||
Reference in New Issue
Block a user