-
Notifications
You must be signed in to change notification settings - Fork 108
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
[linear-ridge-cholesky]使用 SPU 实现线性回归模型 #297
Conversation
Signed-off-by: magic-hya <huangya@asiainfo.com>
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
辛苦按照上方提示签订 CLA 哈 |
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.
Hi,除了 sml/linear_model 下的改动,.vscode 和 examples 下的请不要 commit
好的 |
Signed-off-by: magic-hya <huangya@asiainfo.com>
recheck |
I have read the CLA Document and I hereby sign the CLA |
recheck |
Hi @magic-hya Please use buildifier to format bazel files. Thanks |
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.
另外,sml对目录结构做了一次重构,麻烦您按照现在的目录结构有序放置文件,并修改对应的BUILD.bazel文件
感谢支持~
name = "ridge", | ||
srcs = ["ridge.py"], | ||
deps = [ | ||
"//sml/utils:fxp_approx", |
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.
fxp_approx似乎没有用到,可以去掉这个deps
sml/linear_model/ridge.py
Outdated
dot(X.T, X) | ||
""" | ||
|
||
def __init__(self, alpha=1.0, solver="lsqr") -> None: |
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.
还需要支持是否拟合bias项的选项
sml/linear_model/ridge.py
Outdated
if y.ndim == 1: | ||
y = y.reshape(-1, 1) | ||
alpha = jnp.asarray(self.alpha, dtype=x.dtype).ravel() | ||
print(f"<<<solver: {self.solver}") |
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.
算法主逻辑里不要加print语句吧
sml/linear_model/ridge_test.py
Outdated
|
||
x1, x2, y = dsutil.load_dataset_by_config(dataset_config) | ||
result = spsim.sim_jax(sim, proc)(x1, x2, y) | ||
print(result[:10]) |
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.
单元测试需要比较明文sklearn的结果~
sml/linear_model/ridge_emul.py
Outdated
|
||
# run | ||
result = emulator.run(proc)(x1, x2, y) | ||
print(result[:10]) |
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.
麻烦比较一下明文sklearn的结果,并注明一下误差大小~
|
||
|
||
class Solver(Enum): | ||
SVD = 'svd' # not supported |
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.
当前utils的extmath.py中有svd的实现,但是在定点代数下发现比较容易溢出,如果您有兴趣可以调用里面的api实现
sml/linear_model/ridge.py
Outdated
Xy = jnp.dot(x.T, y) | ||
|
||
for i in range(n_features): | ||
A = A.at[i, i].set(A[i][i] + alpha[0]) |
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.
直接加一个对角阵即可,无需循环赋值~
Signed-off-by: magic-hya <huangya@asiainfo.com>
1.添加了fit_bias选项
|
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.
另外,麻烦确保commit的代码已经:
使用black格式化过python代码,以及isort重排import语句
sml/linear_model/ridge.py
Outdated
|
||
from scipy import linalg | ||
from enum import Enum | ||
from scipy import linalg, sparse |
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.
cleanup一下import语句
sml/linear_model/ridge.py
Outdated
""" | ||
if y.ndim == 1: | ||
y = y.reshape(-1, 1) | ||
alpha = jnp.asarray(self.alpha, dtype=x.dtype).ravel() |
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.
似乎不必要转化为array?或许可以直接转化为float类型
sml/linear_model/tests/ridge_test.py
Outdated
|
||
|
||
class UnitTests(unittest.TestCase): | ||
def test_simple(self): |
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.
测试函数名可以改为:test_ridge,明确一下测试函数的语意
1.代码已使用black+isort格式化,请检查
|
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.
LGTM
What problem does this PR solve?
I have read the CLA Document and I hereby sign the CLA
Issue Number: Fixed #274
使用cholesky分解法实现ridge,在spu镜像中完成emul和test单元测试
Possible side effects?
在diabetes数据集上,与sklearn的误差在0.01-0.02之间