Skip to content
Closed
Prev Previous commit
Next Next commit
reviewer comments
  • Loading branch information
dorx committed Aug 1, 2014
commit e6b83f35375701f71f699697a83236e7e0c76d6c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ trait TestResult {
* Specific classes implementing this trait should override this method to output test-specific
* information.
*/
def explain: String = {
s"pValue = $pValue \n" +
override def toString: String = {
s"pValue = $pValue \n" + // TODO explain what pValue is
s"degrees of freedom = $degreesOfFreedom \n" +
s"statistic = $statistic"
}
Expand All @@ -47,14 +47,14 @@ trait TestResult {
* :: Experimental ::
*/
@Experimental
class ChiSquaredTestResult(override val pValue: Double,
case class ChiSquaredTestResult(override val pValue: Double,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need to be a case class? Scala compiler will add many methods to a case class and make it very hard to extend.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Case class is a logical choice here since it's essentially an immutable object holding a bunch of invariant fields and doesn't do any stateful computations inside of the class. Is there development plan for extending this classes in the future?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No case class features are used, especially pattern matching. This case class will extend Product5 and make it impossible to add a field, for example, whether correction is used or not. Also, with a case class, it is very hard to add a static method. We might want to write the test result to JSON and later parse it back. A natural choice would be ChiSquaredTestResult.fromJSON(json: String) but it is very complicated to match the type signature generated by Scala's compiler. We had this problem with LabeledPoint in MLlib, which is a public case class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, shall we rename it to ChiSqTestResult? So chiSqTest() returns ChiSqTestResult.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether correction is used or not can actually be reflected in the method name (pearson v yates). I doubt there's a lot of use cases for parsing the result back from JSON so let's not worry about it for now (also, don't static methods usually come in the companion object anyway?). The way I see case classes is that they're like data structs that encapsulates immutable fields (the list of fields can be modified in later releases given that this is all experimental) and we get free getter methods for constructor arguments with a case class, but if there are compiler optimization complications, I can change it to a regular class.

override val degreesOfFreedom: Array[Int],
override val statistic: Double,
val method: String) extends TestResult {

override def explain: String = {
override def toString: String = {
"Chi squared test summary: \n" +
s"method: $method \n" +
super.explain
super.toString
}
}