Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class RandomGridSearch(n: Int) {
- private val paramDistr = mutable.Map.empty[Param[_],Any]
- def addDistr[T](param: Param[T], distr: Any ): this.type = distr match {
- case _ : Rand[_] => {paramDistr.put(param, distr)
- this}
- case _ : Array[_] => { paramDistr.put(param, distr)
- this}
- case _ => throw new NotImplementedError("Not an Array or of package breeze type")
- }
- def build(): Array[ParamMap] = {
- var paramMaps = (1 to n).map( _ => new ParamMap())
- paramDistr.foreach{
- case (param, distribution) =>
- val values = distribution match {
- case d :Rand[_] => {
- paramMaps.map(_.put(param.asInstanceOf[Param[Any]],d.sample()))
- }
- case d: Array[_] => {
- val r = scala.util.Random
- paramMaps.map(_.put(param.asInstanceOf[Param[Any]], d(r.nextInt(d.length))) )
- }
- }
- }
- paramMaps.toArray
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement