-
-
Notifications
You must be signed in to change notification settings - Fork 255
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
Adding Multi-Task ElasticNet support #194
Conversation
@YuhanLiin i'm implementing the My question is how to restrict the trait bounds to implement the |
Is it possible to make functions like |
@YuhanLiin Thanks for all the remarks! I passed your comments on the latest commit. As for making
For |
Making |
let norm_cols_x = x.map_axis(Axis(0), |col| col.dot(&col)); | ||
let mut gap = F::one() + tol; | ||
let d_w_tol = tol; | ||
let tol = tol * y.fold(F::zero(), |sum, &y_ij| sum + y_ij.powi(2)); |
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.
Instead of fold
you can do y.iter().map(|x| x*x).sum()
. Since iter
is called before map
it won't create a new array. For 1D arrays it's even simpler since you can just call y.dot(&y)
to dot product y
with itself.
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.
You should also apply this change to all the other similar fold
calls
gap | ||
} | ||
|
||
fn variance_params<F: Float + Lapack, T: AsTargets<Elem = F>, D: Data<Elem = F>, I: Dimension>( |
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.
This AsTargets<Elem = F>
is very complex to deal with. I can't do much with it, since I need to have an ArrayBase
in order to call ndim()
, shape()
and to make the computation target - y_est
. Do you know how I can circumvent this issue? I don't understand the need for an AsTarget
trait in the first place. At least it should support multi-task targets.
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.
Actually it should have some way to retrieve the dimension of the targets.
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.
Currently AsTargets
has the method as_multi_targets
, which returns a 2D array view, so you can call it to retrieve the target for both cases. For the single target case this returns an array of dimension (n, 1). This means your code needs to treat single-task and multi-task-with-only-one-task as equivalent cases. y_est
will need to be a 2D array in all cases; for single-task just insert Axis(1)
into y_est
.
After your other PR, this should be bounded with AsMultiTargets
(now that I think about it, we need AsMultiTargets
as a super-trait of AsSingleTarget
for this to work).
@@ -429,7 +426,7 @@ fn duality_gap<'a, F: Float>( | |||
} else { | |||
(F::one(), r_norm2) | |||
}; | |||
let l1_norm = w.fold(F::zero(), |sum, w_i| sum + w_i.abs()); | |||
let l1_norm = w.map(|w_i| w_i.abs()).sum(); |
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.
Use dot
let w_norm2 = w.fold(F::zero(), |sum, &wij| sum + wij.powi(2)); | ||
let r_norm2 = r.map(|rij| rij.powi(2)).sum(); | ||
let w_norm2 = w.map(|wij| wij.powi(2)).sum(); |
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.
Call iter()
before map
to prevent creating a new array
Since #206 has been merged, ElasticNet is now easier to adapt to the multi-task case. I'm still working on it.
|
Work continued in #238 |
I am closing as superseded by #238 |
The goal of this PR is to add multi-task ElasticNet to the
elasticnet
crate.A quick roadmap: