Front page | perl.ai |
Postings from December 2006
Re: AI::Genetic
Thread Previous
|
Thread Next
From:
Benjamin Tucker
Date:
December 8, 2006 07:13
Subject:
Re: AI::Genetic
Message ID:
12372ED9-1476-4365-8107-F78C46A6AEC8@greenriver.org
I don't actually have any experience with AI::Genetic, but
Storable.pm is probably your best bet. Take a look at how
AI::Categorizer interfaces with it:
http://search.cpan.org/src/KWILLIAMS/AI-Categorizer-0.07/lib/AI/
Categorizer/Storable.pm
If you throw something like this into the bottom of one of your perl
files, you should be able just to call
$gen->store_state('filename') and then $gen->restore_state
('filename') (where $gen is an instance of AI::Genetic)
package AI::Genetic;
use strict;
use Storable;
use File::Spec ();
use File::Path ();
sub save_state {
my ($self, $path) = @_;
if (-e $path) {
File::Path::rmtree($path) or die "Couldn't overwrite $path: $!";
}
mkdir($path, 0777) or die "Can't create $path: $!";
Storable::nstore($self, File::Spec->catfile($path, 'self'));
}
sub restore_state {
my ($package, $path) = @_;
return Storable::retrieve(File::Spec->catfile($path, 'self'));
}
1;
Ben
On Dec 8, 2006, at 9:37 AM, Brad Larsen wrote:
> One (possibly stupid) suggestion is to look at Data::Dumper. It
> should work, but may be very slow if the object in question is
> large. Let us know if you find anything better.
>
> Cheers,
> Brad Larsen
>
> greggallen@gmail.com wrote:
>> I know this is going to turn out to be a stupid question, but
>> could someone tell me the easiest way to store and retrieve the
>> state of the entire AI::Genetic colony, and parameters, to a disk
>> file so it can be read in and out at will?
>> I'm doing some constrained optimization experiments that can take
>> several days, even a week, to run in the background, but I have a
>> computer (Mac OS X 10.4.8) that is shared, and I need to install
>> software and restart it almost daily.
>> I would like to save the entire thing about every hour, but I can
>> handle the timing part myself.
>> Sincerely,
>> Gregg Allen
>> Cerebra, Inc.
Thread Previous
|
Thread Next