Bug in nested iterations? (was: What is wrong with this?)

Joaquin Sitte j.sitte at qut.edu.au
Thu May 26 01:19:09 UTC 2005


Hi Hans-Martin,

Thank you for your reply. 

I had already checked out the random number generation and concluded that
the problem is not with the random number generator. To see this try the
following:

randomGenerator _ Random new.
randNumbers _ FloatArray new: 10.
1 to: randNumbers size do: [:each | randNumbers at: each put:
randomGenerator next].

This gives 10 different random numbers. By repeating the last message a new
set of random numbers is produced (next takes care of the seeding), as can
be verified by inspecting randNumbers. 

Regardless of the random numbers, the problem I have is the "strange"
behaviour of nested iteration. I expect nested iterations in Squeak to
behave like nested do loops in procedural programming languages.

The "strange" behaviour is evidenced by the following example that does not
use the random number generator.

Define the class Som

ArrayedCollection variableSubclass: #Som
	instanceVariableNames: 'width height'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'NeuralNets'

map_ Som new: 30
map from: 1 to: map size put: (FloatArray new: 4).
count _0.
map do: [:each |  1 to: each size do: [:i | each at: i put: (count _ count
+1)]].

I would expect that the elements of the FloatArray vectors have values
starting at 1 and running through to 120. 
Not so! All elements of the Som end up with the same vector, namely  #(117.0
118.0 119.0 120.0)

Is this a bug in Squeak or am I missing something?

Thanks for any help.

Joaquin

=====================================================
Dr. Joaquin Sitte, Associate Professor.
Head, Smart Devices Lab
School of Software Engineering and Data Communication
Faculty of Information Technology
Queensland University of Technology
GPO Box 2434, Brisbane, Q 4001
Australia
Phone +61 7 3864 9325
Fax +61 7 3864 9390
e-mail j.sitte at qut.edu.au 
homepage http://www.fit.qut.edu.au/~sitte

------------------------------

Message: 18
Date: Wed, 25 May 2005 12:13:52 +1000
From: "Joaquin Sitte" <j.sitte at qut.edu.au>
Subject: What is wrong with this? (Beginner question)
To: <squeak-dev at lists.squeakfoundation.org>
Message-ID: <200505250214.CWE38339 at mail-router02-eth0.qut.edu.au>
Content-Type: text/plain;	charset="us-ascii"

In the course of implementing a Self-organising feature map (SOM) I needed
to initialise the weight vecorts of each of nodes in the map with random
numbers. I wrote the method randomWeights below for the class Som 


ArrayedCollection variableSubclass: #Som
	instanceVariableNames: 'width height'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'NeuralNets'

randomWeights
	
	"initialise the weights of the neurones to random vectors"
	"JS 5/24/2005 23:14 Caution: all rendome vectors are the same. Why?"
	
	|randomGenerator |
	randomGenerator _ Random new.
	self do: [ :each |  1 to: each size do:
		[:index | each at: index put: randomGenerator next]].

It turns out that the weight vectors of each of the nodes in the SOM are set
to the SAME random vector, when I expected them to be all DIFFERENT. What is
wrong with this nested iteration?

The following trial in a workspace 


map _ Som new: 30
map width:6 height:5 inputs: 4
count _1.
1 to: 30 do: [ :each | (map at: each) at: 1 put: count. Count _ count + 1]. 

sets the first weight of each of the 30 nodes to 30 !!!  I would expect them
to be set to 1, 2, ... 30.

Please help.

Thanks

Joaquin

  
Thanks for your comments Hans-Martin. The random number generator is
initialised outside the iteration. Try out the following:
myVector _ FloatArray new: 10
1 to: myVector size do: [:each | myVector at: each put: randomGenerator
next]


=====================================================
Dr. Joaquin Sitte, Associate Professor.
Head, Smart Devices Lab
School of Software Engineering and Data Communication
Faculty of Information Technology
Queensland University of Technology
GPO Box 2434, Brisbane, Q 4001
Australia
Phone +61 7 3864 9325
Fax +61 7 3864 9390
e-mail j.sitte at qut.edu.au 
homepage http://www.fit.qut.edu.au/~sitte


------------------------------

Message: 20
Date: Wed, 25 May 2005 07:18:29 +0200
From: Hans-Martin Mosner <hmm at heeg.de>
Subject: Re: What is wrong with this? (Beginner question)
To: The general-purpose Squeak developers list
	<squeak-dev at lists.squeakfoundation.org>
Message-ID: <42940AA5.4090504 at heeg.de>
Content-Type: text/plain; charset=ISO-8859-1

Joaquin Sitte wrote:

> It turns out that the weight vectors of each of the nodes in the SOM are
set
> to the SAME random vector, when I expected them to be all DIFFERENT. What
is
> wrong with this nested iteration?

You have most likely initialized all your Som instances with the same
vectors.
Since your example does not show the initialization, I can't show you where
exactly.

Cheers,
Hans-Martin






More information about the Squeak-dev mailing list