Algorithm-AM

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

3.13      2024-10-09 08:59:48-05:00 America/Chicago
    Adjust for COW-shared constant-folded PV buffers (GH #63, @richardleach)
3.12      2021-04-03 11:27:25+02:00 Europe/Berlin
    Fixed intermittent crash on Windows
3.11      2017-11-15 10:39:12+01:00 Europe/Berlin
    Added install information
    Turned on warning printing for analogize
3.10      2016-06-05 21:03:55+09:00 Asia/Tokyo
    Fixed bad typos in citation names
    Improved analogize documentation (#50)
    Changed percentage printing format (#56)
3.09      2015-08-28 20:29:15+09:00 Asia/Tokyo
    removed random_outcome (addition was misguided)
    updated documentation
    added data file comment functionality
3.08      2015-06-07 20:39:47+09:00 Asia/Tokyo
    fixed regression in XS (GH #42)
    added include_nulls, include_given, and linear flags to analogize.pl
3.07      2015-06-03 21:01:25+09:00 Asia/Tokyo
    Add detailed gang printing option to analogize
    Fix incorrect gang handling

bin/analogize.pl  view on Meta::CPAN

=over

=item C<config_info>

Describes the configuration used and some simple information about the data,
i.e. cardinality, etc.

=item C<statistical_summary>

A statistical summary of the classification results, including
all predicted outcomes with their scores and percentages and
the total score for all outcomes. Whether the predicted class is
correct, incorrect, or a tie is also included, if the test item
had a known class.

=item C<analogical_set_summary>

The analogical set, showing all items that contributed to the predicted
outcome, along with the amount contributed by each item (score and
percentage overall).

=item C<gang_summary>

A summary of the gang effects on the outcome prediction.

=item C<gang_detailed>

Same as C<gang_summary>, but also includes lists of exemplars for each
gang.

lib/Algorithm/AM/Result.pm  view on Meta::CPAN

        my $normalized = {};
        for my $class (keys %$scores){
            $normalized->{$class} = $scores->{$class} / $total_points
        }
        return $normalized;
    },
};
use Carp 'croak';
use Algorithm::AM::BigInt 'bigcmp';

# For printing percentages in reports
my $percentage_format = '%.3f';

#pod =head1 REPORT METHODS
#pod
#pod The methods below return human eye-friendly reports about the
#pod classification. The return value is a reference, so it must be
#pod dereferenced for printing like so:
#pod
#pod  print ${ $result->statistical_summary };
#pod
#pod =head2 C<config_info>

lib/Algorithm/AM/Result.pm  view on Meta::CPAN

    $self->{raw_gang} = $raw_gang;
    $self->{active_feats} = $active_feats;
    $self->{context_size} = $context_size;
    return;
}

#pod =head2 C<statistical_summary>
#pod
#pod Returns a scalar reference (string) containing a statistical summary
#pod of the classification results. The summary includes all possible
#pod predicted classes with their scores and percentage scores and the
#pod total score for all classes. Whether the predicted class
#pod is correct/incorrect/a tie of some sort is also included, if the
#pod test item had a known class.
#pod
#pod =cut
sub statistical_summary {
    my ($self) = @_;
    my %scores = %{$self->scores};
    my $total_points = $self->total_points;

    # Make a table with information about predictions for different
    # classes. Each row contains a class name, the score,
    # and the percentage predicted.
    my @rows;
    for my $class (sort keys %scores){
        push @rows, [ $class, $scores{$class},
            sprintf($percentage_format,
                100 * $scores{$class} / $total_points) ];
    }
    # add a Total row
    push @rows, [ 'Total', $total_points ];

    my @table = _make_table(['Class', 'Score', 'Percentage'],
        \@rows);
    # copy the rule from the first row into the second to last row
    # to separate the Total row
    splice(@table, $#table - 1, 0, $table[0]);

lib/Algorithm/AM/Result.pm  view on Meta::CPAN

    # make a safe copy
    my %set = %{$self->{_analogical_set}};
    return \%set;
}

#pod =head2 C<analogical_set_summary>
#pod
#pod Returns a scalar reference (string) containing the analogical set,
#pod meaning all items that contributed to the predicted class, along
#pod with the amount contributed by each item (score and
#pod percentage overall). Items are ordered by appearance in the data
#pod set.
#pod
#pod =cut
sub analogical_set_summary {
    my ($self) = @_;
    my $set = $self->analogical_set;
    my $total_points = $self->total_points;

    # Make a table for the analogical set. Each row contains an
    # item with its class, comment, score, and the percentage
    # of total score contributed.
    my @rows;
    foreach my $id (sort keys %$set){
        my $entry = $set->{$id};
        my $score = $entry->{score};
        push @rows, [
            $entry->{item}->class,
            $entry->{item}->comment,
            $score,
            sprintf($percentage_format, 100 * $score / $total_points)
        ];
    }
    my @table = _make_table(
        ['Class', 'Item', 'Score', 'Percentage'], \@rows);
    my $info = "Analogical Set\nTotal Frequency = $total_points\n";
    $info .= join '', @table;
    return \$info;
}

# calculate and store analogical effects in $self->{_analogical_set}

lib/Algorithm/AM/Result.pm  view on Meta::CPAN

    my @gang_rows;
    my $current_row = -1;
    # add information for each gang; sort by order of highest to
    # lowest effect
    foreach my $gang (@$gangs){
        $current_row++;
        $gang_rows[$current_row]++;
        my $features = $gang->{features};
        # add the gang supracontext, effect and score
        push @rows, [
            sprintf($percentage_format, 100 * $gang->{effect}),
            $gang->{score},
            undef,
            undef,
            # print undefined feature slots as asterisks
            map {length($_) ? $_ : '*'} @$features
        ];
        # add each class in the gang, along with the total number
        # and effect of the gang items supporting it
        for my $class (sort keys %{ $gang->{class} }){
            $gang_rows[$current_row]++;
            push @rows, [
                sprintf($percentage_format,
                    100 * $gang->{class}->{$class}->{effect}),
                $gang->{class}->{$class}->{score},
                scalar @{ $gang->{data}->{$class} },
                $class,
                undef
            ];
            if($print_list){
                # add the list of items in the given context
                for my $item (@{ $gang->{data}->{$class} }){
                    $gang_rows[$current_row]++;

lib/Algorithm/AM/Result.pm  view on Meta::CPAN

    given_excluded
    cardinality
    test_in_train
    test_item
    count_method

=head2 C<statistical_summary>

Returns a scalar reference (string) containing a statistical summary
of the classification results. The summary includes all possible
predicted classes with their scores and percentage scores and the
total score for all classes. Whether the predicted class
is correct/incorrect/a tie of some sort is also included, if the
test item had a known class.

=head2 C<analogical_set_summary>

Returns a scalar reference (string) containing the analogical set,
meaning all items that contributed to the predicted class, along
with the amount contributed by each item (score and
percentage overall). Items are ordered by appearance in the data
set.

=head2 C<gang_summary>

Returns a scalar reference (string) containing the gang effects on the
final class prediction.

A single boolean parameter can be provided to turn on list printing,
meaning gang items items are printed. This is false (off) by default.



( run in 0.332 second using v1.01-cache-2.11-cpan-709fd43a63f )