view release on metacpan or search on metacpan
docs/AI-Perceptron-Simple-1.04.html view on Meta::CPAN
# processing data
use AI::Perceptron::Simple ":process_data";
shuffle_stimuli ( ... )
shuffle_data ( ORIGINAL_STIMULI, $new_file_1, $new_file_2, ... );
shuffle_data ( $original_stimuli => $new_file_1, $new_file_2, ... );</code></pre>
<h1 id="EXPORT">EXPORT</h1>
<p>None by default.</p>
<p>All the subroutines from <code>DATA PROCESSING RELATED SUBROUTINES</code>, <code>NERVE DATA RELATED SUBROUTINES</code> and <code>NERVE PORTABILITY RELATED SUBROUTINES</code> sections are importable through tags or manually specifying them.</p>
<p>The tags available include the following:</p>
<dl>
<dt id="process_data---subroutines-under-DATA-PROCESSING-RELATED-SUBROUTINES-section"><code>:process_data</code> - subroutines under <code>DATA PROCESSING RELATED SUBROUTINES</code> section.</dt>
<dd>
docs/AI-Perceptron-Simple-1.04.html view on Meta::CPAN
</dd>
<dt id="attribs-array_ref">attribs => $array_ref</dt>
<dd>
<p>An array reference containing all the attributes / dendrites names. Yes, give them some names :)</p>
</dd>
<dt id="learning_rate-decimal">learning_rate => $decimal</dt>
<dd>
<p>Optional. The default is <code>0.05</code>.</p>
<p>The learning rate of the perceptron for the fine-tuning process.</p>
<p>This value is usually between 0 and 1. However, it all depends on your combination of numbers for the other options.</p>
</dd>
<dt id="threshold-decimal">threshold => $decimal</dt>
<dd>
<p>Optional. The default is <code>0.5</code></p>
<p>This is the passing rate to determine the neuron output (<code>0</code> or <code>1</code>).</p>
<p>Generally speaking, this value is usually between <code>0</code> and <code>1</code>. However, it all depend on your combination of numbers for the other options.</p>
</dd>
</dl>
<h2 id="get_attributes">get_attributes</h2>
docs/AI-Perceptron-Simple-1.04.html view on Meta::CPAN
<h2 id="train-stimuli_train_csv-expected_output_header-save_nerve_to_file">train ( $stimuli_train_csv, $expected_output_header, $save_nerve_to_file )</h2>
<h2 id="train-stimuli_train_csv-expected_output_header-save_nerve_to_file-display_stats-identifier">train ( $stimuli_train_csv, $expected_output_header, $save_nerve_to_file, $display_stats, $identifier )</h2>
<p>Trains the perceptron.</p>
<p><code>$stimuli_train_csv</code> is the set of data / input (in CSV format) to train the perceptron while <code>$save_nerve_to_file</code> is the filename that will be generate each time the perceptron finishes the training process. This data file ...
<p><code>$expected_output_header</code> is the header name of the columns in the csv file with the actual category or the exepcted values. This is used to determine to tune the nerve up or down. This value should only be 0 or 1 for the sake of simpli...
<p><code>$display_stats</code> is <b>optional</b> and the default is 0. It will display more output about the tuning process. It will show the followings:</p>
<dl>
<dt id="tuning-status">tuning status</dt>
<dd>
<p>Indicates the nerve was tuned up, down or no tuning needed</p>
</dd>
<dt id="old-sum">old sum</dt>
docs/AI-Perceptron-Simple-1.04.html view on Meta::CPAN
<p>This is the index of the column that contains the predicted output values. <code>$index</code> starts from <code>0</code>.</p>
<p>This column will be filled with binary numbers and the full new data will be saved to the file specified in the <code>results_write_to</code> key.</p>
</dd>
<dt id="results_write_to-new_csv_file">results_write_to => $new_csv_file</dt>
<dd>
<p>Optional.</p>
<p>The default behaviour will write the predicted output back into <code>stimuli_validate</code> ie the original data. The sequence of the data will be maintained.</p>
</dd>
</dl>
<p><i>*This method will call <code>_real_validate_or_test</code> to do the actual work.</i></p>
<h1 id="TESTING-RELATED-SUBROUTINES-METHODS">TESTING RELATED SUBROUTINES/METHODS</h1>
<p>All the testing methods here have the same parameters as the actual <code>test</code> method and they all do the same stuff. They are also used in the same way.</p>
docs/AI-Perceptron-Simple-1.04.html view on Meta::CPAN
<h2 id="calculate_balanced_accuracy-c_matrix_ref">&_calculate_balanced_accuracy( $c_matrix_ref )</h2>
<p>Calculates and adds the data for the <code>balanced_accuracy</code> key in the confusion matrix hash.</p>
<h2 id="display_exam_results">display_exam_results ( ... )</h2>
<p>The parameters are the same as <code>display_confusion_matrix</code>. See the next method.</p>
<h2 id="display_confusion_matrix-confusion_matrix-labels">display_confusion_matrix ( \%confusion_matrix, \%labels )</h2>
<p>Display the confusion matrix. If <code>%confusion_matrix</code> has <code>more_stats</code> elements, it will display them if they exists. The default elements ie <code>accuracy</code> and <code>sensitivity</code> must be present, while the rest c...
<p><code>%confusion_matrix</code> is the same confusion matrix returned by the <code>get_confusion_matrix</code> method.</p>
<p>For <code>%labels</code>, since <code>0</code>'s and <code>1</code>'s won't make much sense as the output labels in most cases, therefore, the following keys must be specified:</p>
<dl>
<dt id="zero_as-category_zero_name">zero_as => $category_zero_name</dt>
<dd>
</dd>
<dt id="one_as-category_one_name">one_as => $category_one_name</dt>
<dd>
</dd>
</dl>
<p>Please take note that non-ascii characters ie. non-English alphabets <b>might</b> cause the output to go off :)</p>
<p>For the <code>%labels</code>, there is no need to enter "actual X", "predicted X" etc. It will be prefixed with <code>A: </code> for actual and <code>P: </code> for the predicted values by default.</p>
<h2 id="build_matrix-c_matrix-labels">&_build_matrix ( $c_matrix, $labels )</h2>
<p>Builds the matrix using <code>Text::Matrix</code> module.</p>
<p><code>$c_matrix</code> and <code>$labels</code> are the same as the ones passed to <code>display_exam_results</code> and <code></code>display_confusion_matrix.</p>
<p>Returns a list <code>( $matrix, $c_matrix )</code> which can directly be passed to <code>_print_extended_matrix</code>.</p>
<h2 id="print_extended_matrix-matrix-c_matrix">&_print_extended_matrix ( $matrix, $c_matrix )</h2>
lib/AI/Perceptron/Simple.pm view on Meta::CPAN
A Newbie Friendly Module to Create, Train, Validate and Test Perceptrons / Neurons
=head1 VERSION
Version 1.04
=cut
our $VERSION = '1.04';
# default values
use constant LEARNING_RATE => 0.05;
use constant THRESHOLD => 0.5;
use constant TUNE_UP => 1;
use constant TUNE_DOWN => 0;
=head1 SYNOPSIS
#!/usr/bin/perl
use AI::Perceptron::Simple qw(...);
lib/AI/Perceptron/Simple.pm view on Meta::CPAN
# processing data
use AI::Perceptron::Simple ":process_data";
shuffle_stimuli ( ... )
shuffle_data ( ORIGINAL_STIMULI, $new_file_1, $new_file_2, ... );
shuffle_data ( $original_stimuli => $new_file_1, $new_file_2, ... );
=head1 EXPORT
None by default.
All the subroutines from C<DATA PROCESSING RELATED SUBROUTINES>, C<NERVE DATA RELATED SUBROUTINES> and C<NERVE PORTABILITY RELATED SUBROUTINES> sections are importable through tags or manually specifying them.
The tags available include the following:
=over 4
=item C<:process_data> - subroutines under C<DATA PROCESSING RELATED SUBROUTINES> section.
=item C<:local_data> - subroutines under C<NERVE DATA RELATED SUBROUTINES> section.
lib/AI/Perceptron/Simple.pm view on Meta::CPAN
The value or thickness of ALL the dendrites when a new perceptron is created.
Generally speaking, this value is usually between 0 and 1. However, it all depend on your combination of numbers for the other options.
=item attribs => $array_ref
An array reference containing all the attributes / dendrites names. Yes, give them some names :)
=item learning_rate => $decimal
Optional. The default is C<0.05>.
The learning rate of the perceptron for the fine-tuning process.
This value is usually between 0 and 1. However, it all depends on your combination of numbers for the other options.
=item threshold => $decimal
Optional. The default is C<0.5>
This is the passing rate to determine the neuron output (C<0> or C<1>).
Generally speaking, this value is usually between C<0> and C<1>. However, it all depend on your combination of numbers for the other options.
=back
=cut
sub new {
lib/AI/Perceptron/Simple.pm view on Meta::CPAN
=head2 train ( $stimuli_train_csv, $expected_output_header, $save_nerve_to_file, $display_stats, $identifier )
Trains the perceptron.
C<$stimuli_train_csv> is the set of data / input (in CSV format) to train the perceptron while C<$save_nerve_to_file> is
the filename that will be generate each time the perceptron finishes the training process. This data file is the data of the C<AI::Perceptron::Simple>
object and it is used in the C<validate> method.
C<$expected_output_header> is the header name of the columns in the csv file with the actual category or the exepcted values. This is used to determine to tune the nerve up or down. This value should only be 0 or 1 for the sake of simplicity.
C<$display_stats> is B<optional> and the default is 0. It will display more output about the tuning process. It will show the followings:
=over 4
=item tuning status
Indicates the nerve was tuned up, down or no tuning needed
=item old sum
The original sum of all C<weightage * input> or C<dendrite_size * binary_input>
lib/AI/Perceptron/Simple.pm view on Meta::CPAN
=item predicted_column_index => $column_number
This is the index of the column that contains the predicted output values. C<$index> starts from C<0>.
This column will be filled with binary numbers and the full new data will be saved to the file specified in the C<results_write_to> key.
=item results_write_to => $new_csv_file
Optional.
The default behaviour will write the predicted output back into C<stimuli_validate> ie the original data. The sequence of the data will be maintained.
=back
I<*This method will call C<_real_validate_or_test> to do the actual work.>
=cut
sub take_mock_exam {
my ( $self, $data_hash_ref ) = @_;
$self->_real_validate_or_test( $data_hash_ref );
lib/AI/Perceptron/Simple.pm view on Meta::CPAN
$c_matrix->{ balanced_accuracy } = $numerator / $denominator; # numerator already in %
}
=head2 display_exam_results ( ... )
The parameters are the same as C<display_confusion_matrix>. See the next method.
=head2 display_confusion_matrix ( \%confusion_matrix, \%labels )
Display the confusion matrix. If C<%confusion_matrix> has C<more_stats> elements, it will display them if they exists. The default elements ie C<accuracy> and C<sensitivity> must be present, while the rest can be absent.
C<%confusion_matrix> is the same confusion matrix returned by the C<get_confusion_matrix> method.
For C<%labels>, since C<0>'s and C<1>'s won't make much sense as the output labels in most cases, therefore, the following keys must be specified:
=over 4
=item zero_as => $category_zero_name
=item one_as => $category_one_name
=back
Please take note that non-ascii characters ie. non-English alphabets B<might> cause the output to go off :)
For the C<%labels>, there is no need to enter "actual X", "predicted X" etc. It will be prefixed with C<A: > for actual and C<P: > for the predicted values by default.
=cut
sub display_exam_results {
my ( $self, $c_matrix, $labels ) = @_;
$self->display_confusion_matrix( $c_matrix, $labels );
}
t/02-creation.t view on Meta::CPAN
# print AI::Perceptron::Simple::LEARNING_RATE;
# all important parameter test
my $perceptron = AI::Perceptron::Simple->new( {
initial_value => $initial_value,
attribs => \@attributes
} );
is( ref $perceptron, $module_name, "Correct object" );
# default learning_rate() threshold()
is( $perceptron->learning_rate, 0.05, "Correct default learning rate -> ".$perceptron->learning_rate );
is( $perceptron->threshold, 0.5, "Correct default passing rate -> ".$perceptron->threshold );
# new learning_rate() threshold()
# direct invocation is seldom used, but might be useful in some ways if there's a loop
$perceptron->learning_rate(0.123);
is( $perceptron->learning_rate, 0.123, "Correct new learning_rate -> ".$perceptron->learning_rate );
$perceptron->threshold(0.4);
is( $perceptron->threshold, 0.4, "Correct new passing rate -> ".$perceptron->threshold );
$perceptron = AI::Perceptron::Simple->new( {