Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

   1  <?php
   2  
   3  declare(strict_types=1);
   4  
   5  namespace Phpml\Math\Kernel;
   6  
   7  use Phpml\Exception\InvalidArgumentException;
   8  use Phpml\Math\Kernel;
   9  use Phpml\Math\Product;
  10  
  11  class RBF implements Kernel
  12  {
  13      /**
  14       * @var float
  15       */
  16      private $gamma;
  17  
  18      public function __construct(float $gamma)
  19      {
  20          $this->gamma = $gamma;
  21      }
  22  
  23      public function compute($a, $b): float
  24      {
  25          if (!is_array($a) || !is_array($b)) {
  26              throw new InvalidArgumentException(sprintf('Arguments of %s must be arrays', __METHOD__));
  27          }
  28  
  29          $score = 2 * Product::scalar($a, $b);
  30          $squares = Product::scalar($a, $a) + Product::scalar($b, $b);
  31  
  32          return exp(-$this->gamma * ($squares - $score));
  33      }
  34  }