spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkbradley <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-3530][MLLIB] pipeline and parameters wi...
Date Mon, 10 Nov 2014 22:23:15 GMT
Github user jkbradley commented on a diff in the pull request:

    https://github.com/apache/spark/pull/3099#discussion_r20118192
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/param/params.scala ---
    @@ -0,0 +1,305 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.ml.param
    +
    +import java.lang.reflect.Modifier
    +
    +import scala.annotation.varargs
    +import scala.collection.mutable
    +
    +import org.apache.spark.ml.Identifiable
    +
    +/**
    + * A param with self-contained documentation and optionally default value. Primitive-typed
param
    + * should use the specialized versions, which are more friendly to Java users.
    + *
    + * @param parent parent object
    + * @param name param name
    + * @param doc documentation
    + * @tparam T param value type
    + */
    +class Param[T] (
    +    val parent: Params,
    +    val name: String,
    +    val doc: String,
    +    val default: Option[T] = None) extends Serializable {
    +
    +  /**
    +   * Creates a param pair with the given value (for Java).
    +   */
    +  def w(value: T): ParamPair[T] = this -> value
    +
    +  /**
    +   * Creates a param pair with the given value (for Scala).
    +   */
    +  def ->(value: T): ParamPair[T] = ParamPair(this, value)
    +
    +  override def toString: String = {
    +    if (default.isDefined) {
    +      s"$name: $doc (default: ${default.get})"
    +    } else {
    +      s"$name: $doc"
    +    }
    +  }
    +}
    +
    +// specialize primitive-typed params because Java doesn't recognize scala.Double, scala.Int,
...
    +
    +/** Specialized version of [[Param[Double]]] for Java. */
    +class DoubleParam(parent: Params, name: String, doc: String, default: Option[Double]
= None)
    +    extends Param[Double](parent, name, doc, default) {
    +  override def w(value: Double): ParamPair[Double] = super.w(value)
    +}
    +
    +/** Specialized version of [[Param[Int]]] for Java. */
    +class IntParam(parent: Params, name: String, doc: String, default: Option[Int] = None)
    +    extends Param[Int](parent, name, doc, default) {
    +  override def w(value: Int): ParamPair[Int] = super.w(value)
    +}
    +
    +/** Specialized version of [[Param[Float]]] for Java. */
    +class FloatParam(parent: Params, name: String, doc: String, default: Option[Float] =
None)
    +    extends Param[Float](parent, name, doc, default) {
    +  override def w(value: Float): ParamPair[Float] = super.w(value)
    +}
    +
    +/** Specialized version of [[Param[Long]]] for Java. */
    +class LongParam(parent: Params, name: String, doc: String, default: Option[Long] = None)
    +    extends Param[Long](parent, name, doc, default) {
    +  override def w(value: Long): ParamPair[Long] = super.w(value)
    +}
    +
    +/** Specialized version of [[Param[Boolean]]] for Java. */
    +class BooleanParam(parent: Params, name: String, doc: String, default: Option[Boolean]
= None)
    +    extends Param[Boolean](parent, name, doc, default) {
    +  override def w(value: Boolean): ParamPair[Boolean] = super.w(value)
    +}
    +
    +/**
    + * A param amd its value.
    + */
    +case class ParamPair[T](param: Param[T], value: T)
    +
    +/**
    + * Trait for components that take parameters. This also provides an internal param map
to store
    + * parameter values attached to the instance.
    + */
    +trait Params extends Identifiable with Serializable {
    +
    +  /** Returns all params. */
    +  def params: Array[Param[_]] = {
    +    val methods = this.getClass.getMethods
    +    methods.filter { m =>
    +        Modifier.isPublic(m.getModifiers) &&
    +          classOf[Param[_]].isAssignableFrom(m.getReturnType) &&
    +          m.getParameterTypes.isEmpty
    --- End diff --
    
    Should this check be included in getParam?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message