16 for (
size_t i = 0; i < n - 1; ++i)
18 size_t j = i + rand() / (RAND_MAX / (n - i) + 1);
27 size_t size,
double validation_split,
28 int shuffle,
unsigned long batch_size,
size_t epochs,
double eta,
double alpha,
29 double(*f_cost)(
double,
double),
double(*f_cost_de)(
double,
double)
32 if (net == NULL || data == NULL || target == NULL ||
size == 0 || validation_split < 0 || validation_split > 1)
34 if (validation_split == 0) {
35 if (batch_size == 0 || epochs == 0 || eta == 0 || f_cost_de == NULL)
42 size_t validationsize = (size_t)floor(
size * validation_split);
43 size_t trainingsize =
size - validationsize;
45 double __status;
if (status == NULL) status = &__status;
49 for(
size_t i = 0; i <
size; ++i) order[i] = i;
51 if (validation_split != 1) {
52 double stepstatus = (1/(double)(epochs * trainingsize)) * 100;
55 for(
size_t e = 0; e < epochs; ++e)
59 for(
size_t i = 0; i < trainingsize; i+=batch_size)
61 for(
size_t j = 0; j < batch_size && i+j < trainingsize; ++j, (*status) += stepstatus)
75 if (validation_split == 0)
77 double *err = calloc(net->
outputl->
size,
sizeof(
double));
78 for(
size_t i = trainingsize; i <
size; ++i)
85 err[i] /= (
double)(
size - trainingsize);
void PCFNN_NETWORK_feedforward(struct PCFNN_NETWORK *net, double *inputs)
Feedforward the PCFNN_NETWORK net.
void PCFNN_NETWORK_apply_delta(struct PCFNN_NETWORK *net)
Apply all delta calculated by PCFNN_NETWORK_backprop on the network net.
void PCFNN_NETWORK_init_batch(struct PCFNN_NETWORK *net)
Initialize batch for the network net.
struct PCFNN_LAYER * outputl
void PCFNN_NETWORK_clear_batch(struct PCFNN_NETWORK *net)
Partially clear batch data of the network net.
double * PCFNN_NETWORK_train(struct PCFNN_NETWORK *net, double **data, double **target, size_t size, double validation_split, int shuffle, unsigned long batch_size, size_t epochs, double eta, double alpha, double(*f_cost)(double, double), double(*f_cost_de)(double, double), double *status)
Train the network net.
struct PCFNN_NEURON ** neurons
ANN_INLINE void __fisher_yates_shuffle(size_t *array, size_t n)
void PCFNN_NETWORK_free_batch(struct PCFNN_NETWORK *net)
Free all memory allocation for the batch of the network net.
void PCFNN_NETWORK_backprop(struct PCFNN_NETWORK *net, double *target, double eta, double alpha, double(*f_cost)(double, double))
Run the Backpropagation Algorithm on the network net.