scout-essentials 1.5.0 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/scout/annotation/array.rb +2 -2
- data/lib/scout/misc/math.rb +13 -0
- data/lib/scout/named_array.rb +12 -3
- data/scout-essentials.gemspec +3 -3
- data/test/scout/misc/test_math.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fe20bd6954a0372235430a8baa5990efbd23d00b5ebd37048dbeb253ebdb78d
|
4
|
+
data.tar.gz: 41ba7642cc7c683d482e1173c27d0f23a632c3651856d8adaf9d150b81904e2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1badc3ef7083453c39ff6778c1a1f516865ea3e59d7c01c7f0e1047bda5e9835d7ee490db35de6ac684b85d63bdac3369a442e669a32cc14b3242f6f1ee1092d
|
7
|
+
data.tar.gz: 671d77a07f9d9b847bc6397e365b9f944a85261818edd70aaf9a6cc5c75beef3d4e255b52081bc01b3762bb68df5632a5e10cf0041bb4472e360c8eea774d6c6
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.6.1
|
@@ -62,8 +62,8 @@ module AnnotatedArray
|
|
62
62
|
|
63
63
|
%w(compact uniq flatten reverse sort_by).each do |method|
|
64
64
|
|
65
|
-
self.define_method(method) do |*args|
|
66
|
-
res = super(*args)
|
65
|
+
self.define_method(method) do |*args,&block|
|
66
|
+
res = super(*args, &block)
|
67
67
|
|
68
68
|
annotate(res)
|
69
69
|
res.extend AnnotatedArray
|
data/lib/scout/misc/math.rb
CHANGED
@@ -106,4 +106,17 @@ module Misc
|
|
106
106
|
sd = Misc.sd(list)
|
107
107
|
(e.to_f - m) / sd
|
108
108
|
end
|
109
|
+
|
110
|
+
def self.softmax(array)
|
111
|
+
# Compute the exponentials of the input array elements
|
112
|
+
exp_array = array.map { |x| Math.exp(x) }
|
113
|
+
|
114
|
+
# Sum of all exponentials
|
115
|
+
sum_exp = exp_array.sum
|
116
|
+
|
117
|
+
# Compute the softmax values by dividing each exponential by the sum of exponentials
|
118
|
+
softmax_array = exp_array.map { |x| x / sum_exp }
|
119
|
+
|
120
|
+
return softmax_array
|
121
|
+
end
|
109
122
|
end
|
data/lib/scout/named_array.rb
CHANGED
@@ -84,9 +84,18 @@ module NamedArray
|
|
84
84
|
|
85
85
|
|
86
86
|
def concat(other)
|
87
|
-
|
88
|
-
|
89
|
-
|
87
|
+
if Hash === other
|
88
|
+
new_fields = []
|
89
|
+
other.each do |k,v|
|
90
|
+
new_fields << k
|
91
|
+
self << v
|
92
|
+
end
|
93
|
+
self.fields.concat(new_fields)
|
94
|
+
else
|
95
|
+
super(other)
|
96
|
+
self.fields.concat(other.fields) if NamedArray === other
|
97
|
+
self
|
98
|
+
end
|
90
99
|
end
|
91
100
|
|
92
101
|
def to_hash
|
data/scout-essentials.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: scout-essentials 1.
|
5
|
+
# stub: scout-essentials 1.6.1 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "scout-essentials".freeze
|
9
|
-
s.version = "1.
|
9
|
+
s.version = "1.6.1".freeze
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Miguel Vazquez".freeze]
|
14
|
-
s.date = "2024-
|
14
|
+
s.date = "2024-06-17"
|
15
15
|
s.description = "Things a scout can use anywhere".freeze
|
16
16
|
s.email = "mikisvaz@gmail.com".freeze
|
17
17
|
s.extra_rdoc_files = [
|
@@ -5,5 +5,11 @@ class TestMiscMath < Test::Unit::TestCase
|
|
5
5
|
def test_mean
|
6
6
|
assert_equal 4, Misc.mean([6,2])
|
7
7
|
end
|
8
|
+
|
9
|
+
def test_softmax
|
10
|
+
assert_equal 0.5, Misc.softmax([1,1]).first
|
11
|
+
assert Misc.softmax([1,2]).first < 0.5
|
12
|
+
assert Misc.softmax([2,1]).first > 0.5
|
13
|
+
end
|
8
14
|
end
|
9
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scout-essentials
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoulda
|