AI-NeuralNet-FastSOM

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
        - added original AI::NN::SOM test suite (and it works!)
 
0.04  Sat Jul 18 16:45:27 2009
        - removed dependence on Inline::C
        - minor refactor
 
0.03  Sat Jul 18 09:30:08 2009
        - created wrappers for most c-level stuff
 
0.02  Wed Jul 15 18:56:13 2009
        - moved data structures into C structs
 
0.01  Thu Jul  2 09:07:01 2009
        - original version; created by h2xs 1.23 with options
                -AXn AI::NeuralNet::FastSOM

FastSOM.h  view on Meta::CPAN

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
*                              +---Vector---+---NV
 *                              |             \--NV
 *                               \--Vector---+---NV
 *                                            \--NV
 *
 * References
 * ==========
 *
 * Each of Rect, Map, Array, and Vector contains a member 'ref' which is
 * an SV* pointing to an RV. The RV can be returned directly to perl-land
 * after being blessed into its respective class.
 *
 * The RV references an SV containing an IV. The IV is set to the base
 * address of its component structure. This is so the class code can know
 * which instance of the class is being referred to on callback.
 *
 * The reference count of the SV has its initial reference count set to one,
 * representing its parents ownership. If a parent dies or a perl-land
 * reference is taken of any componenet, its reference count should
 * be adjusted accordingly.
 *
 * When the count reaches zero perl will call the classes DESTROY method,
 * at which point we can decrease the reference count on each child and
 * free the component structure.
 *
 * The intent of all this reference count tom-foolery is to keep the
 * component structures from disappearing from underneath perl-land
 * references to them. As a bonus, we get a neat destruction mechanism
 * without having to reimplement OOP in C.
 */
 
/*
 * SOM_Vector : holds Z NVs
 *
 * should be allocated:
 *      sizeof(SOM_Vector) + sizeof(NV)*(Z-1)
 *

FastSOM.h  view on Meta::CPAN

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
        NV element;
} SOM_Vector;
 
/*
 * SOM_Array : holds Y ptrs to SOM_Vector thingys
 *
 * should be allocated:
 *      sizeof(SOM_Array) + sizeof(SOM_Vector*)*(Y-1)
 *
 * 'ref' and 'vector' elements similar in functionality to the 'ref' and
 * 'element' members, respectively, of the SOM_Vector struct.
 *
 * 'Y' is the number of SOM_Vector pointers in the 'vector' array.
 *
 * 'Z' is provided here only for propogation down the line in creating
 * the SOM_Vectors.
 */
typedef struct {
        SV *ref;
        IV Y;
        IV Z;
        SOM_Vector *vector;
} SOM_Array;
 
/*
 * SOM_Map : holds X ptrs to SOM_Array thingys
 *
 * should be allocated:
 *      sizeof(SOM_Map) + sizeof(SOM_Array*)*(X-1)
 *
 * 'ref' and 'array' are similar in functionality to the 'ref' and 'element'
 * members, respectively, of the SOM_Vector struct.
 *
 * 'X' is the number of SOM_Array pointers in the 'array' array.
 *
 * 'Y' and 'Z' are provided here only for propagation down the line in
 * creation of SOM_Array and SOM_Vector structs.
 */
typedef struct {
        SV *ref;
        IV X;
        IV Y;

META.json  view on Meta::CPAN

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
   },
   "name" : "AI-NeuralNet-FastSOM",
   "no_index" : {
      "directory" : [
         "t",
         "inc"
      ]
   },
   "prereqs" : {
      "build" : {
         "requires" : {
            "ExtUtils::MakeMaker" : "0"
         }
      },
      "configure" : {
         "requires" : {
            "ExtUtils::MakeMaker" : "0"
         }
      },
      "runtime" : {
         "requires" : {
            "Storable" : "0"
         }
      }
   },
   "release_status" : "stable",
   "version" : "0.19",
   "x_serialization_backend" : "JSON::PP version 2.27300"
}

META.yml  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
---
abstract: 'Perl extension for fast Kohonen Maps'
author:
  - 'Rick Myers <jrm@cpan.org>'
build_requires:
  ExtUtils::MakeMaker: '0'
configure_requires:
  ExtUtils::MakeMaker: '0'
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 7.1, CPAN::Meta::Converter version 2.150005'
license: perl
meta-spec:
  version: '1.4'
name: AI-NeuralNet-FastSOM
no_index:
  directory:
    - t
    - inc
requires:
  Storable: '0'
