AI-PSO

 view release on metacpan or  search on metacpan

examples/NeuralNet/pso_ann.pl  view on Meta::CPAN


my $numInputs = 3;
my $numHidden = 2;
my $xferFunc = "Logistic";
my $annConfig = "pso.ann";
my $annInputs = "pso.dat";

my $expectedValue = 3.5;	# this is the value that we want to train the ANN to produce (just like the example in t/PTO.t)


sub test_fitness_function(@) {
    my (@arr) = (@_);
	&writeAnnConfig($annConfig, $numInputs, $numHidden, $xferFunc, @arr);
	my $netValue = &runANN($annConfig, $annInputs);
	print "network value = $netValue\n";

	# the closer the network value gets to our desired value
	# then we want to set the fitness closer to 1.
	#
	# This is a special case of the sigmoid, and looks an awful lot
	# like the hyperbolic tangent ;)

t/PSO.t  view on Meta::CPAN

	themMax        => 1.0,
	exitFitness    => 0.99,
	verbose        => 1,
);

my %test_params2 = %test_params;
$test_params2{psoRandomRange} = 4.0;

# simple test function to sum the position values up to 3.5
my $testValue = 3.5;
sub test_fitness_function(@) {
        my (@arr) = (@_);
        my $sum = 0;
	my $ret = 0;
        foreach my $val (@arr) {
                $sum += $val;
        }
	# sigmoid-like ==> squash the result to [0,1] and get as close to 3.5 as we can
	return 2 / (1 + exp(abs($testValue - $sum)));

	return $ret;

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.157 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )