coral-media/ext-fann

FANN (Fast Artificial Neural Network) bindings for PHP

Installs: 3

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Language:C

Type:php-ext

Ext name:ext-fann

pkg:composer/coral-media/ext-fann

v1.0.0 2026-02-14 21:51 UTC

This package is auto-updated.

Last update: 2026-02-14 22:00:08 UTC


README

coral-media/ext-fann is a PHP extension that wraps the Fast Artificial Neural Network (FANN) C library using vendored sources (lib/libfann).

Requirements

  • PHP >= 8.1
  • A C toolchain (phpize, make, compiler)
  • No system libfann-dev required (vendored build)

Install (PIE)

From the extension root:

pie install --with-fann

Build From Source (manual)

phpize
./configure --with-fann
make -j"$(nproc)"
make test

The extension module will be built as fann.

Minimal Example

<?php
$ann = fann_create_standard(3, 2, 3, 1);
fann_set_training_algorithm($ann, FANN_TRAIN_INCREMENTAL);
fann_set_learning_rate($ann, 0.7);
fann_set_activation_function_hidden($ann, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output($ann, FANN_SIGMOID_SYMMETRIC);

for ($epoch = 0; $epoch < 200; $epoch++) {
    fann_train($ann, [0.0, 0.0], [0.0]);
    fann_train($ann, [0.0, 1.0], [1.0]);
    fann_train($ann, [1.0, 0.0], [1.0]);
    fann_train($ann, [1.0, 1.0], [0.0]);
}

$out = fann_run($ann, [0.0, 1.0]);
var_dump($out);

fann_destroy($ann);

Tests

Run all PHPT tests:

make test

API Coverage

Implemented functions are grouped below. Full API reference: docs/api/index.md.

Network Creation, Persistence, and Lifecycle

Execution and Basic Training

Training Data I/O and Dataset Utilities

Training Metrics and Error Handling

Training Algorithm and Hyperparameters

Activation Functions and Steepness

Network Introspection, Topology, and Weights

Input/Output Scaling (Runtime + Parameter Setup)

Cascade Training Controls

Constants

  • Full exposure of currently registered FANN_* constants (training algorithms, activation functions, stop/error functions, net types, and error codes).

Vendored Dependency

  • FANN source is vendored under lib/libfann
  • License file: lib/libfann/COPYING.txt