version: '0.19'
x_serialization_backend: 'CPAN::Meta::YAML version 0.012'

examples/eigenvector_initialization.pl  view on Meta::CPAN

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
sub _find_num {
    my $v = shift;
    my $l = shift;
    for my $i (0..$#$l) {
        return $i if $v == $l->[$i];
    }
    return undef;
}
 
        for (@es_idx) {                                                  # from the highest values downwards, take the index
            push @training_vectors, [ list $E->dice($_) ] ;              # get the corresponding vector
        }
    }
 
    $nn->initialize (@training_vectors[0..0]);                           # take only the biggest ones (the eigenvalues are big, actually)
#warn $nn->as_string;
    my @mes = $nn->train ($epochs, @vs);
    warn "eigen:    length until error is < $epsilon ". scalar (grep { $_ >= $epsilon } @mes);
}
 
__END__

examples/load_save.pl  view on Meta::CPAN

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
sub _find_num {
    my $v = shift;
    my $l = shift;
    for my $i (0..$#$l) {
        return $i if $v == $l->[$i];
    }
    return undef;
}
 
        for (@es_idx) {                                                  # from the highest values downwards, take the index
            push @training_vectors, [ list $E->dice($_) ] ;              # get the corresponding vector
        }
    }
 
    $nn->initialize (@training_vectors[0..0]);                           # take only the biggest ones (the eigenvalues are big, actually)
#warn $nn->as_string;
    my @mes = $nn->train ($epochs, @vs);
    warn "eigen:    length until error is < $epsilon ". scalar (grep { $_ >= $epsilon } @mes);
}
 
__END__

lib/AI/NeuralNet/FastSOM/Hexa.pm  view on Meta::CPAN

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
Example:
 
   my $m = $nn->map;
   for my $x (0 .. $nn->diameter -1) {
       for my $y (0 .. $nn->diameter -1){
           warn "vector at $x, $y: ". Dumper $m->[$x]->[$y];
       }
   }
 
This array represents a hexagon like this (ASCII drawing is so cool):
 
               <0,0>
           <0,1>   <1,0>
       <0,2>   <1,1>   <2,0>
   <0,3>   <1,2>   <2,1>   <3,0>
  ...............................
 
 
=item I<as_string>

lib/AI/NeuralNet/FastSOM/Rect.pm  view on Meta::CPAN

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
=head2 Methods
 
=over
 
=item I<map>
 
I<$m> = I<$nn>->map
 
This method returns the 2-dimensional array of vectors in the grid
(as a reference to an array of references to arrays of vectors). The
representation of the 2-dimensional array is straightforward.
 
Example:
 
   my $m = $nn->map;
   for my $x (0 .. 5) {
       for my $y (0 .. 4){
           warn "vector at $x, $y: ". Dumper $m->[$x]->[$y];
       }
   }

t/rect.t  view on Meta::CPAN

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    my $v2 = $nn3->map->[0]->[0];
    is( $v, $v2, 'vector eq' );
 
    my $v3 = $nn2->map->[0][0];
    is( $v, $v3, 'vector shorter' );
 
    my $m = $nn->map;
    $m->[0][0][0] = 3.245;
    is( $m->[0][0][0], 3.245, 'element set' );
    $m->[0][0][0] = 1.25;
    is( $m->[0][0][0], 1.25, 'element reset' );
    $m->[0][0][1] = 4.8;
    is( $m->[0][0][1], 4.8, 'element set z' );
    $m->[0][0][1] = 2.6;
    is( $m->[0][0][1], 2.6, 'element reset z' );
    $m->[0][1][0] = 8.9;
    is( $m->[0][1][0], 8.9, 'element set y' );
    $m->[0][1][0] = 1.2;
    is( $m->[0][1][0], 1.2, 'element reset y' );
    $m->[1][0][0] = 5.4;
    is( $m->[1][0][0], 5.4, 'element set z' );
    $m->[1][0][0] = 3.23;
    is( $m->[1][0][0], 3.23, 'element reset z');
 
    $m->[4][5][2] = 2.29;
    is( $m->[4][5][2], 2.29, 'last element set' );
    is( $m->[-1][5][2], 2.29, 'negative x' );
    is( $m->[4][-1][2], 2.29, 'negative y' );
    is( $m->[4][5][-1], 2.29, 'negative z' );
    is( $m->[-1][-1][-1], 2.29, 'negative all' );
}
 
{



( run in 2.313 seconds using v1.01-cache-2.11-cpan-26ccb49234f )