| @@ 159-164 (lines=6) @@ | ||
| 156 | return function ($x, $y) { |
|
| 157 | return Matrix::dot($x, $y)[0]; |
|
| 158 | }; |
|
| 159 | case self::KERNEL_RBF: |
|
| 160 | // k(x,y)=exp(-γ.|x-y|) where |..| is Euclidean distance |
|
| 161 | $dist = new Euclidean(); |
|
| 162 | return function ($x, $y) use ($dist) { |
|
| 163 | return exp(-$this->gamma * $dist->sqDistance($x, $y)); |
|
| 164 | }; |
|
| 165 | ||
| 166 | case self::KERNEL_SIGMOID: |
|
| 167 | // k(x,y)=tanh(γ.xT.y+c0) where c0=1 |
|
| @@ 173-178 (lines=6) @@ | ||
| 170 | return tanh($this->gamma * $res); |
|
| 171 | }; |
|
| 172 | ||
| 173 | case self::KERNEL_LAPLACIAN: |
|
| 174 | // k(x,y)=exp(-γ.|x-y|) where |..| is Manhattan distance |
|
| 175 | $dist = new Manhattan(); |
|
| 176 | return function ($x, $y) use ($dist) { |
|
| 177 | return exp(-$this->gamma * $dist->distance($x, $y)); |
|
| 178 | }; |
|
| 179 | } |
|
| 180 | } |
|
| 181 | ||