[erlang-questions] Process Dictionary limitations??
Thu Oct 11 18:58:35 CEST 2012
On 10/11/2012 08:48 AM, Charles Hixson wrote:
> On 10/11/2012 02:20 AM, Attila Rajmund Nohl wrote:
>> 2012/10/11 Charles Hixson<>:
>>> I'm choosing a language to implement a ... well, neural network is wrong,
>>> and so is cellular automaton, but it gives the idea. Anyway, I'm going to
>>> need, in each cell, a few stateful items, e.g. activation level.
>>> When I look at what Erlang can do, I see that the Process Dictionary looks
>>> as if it would serve my needs, but then I am immediately warned not to use
>>> it, that it will cause bugs. These stateful terms will not be exported from
>>> the cell within which they are resident. Is this still likely to cause
>>> problems? Is there some better approach to maintaining state? (I can't
>>> just generate a new process, because other cells will need to know how to
>>> access this one, or to test that it has been rolled out.)
>> I don't really understand why you can't generate a new process for
>> each cell - just send a message to the neighbouring cells that there's
>> a new cell. I think each cell needs to know its neighbours anyway.
> Because lots of other processes would have links to the cell that were the process id. (There isn't really any other way to link to an active process.) It doesn't know who has these links. "Neighbors" isn't the right way to think about it, as they aren't neighbors in any meaningful sense of the term. (The links are one way.)
> Perhaps I should have called it a weighted directed graph, but that isn't quite the right model either. But with that analogy the weights need to be adjustable. Or I could have called it a neural net, but that also isn't quite the right model, at least as I understand it.
> Each cell needs to know the cells that it links to, and the cell that most recently linked to it. And it's activation level. And the weight of each link to a "following" cell. The activation levels and weights need to be able to change, but should not be visible outside the cell (though the cell should be able to receive messages that causes it to change these values).
> It's also possible that eventually I might need some "regional values", that would do things like adjust the sensitivity of all cells in a region to being activated, but I can see a way to do that with message passing (though it does add significantly to the overhead). OTOH, maybe I'll never need these "emotional variations". (So far I don't have a well-defined idea of what "region" would mean.)
You mentioned the variable number suffix as an emacs problem, but there is a parse transform that can help hide the variable number suffixes for you, here: https://github.com/spawngrid/seqbind . However, it is probably best to avoid parse transforms while learning Erlang, since the source code may not match examples.
The weighted directed graph or neural net type of application is probably best done with an Erlang process per cell with messages inbetween. That approach matches an actor model, and Erlang. A tutorial that should be helpful is here: http://www.trapexit.org/Erlang_and_Neural_Networks
More information about the erlang-questions