class Newral::Classifier::Node
Attributes
center[RW]
parent_node[W]
sub_nodes[R]
Public Class Methods
new( sub_nodes, from_point: false )
click to toggle source
# File lib/newral/classifier/node.rb, line 11 def initialize( sub_nodes, from_point: false ) if from_point @sub_nodes = [Vector.elements( sub_nodes )] @center = Vector.elements sub_nodes else @sub_nodes = sub_nodes @center = Vector.elements( [0]*sub_nodes.first.center.size ) sub_nodes.each do |node| @center = @center + node.center end @center = @center/@sub_nodes.size.to_f @sub_nodes.each do |node| node.parent_node = self end end @parent_node = nil end
Public Instance Methods
flatten_points()
click to toggle source
# File lib/newral/classifier/node.rb, line 38 def flatten_points @sub_nodes.collect do |node| if !node.kind_of?( Node ) [node] elsif node.sub_nodes.size == 1 node.center else node.flatten_points end end.flatten end
to_cluster()
click to toggle source
a dendogram can produce very nested node sets, so you can also flatten them by converting them to a cluster
# File lib/newral/classifier/node.rb, line 52 def to_cluster points = flatten_points Data::Cluster.new( points: points.collect{|p| p.to_a } ) end
to_s()
click to toggle source
# File lib/newral/classifier/node.rb, line 30 def to_s if @sub_nodes.size == 1 @sub_nodes.first.to_s else "=>(#{@sub_nodes.collect{|node| node.to_s }.join(',')})" end end