Skip to content

Commit

Permalink
sigmoid in ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
doolin committed Jan 26, 2016
1 parent d947c2a commit 6e6ec11
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nb/dss/nn/ruby/lib/perceptron.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ def step_function(x)
def think(u)
step_function(@weights.dot(u).to_f + @bias)
end

def sigmoid(t)
1.0 / (1.0 + Math.exp(-t))
end
end
6 changes: 6 additions & 0 deletions nb/dss/nn/ruby/spec/perceptron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,10 @@
expect(subject.think(u)).to be 0
end
end

describe "sigmoid" do
it "computes a sigmoid" do
expect(subject.sigmoid(1.0)).to be 1.0
end
end
end

0 comments on commit 6e6ec11

Please sign in to comment.