Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with fann_set_callback #30

Open
a1exsnow opened this issue Jan 4, 2017 · 3 comments
Open

Problem with fann_set_callback #30

a1exsnow opened this issue Jan 4, 2017 · 3 comments

Comments

@a1exsnow
Copy link

a1exsnow commented Jan 4, 2017

Hi!

I'm trying to use fann_set_callback based on your test:
https://github.com/bukka/php-fann/blob/master/tests/fann_set_callback_basic.phpt

When I run it, callback function is called only once. And if I try to save result to file in the end of the test I get error. So I added:
fann_save($ann, dirname( __FILE__ ) . "/fann_result.net");

and get:
PHP Warning: fann_save() expects parameter 1 to be resource, null given in fann_callback_test.php on line 40

Indeed, $ann is null. Without setting callback everything is fine. Any ideas?

Thanks, Alex.

@bukka
Copy link
Owner

bukka commented Jan 8, 2017

Looks like $ann has not been created. Can you post the whole program (just the fann related part ofc)?

@a1exsnow
Copy link
Author

a1exsnow commented Jan 10, 2017

As I said, I've just added one line to your test script, so:

function ann_callback( $ann, $train_data, $max_epochs, $epochs_between_reports, $desired_error, $epochs ) {
    var_dump($ann);
    var_dump($train_data);
    var_dump($max_epochs);
    var_dump($epochs_between_reports);
    var_dump($desired_error);
    var_dump($epochs);
}
$num_input = 2;
$num_output = 1;
$num_layers = 3;
$num_neurons_hidden = 3;
$desired_error = 0.001;
$max_epochs = 50000;
$epochs_between_reports = 1000;
$ann = fann_create_standard($num_layers, $num_input, $num_neurons_hidden, $num_output);
fann_set_callback($ann, 'ann_callback');
$filename = ( dirname( __FILE__ ) . "/fann_set_callback.tmp" );				 
$content = <<<EOF
4 2 1
-1 -1
-1
-1 1
1
1 -1
1
1 1
-1
EOF;
file_put_contents( $filename, $content );
$train_data = fann_read_train_from_file( $filename );
fann_train_on_data( $ann, $train_data, $max_epochs, $epochs_between_reports, $desired_error );

fann_save($ann, dirname( __FILE__ ) . "/fann_result.net");

@AlexKirsanoff
Copy link

AlexKirsanoff commented May 26, 2018

Fix:

$callback = function () {

    // do something...

    return true; // should return true
};
fann_set_callback($ann, $callback);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants