Class: FeldtRuby::Statistics::DiffusionKDE

Inherits:
Object
  • Object
show all
Defined in:
lib/feldtruby/statistics.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rvalue) ⇒ DiffusionKDE

Given a R object with the four sub-values named densities, mesh, sum_density, mesh_interval, min, max we can calculate the probability of new values.



198
199
200
201
202
203
204
# File 'lib/feldtruby/statistics.rb', line 198

def initialize(rvalue)
  @probabilities = rvalue.probabilities
  @densities = rvalue.densities
  @mesh = rvalue.mesh
  @mesh_interval = rvalue.mesh_interval.to_f
  @min, @max = rvalue.min.to_f, rvalue.max.to_f
end

Instance Attribute Details

#densitiesObject (readonly)

Returns the value of attribute densities.



194
195
196
# File 'lib/feldtruby/statistics.rb', line 194

def densities
  @densities
end

#meshObject (readonly)

Returns the value of attribute mesh.



194
195
196
# File 'lib/feldtruby/statistics.rb', line 194

def mesh
  @mesh
end

Instance Method Details

#density_of(value) ⇒ Object



206
207
208
209
210
# File 'lib/feldtruby/statistics.rb', line 206

def density_of(value)
  return 0.0 if value < @min || value > @max
  bin_index = ((value - @min) / @mesh_interval).floor
  @densities[bin_index]
end

#probability_of(value) ⇒ Object



212
213
214
215
216
# File 'lib/feldtruby/statistics.rb', line 212

def probability_of(value)
  return 0.0 if value < @min || value > @max
  bin_index = ((value - @min) / @mesh_interval).floor
  @probabilities[bin_index]
end