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
added lightning.KernelSVC (binary only) #176
Conversation
feature_norm = ast.SqrtExpr( | ||
utils.apply_op_to_expressions( | ||
ast.BinNumOpType.ADD, | ||
*[utils.mul(ast.FeatureRef(i), ast.FeatureRef(i)) | ||
for i in range(len(support_vector))]), | ||
to_reuse=True) |
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.
Have no idea how to avoid zero norm 🙁
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.
What is the lighting's behavior for zero feature vector norm? Can we get away with the same logic that we use for Support Vector norm?
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.
It relies on scikit-learn code:
https://github.com/scikit-learn/scikit-learn/blob/95d4f0841d57e8b5f6b2a570312e9d832e69debc/sklearn/metrics/pairwise.py#L1169-L1173
https://github.com/scikit-learn/scikit-learn/blob/95d4f0841d57e8b5f6b2a570312e9d832e69debc/sklearn/preprocessing/_data.py#L1730
https://github.com/scikit-learn/scikit-learn/blob/95d4f0841d57e8b5f6b2a570312e9d832e69debc/sklearn/preprocessing/_data.py#L63-L78
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.
If I understand the logic correctly it does the same thing (falls back to 1.0), shall we do the same here?
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.
To be honest, I'm not sure that complicating generated code in a such way worth it...
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.
I'd say we should always prefer correctness even if it means a slightly more complex code. Btw, does it really become that complex? Especially considering that we reuse the expression (to_reuse=True) here. AST doesn't look bad at all. Thanks for implementing this! 👍
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.
we should always prefer correctness even if it means a slightly more complex code.
Yeah, no doubt!
In languages which implement to_reuse=True
it looks OK, but if they don't... Though, there are many other places where without caching code looks terrible.
I thought about more elegant solution, but didn't come to any.
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.
I thought about more elegant solution, but didn't come to any.
Well, TBH, the existing solution looks more than good to me at least at this point 👍
feature_norm = ast.SqrtExpr( | ||
utils.apply_op_to_expressions( | ||
ast.BinNumOpType.ADD, | ||
*[utils.mul(ast.FeatureRef(i), ast.FeatureRef(i)) | ||
for i in range(len(support_vector))]), | ||
to_reuse=True) |
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.
What is the lighting's behavior for zero feature vector norm? Can we get away with the same logic that we use for Support Vector norm?
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.
Fantastic addition to the catalog, thank you 👍 A few minor comments
Let's add a fallback logic for the feature norm and this is good to go. Thanks for addressing comments 👍 |
be4fde2
to
91d0c3f
Compare
ast.NumVal(0.0), | ||
ast.CompOpType.EQ), | ||
ast.NumVal(1.0), | ||
ast.SqrtExpr( |
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.
[Nitpick] This part can be extracted into a separate variable and cached, this way making expected AST a little simpler:
feature_norm = ast.SqrtExpr(
ast.BinNumExpr(
ast.FeatureRef(0),
ast.FeatureRef(0),
ast.BinNumOpType.MUL),
to_reuse=True)
...
ast.IfExpr(
ast.CompExpr(
feature_norm,
ast.NumVal(0.0),
ast.CompOpType.EQ),
ast.NumVal(1.0),
feature_norm)
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.
Sure, will do this in a separate PR.
Refer to #172 (comment).
KernelSVC
is the last model fromlightning
library that can be added tom2cgen
.Adding only binary classification to not make PR too huge.