fann_train_epoch
(PECL fann >= 1.0.0)
fann_train_epoch — Train one epoch with a set of training data
Description
$ann
, resource $data
)Train one epoch with the training data stored in data. One epoch is where all of the training data is considered exactly once.
This function returns the MSE error as it is calculated either before or during the actual training. This is not the actual MSE after the training epoch, but since calculating this will require to go through the entire training set once more. It is more than adequate to use this value during training.
The training algorithm used by this function is chosen by fann_set_training_algorithm() function.
Return Values
The MSE, or FALSE
on error.
See Also
- fann_train_on_data() - Trains on an entire dataset for a period of time
- fann_test_data() - Test a set of training data and calculates the MSE for the training data
- fann_get_MSE() - Reads the mean square error from the network
- fann_set_training_algorithm() - Sets the training algorithm
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Другие базовые расширения
- FANN (Fast Artificial Neural Network)
- fann_cascadetrain_on_data
- fann_cascadetrain_on_file
- fann_clear_scaling_params
- fann_copy
- fann_create_from_file
- fann_create_shortcut_array
- fann_create_shortcut
- fann_create_sparse_array
- fann_create_sparse
- fann_create_standard_array
- fann_create_standard
- fann_create_train_from_callback
- fann_create_train
- fann_descale_input
- fann_descale_output
- fann_descale_train
- fann_destroy_train
- fann_destroy
- fann_duplicate_train_data
- fann_get_activation_function
- fann_get_activation_steepness
- fann_get_bias_array
- fann_get_bit_fail_limit
- fann_get_bit_fail
- fann_get_cascade_activation_functions_count
- fann_get_cascade_activation_functions
- fann_get_cascade_activation_steepnesses_count
- fann_get_cascade_activation_steepnesses
- fann_get_cascade_candidate_change_fraction
- fann_get_cascade_candidate_limit
- fann_get_cascade_candidate_stagnation_epochs
- fann_get_cascade_max_cand_epochs
- fann_get_cascade_max_out_epochs
- fann_get_cascade_min_cand_epochs
- fann_get_cascade_min_out_epochs
- fann_get_cascade_num_candidate_groups
- fann_get_cascade_num_candidates
- fann_get_cascade_output_change_fraction
- fann_get_cascade_output_stagnation_epochs
- fann_get_cascade_weight_multiplier
- fann_get_connection_array
- fann_get_connection_rate
- fann_get_errno
- fann_get_errstr
- fann_get_layer_array
- fann_get_learning_momentum
- fann_get_learning_rate
- fann_get_MSE
- fann_get_network_type
- fann_get_num_input
- fann_get_num_layers
- fann_get_num_output
- fann_get_quickprop_decay
- fann_get_quickprop_mu
- fann_get_rprop_decrease_factor
- fann_get_rprop_delta_max
- fann_get_rprop_delta_min
- fann_get_rprop_delta_zero
- fann_get_rprop_increase_factor
- fann_get_sarprop_step_error_shift
- fann_get_sarprop_step_error_threshold_factor
- fann_get_sarprop_temperature
- fann_get_sarprop_weight_decay_shift
- fann_get_total_connections
- fann_get_total_neurons
- fann_get_train_error_function
- fann_get_train_stop_function
- fann_get_training_algorithm
- fann_init_weights
- fann_length_train_data
- fann_merge_train_data
- fann_num_input_train_data
- fann_num_output_train_data
- fann_print_error
- fann_randomize_weights
- fann_read_train_from_file
- fann_reset_errno
- fann_reset_errstr
- fann_reset_MSE
- fann_run
- fann_save_train
- fann_save
- fann_scale_input_train_data
- fann_scale_input
- fann_scale_output_train_data
- fann_scale_output
- fann_scale_train_data
- fann_scale_train
- fann_set_activation_function_hidden
- fann_set_activation_function_layer
- fann_set_activation_function_output
- fann_set_activation_function
- fann_set_activation_steepness_hidden
- fann_set_activation_steepness_layer
- fann_set_activation_steepness_output
- fann_set_activation_steepness
- fann_set_bit_fail_limit
- fann_set_callback
- fann_set_cascade_activation_functions
- fann_set_cascade_activation_steepnesses
- fann_set_cascade_candidate_change_fraction
- fann_set_cascade_candidate_limit
- fann_set_cascade_candidate_stagnation_epochs
- fann_set_cascade_max_cand_epochs
- fann_set_cascade_max_out_epochs
- fann_set_cascade_min_cand_epochs
- fann_set_cascade_min_out_epochs
- fann_set_cascade_num_candidate_groups
- fann_set_cascade_output_change_fraction
- fann_set_cascade_output_stagnation_epochs
- fann_set_cascade_weight_multiplier
- fann_set_error_log
- fann_set_input_scaling_params
- fann_set_learning_momentum
- fann_set_learning_rate
- fann_set_output_scaling_params
- fann_set_quickprop_decay
- fann_set_quickprop_mu
- fann_set_rprop_decrease_factor
- fann_set_rprop_delta_max
- fann_set_rprop_delta_min
- fann_set_rprop_delta_zero
- fann_set_rprop_increase_factor
- fann_set_sarprop_step_error_shift
- fann_set_sarprop_step_error_threshold_factor
- fann_set_sarprop_temperature
- fann_set_sarprop_weight_decay_shift
- fann_set_scaling_params
- fann_set_train_error_function
- fann_set_train_stop_function
- fann_set_training_algorithm
- fann_set_weight_array
- fann_set_weight
- fann_shuffle_train_data
- fann_subset_train_data
- fann_test_data
- fann_test
- fann_train_epoch
- fann_train_on_data
- fann_train_on_file
- fann_train
Коментарии
This code demonstrates training XOR using fann_train_epoch and will let you watch the training process by observing a psudo MSE (mean squared error).
Other training functions: fann_train_on_data, fann_train_on_file, fann_train.
fann_train_epoch is useful when you want to observe the ANN while it is training and perhaps save snapshots or compare competing networks during training.
fann_train_epoch is different from fann_train in that it takes a data resource (training file) whereas fann_train takes an array of inputs and a separate array of outputs so use fann_train_epoch for observing training on data files (callback training resources) and use fann_train when observing manually specified data.
Example code:
<?php
$num_input = 2;
$num_output = 1;
$num_layers = 3;
$num_neurons_hidden = 3;
$desired_error = 0.0001;
$max_epochs = 500000;
$current_epoch = 0;
$epochs_between_saves = 100; // Minimum number of epochs between saves
$epochs_since_last_save = 0;
$filename = dirname(__FILE__) . "/xor.data";
// Initialize psudo mse (mean squared error) to a number greater than the desired_error
// this is what the network is trying to minimize.
$psudo_mse_result = $desired_error * 10000; // 1
$best_mse = $psudo_mse_result; // keep the last best seen MSE network score here
// Initialize ANN
$ann = fann_create_standard($num_layers, $num_input, $num_neurons_hidden, $num_output);
if ($ann) {
echo 'Training ANN... ' . PHP_EOL;
// Configure the ANN
fann_set_training_algorithm ($ann , FANN_TRAIN_BATCH);
fann_set_activation_function_hidden($ann, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output($ann, FANN_SIGMOID_SYMMETRIC);
// Read training data
$train_data = fann_read_train_from_file($filename);
// Check if psudo_mse_result is greater than our desired_error
// if so keep training so long as we are also under max_epochs
while(($psudo_mse_result > $desired_error) && ($current_epoch <= $max_epochs)){
$current_epoch++;
$epochs_since_last_save++;
// See: function.fann-train-epoch
// Train one epoch with the training data stored in data.
//
// One epoch is where all of the training data is considered
// exactly once.
//
// This function returns the MSE error as it is calculated
// either before or during the actual training. This is not the
// actual MSE after the training epoch, but since calculating this
// will require to go through the entire training set once more.
// It is more than adequate to use this value during training.
$psudo_mse_result = fann_train_epoch ($ann , $train_data );
echo 'Epoch ' . $current_epoch . ' : ' . $psudo_mse_result . PHP_EOL; // report
// If we haven't saved the ANN in a while...
// and the current network is better then the previous best network
// as defined by the current MSE being less than the last best MSE
// Save it!
if(($epochs_since_last_save >= $epochs_between_saves) && ($psudo_mse_result < $best_mse)){
$best_mse = $psudo_mse_result; // we have a new best_mse
// Save a Snapshot of the ANN
fann_save($ann, dirname(__FILE__) . "/xor.net");
echo 'Saved ANN.' . PHP_EOL; // report the save
$epochs_since_last_save = 0; // reset the count
}
} // While we're training
echo 'Training Complete! Saving Final Network.' . PHP_EOL;
// Save the final network
fann_save($ann, dirname(__FILE__) . "/xor.net");
fann_destroy($ann); // free memory
}
echo 'All Done!' . PHP_EOL;
?>