Skip to content
Prev Previous commit
Next Next commit
Make Link as object
  • Loading branch information
yanboliang committed Jan 11, 2016
commit abed2f36ea3e0c9326f820a44035952f2035b1fa
10 changes: 5 additions & 5 deletions mllib/src/main/scala/org/apache/spark/ml/optim/GLMFamilies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private[ml] abstract class Family(val link: Link) extends Serializable {
* The default link for the Binomial family is the logit link.
* @param link a link function instance
*/
private[ml] class Binomial(link: Link = new Logit) extends Family(link) {
private[ml] class Binomial(link: Link = Logit) extends Family(link) {

override def startingMu(y: Double, yMean: Double): Double = (y + 0.5) / 2.0

Expand All @@ -74,7 +74,7 @@ private[ml] class Binomial(link: Link = new Logit) extends Family(link) {
* The default link for the Poisson family is the log link.
* @param link a link function instance
*/
private[ml] class Poisson(link: Link = new Log) extends Family(link) {
private[ml] class Poisson(link: Link = Log) extends Family(link) {

override def deviance(y: RDD[Double], mu: RDD[Double]): Double = {
mu.zip(y).map { case (mu, y) =>
Expand All @@ -92,7 +92,7 @@ private[ml] class Poisson(link: Link = new Log) extends Family(link) {
/**
* A description of the link function to be used in the model.
*/
private[ml] abstract class Link extends Serializable {
private[ml] trait Link extends Serializable {

/** The link function. */
def link(mu: Double): Double
Expand All @@ -104,7 +104,7 @@ private[ml] abstract class Link extends Serializable {
def unlink(eta: Double): Double
}

private[ml] class Logit extends Link {
private[ml] object Logit extends Link {

override def link(mu: Double): Double = math.log(mu / (1.0 - mu))

Expand All @@ -113,7 +113,7 @@ private[ml] class Logit extends Link {
override def unlink(eta: Double): Double = 1.0 / (1.0 + math.exp(-1.0 * eta))
}

private[ml] class Log extends Link {
private[ml] object Log extends Link {

override def link(mu: Double): Double = math.log(mu)

Expand Down