AI-Perceptron-Simple

 view release on metacpan or  search on metacpan

docs/AI-Perceptron-Simple-1.04.html  view on Meta::CPAN

    $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 =&gt; $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>

</dd>
</dl>

<p>Most of the stuff are OO.</p>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<p>This module provides methods to build, train, validate and test a perceptron. It can also save the data of the perceptron for future use for any actual AI programs.</p>

<p>This module is also aimed to help newbies grasp hold of the concept of perceptron, training, validation and testing as much as possible. Hence, all the methods and subroutines in this module are decoupled as much as possible so that the actual scr...

<p>The implementation here is super basic as it only takes in input of the dendrites and calculate the output. If the output is higher than the threshold, the final result (category) will be 1 aka perceptron is activated. If not, then the result will...

<p>Depending on how you view or categorize the final result, the perceptron will fine tune itself (aka train) based on the learning rate until the desired result is met. Everything from here on is all mathematics and numbers which only makes sense to...

<p>Whenever the perceptron fine tunes itself, it will increase/decrease all the dendrites that is significant (attributes labelled 1) for each input. This means that even when the perceptron successfully fine tunes itself to suite all the data in you...

<h1 id="CONVENTIONS-USED">CONVENTIONS USED</h1>

<p>Please take note that not all subroutines/method must be used to make things work. All the subroutines and methods are listed out for the sake of writing the documentation.</p>

<p>Private methods/subroutines are prefixed with <code>_</code> or <code>&amp;_</code> and they aren&#39;t meant to be called directly. You can if you want to. There are quite a number of them to be honest, just ignore them if you happen to see them ...

<p>Synonyms are placed before the actual ie. technical subroutines/methods. You will see <code>...</code> as the parameters if they are synonyms. Move to the next subroutine/method until you find something like <code>\%options</code> as the parameter...

<h1 id="DATASET-STRUCTURE">DATASET STRUCTURE</h1>

<p><i>This module can only process CSV files.</i></p>

<p>Any field ie columns that will be used for processing must be binary ie. <code>0</code> or <code>1</code> only. Your dataset can contain other columns with non-binary data as long as they are not one of the dendrites.</p>

<p>There are soem sample dataset which can be found in the <code>t</code> directory. The original dataset can also be found in <code>docs/book_list.csv</code>. The files can also be found <a href="https://github.com/Ellednera/AI-Perceptron-Simple">he...

<h1 id="PERCEPTRON-DATA">PERCEPTRON DATA</h1>

<p>The perceptron/neuron data is stored using the <code>Storable</code> module.</p>

<p>See <code>Portability of Nerve Data</code> section below for more info on some known issues.</p>

<h1 id="DATA-PROCESSING-RELATED-SUBROUTINES">DATA PROCESSING RELATED SUBROUTINES</h1>

<p>These subroutines can be imported using the tag <code>:process_data</code>.</p>

<p>These subroutines should be called in the procedural way.</p>

<h2 id="shuffle_stimuli">shuffle_stimuli ( ... )</h2>

<p>The parameters and usage are the same as <code>shuffled_data</code>. See the next two subroutines.</p>

<h2 id="shuffle_data-original_data-shuffled_1-shuffled_2">shuffle_data ( $original_data =&gt; $shuffled_1, $shuffled_2, ... )</h2>

<h2 id="shuffle_data-ORIGINAL_DATA-shuffled_1-shuffled_2">shuffle_data ( ORIGINAL_DATA, $shuffled_1, $shuffled_2, ... )</h2>

<p>Shuffles <code>$original_data</code> or <code>ORIGINAL_DATA</code> and saves them to other files.</p>

<h1 id="CREATION-RELATED-SUBROUTINES-METHODS">CREATION RELATED SUBROUTINES/METHODS</h1>

<h2 id="new-options">new ( \%options )</h2>

<p>Creates a brand new perceptron and initializes the value of each attribute / dendrite aka. weight. Think of it as the thickness or plasticity of the dendrites.</p>

<p>For <code>%options</code>, the followings are needed unless mentioned:</p>

<dl>

<dt id="initial_value-decimal">initial_value =&gt; $decimal</dt>
<dd>

<p>The value or thickness of ALL the dendrites when a new perceptron is created.</p>

<p>Generally speaking, this value is usually between 0 and 1. However, it all depend on your combination of numbers for the other options.</p>

</dd>
<dt id="attribs-array_ref">attribs =&gt; $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 =&gt; $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 =&gt; $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>

docs/AI-Perceptron-Simple-1.04.html  view on Meta::CPAN

<h2 id="calculate_false_discovery_rate-c_matrix_ref">&amp;_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">&amp;_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">&amp;_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>&#39;s and <code>1</code>&#39;s won&#39;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 =&gt; $category_zero_name</dt>
<dd>

</dd>
<dt id="one_as-category_one_name">one_as =&gt; $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 &quot;actual X&quot;, &quot;predicted X&quot; 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">&amp;_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">&amp;_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>&amp;_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&#39;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&#39;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&#39;s that <b>MIGHT</b> be done in the future. Don&#39;t put too much hope in them please :)</p>

<ul>

<li><p>Clean up and refactor source codes</p>

</li>
<li><p>Add more useful data for confusion matrix</p>

</li>
<li><p>Implement shuffling data feature</p>

</li>
<li><p>Implement fast/smart training feature</p>

</li>
<li><p>Write a tutorial or something for this module</p>

</li>



( run in 0.493 second using v1.01-cache-2.11-cpan-39bf76dae61 )