-
Notifications
You must be signed in to change notification settings - Fork 8
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
API discussion #17
Comments
|
Ok, on the API front I'll just follow your lead, if you think it's worth experimenting with a struct Simple <: CovarianceEstimator
corrected::Bool
end
Simple() = Simple(false)
Simple(corrected=false) = Simple(corrected)
Simple(; corrected=false) = Simple(corrected) Ok for (2, 3 and 4). I think for (3) what we can do now is just keep track of them in the docstrings of the methods and update over time if the methods are improved. I'll try adding a few of those. |
Another note: I'm currently looking at http://strimmerlab.org/publications/journals/shrinkcov2005.pdf the nice thing is that it suggests all 6 common targets for linear-shrinkage estimator (table 2 p11). Target They show the optimal shrinkage intensity for all forms using Ledoit Wolf's theorem which is quite neat. (I should check numerically that their nice formula for the optimal intensity corresponds to what we've computed in which case it's quite a bit simpler). Anyway this may suggest a more generic API maybe for
Otherwise we'll end up with estimators with names |
Merging The six targets and optimal shrinking coefficients in that paper look really neat. Good work! I like the idea of a more generic API. I've started working on it here: https://github.com/mateuszbaran/CovarianceEstimation.jl/commits/new-api-test . It make things like |
Maybe targets can just be symbols instead of empty structs? and on top of that you'd want to be able to allow synonyms for the targets so that a user can refer to them using different ways (I think we should kind of maybe inspire ourselves from DiffEq and how they do to list all of the bazillion of ODE solvers that are out there) Maybe something like this? const Shrinkage = Union{Symbol, Real}
struct LinearShrinkage <: CovarianceEstimator
shrinkage::Shrinkage
target::Symbol
# constructors with checks
end and then maybe have acceptable targets in a big Dictionary allowing for synonyms like const targets = Dict{String, Symbol}(
"ledoitwolf" ==> :constant_correlation,
"constant-correlation" ==> :constant_correlation,
# ...
) with relevant function lw_optimalshrinkage(target, args...)
target == :constant_correlation && lw_optimalshrinkage_constant_correlation(args...)
target == : ... # etc.
end and then eventually cov(X, method = LinearShrinkage(), X) # defaults to Ledoitwolf with optimal shrinkage
cov(X, method = LinearShrinkage(target="constant-correlation", shrinkage=0.5)) and variants? Either way I think this can mature a bit as we go, it doesn't prevent us from coding the methods and refactoring later :) |
Actually, DiffEq uses a ton of empty structs: https://github.com/JuliaDiffEq/OrdinaryDiffEq.jl/blob/master/src/algorithms.jl . It's primarily for polymorphic dispatch. In my proposal you can easily add a new target/shrinkage estimation method by adding a new method to Here:
It's not a good idea to keep And I don't really see the benefit of referring to targets by I'd really like to use polymorphic dispatch for I agree API design shouldn't be rushed. Modifying it will be much less work than actually implementing algorithms :). |
Ok cool, that makes sense to me. I'm not familiar with Re performance issue, I don't think it matters given that we're not doing operations on I'll merge your |
…on linear shrinkage targets with lw shrinkage
Great! Apart from #18 I'm going to work on nonlinear Ledoit-Wolf estimator soon so we'll see how this API works in practice. You are right, this is a minor performance issue. Anyway I think it's better to make the type concrete here than to worry where exactly it's going to be optimized. Functions in Julia tend to have non-concretely typed arguments so this type instability could propagate quite far. BTW, |
A few comments/questions
Simple
,Uncorrected
are a bit useless, would it maybe make sense to have something that's closer to the initialcov
call such as:prec(X, ...)
orprec(::Method, X)
? (by the way I've added a few other methods to Other covariance estimators #8)The text was updated successfully, but these errors were encountered: