-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Optional arg and Regression interface. #131
Conversation
- Renamed spec type to usage. - Created special constructors for regression models to hide the optional arguments. Each type is now defined only in that module and does not pollute the main Regression module. - Changed to using polymorphic variants to express regularizers.
Before: #show_module Regression ;;
module Regression :
sig
module type Linear_model_intf =
sig
type spec
val default : spec
type input
type t
val describe : t -> string
val eval : t -> input -> float
val regress : ?spec:spec -> input array -> resp:float array -> t
val residuals : t -> float array
val coefficients : t -> float array
val residual_standard_error : t -> float
val coeff_of_determination : t -> float
val confidence_interval : t -> alpha:float -> input -> float * float
val prediction_interval : t -> alpha:float -> input -> float * float
val coefficient_tests : ?null:float -> t -> Inference.test array
val f_statistic : t -> float
end
module Univariate : sig end
type lambda_spec = Spec of float | From of float array
type multivariate_spec = { add_constant_column : bool; lambda_spec : lambda_spec option; }
module Multivariate : sig end
type tikhonov_spec = { regularizer : float array array; lambda_spec : lambda_spec option; }
module Tikhonov : sig end
end
utop # #show_module Regression.Multivariate ;;
module Multivariate :
sig
type spec = Regression.multivariate_spec
val default : spec
type input = float array
type t
val describe : t -> string
val eval : t -> input -> float
val regress : ?spec:spec -> input array -> resp:float array -> t
val residuals : t -> float array
val coefficients : t -> float array
val residual_standard_error : t -> float
val coeff_of_determination : t -> float
val confidence_interval : t -> alpha:float -> input -> float * float
val prediction_interval : t -> alpha:float -> input -> float * float
val coefficient_tests : ?null:float -> t -> Inference.test array
val f_statistic : t -> float
val aic : t -> float
val press : t -> float
end After: utop # #show_module Regression ;;
module Regression :
sig
module type Linear_model_intf =
sig
type opt
val default : opt
type input
type t
val describe : t -> string
val eval : t -> input -> float
val regress : ?opt:opt -> input array -> resp:float array -> t
val residuals : t -> float array
val coefficients : t -> float array
val residual_standard_error : t -> float
val coeff_of_determination : t -> float
val confidence_interval : t -> alpha:float -> input -> float * float
val prediction_interval : t -> alpha:float -> input -> float * float
val coefficient_tests : ?null:float -> t -> Oml.Inference.test array
val f_statistic : t -> float
end
module Univariate : sig end
module Multivariate : sig end
module Tikhonov : sig end
end
utop # #show_module Regression.Univariate ;;
module Univariate :
sig
type opt = float array
val opt : ?weights:float array -> unit -> opt
val default : opt
type input = float
type t
val describe : t -> string
val eval : t -> input -> float
val regress : ?opt:opt -> input array -> resp:float array -> t
val residuals : t -> float array
val coefficients : t -> float array
val residual_standard_error : t -> float
val coeff_of_determination : t -> float
val confidence_interval : t -> alpha:float -> input -> float * float
val prediction_interval : t -> alpha:float -> input -> float * float
val coefficient_tests : ?null:float -> t -> Oml.Inference.test array
val f_statistic : t -> float
val alpha : t -> float
val beta : t -> float
val alpha_test : ?null:float -> t -> Oml.Inference.test
val beta_test : ?null:float -> t -> Oml.Inference.test
end
utop # #show_module Regression.Multivariate ;;
module Multivariate :
sig
type opt = { add_constant_column : bool; l2_regularizer : [ `From of float array | `S of float ] option; }
val opt : ?l2_regularizer:[ `From of float array | `S of float ] -> ?add_constant_column:bool -> unit -> opt
val default : opt
type input = float array
type t
val describe : t -> string
val eval : t -> input -> float
val regress : ?opt:opt -> input array -> resp:float array -> t
val residuals : t -> float array
val coefficients : t -> float array
val residual_standard_error : t -> float
val coeff_of_determination : t -> float
val confidence_interval : t -> alpha:float -> input -> float * float
val prediction_interval : t -> alpha:float -> input -> float * float
val coefficient_tests : ?null:float -> t -> Oml.Inference.test array
val f_statistic : t -> float
val aic : t -> float
val press : t -> float
end |
@@ -63,7 +63,7 @@ module Univariate = struct | |||
; inferred_var : float (* inferred variance of error. *) | |||
; s_yy : float (* sum of diff or resp to mean, TSS. *) | |||
; s_xx : float (* sum of diff of pred to mean. *) | |||
; goodness_of_fit : float option | |||
(*; goodness_of_fit : float option *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just delete?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No particular good reason, laziness I guess. I already filed an issue #130 that should address this.
This looks great, definitely seems simpler to me. |
Refactor Optional arg and Regression interface.
optional arguments. Each type is now defined only in that module and
does not pollute the main Regression module.