| 169 | } |
| 170 | |
| 171 | func (this *Kernel) kernel_function(i, j int) float64 { |
| 172 | switch this.kernel_type { |
| 173 | case LINEAR: |
| 174 | return dot(this.x[i], this.x[j]) |
| 175 | case POLY: |
| 176 | return powi(this.gamma*dot(this.x[i], this.x[j])+this.coef0, this.degree) |
| 177 | case RBF: |
| 178 | return math.Exp(-this.gamma * (this.x_square[i] + this.x_square[j] - 2*dot(this.x[i], this.x[j]))) |
| 179 | case SIGMOID: |
| 180 | return math.Tanh(this.gamma*dot(this.x[i], this.x[j]) + this.coef0) |
| 181 | case PRECOMPUTED: |
| 182 | return this.x[i][int(this.x[j][0].value)].value |
| 183 | } |
| 184 | return 0 |
| 185 | } |
| 186 | |
| 187 | func NewKernel(l int, x_ [][]SVM_Node, param *SVM_Parameter) *Kernel { |
| 188 | this := new(Kernel) |