[erlang-questions] Beginner questions

Gene Sher <>
Mon Dec 24 18:43:56 CET 2012


Hello All,

To answer Reeves' comments: The code is in a fully functional state, I left
the start/0 function in there though, for later use. To start the programs
without errors it's important to start them with proper parameters. I'll
extend the readme file to include these notes. Although a larger update is
planned in a while, that will add Hall of fame style selection function,
and other modifications improving the system's performance. Same updates
will be added to DXNN V1.

Some other notes applicable to DXNN1 and 2:

There are two ways to go about applying single and multi specie populations
to a problem:

population_monitor:start(Init_State), executed with default constraints (in
which you can define the constraints of the species and population) from
the population_monitor:test(). and with:
population_monitor:start({OpMode,Population_Id,Selection_Algorithm}). which
is executed from:

continue(OpMode,Selection_Algorithm)->
    Population_Id = test,
    population_monitor:start({OpMode,Population_Id,Selection_Algorithm}).
continue(OpMode,Selection_Algorithm,Population_Id)->
    population_monitor:start({OpMode,Population_Id,Selection_Algorithm}).
%The function continue/2 and continue/3 are used to summon an already
existing population with Population_Id, and continue with the experiment
using the Selection_Algorithm.

This allows you to continue with the evolution of an existing population of
NN based agents, based on the id of the existing population, and some
initial parameters you wish to use to continue with the evolutionary run.

