1<?php 2 3namespace Rubix\ML\Kernels\SVM; 4 5use Rubix\ML\Specifications\ExtensionIsLoaded; 6use svm; 7 8/** 9 * RBF 10 * 11 * Non-linear radial basis function computes the distance from a centroid or origin. 12 * 13 * @category Machine Learning 14 * @package Rubix/ML 15 * @author Andrew DalPino 16 */ 17class RBF implements Kernel 18{ 19 /** 20 * The kernel coefficient. 21 * 22 * @var float|null 23 */ 24 protected $gamma; 25 26 /** 27 * @param float|null $gamma 28 */ 29 public function __construct(?float $gamma = null) 30 { 31 ExtensionIsLoaded::with('svm')->check(); 32 33 $this->gamma = $gamma; 34 } 35 36 /** 37 * Return the options for the libsvm runtime. 38 * 39 * @internal 40 * 41 * @return mixed[] 42 */ 43 public function options() : array 44 { 45 return [ 46 svm::OPT_KERNEL_TYPE => svm::KERNEL_RBF, 47 svm::OPT_GAMMA => $this->gamma, 48 ]; 49 } 50 51 /** 52 * Return the string representation of the object. 53 * 54 * @return string 55 */ 56 public function __toString() : string 57 { 58 return "RBF (gamma: {$this->gamma})"; 59 } 60} 61