JMP社群的各位朋友,大家好!
在我的 JSL 腳本中,我經常像這樣逐列生成:
...
DT << New Column( "Some Name1", Numeric, "Continuous", Formula( Some Formula1 ) );
DT << New Column( "Some Name2", Numeric, "Continuous", Formula( Some Formula2 ) );
DT << New Column( "Some Name3", Numeric, "Continuous", Formula( Some Formula3 ) );
...
通常我的資料表非常大,可以達到上億行。我使用的公式經常包含統計函數,例如列平均值 (Col Mean()) 、列最大值 (Col Maximum())等,這導致行數越多,計算速度就越慢。可能有些新列之間存在依賴關係,但請暫時假設它們之間沒有依賴關係。
我的腳本運行結果顯示,JMP 19.1 只使用了我 16 核心 32 個執行緒的 CPU 3-4%。
是否可以加速計算(例如透過並行化),但無需建立子集並合併子集結果?我能否在 JMP 中使用 JSL 並行處理同一個資料表?
如果不行,你認為「子集公式計算-合併」的方法值得一試嗎?
乾杯
搶
根據您的計算(以及是否需要公式),您可以建立一個總計表,在其中進行計算,然後將結果更新回您的表格。
有一個工具可以用來管理矩陣的平行化:並行分配。
除非你基於少量輸入列創建大量新列,而且你使用的函數非常有限,否則我不確定這是否真的能加快速度。
以下是一個例子:
Names default to here(1);
dt = Open("$Sample_data/Pollen.jmp");
//first a simple demo of parallel assign to calculate column means
moutmeans = J(n col(dt), 1, .); //blank matrix that will be populated
mdata = dt << get as matrix; //input data as a matrix
Parallel Assign(
{ mdata = mdata }, //variables needed in the 'worker thread'
moutmeans[a, b] = mean(mdata[0,a]); //this fills in one cell
);
show(moutmeans); //col means are here
// Now for new columns
//mdata = mdata[1::2,0]; //a way to start small if you add show()
nrows = nrow(mdata);
cnames = dt << get column names(); //used to find position of columns in matrix
// Write formulas for each columns using column names as placeholders
// to be replaced by matrix values later, this would work for pretty simple logic
formulas = Eval List({
Expr(edge + nub + 10),
Eval Expr(nub - Expr( col mean(dt:nub) ) ) //note this col mean evaluates now
});
newcnames = {"a","b"}; //new column names used later
mout = J(nrows, length(formulas), .); //empty matrix to populate
Parallel Assign(
{
mdata = mdata,
formulas = formulas,
cnames = cnames
},
mout[a, b] = (
f = formulas[b];
//assign values to all potential variables used in matricies
//(bad idea if lots of unused columns)
for(i=1, i<= n items(cnames), i++,
//Make a list with the variable to assign and value to assign it to,
// then replace the list with assign
Eval( Substitute(
Eval List( {as name( name expr( cnames[i] ) ), mdata[a,i]} ),
Expr({}),
Expr( assign() )
) );
);
eval(f);
);
);
//put new columns in table
for each({c,i}, newcnames, dt << New Column(c,Numeric,Continuous, << Set Values(mout[0,i])));
//add columns to double check it worked
dt << New Column("a-check", Numeric, "Continuous", Format("Best", 12), Formula(:edge + :nub + 10));
dt << New Column("b-check", Numeric, "Continuous", Format("Best", 12), Formula(:nub - Col Mean(:nub)));
您可以嘗試在建立所有欄位之前抑制公式計算,然後再使用「執行公式」。