Granted, you can use population_monitor:start/1 directly, but you will then
have to specify all the parameters from the console, that's why the
population_monitor:test() was provided (perhaps test was a poor choice for
the function's name). For complete experiments, which are usually composed
of many evolutionary runs, you would run the benchmark module's functions.
These execute the population_monitor:start/1 with appropriate parameters,
and also keep track of the resulting evolutionary statistics, and enter
these stats into the experiment table, which can be processed to produce
GNUPlot files, to graph fitness vs evaluations, diversity vs evaluations
and other things. As with a single evolutionary run and the "continue"
function, an experiment too can be recovered from a crash, and continue
running new evolutionary runs, accumulating the data into the experiment
entry with the specified Id.

Best regards,
-Gene


On Mon, Dec 24, 2012 at 12:16 PM, Gene Sher <>wrote:

> Hello all,
>
> The problem is not with the code, but that population_monitor should not
> be started with start(). Population_monitor should be started with the
> properly set up constraints. To use the default constraints you start with
> population_monitor:test().
> test()->
>     init_population(#state{op_mode = [gt,benchmark]},?INIT_CONSTRAINTS).
> %The test/0 function starts the population monitor through
> init_population/1 with a set of default parameters specified by the macros
> of this module.
>
> prep_PopState(PMP,Specie_Constraints)->
>     S=#state{
>         op_mode=PMP#pmp.op_mode,
>         population_id = PMP#pmp.population_id,
>         survival_percentage=PMP#pmp.survival_percentage,
>         specie_size_limit=PMP#pmp.specie_size_limit,
>         init_specie_size=PMP#pmp.init_specie_size,
>         polis_id=PMP#pmp.polis_id,
>         generation_limit=PMP#pmp.generation_limit,
>         evaluations_limit=PMP#pmp.evaluations_limit,
>         fitness_goal=PMP#pmp.fitness_goal,
>         benchmarker_pid=PMP#pmp.benchmarker_pid
>     },
>     init_population(S,Specie_Constraints).
>
> init_population(Init_State,Specie_Constraints)->
>     random:seed(now()),
>     Population_Id = Init_State#state.population_id,
>     %OpMode = Init_State#state.op_mode,
>     F = fun()->
>         case genotype:read({population,Population_Id}) of
>             undefined ->
>
> create_Population(Population_Id,Init_State#state.init_specie_size,Specie_Constraints);
>             _ ->
>                 delete_population(Population_Id),
>
> create_Population(Population_Id,Init_State#state.init_specie_size,Specie_Constraints)
>         end
>     end,
>     Result = mnesia:transaction(F),
>     case Result of
>         {atomic,_} ->
>             population_monitor:start(Init_State);
>         Error ->
>             io:format("******** ERROR in PopulationMonitor:~p~n",[Error])
>     end.
> %The function init_population/1 creates a new population with the id
> Population_Id, composed of length(Specie_Constraints) species, where each
> specie uses the particular specie constraint specified within the
> Specie_Constraints list. The function first checks if a population with the
> noted Population_Id already exists, if a population does exist, then the
> function first delets it, and then creates a fresh one. Since the ids are
> usually generated with the genotype:create_UniqueId/0, the only way an
> already existing Population_Id is dropped into the function as a parameter
> is if it is intended, usually when runing tests, with the Population_Id =
> test.
>
> You will note that population_monitor;start(Init_state) is the only way to
> properly start the population monitor. I did not wish to remove the
> function population_monitor:start() from the module, for the sake of future
> extensions. But there are no problems with the code.
>
> Best regards,
> -Gene
>
>
> On Mon, Dec 24, 2012 at 4:35 AM, OJ Reeves <> wrote:
>
>> All,
>>
>> The first issue is that the init() function isn't correct for this
>> gen_server.
>>
>> On line 83, the init function starts like this:
>> init(S) ->
>> When it should (apparently) be like this:
>> init([S]) ->
>>
>> This doesn't make the server run though. The next error states:
>>
>> 6> population_monitor:start().
>> ******** Population monitor started with parameters:{state,
>>                                                      [gt],
>>                                                      test,[],[],undefined,
>>
>>  undefined,undefined,[],0,
>>                                                      0,0,0,0,undefined,
>>                                                      undefined,undefined,
>>                                                      undefined,undefined,
>>                                                      undefined,0.5,10,10,
>>
>>  mathema,100,100000,inf,
>>                                                      undefined,false}
>> {error,{{badrecord,population},
>>         [{population_monitor,extract_AgentIds,2,
>>
>>  [{file,"population_monitor.erl"},{line,372}]},
>>          {population_monitor,init,1,
>>                              [{file,"population_monitor.erl"},{line,89}]},
>>          {gen_server,init_it,6,[{file,"gen_server.erl"},{line,304}]},
>>          {proc_lib,init_p_do_apply,3,
>>                    [{file,"proc_lib.erl"},{line,227}]}]}}
>>
>> I get the feeling that there's going to be more stuff requiring fixes as
>> you go. Perhaps the best thing its to get in touch with the author directly
>> and find out about the state of the source base before continuing.
>>
>> Cheers
>> OJ
>>
>>
>> On Mon, Dec 24, 2012 at 5:49 PM, Ivan Uemlianin <> wrote:
>>
>>> Dear Bob
>>>
>>> This line should be part of the function population_monitor:init/1
>>> (that's file population_monitor, function init, which takes one argument).
>>>
>>> The error it complains of is {badrecord,state}, so perhaps the record S
>>> has been badly set up.
>>>
>>> Are you learning erlang through neuroevolution :) ?  Do you have other
>>> reference resources?
>>>
>>> Nadolig Llawen
>>>
>>> Ivan
>>>
>>>
>>> --
>>> festina lente
>>>
>>>
>>> On 24 Dec 2012, at 07:24, Bob Matthews <> wrote:
>>>
>>> Thank you Ivan
>>>
>>> line 82: Population_Id = S#state.population_id,
>>>
>>> Merry Xmas to you too :)
>>>
>>> Bob
>>> Dunedin
>>> New Zealand
>>>
>>> On 24/12/2012 8:14 p.m., Ivan Uemlianin wrote:
>>>
>>> I dont have my computer with me but the error is at line 82 of the file
>>> population_monitor.erl.
>>>
>>>  Best wishes
>>>
>>>  Ivan
>>>
>>> --
>>> festina lente
>>>
>>>
>>> On 24 Dec 2012, at 01:32, Bob Matthews <> wrote:
>>>
>>>   The code that I am looking at is DXNN2 copyrighted to Gene Sher.
>>>
>>> The error message I got which I am having difficulty interpreting is as
>>> follows....................
>>>
>>> 4> population_monitor:start().
>>> {error,{{badrecord,state},
>>>         [{population_monitor,init,1,
>>>
>>> [{file,"population_monitor.erl"},{line,82}]},
>>>          {gen_server,init_it,6,[{file,"gen_server.erl"},{line,304}]},
>>>          {proc_lib,init_p_do_apply,3,
>>>                    [{file,"proc_lib.erl"},{line,227}]}]}}
>>>
>>> I am using the latest versionR15B03
>>>
>>> Thank you for you help
>>>
>>> Bob
>>> Dunedin New Zealand
>>>
>>> On 24/12/2012 11:58 a.m., Matti Oinas wrote:
>>>
>>> Hi,
>>>
>>> My first proposal is to change the editor to something more usable like
>>> emacs or if you prefer something different then notepad++, sublime text or
>>> eclipse + erlIDE. Everyone of these are able to show you the line numbers
>>> and offer syntax highlight features.
>>>
>>> It would help a lot if you tell us which code you are looking at. Server
>>> callbacks probably mean gen_server callbacks so it doesn't matter if you
>>> are using windows or linux.
>>>
>>> Matti
>>>
>>> On 12/24/2012 12:08 AM, Bob Matthews wrote:
>>>
>>> Hi
>>>
>>> I have just started to learn Erlang............
>>> I am using Windows 7 on a PC
>>>
>>> *Question 1*)  when I get an error message, what is the easiest way for
>>> me to find the exact line number?
>>> I use ms Word as an editor.
>>>
>>> *Question 2*) the code I am looking at was run on Unix, on a server.
>>> Part of the code talks about server call-backs etc.
>>> It is unclear how I translate that to a windows PC
>>>
>>> Many thanks
>>>
>>> Bob
>>>
>>>
>>> _______________________________________________
>>> erlang-questions mailing ://erlang.org/mailman/listinfo/erlang-questions
>>>
>>>
>>> No virus found in this message.
>>> Checked by AVG - www.avg.com
>>> Version: 2013.0.2805 / Virus Database: 2634/5951 - Release Date: 12/11/12
>>> Internal Virus Database is out of date.
>>>
>>>
>>>   _______________________________________________
>>> erlang-questions mailing list
>>> 
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>
>>> No virus found in this message.
>>> Checked by AVG - www.avg.com
>>> Version: 2013.0.2805 / Virus Database: 2634/5951 - Release Date: 12/11/12
>>> Internal Virus Database is out of date.
>>>
>>>
>>>
>>> _______________________________________________
>>> erlang-questions mailing list
>>> 
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>
>>>
>>
>>
>> --
>>
>> OJ Reeves
>> +61 431 952 586
>> http://buffered.io/
>>
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121224/3bd6547d/attachment.html>


More information about the erlang-questions mailing list