ICECommander has asked for the wisdom of the Perl Monks concerning the following question:

UPDATE: Workaround->use other AI module (AI::NeuralNet::SOM).

I am trying to pass an array reference to the AI::NeuralNet::Kohonen module but it is telling me that the input is undefined. The following code shows the gist of the input (it's a bit more complicated and is actually in a subroutine, but that is not relevant to the problem).
use strict; use warnings; use AI::NeuralNet::Kohonen; push @inputs, [41 scalar entries go here]; # the above statement is actually in a loop my $input_ref = \@inputs;
I then try to throw it in the module and train it:
our $som = AI::NeuralNet::Kohonen->new( map_dim_x => $map_dim_x, # 39 map_dim_y => $map_dim_y, # 19 epochs => $epochs, # 100 input => $input_ref ); $som->train();
Then I get the following error:
{weight_dim} not set at /home/gotszlin/perl/lib/perl5/site_perl/5.8.5/ +/AI/NeuralNet/Kohonen.pm line 209 AI::NeuralNet::Kohonen::new('AI::NeuralNet::Kohonen', 'map_dim_x', 39, + 'map_dim_y', 19, 'epochs', 10, 'input', 'ARRAY(0x926af84)', ...) cal +led at system_net.pl line 50 NSTAD_net::som_train(39, 19, 10, 'ARRAY(0x926af84)', 'my_first_som +.txt') called at system_main.pl line 35 Can't call method "train" on an undefined value at system_net.pl line +56.
I don't think that the weight_dim not being set has anything to do with it. I have tried other possibilities like passing @$input_ref, but that doesn't solve it. What am I doing wrong?

Replies are listed 'Best First'.
Re: Can't call method on undefined value
by jbert (Priest) on Jun 28, 2007 at 19:19 UTC
    The call to the constructor (new) is failing and returning undef. You aren't checking for this failure (see the previous replies for the ...or die "..." idiom) so you end up with $som containing undef (which is the return value from your failed call to new) and hence the error when you try to call the method.

    The 'weight_dim' error is the first thing to try. If it *is* necessary and not in the docs, the module author might appreciate an email to that effect.

    Otherwise, try reading the module source to see why it might be returning undef, or stepping into it with the perl debugger.

    And come back here if none of the above helps :-)

Re: Can't call method on undefined value
by Codon (Friar) on Jun 28, 2007 at 19:05 UTC
    I have no experience with any of the AI modules, but have you tried
    my $som = AI::NeuralNet::Kohonen->new( ... ) || die "could not instani +ate AI: $!\n";

    If an object is not defined after trying to instantiate it, it usually means the instantiation of that object failed. Examine why.

    Ivan Heffner
    Sr. Software Engineer
    WhitePages.com, Inc.
Re: Can't call method on undefined value
by jZed (Prior) on Jun 28, 2007 at 19:06 UTC
    Does it work if you set the weight_dim? If not and you get the same error it's a bug.
Re: Can't call method on undefined value
by ICECommander (Initiate) on Jun 28, 2007 at 19:18 UTC
    Seems to be a bug, I'm going to use the other AI module for self organizing maps. Thanks.