Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/5431#discussion_r28290414
--- Diff: mllib/src/main/scala/org/apache/spark/ml/param/params.scala ---
@@ -179,52 +179,96 @@ trait Params extends Identifiable with Serializable {
/**
* Sets a parameter (by name) in the embedded param map.
*/
- private[ml] def set(param: String, value: Any): this.type = {
+ protected final def set(param: String, value: Any): this.type = {
set(getParam(param), value)
}
/**
- * Gets the value of a parameter in the embedded param map.
+ * Optionally returns the user-supplied value of a param.
+ */
+ final def get[T](param: Param[T]): Option[T] = {
+ shouldOwn(param)
+ paramMap.get(param)
+ }
+
+ /**
+ * Clears the user-supplied value for the input param.
+ */
+ final def clear(param: Param[_]): this.type = {
+ shouldOwn(param)
+ paramMap.remove(param)
+ this
+ }
+
+ /**
+ * Gets the value of a param in the embedded param map or its default
value. Throws an exception
+ * if neither is set.
*/
- protected def get[T](param: Param[T]): T = {
- require(param.parent.eq(this))
- paramMap(param)
+ final def getOrDefault[T](param: Param[T]): T = {
+ shouldOwn(param)
+ get(param).orElse(getDefault(param)).get
}
/**
- * Internal param map.
+ * Sets a default value. Make sure that the input param is initialized
before this gets called.
--- End diff --
done
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]