ruby 感知器类的初始规范

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 感知器类的初始规范相关的知识,希望对你有一定的参考价值。

require 'spec_helper'
require 'perceptron'

RSpec.describe Perceptron do
  describe '#activation' do
    describe 'logic AND' do
      bias = -1
      weights = [bias, 1, 1]
      describe 'when inputs are 0 and 0' do
        it 'returns 0 AND 0' do
          a = 0
          b = 0
          inputs = [a, b]
          perceptron = Perceptron.new(inputs.count, weights)
          expect(perceptron.predict(inputs)).to eq(a & b)
        end
      end
      describe 'when inputs are 0 and 1' do
        it 'returns 0 AND 1' do
          a = 0
          b = 1
          inputs = [a, b]
          perceptron = Perceptron.new(inputs.count, weights)
          expect(perceptron.predict(inputs)).to eq(a & b)
        end
      end
      describe 'when inputs are 1 and 0' do
        it 'returns 1 AND 0' do
          a = 1
          b = 0
          inputs = [a, b]
          perceptron = Perceptron.new(inputs.count, weights)
          expect(perceptron.predict(inputs)).to eq(a & b)
        end
      end
      describe 'when inputs are 1 and 1' do
        it 'returns 1 AND 1' do
          a = 1
          b = 1
          inputs = [a, b]
          perceptron = Perceptron.new(inputs.count, weights)
          expect(perceptron.predict(inputs)).to eq(a & b)
        end
      end
    end
  end
end        

以上是关于ruby 感知器类的初始规范的主要内容,如果未能解决你的问题,请参考以下文章