PHP 8.4.1 Released!

fann_scale_input

(PECL fann >= 1.0.0)

fann_scale_inputEscalar datos en un vector de entrada antes de alimentarlo a una RNA basada en parámetros previamente calculados

Descripción

fann_scale_input(resource $ann, array $input_vector): bool

Escalar datos en un vector de entrada antes de alimentarlo a una RNA basada en parámetros previamente calculados.

Parámetros

ann

Un resource de red neuronal.

input_vector

El vector de entrada a escalar

Valores devueltos

Devuelve true en caso de éxito, o false de lo contrario.

Ver también

  • fann_descale_input() - Escalar datos en un vector de entrada después de obtenerlo de una RNA basada en parámetros previamente calculados
  • fann_scale_output() - Escalar datos en un vector de entrada antes de alimentarlo a una RNA basada en parámetros previamente calculados

add a note

User Contributed Notes 4 notes

up
1
geekgirl dot joy at gmail dot com
3 years ago
<?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)
}
*/
up
0
geekgirl dot joy at gmail dot com
3 years ago
<?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)
}
*/
up
0
saakyanalexandr at gmail dot com
4 years ago
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
up
-1
Nolife
7 years ago
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.
To Top