PrePAN

Sign in to PrePAN

AI::Perceptron::Simple A Newbie Friendly Module to Create, Train, Validate and Test Perceptrons / Neurons

Good

Synopsis

#!/usr/bin/perl
 
use AI::Perceptron::Simple qw(...);
 
# create a new nerve / neuron / perceptron
$perceptron = AI::Perceptron::Simple->new( {
    initial_value => $any_value_that_makes_sense, # size of each dendrite :)
    learning_rate => 0.3, # optional
    threshold => 0.85, # optional
    attribs => \@attributes, # dendrites
} );
 
# train
$perceptron->tame( ... );
$perceptron->exercise( ... );
$perceptron->train( $training_data_csv, $expected_column_name, $save_nerve_to );
# or
$perceptron->train(
    $training_data_csv, $expected_column_name, $save_nerve_to, 
    $show_progress, $identifier); # these two parameters must go together
 
 
# validate
$perceptron->take_lab_test( ... );
$perceptron->take_mock_exam( ... );
 
# fill results to original file
$perceptron->validate( { 
    stimuli_validate => $validation_data_csv, 
    predicted_column_index => 4,
 } );
# or        
# fill results to a new file
$perceptron->validate( {
    stimuli_validate => $validation_data_csv,
    predicted_column_index => 4,
    results_write_to => $new_csv
} );
 
 
# test - see "validate" method, same usage
$perceptron->take_real_exam( ... );
$perceptron->work_in_real_world( ... );
$perceptron->test( ... );
 
 
# confusion matrix
my %c_matrix = $perceptron->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
$perceptron->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( $perceptron, $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 ( $perceptron, $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, ... );

Description

This is a module meant to help newbies understand how perceptrons work. This module has can create, train, validate and test perceptrons. Synonyms are also included to make the technical terminologies easy to understand.

Comments

Please sign up to post a review.