AI-NeuralNet-Simple
view release on metacpan or search on metacpan
double error;
c_feed(n, &input[j*n->size.input], &output[j*n->size.output], 1);
if (mse >= 0.0 || i == iterations - 1) {
error = mean_square_error(n, &output[j*n->size.output]);
if (error > max_error)
max_error = error;
}
}
if (mse >= 0 && max_error <= mse) /* Below their target! */
break;
}
free(input);
free(output);
return max_error;
}
SV* c_infer(int handle, SV *array_ref)
{
NEURAL_NETWORK *n = c_get_network(handle);
int i;
AV *perl_array, *result = newAV();
/* feed the data */
perl_array = get_array(array_ref);
for (i = 0; i < n->size.input; i++)
n->tmp[i] = get_float_element(perl_array, i);
c_feed(n, n->tmp, NULL, 0);
/* read the results */
for (i = 0; i < n->size.output; i++) {
av_push(result, newSVnv(n->neuron.output[i]));
}
return newRV_noinc((SV*) result);
}
void c_feed(NEURAL_NETWORK *n, double *input, double *output, int learn)
{
int i;
for (i=0; i < n->size.input; i++) {
n->neuron.input[i] = input[i];
}
if (learn)
for (i=0; i < n->size.output; i++)
n->neuron.target[i] = output[i];
c_feed_forward(n);
if (learn) c_back_propagate(n);
}
/*
* The original author of this code is M. Tim Jones <mtj@cogitollc.com> and
* written for the book "AI Application Programming", by Charles River Media.
*
* It's been so heavily modified that it bears little resemblance to the
* original, but credit should be given where credit is due. Therefore ...
*
* Copyright (c) 2003 Charles River Media. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, is hereby granted without fee provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. 2.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. 3.
* Neither the name of Charles River Media nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY CHARLES RIVER MEDIA AND CONTRIBUTORS 'AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL CHARLES RIVER MEDIA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
MODULE = AI::NeuralNet::Simple PACKAGE = AI::NeuralNet::Simple
PROTOTYPES: DISABLE
int
is_array_ref (ref)
SV * ref
AV *
get_array (aref)
SV * aref
float
get_float_element (array, index)
AV * array
int index
SV *
get_element (array, index)
AV * array
int index
AV *
get_array_from_aoa (aref, index)
SV * aref
int index
float
c_get_learn_rate (handle)
int handle
( run in 2.309 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )