我正在嘗試計算特征方陣 ( Information_Gains_Matrix) 和相應的方權重矩陣 ( Weights_Matrix) 的莫蘭指數。對于中的每個特征,Information_Gains_Matrix我想在固定的情況下計算莫蘭指數Weights_Matrix。因此,我嘗試使用 multiprocessing pool.map 來處理Information_Gains_Matrix. 我可以讓代碼在小型測試數據集上以各種方式執行此操作。然而,當我使用實際的大數據集時,代碼運行,但隨后CPU使用率下降到0%,進程掛起,并且沒有任何釋放。import multiprocessingfrom multiprocessing import RawArray, Pool, Lockfrom functools import partial import numpy as np## Set up initial fake dataInformation_Gains_Matrix = np.random.uniform(0,1,(22000,22000))Weights_Matrix = np.random.uniform(0,1,(22000,22000))## Function I want to parallelise. def Feature_Moran_Index(Chunks,Wij,N): Moran_Index_Scores = np.zeros(Chunks.shape[0]) for i in np.arange(Chunks.shape[0]): print(Chunks[i]) # Print ind to show it's running Feature = Information_Gains_Matrix[Chunks[i],:] X_bar = np.mean(Feature) if X_bar != 0: Deviance = Feature - X_bar Outer_Deviance = np.outer(Deviance,Deviance) Deviance2 = Deviance * Deviance Denom = np.sum(Deviance2) Moran_Index_Scores[i] = (N/Wij) * (np.sum((W * np.ndarray.flatten(Outer_Deviance)))/Denom) return Moran_Index_Scores## Set up chunks inds for each core.Use_Cores = (multiprocessing.cpu_count()-2)Chunk_Size = np.ceil(Information_Gains_Matrix.shape[0] / Use_Cores)Range = np.arange(Information_Gains_Matrix.shape[0]).astype("i")Chunk_Range = np.arange(Chunk_Size).astype("i")Chunks = []for i in np.arange(Use_Cores-1): Chunks.append(Range[Chunk_Range]) Range = np.delete(Range,Chunk_Range)我對這種方法沒有忠誠度,如果有人可以幫助我以任何方式跨特征并行計算莫蘭指數,我將非常感激,因為我似乎無法讓它發揮作用。
1 回答

收到一只叮咚
TA貢獻1821條經驗 獲得超5個贊
在 中Feature_Moran_Index
,Deviance
具有形狀(22000,)
,并且Outer_Deviance
具有形狀(22000, 22000)
并使用 3.8GB 的 RAM。
數量
np.sum(W * np.ndarray.flatten(Outer_Deviance))
等于
np.sum(W_np * Outer_Deviance)
等于
Deviance @ W_np @ Deviance
將第一個表達式替換為最后一個表達式并刪除 的定義后Outer_Deviance
,您的程序將運行至完成,內存使用量為 c。11GB。
添加回答
舉報
0/150
提交
取消