Algorithm-AM

 view release on metacpan or  search on metacpan

t/06-Batch.t  view on Meta::CPAN

            exclude_given => 0,
            linear => 1,
            probability => .5,
            repeat => 2
        );
        ok(!$batch->exclude_nulls, 'exclude nulls turned off');
        ok(!$batch->exclude_given, 'exclude given turned off');
        ok($batch->linear, 'pointer counting set to linear');
        is($batch->probability, .5, 'probability set to .5');
        is($batch->repeat, 2, 'repeat set to 2');
    };

    subtest 'configuration via accessors' => sub {
        plan tests => 5;
        my $batch = Algorithm::AM::Batch->new(
            training_set => Algorithm::AM::DataSet->new(
                cardinality => 3),
            test_set => Algorithm::AM::DataSet->new(
                cardinality => 3),
        );
        $batch->exclude_nulls(0);
        $batch->exclude_given(0);
        $batch->linear(1);
        $batch->probability(.5);
        $batch->repeat(2);
        ok(!$batch->exclude_nulls, 'exclude nulls turned off');
        ok(!$batch->exclude_given, 'exclude given turned off');
        ok($batch->linear, 'pointer counting set to linear');
        is($batch->probability, .5, 'probability set to .5');
        is($batch->repeat, 2, 'repeat set to 2');
    };
    return;
}

sub test_classify {
    subtest 'run batch classification' => sub {
        plan tests => 8;
        my $train = chapter_3_train();
        my $test = chapter_3_test();
        # just duplicate one item to test classifying multiple items
        $test->add_item($test->get_item(0));
        # add test to train to test exclude_given
        $train->add_item($test->get_item(0));
        my $batch = Algorithm::AM::Batch->new(
            training_set => $train,
            repeat => 2,
            exclude_nulls => 0,
            exclude_given => 0,
            linear => 1,
        );
        my @results = $batch->classify_all($test);
        is(scalar @results, 4, '2 items are analyzed twice') or
            note scalar @results;
        isa_ok($results[0], 'Algorithm::AM::Result');
        isa_ok($results[1], 'Algorithm::AM::Result');
        isa_ok($results[2], 'Algorithm::AM::Result');
        isa_ok($results[3], 'Algorithm::AM::Result');

        # test was in train, so not excluding given would mean that
        # exclude_given was set to false successfully
        # TODO: this seems fragile, as it relies on AM having
        # exclude_given set to true by default.
        ok(!$results[0]->given_excluded,
            'exclude_given passed on to classifier');
        ok(!$results[0]->exclude_nulls,
            'exclude_nulls passed on to classifier');
        is($results[0]->count_method, 'linear',
            'linear passed on to classifier');
    };
    return;
}



( run in 1.264 second using v1.01-cache-2.11-cpan-b16cb0d3907 )