Skip to content

Instantly share code, notes, and snippets.

@samithaj
Forked from micrypt/radialBasis.scala
Created December 14, 2016 03:44
Show Gist options
  • Save samithaj/d2e506b1424dba494d913013a4776beb to your computer and use it in GitHub Desktop.
Save samithaj/d2e506b1424dba494d913013a4776beb to your computer and use it in GitHub Desktop.
Radial Basis Function
import scala.math.{E, pow}
// Vector length
def vecLength(implicit values: List[Double]) = pow(values.sum, .5)
// Radial basis function
def rbf(v1: List[Double], v2: List[Double], gamma:Int = 20) = {
val dv = { for(i <- (0 to v1.length)) yield (v1(i)-v2(i)) }.toList
val l = vecLength(dv)
pow(E, (-gamma*l))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment