AI::NeuralNet::Kohonen::Node - a node for AI::NeuralNet::Kohonen


AI-NeuralNet-Kohonen documentation Contained in the AI-NeuralNet-Kohonen distribution.

Index


Code Index:

NAME

Top

AI::NeuralNet::Kohonen::Node - a node for AI::NeuralNet::Kohonen

DESCRIPTION

Top

Implimentation of a node in a SOM - see AI::NeuralNet::Kohonen.

CONSTRUCTOR (new)

Top

Returns a new Node object. If no wieghts are supplied, the node's weights are randomized with real nubmers.

dim

The number of dimensions of this node's weights. Do not supply if you are supplying weight.

weight

Optional: a reference to an array containing the weight for this node. Supplying this allows the constructor to work out dim, above.

values

The values of the vector. Use x for unknown values.

missing_mask

Used to donate missing input in the node. Default is x.

METHOD distance_from

Top

Find the distance of this node from the target.

Accepts: the target vector as an array reference.

Returns: the distance.

	               __________________
	              / i=n            2
	Distance  =  /   E  ( V  -  W )
	           \/   i=0    i     i

Where V is the current input vector, and W is this node's weight vector.

METHOD distance_effect

Top

Calculates the effect on learning of distance from a given point (intended to be the BMU).

Accepts: the distance of this node from the given point; the radius of the neighbourhood of affect around the given point.

Returns:

	               (            2  )
	               (    distance   )
	THETA(t) = exp ( - ----------- )
	               (          2    )
	               (   2 sigma (t) )

Where distance is the distance of the node from the BMU, and sigma is the width of the neighbourhood as calculated elsewhere (see FINDING THE NEIGHBOURS OF THE BMU in AI::NeuralNet::Kohonen). THETA also decays over time.

The time t is always that of the calling object, and is not referenced here.

SEE ALSO

Top

The AI::NeuralNet::Kohonen.

AUTHOR AND COYRIGHT

Top

This implimentation Copyright (C) Lee Goddard, 2003. All Rights Reserved.

Available under the same terms as Perl itself.


AI-NeuralNet-Kohonen documentation Contained in the AI-NeuralNet-Kohonen distribution.
package AI::NeuralNet::Kohonen::Node;

use vars qw/$VERSION $TRACE/;
$VERSION = 0.12;	# 05 May 2006; no warnings 'numeric' inserted
$TRACE = 1;

use strict;
use warnings;
use Carp qw/cluck carp confess croak/;

sub new {
	my $class	= shift;
	my %args	= @_;
	my $self 	= bless \%args,$class;
	$self->{missing_mask} = 'x' unless defined $self->{missing_mask};
	if (not defined $self->{weight}){
		if (not defined $self->{dim}){
			cluck "No {dim} or {weight}!";
			return undef;
		}
		$self->{weight} = [];
		for my $w (0..$self->{dim}){
			$self->{weight}->[$w] = rand;
		}
	} elsif (not ref $self->{weight} or ref $self->{weight} ne 'ARRAY') {
		cluck "{weight} should be an array reference!";
		return undef;
	} else {
		$self->{dim} = $#{$self->{weight}};
	}
	return $self;
}


sub distance_from { my ($self,$target) = (shift,shift);
	if (not defined $target or not ref $target or ref $target ne 'AI::NeuralNet::Kohonen::Input'){
		cluck "distance_from requires a target ::Input object!";
		return undef;
	}
	if ($#{$target->{values}} != $self->{dim}){
		croak "distance_from requires the target's {value} field dim match its own {dim}!\n"
		."(".($#{$target->{values}})." v {".$self->{dim}."} ) ";
	}
	my $distance = 0;
	for (my $i=0; $i<=$self->{dim}; ++$i){
		no warnings 'numeric';
		next if $target->{values}->[$i] eq $self->{missing_mask};
		$distance += (
			( $target->{values}->[$i] - $self->{weight}->[$i] )
		  * ( $target->{values}->[$i] - $self->{weight}->[$i] )
		);
	}
	return sqrt($distance);
}


sub distance_effect { my ($self,$distance,$sigma) = (shift,shift,shift);
	confess "Wrong args" unless defined $distance and defined $sigma;
	return exp (-($distance*$distance) / 2 * ($sigma*$sigma))
}

1;

__END__