Skip to content
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

Merged
merged 1 commit into from
Jan 29, 2016
Merged

Conversation

rleonid
Copy link
Owner

@rleonid rleonid commented Jan 29, 2016

  • 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.

- 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.
@rleonid
Copy link
Owner Author

rleonid commented Jan 29, 2016

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 *)
Copy link

Choose a reason for hiding this comment

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

Why not just delete?

Copy link
Owner Author

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.

@ihodes
Copy link

ihodes commented Jan 29, 2016

This looks great, definitely seems simpler to me.

rleonid added a commit that referenced this pull request Jan 29, 2016
Refactor Optional arg and Regression interface.
@rleonid rleonid merged commit d29b56f into master Jan 29, 2016
@rleonid rleonid deleted the refine_regression branch January 29, 2016 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants