ioam / topographica

A general-purpose neural simulator focusing on topographic maps.
topographica.org
BSD 3-Clause "New" or "Revised" License
53 stars 32 forks source link

Dynamic parameters for initializing weight patterns #53

Open sf-issues opened 12 years ago

sf-issues commented 12 years ago

Converted from SourceForge issue 1948299, submitted by jbednar Submit Date: 2008-04-21 22:20 GMT

Right now, http://topographica.org/User_Manual/patterns.html has this code:

CFProjection.weights_generator=topo.patterns.basic.Selector(generators=[ topo.patterns.basic.Gaussian(orientation=DynamicNumber( UniformRandom(lbound=-pi,ubound=pi,seed=99))), topo.patterns.basic.Gaussian(aspect_ratio=1.0, x=DynamicNumber(UniformRandom(lbound=-0.2,ubound=0.2,seed=12)), y=DynamicNumber(UniformRandom(lbound=-0.2,ubound=0.2,seed=34))), topo.patterns.basic.Rectangle(size=0.3,orientation=DynamicNumber( UniformRandom(lbound=-pi,ubound=pi,seed=99))), topo.patterns.basic.Disk(size=0.2)])

and this picture of the results:

http://topographica.org/User_Manual/images/fourclassweights.png

For one thing, the example uses DynamicNumber, which I guess means that we need a to-do item to search for that in the docs in case it's mentioned anywhere else. More importantly, once I remove DynamicNumber:

CFProjection.weights_generator=topo.patterns.basic.Selector(generators=[ topo.patterns.basic.Gaussian(orientation=UniformRandom(lbound=-pi,ubound=pi,seed=99)), topo.patterns.basic.Gaussian(aspect_ratio=1.0, x=UniformRandom(lbound=-0.2,ubound=0.2,seed=12), y=UniformRandom(lbound=-0.2,ubound=0.2,seed=34)), topo.patterns.basic.Rectangle(size=0.3,orientation=UniformRandom(lbound=-pi,ubound=pi,seed=99)), topo.patterns.basic.Disk(size=0.2)])

the result is now that all units have the same weight pattern, presumably because the simulation time does not advance while the CFs are being drawn. I can change Dynamic.time_fn, but that would be a global change that would mess up all of the input patterns.

There's a note saying that we should add a time_fn slot to allow instances to override the setting, but that note is misleading. Selector.index would work by adding a time_fn slot, because the (single) Selector.index parameter would then have a time_fn of None. But what is documented above (for orientation) requires that a specific instance of a Gaussian have a time_fn of None for the Gaussian orientation parameter (the orientation parameter instance itself still having a default time_fn of sim.time()). For that, we need to override the time_fn for the Gaussian instance itself, not the Dynamic Parameter instance, which could take some serious thought.

In any case, it would be great to fix this, because we want people to be able to set up any arbitrary initial configuration of the weights. But we must at least fix the documentation before doing the next release.

sf-issues commented 12 years ago

Submitted by ceball Date: 2008-05-10 07:37 GMT

r8507 - CFProjection's weights_generator is set to have a time_fn of None. Also, any Parameterized class or instance can override its time_fn using set_dynamic_time_fn().

Not perfect, but I think it's working.

sf-issues commented 12 years ago

Submitted by sf-robot Date: 2008-05-25 02:20 GMT

This Tracker item was closed automatically by the system. It was previously set to a Pending status, and the original submitter did not respond within 14 days (the time period specified by the administrator of this Tracker).

sf-issues commented 12 years ago

Submitted by jbednar Date: 2010-07-06 22:56 GMT

From: C. E. Ball Date: May 10 12:08:17 2008 +0800

On Sat, May 10, 2008 at 10:38 AM, C. E. Ball ceball@gmail\.com wrote:

On Fri, May 9, 2008 at 11:02 PM, James A. Bednar jbednar@inf\.ed\.ac\.uk wrote:

From: J Antolik Date: May 9 15:46:40 2008 +0100
when we last time talked about it I already did it in the way as
Chris suggested by modifying the CFProjections. That alone doesn't
work. On top of that I have to set the '_Dynamic_time_fn' variable
(not the time_fn, which is what I was missing before) on the
Gaussian and the Choice variables and that seems to work as far as
I can tell.

Chris, Jan's trouble seems to be that he is indeed using nested objects, as you were concerned about. Sound's like it's working ok at the moment, but we'll want to make it work smoothly in the long run.

The only 'compound' object I made this work for is Selector. Any other class that contains subgenerators (or anything else with Dynamic parameters involved) needs to override Parameterized.set_dynamic_time_fn(), to ensure that set_dynamic_time_fn() is called on its subobjects. Right now, I don't see a way to avoid that (Parameterized.set_dynamic_time_fn would otherwise have to go through all attributes looking for other Parameterized instances, inspect lists for Parameterized instances, and so on...).

Anyway, I'll try to look at this over the weekend.

set_dynamic_time_fn() now accepts an optional argument that specifies an attribute name containing an iterable collection of subobjects on which set_dynamic_time_fn() should also be called. So, for instance, CFProjection could now contain the line: self.set_dynamic_time_fn(None,sublistattr='generators')

Then, any PatternGenerator with a 'generators' list will have the dynamic time fn set on itself and its generators.

That was the best I could think of for now. It avoids the need to override set_dynamic_time_fn on subclasses of Parameterized.

I guess that ideally, (dynamic_)time_fn would be a Parameter.

Writing Gaussian(x=UniformRandom(),time_fn=None) would certainly be convenient. The way I've implemented the dynamic time stuff, though, means it would probably require some thought, and I don't want to do that right now. You are welcome to take that on. Otherwise, please give me an example of code that does not work.

Chris

sf-issues commented 12 years ago

Submitted by jbednar Date: 2012-02-23 10:30 GMT

The documentation has been fixed (patterns.html and noise.html both seem fine), so it's ok for release. Still a bit awkward to use, but now low priority.