fann_scale_input
(PECL fann >= 1.0.0)
fann_scale_input — Scale data in input vector before feed it to ann based on previously calculated parameters
Description
bool fann_scale_input
( resource
$ann
, array $input_vector
)Scale data in input vector before feed it to ann based on previously calculated parameters.
Parameters
-
ann
-
Neural network resource.
-
input_vector
-
Input vector that will be scaled
Return Values
Returns TRUE
on success, or FALSE
otherwise.
See Also
- fann_descale_input() - Scale data in input vector after get it from ann based on previously calculated parameters
- fann_scale_output() - Scale data in output vector before feed it to ann based on previously calculated parameters
- 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
Коментарии
Please note -> ALLfann scaling related functions are not functional.
They are implemented wrong so the scaling is calculated within the library but it's not referenced back to the input variables.
fann_scale_input and fann_scale_output return not bool value. This function return scaling vector.
Example
$r = fann_scale_input($ann, $input);
$output = fann_run($ann, $input);
$s = fann_scale_output ( $ann, $output);
$r and $s is array
<?php
// This example will use the XOR dataset with negative one represented
// as zero and one represented as one-hundred and demonstrate how to
// scale those values so that FANN can understand them and then how
// to de-scale the value FANN returns so that you can understand them.
// Scaling allows you to take raw data numbers like -1234.975 or 4502012
// in your dataset and convert them into an input/output range that
// your neural network can understand.
// De-scaling lets you take the scaled data and convert it back into
// the original range.
// scale_test.data
// Note the values are "raw" or un-scaled.
/*
4 2 1
0 0
0
0 100
100
100 0
100
100 100
0
*/
////////////////////
// Configure ANN //
////////////////////
// New ANN
$ann = fann_create_standard_array(3, [2,3,1]);
// Set activation functions
fann_set_activation_function_hidden($ann, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output($ann, FANN_SIGMOID_SYMMETRIC);
// Read raw (un-scaled) training data from file
$train_data = fann_read_train_from_file("scale_test.data");
// Scale the data range to -1 to 1
fann_set_input_scaling_params($ann , $train_data, -1, 1);
fann_set_output_scaling_params($ann , $train_data, -1, 1);
///////////
// Train //
///////////
// Presumably you would train here (uncomment to perform training)...
// fann_train_on_data($ann, $train_data, 100, 10, 0.01);
// But it's not needed to test the scaling because the training file
// in this case is just used to compute/derive the scale range.
// However, doing the training will improve the answer the ANN gives
// in correlation to the training data.
//////////
// Test //
//////////
$raw_input = array(0, 100); // test XOR (0,100) input
$scaled_input = fann_scale_input ($ann , $raw_input); // scaled XOR (-1,1) input
$descaled_input = fann_descale_input ($ann , $scaled_input); // de-scaled XOR (0,100) input
$raw_output = fann_run($ann, $scaled_input); // get the answer/output from the ANN
$output_descale = fann_descale_output($ann, $raw_output); // de-scale the output
////////////////////
// Report Results //
////////////////////
echo 'The raw_input:' . PHP_EOL;
var_dump($raw_input);
echo 'The raw_input Scaled then De-Scaled (values are unchanged/correct):' . PHP_EOL;
var_dump($descaled_input);
echo 'The Scaled input:' . PHP_EOL;
var_dump($scaled_input);
echo "The raw_output of the ANN (Scaled input):" . PHP_EOL;
var_dump($raw_output);
echo 'The De-Scaled output:' . PHP_EOL;
var_dump($output_descale);
////////////////////
// Example Output //
////////////////////
/*
The raw_input:
array(2) {
[0]=>
float(0)
[1]=>
float(100)
}
The raw_input Scaled then De-Scaled (values are unchanged/correct):
array(2) {
[0]=>
float(0)
[1]=>
float(100)
}
The Scaled input:
array(2) {
[0]=>
float(-1)
[1]=>
float(1)
}
The raw_output of the ANN (Scaled input):
array(1) {
[0]=>
float(1)
}
The De-Scaled output:
array(1) {
[0]=>
float(100)
}
*/
<?php
// This example will use the XOR dataset with negative one represented
// as zero and one represented as one-hundred and demonstrate how to
// scale those values so that FANN can understand them and then how
// to de-scale the value FANN returns so that you can understand them.
// Scaling allows you to take raw data numbers like -1234.975 or 4502012
// in your dataset and convert them into an input/output range that
// your neural network can understand.
// De-scaling lets you take the scaled data and convert it back into
// the original range.
// scale_test.data
// Note the values are "raw" or un-scaled.
/*
4 2 1
0 0
0
0 100
100
100 0
100
100 100
0
*/
////////////////////
// Configure ANN //
////////////////////
// New ANN
$ann = fann_create_standard_array(3, [2,3,1]);
// Set activation functions
fann_set_activation_function_hidden($ann, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output($ann, FANN_SIGMOID_SYMMETRIC);
// Read raw (un-scaled) training data from file
$train_data = fann_read_train_from_file("scale_test.data");
// Scale the data range to -1 to 1
fann_set_input_scaling_params($ann , $train_data, -1, 1);
fann_set_output_scaling_params($ann , $train_data, -1, 1);
///////////
// Train //
///////////
// Presumably you would train here (uncomment to perform training)...
// fann_train_on_data($ann, $train_data, 100, 10, 0.01);
// But it's not needed to test the scaling because the training file
// in this case is just used to compute/derive the scale range.
// However, doing the training will improve the answer the ANN gives
// in correlation to the training data.
//////////
// Test //
//////////
$raw_input = array(0, 100); // test XOR (0,100) input
$scaled_input = fann_scale_input ($ann , $raw_input); // scaled XOR (-1,1) input
$descaled_input = fann_descale_input ($ann , $scaled_input); // de-scaled XOR (0,100) input
$raw_output = fann_run($ann, $scaled_input); // get the answer/output from the ANN
$output_descale = fann_descale_output($ann, $raw_output); // de-scale the output
////////////////////
// Report Results //
////////////////////
echo 'The raw_input:' . PHP_EOL;
var_dump($raw_input);
echo 'The raw_input Scaled then De-Scaled (values are unchanged/correct):' . PHP_EOL;
var_dump($descaled_input);
echo 'The Scaled input:' . PHP_EOL;
var_dump($scaled_input);
echo "The raw_output of the ANN (Scaled input):" . PHP_EOL;
var_dump($raw_output);
echo 'The De-Scaled output:' . PHP_EOL;
var_dump($output_descale);
////////////////////
// Example Output //
////////////////////
/*
The raw_input:
array(2) {
[0]=>
float(0)
[1]=>
float(100)
}
The raw_input Scaled then De-Scaled (values are unchanged/correct):
array(2) {
[0]=>
float(0)
[1]=>
float(100)
}
The Scaled input:
array(2) {
[0]=>
float(-1)
[1]=>
float(1)
}
The raw_output of the ANN (Scaled input):
array(1) {
[0]=>
float(1)
}
The De-Scaled output:
array(1) {
[0]=>
float(100)
}
*/