AI-Perceptron-Simple
view release on metacpan or search on metacpan
docs/AI-Perceptron-Simple-1.04.html view on Meta::CPAN
<li><a href="#shuffle_data-original_data-shuffled_1-shuffled_2">shuffle_data ( $original_data => $shuffled_1, $shuffled_2, ... )</a></li>
<li><a href="#shuffle_data-ORIGINAL_DATA-shuffled_1-shuffled_2">shuffle_data ( ORIGINAL_DATA, $shuffled_1, $shuffled_2, ... )</a></li>
</ul>
</li>
<li><a href="#CREATION-RELATED-SUBROUTINES-METHODS">CREATION RELATED SUBROUTINES/METHODS</a>
<ul>
<li><a href="#new-options">new ( \%options )</a></li>
<li><a href="#get_attributes">get_attributes</a></li>
<li><a href="#learning_rate-value">learning_rate ( $value )</a></li>
<li><a href="#learning_rate">learning_rate</a></li>
<li><a href="#threshold-value">threshold ( $value )</a></li>
<li><a href="#threshold">threshold</a></li>
</ul>
</li>
<li><a href="#TRAINING-RELATED-SUBROUTINES-METHODS">TRAINING RELATED SUBROUTINES/METHODS</a>
<ul>
<li><a href="#tame">tame ( ... )</a></li>
<li><a href="#exercise">exercise ( ... )</a></li>
<li><a href="#train-stimuli_train_csv-expected_output_header-save_nerve_to_file">train ( $stimuli_train_csv, $expected_output_header, $save_nerve_to_file )</a></li>
<li><a href="#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 )</a></li>
<li><a href="#calculate_output-self-stimuli_hash">&_calculate_output( $self, \%stimuli_hash )</a></li>
<li><a href="#tune-self-stimuli_hash-tune_up_or_down">&_tune( $self, \%stimuli_hash, $tune_up_or_down )</a></li>
</ul>
</li>
<li><a href="#VALIDATION-RELATED-METHODS">VALIDATION RELATED METHODS</a>
<ul>
<li><a href="#take_mock_exam">take_mock_exam (...)</a></li>
<li><a href="#take_lab_test">take_lab_test (...)</a></li>
<li><a href="#validate-options">validate ( \%options )</a></li>
</ul>
</li>
<li><a href="#TESTING-RELATED-SUBROUTINES-METHODS">TESTING RELATED SUBROUTINES/METHODS</a>
<ul>
<li><a href="#take_real_exam">take_real_exam (...)</a></li>
<li><a href="#work_in_real_world">work_in_real_world (...)</a></li>
<li><a href="#test-options">test ( \%options )</a></li>
<li><a href="#real_validate_or_test-data_hash_ref">_real_validate_or_test ( $data_hash_ref )</a></li>
<li><a href="#fill_predicted_values-self-stimuli_validate-predicted_index-aoa">&_fill_predicted_values ( $self, $stimuli_validate, $predicted_index, $aoa )</a></li>
</ul>
</li>
<li><a href="#RESULTS-RELATED-SUBROUTINES-METHODS">RESULTS RELATED SUBROUTINES/METHODS</a>
<ul>
<li><a href="#get_exam_results">get_exam_results ( ... )</a></li>
<li><a href="#get_confusion_matrix-options">get_confusion_matrix ( \%options )</a></li>
<li><a href="#collect_stats-options">&_collect_stats ( \%options )</a></li>
<li><a href="#calculate_total_entries-c_matrix_ref">&_calculate_total_entries ( $c_matrix_ref )</a></li>
<li><a href="#calculate_accuracy-c_matrix_ref">&_calculate_accuracy ( $c_matrix_ref )</a></li>
<li><a href="#calculate_sensitivity-c_matrix_ref">&_calculate_sensitivity ( $c_matrix_ref )</a></li>
<li><a href="#calculate_precision-c_matrix_ref">&_calculate_precision ( $c_matrix_ref )</a></li>
<li><a href="#calculate_specificity-c_matrix_ref">&_calculate_specificity ( $c_matrix_ref )</a></li>
<li><a href="#calculate_f1_score-c_matrix_ref">&_calculate_f1_score ( $c_matrix_ref )</a></li>
<li><a href="#calculate_negative_predicted_value-c_matrix_ref">&_calculate_negative_predicted_value( $c_matrix_ref )</a></li>
<li><a href="#calculate_false_negative_rate-c_matrix_ref">&_calculate_false_negative_rate( $c_matrix_ref )</a></li>
<li><a href="#calculate_false_positive_rate-c_matrix_ref">&_calculate_false_positive_rate( $c_matrix_ref )</a></li>
<li><a href="#calculate_false_discovery_rate-c_matrix_ref">&_calculate_false_discovery_rate( $c_matrix_ref )</a></li>
<li><a href="#calculate_false_omission_rate-c_matrix_ref">&_calculate_false_omission_rate( $c_matrix_ref )</a></li>
<li><a href="#calculate_balanced_accuracy-c_matrix_ref">&_calculate_balanced_accuracy( $c_matrix_ref )</a></li>
<li><a href="#display_exam_results">display_exam_results ( ... )</a></li>
<li><a href="#display_confusion_matrix-confusion_matrix-labels">display_confusion_matrix ( \%confusion_matrix, \%labels )</a></li>
<li><a href="#build_matrix-c_matrix-labels">&_build_matrix ( $c_matrix, $labels )</a></li>
<li><a href="#print_extended_matrix-matrix-c_matrix">&_print_extended_matrix ( $matrix, $c_matrix )</a></li>
</ul>
</li>
<li><a href="#NERVE-DATA-RELATED-SUBROUTINES">NERVE DATA RELATED SUBROUTINES</a>
<ul>
<li><a href="#preserve">preserve ( ... )</a></li>
<li><a href="#save_perceptron-nerve-nerve_file">save_perceptron ( $nerve, $nerve_file )</a></li>
<li><a href="#revive">revive (...)</a></li>
<li><a href="#load_perceptron-nerve_file_to_load">load_perceptron ( $nerve_file_to_load )</a></li>
</ul>
</li>
<li><a href="#NERVE-PORTABILITY-RELATED-SUBROUTINES">NERVE PORTABILITY RELATED SUBROUTINES</a>
<ul>
<li><a href="#preserve_as_yaml">preserve_as_yaml ( ... )</a></li>
<li><a href="#save_perceptron_yaml-nerve-yaml_nerve_file">save_perceptron_yaml ( $nerve, $yaml_nerve_file )</a></li>
<li><a href="#revive_from_yaml">revive_from_yaml (...)</a></li>
<li><a href="#load_perceptron_yaml-yaml_nerve_file">load_perceptron_yaml ( $yaml_nerve_file )</a></li>
</ul>
</li>
<li><a href="#TO-DO">TO DO</a></li>
<li><a href="#KNOWN-ISSUES">KNOWN ISSUES</a>
<ul>
<li><a href="#Portability-of-Nerve-Data">Portability of Nerve Data</a></li>
</ul>
</li>
<li><a href="#AUTHOR">AUTHOR</a></li>
<li><a href="#BUGS">BUGS</a></li>
<li><a href="#SUPPORT">SUPPORT</a></li>
<li><a href="#ACKNOWLEDGEMENTS">ACKNOWLEDGEMENTS</a></li>
<li><a href="#SEE-ALSO">SEE ALSO</a></li>
<li><a href="#LICENSE-AND-COPYRIGHT">LICENSE AND COPYRIGHT</a></li>
</ul>
<h1 id="NAME">NAME</h1>
<p>AI::Perceptron::Simple</p>
<p>A Newbie Friendly Module to Create, Train, Validate and Test Perceptrons / Neurons</p>
<h1 id="VERSION">VERSION</h1>
<p>Version 1.04</p>
<h1 id="SYNOPSIS">SYNOPSIS</h1>
<pre><code> #!/usr/bin/perl
use AI::Perceptron::Simple qw(...);
# create a new nerve / neuron / perceptron
$nerve = AI::Perceptron::Simple->new( {
initial_value => $size_of_each_dendrite,
learning_rate => 0.3, # optional
threshold => 0.85, # optional
attribs => \@dendrites,
} );
# train
$nerve->tame( ... );
$nerve->exercise( ... );
$nerve->train( $training_data_csv, $expected_column_name, $save_nerve_to );
# or
$nerve->train(
$training_data_csv, $expected_column_name, $save_nerve_to,
$show_progress, $identifier); # these two parameters must go together
# validate
$nerve->take_lab_test( ... );
$nerve->take_mock_exam( ... );
# fill results to original file
$nerve->validate( {
stimuli_validate => $validation_data_csv,
predicted_column_index => 4,
} );
# or
# fill results to a new file
$nerve->validate( {
stimuli_validate => $validation_data_csv,
predicted_column_index => 4,
results_write_to => $new_csv
} );
# test - see "validate" method, same usage
$nerve->take_real_exam( ... );
$nerve->work_in_real_world( ... );
$nerve->test( ... );
# confusion matrix
my %c_matrix = $nerve->get_confusion_matrix( {
full_data_file => $file_csv,
actual_output_header => $header_name,
predicted_output_header => $predicted_header_name,
more_stats => 1, # optional
} );
# accessing the confusion matrix
my @keys = qw( true_positive true_negative false_positive false_negative
total_entries accuracy sensitivity );
for ( @keys ) {
print $_, " => ", $c_matrix{ $_ }, "\n";
}
# output to console
$nerve->display_confusion_matrix( \%c_matrix, {
zero_as => "bad apples", # cat milk green etc.
one_as => "good apples", # dog honey pink etc.
} );
# saving and loading data of perceptron locally
# NOTE: nerve data is automatically saved after each trainning process
use AI::Perceptron::Simple ":local_data";
my $nerve_file = "apples.nerve";
preserve( ... );
save_perceptron( $nerve, $nerve_file );
# load data of percpetron for use in actual program
my $apple_nerve = revive( ... );
my $apple_nerve = load_perceptron( $nerve_file );
# for portability of nerve data
use AI::Perceptron::Simple ":portable_data";
my $yaml_nerve_file = "pearls.yaml";
preserve_as_yaml ( ... );
save_perceptron_yaml ( $nerve, $yaml_nerve_file );
# load nerve data on the other computer
my $pearl_nerve = revive_from_yaml ( ... );
my $pearl_nerve = load_perceptron_yaml ( $yaml_nerve_file );
# 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>
</dd>
<dt id="local_data---subroutines-under-NERVE-DATA-RELATED-SUBROUTINES-section"><code>:local_data</code> - subroutines under <code>NERVE DATA RELATED SUBROUTINES</code> section.</dt>
<dd>
</dd>
<dt id="portable_data---subroutines-under-NERVE-PORTABILITY-RELATED-SUBROUTINES-section"><code>:portable_data</code> - subroutines under <code>NERVE PORTABILITY RELATED SUBROUTINES</code> section.</dt>
<dd>
docs/AI-Perceptron-Simple-1.04.html view on Meta::CPAN
<p>Calculates and adds the data for the <code>F1_Score</code> key in the confusion matrix hash.</p>
<h2 id="calculate_negative_predicted_value-c_matrix_ref">&_calculate_negative_predicted_value( $c_matrix_ref )</h2>
<p>Calculates and adds the data for the <code>negative_predicted_value</code> key in the confusion matrix hash.</p>
<h2 id="calculate_false_negative_rate-c_matrix_ref">&_calculate_false_negative_rate( $c_matrix_ref )</h2>
<p>Calculates and adds the data for the <code>false_negative_rate</code> key in the confusion matrix hash.</p>
<h2 id="calculate_false_positive_rate-c_matrix_ref">&_calculate_false_positive_rate( $c_matrix_ref )</h2>
<p>Calculates and adds the data for the <code>false_positive_rate</code> key in the confusion matrix hash.</p>
<h2 id="calculate_false_discovery_rate-c_matrix_ref">&_calculate_false_discovery_rate( $c_matrix_ref )</h2>
<p>Calculates and adds the data for the <code>false_discovery_rate</code> key in the confusion matrix hash.</p>
<h2 id="calculate_false_omission_rate-c_matrix_ref">&_calculate_false_omission_rate( $c_matrix_ref )</h2>
<p>Calculates and adds the data for the <code>false_omission_rate</code> key in the confusion matrix hash.</p>
<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>
<p>Extends and outputs the matrix on the screen.</p>
<p><code>$matrix</code> and <code>$c_matrix</code> are the same as returned by <code>&_build_matrix</code>.</p>
<h1 id="NERVE-DATA-RELATED-SUBROUTINES">NERVE DATA RELATED SUBROUTINES</h1>
<p>This part is about saving the data of the nerve. These subroutines can be imported using the <code>:local_data</code> tag.</p>
<p><b>The subroutines are to be called in the procedural way</b>. No checking is done currently.</p>
<p>See <code>PERCEPTRON DATA</code> and <code>KNOWN ISSUES</code> sections for more details on the subroutines in this section.</p>
<h2 id="preserve">preserve ( ... )</h2>
<p>The parameters and usage are the same as <code>save_perceptron</code>. See the next subroutine.</p>
<h2 id="save_perceptron-nerve-nerve_file">save_perceptron ( $nerve, $nerve_file )</h2>
<p>Saves the <code>AI::Perceptron::Simple</code> object into a <code>Storable</code> file. There shouldn't be a need to call this method manually since after every training process this will be called automatically.</p>
<h2 id="revive">revive (...)</h2>
<p>The parameters and usage are the same as <code>load_perceptron</code>. See the next subroutine.</p>
<h2 id="load_perceptron-nerve_file_to_load">load_perceptron ( $nerve_file_to_load )</h2>
<p>Loads the data and turns it into a <code>AI::Perceptron::Simple</code> object as the return value.</p>
<h1 id="NERVE-PORTABILITY-RELATED-SUBROUTINES">NERVE PORTABILITY RELATED SUBROUTINES</h1>
<p>These subroutines can be imported using the <code>:portable_data</code> tag.</p>
<p>The file type currently supported is YAML. Please be careful with the data as you won't want the nerve data accidentally modified.</p>
<h2 id="preserve_as_yaml">preserve_as_yaml ( ... )</h2>
<p>The parameters and usage are the same as <code>save_perceptron_yaml</code>. See the next subroutine.</p>
<h2 id="save_perceptron_yaml-nerve-yaml_nerve_file">save_perceptron_yaml ( $nerve, $yaml_nerve_file )</h2>
<p>Saves the <code>AI::Perceptron::Simple</code> object into a <code>YAML</code> file.</p>
<h2 id="revive_from_yaml">revive_from_yaml (...)</h2>
<p>The parameters and usage are the same as <code>load_perceptron</code>. See the next subroutine.</p>
<h2 id="load_perceptron_yaml-yaml_nerve_file">load_perceptron_yaml ( $yaml_nerve_file )</h2>
<p>Loads the YAML data and turns it into a <code>AI::Perceptron::Simple</code> object as the return value.</p>
<h1 id="TO-DO">TO DO</h1>
<p>These are the to-do's that <b>MIGHT</b> be done in the future. Don't put too much hope in them please :)</p>
<ul>
<li><p>Clean up and refactor source codes</p>
</li>
( run in 0.659 second using v1.01-cache-2.11-cpan-39bf76dae61 )