当我试图发展一个梯度下降,我发现了一个有趣的问题,我不能有效地使用**kwargs。我的功能看起来像
def gradient_descent(g,x,y,alpha,max_its,w,**kwargs):
# switch for verbose
verbose = True
if 'verbose' in kwargs:
verbose = kwargs['verbose']
# determine num train and batch size
num_train = y.size()[1]
batch_size = num_train
if 'batch_size' in kwargs:
batch_size = kwargs['batch_size']
........
错误看起来像:
^{pr2}$类型错误:gradient_descent()接受6个位置参数,但给出了8个。
有什么我没注意到的吗?在
您的函数签名与使用它的参数数目不匹配:
有6个位置参数
^{pr2}$g,x,y,alpha,max_its,w
,但是,在您的调用中:你给了它8
g,x_train,y_train,alpha_choice,max_its,w_train,num_pts,batch_size
我猜你想用
num_pts
作为batch_size
参数,所以它看起来像这样:相关问题 更多 >
编程相关推荐