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 +4 -4
- data/README.md +11 -2
- data/lib/rubyzero/core/functions/activations.rb +5 -1
- data/lib/rubyzero/core/functions/function.rb +7 -0
- data/lib/rubyzero/core/functions/operators.rb +0 -14
- data/lib/rubyzero/version.rb +1 -1
- data/tests/test.rb +6 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 357575700d5bb1cb77bd1edf44327fa01c0837225a7c2035cd967484fb4c1379
|
4
|
+
data.tar.gz: 0010a684b0527243a7070b776bf85ceeb51ac1c85bffcfdb14783965dc851922
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b3c14bae96029ed19cc992eb1e7b16f7529e7e0007bd511e11a917f3bfde962578140e8c48f16398f7c7cbac2657f608d6e6971e0b613a3a7b9a5de6964c5c7
|
7
|
+
data.tar.gz: 92cdda68e7333c9a6627dbc20c0945863a4bc7bb824fea1dd88702b4f20fc9a479542a601cd50ddd9bc84c45166863cee20e9633382338360f9006a7332593d8
|
data/README.md
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
# Rubyzero
|
2
2
|
|
3
|
-
|
3
|
+
A Simple deep learning library for Ruby.
|
4
4
|
|
5
|
-
|
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
|
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
|
data/lib/rubyzero/version.rb
CHANGED
data/tests/test.rb
ADDED
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.
|
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:
|