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 感知器类的初始规范的主要内容,如果未能解决你的问题,请参考以下文章

用不同的参数和默认值在 Ruby 中初始化类的最有效方法是啥?

深入理解Java虚拟机——类加载机制

装饰器、装饰器类与类装饰器(三)

静态成员初始化取决于另一个类的成员的初始化

Java-类加载器

Java中包装器类的行为[重复]