Skip to content

Commit

Permalink
add AlphaComponent annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxr committed Nov 11, 2014
1 parent 731f0e4 commit 6d97fe6
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mllib/src/main/scala/org/apache/spark/ml/Estimator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ package org.apache.spark.ml
import scala.annotation.varargs
import scala.collection.JavaConverters._

import org.apache.spark.annotation.AlphaComponent
import org.apache.spark.ml.param.{ParamMap, ParamPair, Params}
import org.apache.spark.sql.SchemaRDD
import org.apache.spark.sql.api.java.JavaSchemaRDD

/**
* :: AlphaComponent ::
* Abstract class for estimators that fit models to data.
*/
@AlphaComponent
abstract class Estimator[M <: Model[M]] extends PipelineStage with Params {

/**
Expand Down
3 changes: 3 additions & 0 deletions mllib/src/main/scala/org/apache/spark/ml/Evaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@

package org.apache.spark.ml

import org.apache.spark.annotation.AlphaComponent
import org.apache.spark.ml.param.ParamMap
import org.apache.spark.sql.SchemaRDD

/**
* :: AlphaComponent ::
* Abstract class for evaluators that compute metrics from predictions.
*/
@AlphaComponent
abstract class Evaluator extends Identifiable {

/**
Expand Down
4 changes: 4 additions & 0 deletions mllib/src/main/scala/org/apache/spark/ml/Identifiable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ package org.apache.spark.ml

import java.util.UUID

import org.apache.spark.annotation.AlphaComponent

/**
* :: AlphaComponent ::
* Object with a unique id.
*/
@AlphaComponent
trait Identifiable extends Serializable {

/**
Expand Down
3 changes: 3 additions & 0 deletions mllib/src/main/scala/org/apache/spark/ml/Model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@

package org.apache.spark.ml

import org.apache.spark.annotation.AlphaComponent
import org.apache.spark.ml.param.ParamMap

/**
* :: AlphaComponent ::
* A fitted model, i.e., a [[Transformer]] produced by an [[Estimator]].
*
* @tparam M model type
*/
@AlphaComponent
abstract class Model[M <: Model[M]] extends Transformer {
/**
* The parent estimator that produced this model.
Expand Down
7 changes: 7 additions & 0 deletions mllib/src/main/scala/org/apache/spark/ml/Pipeline.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ package org.apache.spark.ml
import scala.collection.mutable.ListBuffer

import org.apache.spark.Logging
import org.apache.spark.annotation.AlphaComponent
import org.apache.spark.ml.param.{Param, ParamMap}
import org.apache.spark.sql.{SchemaRDD, StructType}

/**
* :: AlphaComponent ::
* A stage in a pipeline, either an Estimator or an Transformer.
*/
@AlphaComponent
abstract class PipelineStage extends Serializable with Logging {

/**
Expand All @@ -49,6 +52,7 @@ abstract class PipelineStage extends Serializable with Logging {
}

/**
* :: AlphaComponent ::
* A simple pipeline, which acts as an estimator. A Pipeline consists of a sequence of stages, each
* of which is either an [[Estimator]] or a [[Transformer]]. When [[Pipeline.fit]] is called, the
* stages are executed in order. If a stage is an [[Estimator]], its [[Estimator.fit]] method will
Expand All @@ -59,6 +63,7 @@ abstract class PipelineStage extends Serializable with Logging {
* transformers, corresponding to the pipeline stages. If there are no stages, the pipeline acts as
* an identity transformer.
*/
@AlphaComponent
class Pipeline extends Estimator[PipelineModel] {

/** param for pipeline stages */
Expand Down Expand Up @@ -125,8 +130,10 @@ class Pipeline extends Estimator[PipelineModel] {
}

/**
* :: AlphaComponent ::
* Represents a compiled pipeline.
*/
@AlphaComponent
class PipelineModel(
override val parent: Pipeline,
override val fittingParamMap: ParamMap,
Expand Down
5 changes: 5 additions & 0 deletions mllib/src/main/scala/org/apache/spark/ml/Transformer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import scala.annotation.varargs
import scala.reflect.runtime.universe.TypeTag

import org.apache.spark.Logging
import org.apache.spark.annotation.AlphaComponent
import org.apache.spark.ml.param._
import org.apache.spark.sql.SchemaRDD
import org.apache.spark.sql.api.java.JavaSchemaRDD
Expand All @@ -30,8 +31,10 @@ import org.apache.spark.sql.catalyst.dsl._
import org.apache.spark.sql.catalyst.types._

/**
* :: AlphaComponet ::
* Abstract class for transformers that transform one dataset into another.
*/
@AlphaComponent
abstract class Transformer extends PipelineStage with Params {

/**
Expand Down Expand Up @@ -80,9 +83,11 @@ abstract class Transformer extends PipelineStage with Params {
}

/**
* :: AlphaComponent ::
* Abstract class for transformers that take one input column, apply transformation, and output the
* result as a new column.
*/
@AlphaComponent
abstract class UnaryTransformer[IN, OUT: TypeTag, T <: UnaryTransformer[IN, OUT, T]]
extends Transformer with HasInputCol with HasOutputCol with Logging {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.spark.ml.classification

import org.apache.spark.annotation.AlphaComponent
import org.apache.spark.ml._
import org.apache.spark.ml.param._
import org.apache.spark.mllib.classification.LogisticRegressionWithLBFGS
Expand All @@ -28,8 +29,10 @@ import org.apache.spark.sql.catalyst.dsl._
import org.apache.spark.storage.StorageLevel

/**
* :: AlphaComponent ::
* Params for logistic regression.
*/
@AlphaComponent
private[classification] trait LogisticRegressionParams extends Params
with HasRegParam with HasMaxIter with HasLabelCol with HasThreshold with HasFeaturesCol
with HasScoreCol with HasPredictionCol {
Expand Down Expand Up @@ -108,8 +111,10 @@ class LogisticRegression extends Estimator[LogisticRegressionModel] with Logisti
}

/**
* :: AlphaComponent ::
* Model produced by [[LogisticRegression]].
*/
@AlphaComponent
class LogisticRegressionModel private[ml] (
override val parent: LogisticRegression,
override val fittingParamMap: ParamMap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@

package org.apache.spark.ml.evaluation

import org.apache.spark.annotation.AlphaComponent
import org.apache.spark.ml._
import org.apache.spark.ml.param._
import org.apache.spark.mllib.evaluation.BinaryClassificationMetrics
import org.apache.spark.sql.{DoubleType, Row, SchemaRDD}

/**
* :: AlphaComponent ::
* Evaluator for binary classification, which expects two input columns: score and label.
*/
@AlphaComponent
class BinaryClassificationEvaluator extends Evaluator with Params
with HasScoreCol with HasLabelCol {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@

package org.apache.spark.ml.feature

import org.apache.spark.annotation.AlphaComponent
import org.apache.spark.ml.UnaryTransformer
import org.apache.spark.ml.param.{IntParam, ParamMap}
import org.apache.spark.mllib.feature
import org.apache.spark.mllib.linalg.Vector

/**
* :: AlphaComponent ::
* Maps a sequence of terms to their term frequencies using the hashing trick.
*/
@AlphaComponent
class HashingTF extends UnaryTransformer[Iterable[_], Vector, HashingTF] {

/** number of features */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.spark.ml.feature

import org.apache.spark.annotation.AlphaComponent
import org.apache.spark.ml._
import org.apache.spark.ml.param._
import org.apache.spark.mllib.feature
Expand All @@ -31,9 +32,11 @@ import org.apache.spark.sql.catalyst.dsl._
private[feature] trait StandardScalerParams extends Params with HasInputCol with HasOutputCol

/**
* :: AlphaComponent ::
* Standardizes features by removing the mean and scaling to unit variance using column summary
* statistics on the samples in the training set.
*/
@AlphaComponent
class StandardScaler extends Estimator[StandardScalerModel] with StandardScalerParams {

def setInputCol(value: String): this.type = set(inputCol, value)
Expand Down Expand Up @@ -66,8 +69,10 @@ class StandardScaler extends Estimator[StandardScalerModel] with StandardScalerP
}

/**
* :: AlphaComponent ::
* Model fitted by [[StandardScaler]].
*/
@AlphaComponent
class StandardScalerModel private[ml] (
override val parent: StandardScaler,
override val fittingParamMap: ParamMap,
Expand Down
8 changes: 8 additions & 0 deletions mllib/src/main/scala/org/apache/spark/ml/param/params.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ package org.apache.spark.ml.param

import java.lang.reflect.Modifier

import org.apache.spark.annotation.AlphaComponent

import scala.annotation.varargs
import scala.collection.mutable

import org.apache.spark.ml.Identifiable

/**
* :: AlphaComponent ::
* 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.
*
Expand All @@ -33,6 +36,7 @@ import org.apache.spark.ml.Identifiable
* @param doc documentation
* @tparam T param value type
*/
@AlphaComponent
class Param[T] (
val parent: Params,
val name: String,
Expand Down Expand Up @@ -102,9 +106,11 @@ class BooleanParam(parent: Params, name: String, doc: String, defaultValue: Opti
case class ParamPair[T](param: Param[T], value: T)

/**
* :: AlphaComponent ::
* Trait for components that take parameters. This also provides an internal param map to store
* parameter values attached to the instance.
*/
@AlphaComponent
trait Params extends Identifiable with Serializable {

/** Returns all params. */
Expand Down Expand Up @@ -198,8 +204,10 @@ private[ml] object Params {
}

/**
* :: AlphaComponent ::
* A param to value map.
*/
@AlphaComponent
class ParamMap private[ml] (private val map: mutable.Map[Param[Any], Any]) extends Serializable {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package org.apache.spark.ml.tuning
import com.github.fommil.netlib.F2jBLAS

import org.apache.spark.Logging
import org.apache.spark.annotation.AlphaComponent
import org.apache.spark.ml._
import org.apache.spark.ml.param.{IntParam, Param, ParamMap, Params}
import org.apache.spark.mllib.util.MLUtils
Expand Down Expand Up @@ -49,8 +50,10 @@ private[ml] trait CrossValidatorParams extends Params {
}

/**
* :: AlphaComponent ::
* K-fold cross validation.
*/
@AlphaComponent
class CrossValidator extends Estimator[CrossValidatorModel] with CrossValidatorParams with Logging {

private val f2jBLAS = new F2jBLAS
Expand Down Expand Up @@ -103,8 +106,10 @@ class CrossValidator extends Estimator[CrossValidatorModel] with CrossValidatorP
}

/**
* :: AlphaComponent ::
* Model from k-fold cross validation.
*/
@AlphaComponent
class CrossValidatorModel private[ml] (
override val parent: CrossValidator,
override val fittingParamMap: ParamMap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ package org.apache.spark.ml.tuning
import scala.annotation.varargs
import scala.collection.mutable

import org.apache.spark.annotation.AlphaComponent
import org.apache.spark.ml.param._

/**
* :: AlphaComponent ::
* Builder for a param grid used in grid search-based model selection.
*/
@AlphaComponent
class ParamGridBuilder {

private val paramGrid = mutable.Map.empty[Param[_], Iterable[_]]
Expand Down

0 comments on commit 6d97fe6

Please sign in to comment.