Skip to content

Commit

Permalink
use singleton objects for label parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxr committed Apr 8, 2014
1 parent 3b1a7c6 commit ac44409
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,23 @@ trait LabelParser extends Serializable {
* Label parser for binary labels, which outputs 1.0 (positive) if the value is greater than 0.5,
* or 0.0 (negative) otherwise. So it works with +1/-1 labeling and +1/0 labeling.
*/
class BinaryLabelParser extends LabelParser {
object BinaryLabelParser extends LabelParser {
/** Gets the default instance of BinaryLabelParser. */
def getInstance(): LabelParser = this

/**
* Parses the input label into positive (1.0) if the value is greater than 0.5,
* or negative (0.0) otherwise.
*/
override def parse(labelString: String): Double = if (labelString.toDouble > 0.5) 1.0 else 0.0
}

object BinaryLabelParser extends BinaryLabelParser {
/** Gets the default instance of BinaryLabelParser. */
def getInstance(): BinaryLabelParser = this
}

/**
* Label parser for multiclass labels, which converts the input label to double.
*/
class MulticlassLabelParser extends LabelParser {
override def parse(labelString: String): Double = labelString.toDouble
}

object MulticlassLabelParser extends MulticlassLabelParser {
object MulticlassLabelParser extends LabelParser {
/** Gets the default instance of MulticlassLabelParser. */
def getInstance(): MulticlassLabelParser = this
def getInstance(): LabelParser = this

override def parse(labelString: String): Double = labelString.toDouble
}

0 comments on commit ac44409

Please sign in to comment.