当我从apache-spark中读取代码时,我遇到了这个问题:
val alpha = new DoubleParam(this, "alpha", "alpha for implicit preference",
ParamValidators.gtEq(0))
/** @group getParam */
def getAlpha: Double = $(alpha)
我在网上搜索了很长时间但仍无法找到$(alpha)
在这里的含义的好解释?如何将自定义的类DoubleParam
变量分配给Double
?谢谢!
仅供参考,DoubleParam
类定义为:
class DoubleParam(parent: String, name: String, doc: String, isValid: Double => Boolean)
extends Param[Double](parent, name, doc, isValid) {
def this(parent: String, name: String, doc: String) =
this(parent, name, doc, ParamValidators.alwaysTrue)
def this(parent: Identifiable, name: String, doc: String, isValid: Double => Boolean) =
this(parent.uid, name, doc, isValid)
def this(parent: Identifiable, name: String, doc: String) = this(parent.uid, name, doc)
/** Creates a param pair with the given value (for Java). */
override def w(value: Double): ParamPair[Double] = super.w(value)
}
答案 0 :(得分:8)
$()
是特征Params
中定义的Spark函数。它只是在getOrDefault
对象上调用Params
。
它的定义是
/** An alias for [[getOrDefault()]]. */
protected final def $[T](param: Param[T]): T = getOrDefault(param)