rubyzero 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 998d9df9776d84a808d54a8e7472d4a9ddea9ee6d0c6732705d8204153016b4e
4
- data.tar.gz: 77abc1c5ed65a055339150c4443a72622afd5cb8266c6feb17b707b73678e225
3
+ metadata.gz: 357575700d5bb1cb77bd1edf44327fa01c0837225a7c2035cd967484fb4c1379
4
+ data.tar.gz: 0010a684b0527243a7070b776bf85ceeb51ac1c85bffcfdb14783965dc851922
5
5
  SHA512:
6
- metadata.gz: 1ecf6f49bb0d4a182f204f89fc89d456f51871a7707e4b15bd2d232580b9c62673b1e95ae6159ad3a08535a6d4440d916b6916e33065300ea3674026d75470d3
7
- data.tar.gz: 5f5837d4f2ca18403ecafba1309ec8c2fe00d317da7dee746c2d5822c933a6d7817db739df0be988c66f1044113f50b2e1f09356210a9f8a1baf9be46bc7546d
6
+ metadata.gz: 1b3c14bae96029ed19cc992eb1e7b16f7529e7e0007bd511e11a917f3bfde962578140e8c48f16398f7c7cbac2657f608d6e6971e0b613a3a7b9a5de6964c5c7
7
+ data.tar.gz: 92cdda68e7333c9a6627dbc20c0945863a4bc7bb824fea1dd88702b4f20fc9a479542a601cd50ddd9bc84c45166863cee20e9633382338360f9006a7332593d8
data/README.md CHANGED
@@ -1,8 +1,17 @@
1
1
  # Rubyzero
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rubyzero`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ A Simple deep learning library for Ruby.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ ## Example
6
+ ```ruby
7
+ require 'rubyzero'
8
+ include RubyZero
9
+ model = L.mlp(2,5,1) # 多層パーセプトロンモデルを初期化(入力2次元, 隠れ層5次元, 出力層1次元)
10
+ data = RubyZero::Data::Presets::Xor.new() # XOR演算のデータセット
11
+ trainer = Utils::Trainer.new(model) # 学習を勝手にしてくれるやつ
12
+ trainer.train(data, data, num_epochs:100) # 学習を自動的にするメソッド
13
+ p model # ついでにモデルの中身を表示
14
+ ```
6
15
 
7
16
  ## Installation
8
17
 
@@ -1,7 +1,7 @@
1
1
  module RubyZero::Core::Functions
2
2
  class ReLU < Function
3
3
  def forward(x)
4
- @path_through = RubyZero::Core::Tensor.new(x.data < 0)
4
+ @path_through = RubyZero::Core::Tensor.new(x.data > 0)
5
5
  @path_through.cast_to(RubyZero::FloatTensor)
6
6
  return x * @path_through
7
7
  end
@@ -16,5 +16,9 @@ module RubyZero::Core::Functions
16
16
  data = 1.0 / (1.0 + nmath.exp(-x.data))
17
17
  return RubyZero::Core::Tensor.new(data)
18
18
  end
19
+ def backward(dy)
20
+ x = @inputs[0]
21
+ return [ F.sigmoid(self.forward(x)) * (x.ones_like - F.sigmoid(self.forward(x))) * dy ]
22
+ end
19
23
  end
20
24
  end
@@ -1,4 +1,5 @@
1
1
  require_relative '../exceptions.rb'
2
+ require 'unicode_plot'
2
3
 
3
4
  module RubyZero::Core::Functions
4
5
  # Function class
@@ -25,5 +26,11 @@ module RubyZero::Core::Functions
25
26
  def inspect
26
27
  return "#<#{self.class}>"
27
28
  end
29
+ def self.plot(range: (-10..10).step(0.01))
30
+ inputs = range.to_a
31
+ outputs = inputs.map{|t| self.new().call(RubyZero::Core::Tensor.new(t)).data[0]}
32
+ plot = UnicodePlot.lineplot(inputs, outputs, name: self.name)
33
+ plot.render
34
+ end
28
35
  end
29
36
  end
@@ -68,20 +68,6 @@ module RubyZero::Core::Functions
68
68
  end
69
69
  end
70
70
 
71
- class Log < Function
72
- def forward(x1)
73
- nmath = x1.device.xmo::NMath
74
- new_arr = nmath.log(x1.data)
75
- new_t = RubyZero::Core::Tensor.new(new_arr, device: x1.device)
76
- return new_t
77
- end
78
-
79
- def backward(dy)
80
- x1 = @inputs[0]
81
- return [dy / x1]
82
- end
83
- end
84
-
85
71
  class MulScalar < Function
86
72
  def initialize(scalar)
87
73
  @scalar = scalar
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rubyzero
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/tests/test.rb ADDED
@@ -0,0 +1,6 @@
1
+ require_relative '../lib/rubyzero'
2
+ L = RubyZero::L
3
+ F = RubyZero::F
4
+
5
+ RubyZero::Core::Functions::ReLU.plot
6
+ RubyZero::Core::Functions::Sigmoid.plot
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyzero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - uthree
@@ -73,6 +73,7 @@ files:
73
73
  - lib/rubyzero/version.rb
74
74
  - note.txt
75
75
  - rubyzero.gemspec
76
+ - tests/test.rb
76
77
  homepage: https://github.com/uthree/RubyZero
77
78
  licenses: []
78
79
  metadata: