AI-FuzzyEngine

 view release on metacpan or  search on metacpan

lib/AI/FuzzyEngine.pm  view on Meta::CPAN

474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
    $var_b->fuzzify( pdl([1, 2], [3, 4]) );
 
Defuzzification returns a piddle if any of the membership
degrees of the function's sets is a piddle:
 
    my $val = $var_a->defuzzify(); # $var_a returns a 1dim piddle with two elements
 
So do the fuzzy operations as provided by the fuzzy engine C<$fe> itself.
 
Any operation on more then one piddle expands those to common
dimensions, if possible, or throws a PDL error otherwise.
 
The way expansion is done is best explained by code
(see C<< AI::FuzzyEngine->_cat_array_of_piddles(@pdls) >>).
Assuming all piddles are in C<@pdls>,
calculation goes as follows:
 
    # Get the common dimensions
    my $zeros = PDL->pdl(0);
    # Note: $zeros += $_->zeros() for @pdls does not work here
    $zeros = $zeros + $_->zeros() for @pdls;

t/01-fuzzyEngine.t  view on Meta::CPAN

456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
    my $degree = $v->low;
    is( $degree, 0, 'initial value for degree of low' );
 
    $degree = $v->low(0.2, 0.1);
    is( $degree, 0.1, 'and / or for degree of low work' );
 
    $v->reset;
    is( $v->low, 0, 'reset works' );
 
    # Throw errors!
    throws_ok { $v->fuzzify(0)
              } qr/internal/, 'Checks illegal fuzzify call';
    throws_ok { $v->defuzzify
              } qr/internal/, 'Checks illegal defuzzify call';
    throws_ok { $v->change_set( low => [[]=>[]] )
              } qr/internal/i, 'Blocks change_set';
};
 
$fe = $class->new();



( run in 0.683 second using v1.01-cache-2.11-cpan-87723dcf8b7 )