Method: Qoa::Training#convolution
- Defined in:
- lib/qoa/training.rb
#convolution(layer, inputs) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/qoa/training.rb', line 140 def convolution(layer, inputs) output_size = layer.output_size kernel_size = layer.kernel_size stride = layer.stride output = Array.new(output_size) { Array.new(inputs.length - kernel_size + 1) } layer.weights.each_with_index do |row, i| inputs.each_cons(kernel_size).each_with_index do |input_slice, j| output[i][j] = row.zip(input_slice).map { |a, b| a * b }.reduce(:+) end end output end |