loganb-kder 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/kder/kde.rb +46 -1
  3. data/lib/kder/version.rb +1 -1
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17148d0bed58d5e6a0c2c7d93e93322d4bb5497b
4
- data.tar.gz: 5f4f7639de0cbd1d16526c46d4c083b904f9442e
3
+ metadata.gz: e5b8c12f1724491f1d7e1030dca865ca131aff67
4
+ data.tar.gz: dd269d0ef838ebe5d6c45a62288f2b688971a1fe
5
5
  SHA512:
6
- metadata.gz: f2d329f6b49f4426b1cfb290801fc0845c10f93a45a97b1eaa87e9653e006513e403958ccc117b8ba350023d6ce94005baba5a078a67f84df596274d81006934
7
- data.tar.gz: 83aa31ddc5861e47b54a9333c59594c591669a71c530a8d0986aa1a68e5545ff930e6b6bb1e0dd77d7f30427c49d7a6a768da5a69381c8128eb1a3a3e997c344
6
+ metadata.gz: 1964cd8f5e3446644fc5f26e623c953a94e56dd2f0efac20b2ec42164d458f71038eba37c521034166909b983875e82d6ca66b74f3a71dd625b2168d2d9bdc01
7
+ data.tar.gz: '07429b569c86eeef572489945412a478ef4329162fb0325b520ed6ac15bb8cabca511d10ee2fd994f72330cf804e1d3b443813bfcea28a0a425f8d003ba629fe'
data/lib/kder/kde.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'set'
1
+ require 'matrix'
2
2
 
3
3
  class Kder
4
4
  require_relative 'bandwidth'
@@ -83,5 +83,50 @@ class Kder
83
83
  output << [max,0]
84
84
  output.compact.transpose
85
85
  end
86
+
87
+ #
88
+ # Smooths multiple data sets with a shared x-axis at the same time.
89
+ #
90
+ # values in the form of:
91
+ #
92
+ # [
93
+ # [x1, y1, z1, k1],
94
+ # [x2, y2, 0, z3], # "Hole" where there is no data for z
95
+ # ...
96
+ # ]
97
+ #
98
+ #
99
+ def kdemultivec(values, bw, opts = {}.freeze)
100
+ opts = {sigmas: Sigmas, sampling_density: MeshCount, threshold: MinimumThresholdValue, minimum_delta: DifferenceThreshold}.merge(opts)
101
+
102
+ # Initialization steps
103
+ range = bw*opts[:sigmas]
104
+ min = values.first[0] - range
105
+ max = values.last[0] + range
106
+ step_size = (max-min)/(opts[:sampling_density].to_f)
107
+ step_size = step_size < MinimumStepSize ? MinimumStepSize : step_size
108
+
109
+ # initialize the range variables
110
+ ranges = (min..max).step(step_size).to_a
111
+ output = [Array.new(values.first.length-1, 0).unshift(min)]
112
+ old_intensities = Vector::elements(Array.new(values.first.length-1, 0))
113
+ # Step through the range
114
+ ranges[1..-1].map do |mid|
115
+ high_end = mid + range
116
+ lower_end = mid - range
117
+ selection_range = (lower_end..high_end)
118
+ included = values.select {|v| selection_range.include?(v[0])}
119
+
120
+ intensities = included.collect { |vec| Vector::elements(vec[1..-1],false) * Kder::Statistics.custom_pdf(vec[0] - mid, bw) }.
121
+ inject(&:+) || old_intensities
122
+
123
+ unless intensities.all? { |v| v < opts[:threshold] } or (intensities - old_intensities).all? { |v| v.abs < opts[:minimum_delta] }
124
+ output << intensities.to_a.unshift(mid)
125
+ old_intensities = intensities
126
+ end
127
+ end
128
+ output << Array.new(values.first.length - 1, 0).unshift(max)
129
+ output.compact.transpose
130
+ end
86
131
  end
87
132
  end
data/lib/kder/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Kder
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loganb-kder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Taylor
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-11-15 00:00:00.000000000 Z
12
+ date: 2017-11-18 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A KDE implementation in Ruby.
15
15
  email:
@@ -44,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
44
  version: '0'
45
45
  requirements: []
46
46
  rubyforge_project:
47
- rubygems_version: 2.5.2
47
+ rubygems_version: 2.5.2.1
48
48
  signing_key:
49
49
  specification_version: 4
50
50
  summary: Kernel Density Estimation, and an associated bandwidth estimator, rudimentary