Base Percepteron - GeorgNation/Easy-nEural-Library GitHub Wiki

Class NetworkPCT_Simplified (simple percepteron)

Example

    $neural = new NetworkPCT_Simplified;
    $neural->newNetwork (4, 5); 
    $neural->activateFunction (SEL_FUNCTION_LOGISTIC);
    
    $input  = array (1,0,1,0,1);
    $output = array (0,1,0,1,0);
    
    $neural->train (0, $input, $output, 15000);
    
    $input_test  = array (0,0,0,0,0);
    
    $result = $neural->solve (0, $input_test);

    var_dump ($result);

Functions

public function newNetwork (int $stacks, int $inputs) - Creating a new base percepteron network

When you created object with class, you should call function newNetwork for create the model of network. Function can create $stacks stacks, $inputs inputs, and outputs, which equal with inputs.

public function activateFunction (int $const) - Set activate function for all stacks.

Is default activate function, used sigmoid. This function can apply activate function for all stacks in the model. Function uses the constants with activate functions:

Constant Decimal
SEL_FUNCTION_LINEAR 1
SEL_FUNCTION_HYPERBOLIC_TANH 2
SEL_FUNCTION_ARCTG 4
SEL_FUNCTION_SIGMOID 8
SEL_FUNCTION_SQRT_SIGMOID 16
SEL_FUNCTION_LOGISTIC 32

In the $const, you can use constants, or decimal values.

public function train (int $stackId, array $input, array $output, int $ages = 10000) - Learn the network. When function calls, in the cycle started a learning the library.

You can learn library to variations input data in this way:

    $neural = new NetworkPCT_Simplified;
    $neural->newNetwork (2, 5); 
    $neural->activateFunction (SEL_FUNCTION_LINEAR);

    $cycles = 15000;
    
    $input_one  = array (1,0,1,0,1);
    $output_one = array (0,1,0,1,0);
    
    $input_two  = array (0,1,0,1,0);
    $output_two = array (1,0,1,0,1);
    
    for ($i = 0; $i < $cycles; ++$i)
    {
        $neural->train (0, $input_one, $output_one, 1); // When you learning 2 or more stacks in the for/while, use ONLY one iteration!
        $neural->train (1, $input_two, $output_two, 1);
    }

    $result_one = $neural->solve (0, $input_one);
    $result_two = $neural->solve (1, $input_two);

    var_dump (array ($result_one, $result_two));

public function solve (int $sid, array $input) - Solve

This function solve the result using the stack ID.