我将实现一种时间序列聚类方法,该方法的优化解决方案基于frank-wolfe算法。 我想通过python中的多处理库对其进行并行化,但是我面临以下问题:
Traceback (most recent call last):
File "/home/ridha/Downloads/pycharm-2018.1.2/helpers/pyde/pydev_run_in_console.py", line 52, in run_file
pydev_imports.execfile(file, globals, locals) # execute the script
File "/home/ridha/Desktop/TICC-FW/TICC-master/example.py", line 8, in <module>
(cluster_assignment, cluster_MRFs) = ticc.fit(input_file=fname)
File "/home/ridha/Desktop/TICC-FW/TICC-master/TICC_solver.py", line 111, in fit
train_cluster_inverse)
File "/home/ridha/Desktop/TICC-FW/TICC-master/TICC_solver.py", line 295, in optimize_clusters
val = optRes[cluster].get()
File "/home/ridha/anaconda2/lib/python2.7/multiprocessing/pool.py", line 572, in get
raise self._value
PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed
我的代码是:
probSize = self.window_size * size_blocks
lamb = np.zeros((probSize, probSize)) + self.lambda_parameter
S = np.cov(np.transpose(D_train))
empirical_covariances[cluster] = S
# rho = 1
lamb_vec = lamb.flatten()
lamb_vec_abs = np.absolute(lamb_vec)
s_vec = S.flatten()
aub = np.identity(probSize*probSize)
bub = np.ones(probSize*probSize)
def loss(x):
theta = np.reshape(x, (probSize, probSize))
det_theta = -np.linalg.det(theta)
return det_theta + (np.matmul(s_vec, x)) + (
np.matmul(lamb_vec_abs, np.absolute(x)))
solver = FrankWolfe(f=loss,
g=None, A_ub=aub, b_ub=bub, A_eq=None, b_eq=None, bounds=None,
tol=1.0E-12, gradient_delta=1.0E-10, iteration_limit=1000)
# solver.verbose = True
# apply to process pool
optRes[cluster] = pool.apply_async(solver)
我将不胜感激
答案 0 :(得分:0)
前一段时间,我在多处理上遇到了同样的问题,我现在使用的是名为pathos
的自定义多处理库,但是您必须自己编译该库,然后使用pip
安装它。在这整个麻烦之后,我发现无法腌制lambda。我在代码中只看到一些使用它的参数名称,但是看不到任何调用函数本身的函数,如果有,请尝试替换它。
还要避免在另一个方法或函数内部定义的任何方法或函数。