JMP > JSL > 多次調用擬合模型的腳本加速(N > 2000)?您好 JMP 社區,
我的數據集越來越大,我之前創建的基本腳本(見下文)從速度的角度來看跟不上。
我將不勝感激聽到有關如何優化此類腳本以提高速度的想法。 例如,我懷疑像“Concatenate”這樣的操作相對較慢,對於這種類型的操作使用矩陣可能是有意義的。
Names Default to Here (1);
dt = Current Data Table ();
CList = dt << Get Column Names (string);
dtoutl = New Table ("LSM OUTPUT", "invisible");
dtoutp = New Table ("PVal OUTPUT", "invisible");
For (i = 1, i<= 2000, i++,
fm = dt << Fit Model(
Y( Column (i) ),
Effects( :VISIT, :TREATMENT, :VISIT * :TREATMENT, Column (i+2000) ),
Personality( "Standard Least Squares" ),
Emphasis( "Minimal Report" ),
Run(
Column (i) << {Summary of Fit( 1 ), Analysis of Variance( 1 ),
Parameter Estimates( 1 ), Scaled Estimates( 0 ),
Plot Actual by Predicted( 0 ), Plot Regression( 0 ),
Plot Residual by Predicted( 0 ), Plot Studentized Residuals( 0 ),
Plot Effect Leverage( 0 ), Plot Residual by Normal Quantiles( 0 ),
Box Cox Y Transformation( 0 ), {:VISIT * :TRT01A <<
{LSMeans Contrast( [0 0 1 -1 0 0, 0 0 0 0 1 -1] )}}}
)
);
fmr = report (fm);
table_list = fmr << xpath ("//OutlineBox [text() = 'VISIT*TREATMENT']//TableBox");
temp_lsm = table_list [1];
temp_pval = table_list [2];
temp_tbl_lsm = temp_lsm << Make into Data Table (invisible (1));
temp_tbl_pval = temp_pval << Make into Data Table (invisible (1));
temp_tbl_lsm << New column ("ID", character, nominal, << set each value (CList [i]));
temp_tbl_pval << New column ("ID", character, nominal, << set each value (CList [i]));
fmr << close window;
dtoutl << Concatenate (Data table (temp_tbl_lsm), "Append to First Table");
Wait (0);
dtoutp << Concatenate (Data table (temp_tbl_pval), "Append to First Table");
Close (temp_tbl_lsm, NoSave);
Close (temp_tbl_pval, NoSave);
);
dtoutl << Bring Window to Front;
dtoutp << Bring Window to Front;
歡迎所有反饋。
最好的事物,
TS
腳本編寫回复:JMP > JSL > 多次調用擬合模型的腳本加速(N > 2000)?您好 JMP 社區,
我已經嘗試將矩陣用作聚合分析輸出表的長集合的容器,到目前為止,我已將執行時間縮短了約 5 倍(見下文)。 唯一的小麻煩是我不得不為捕獲的輸出表重建註釋,因為(顯然)矩陣不包含文本。
Names Default to Here (1);
st = Today();
dt = Current Data Table ();
dts = dt << Summary( Group( :VISIT, :TRT01A ), Freq( "None" ), Weight( "None" ), invisible );
annot_lsm = {};
met_l = {};
annot_pv = {};
CList = dt << Get Column Names (string);
For (j = 1, j <= N Rows (dts), j++,
insert into (annot_lsm, dts:VISIT [j] || ", " || dts:TRT01A [j]);
);
annot_pv = annot_lsm;
annot_pv = Concat To(annot_pv, {"Estimate","Std Error", "t Ratio", "Prob>|t|", "SS", "Lower 95%", "Upper 95%"});
Close (dts, NoSave);
mtx_lsm = [];
mtx_pval = [];
For (i = 1, i<= 2000, i++, //2000
fm = dt << Fit Model(
Y( Column (i) ),
Effects( :VISIT, :TRT01A, :VISIT * :TRT01A, Column (i+2000) ),
Personality( "Standard Least Squares" ),
Emphasis( "Minimal Report" ),
Run(
Column (i) << {Summary of Fit( 1 ), Analysis of Variance( 1 ),
Parameter Estimates( 1 ), Scaled Estimates( 0 ),
Plot Actual by Predicted( 0 ), Plot Regression( 0 ),
Plot Residual by Predicted( 0 ), Plot Studentized Residuals( 0 ),
Plot Effect Leverage( 0 ), Plot Residual by Normal Quantiles( 0 ),
Box Cox Y Transformation( 0 ), {:VISIT * :TRT01A <<
{LSMeans Contrast( [0 0 1 -1 0 0, 0 0 0 0 1 -1] )}}}
)
);
fmr = report (fm);
insert into (met_l, CList [i]);
table_list = fmr << xpath ("//OutlineBox [text() = 'VISIT*TRT01A']//TableBox");
temp_lsm = table_list [1];
temp_pval = table_list [2];
temp_mtx_lsm = temp_lsm << Get as Matrix;
temp_mtx_pval = temp_pval << Get as Matrix;
fmr << close window;
mtx_lsm = mtx_lsm |/ temp_mtx_lsm;
mtx_pval = mtx_pval |/ temp_mtx_pval ;
);
dtoutl = as Table (mtx_lsm);
dtoutp = as Table (mtx_pval);
dtoutl << new column ("COMP", Character, Nominal);
dtoutl << new column ("MET_ID", Character, Nominal);
dtoutl:Col1 << set name ("LSMEAN");
dtoutl:Col2 << set name ("STDERR");
dtoutl:Col3 << set name ("UPPER CI");
dtoutl:Col4 << set name ("LOWER CI");
dtoutl << Begin Data Update;
For Each Row( dtoutl, :COMP = annot_lsm[Sequence( 1, N Items (annot_lsm), 1, 1 )] );
For each row( dtoutl, :MET_ID = met_l[Sequence (1,N Items (met_l), 1, 6)] );
dtoutl << End Data Update;
dtoutp << new column ("LABEL", Character, Nominal);
dtoutp << new column ("MET_ID", Character, Nominal);
dtoutp << Begin Data Update;
For Each Row( dtoutp, :LABEL = annot_pv[Sequence( 1, N Items (annot_pv), 1, 1 )] );
For each row( dtoutp, :MET_ID = met_l[Sequence (1,N items (met_l), 1, 13)] );
dtoutp << End Data Update;
回复:JMP > JSL > 多次調用擬合模型的腳本加速(N > 2000)?5X 聽起來很棒!
該平台可能還有一個隱形選項可能會有所幫助。
(試試 JSL 分析器,下一個建議可能會偏離基礎。 使用 < 1% 的時間來製作更快的東西是沒有意義的......)
如果仍然不夠,循環中的最後兩個語句可能是下一個要查看的地方。 我認為您的 JSL 正在以越來越大的尺寸重新分配數組 2000 次。 如果您可以預先分配數組(使用 J(nr,nc,initvalue) 函數)並使用類似 mtx_lsm[a::b,0] = temp_mtx_lsm[0,0] 的內容存儲到它們中,您將節省一些時間.
編輯:這可能是一個 N^2 問題,因為它不僅會重新分配,還會復制數據;從 1000 次運行到 2000 次運行將復制 4 倍(而不是 2 倍)的數據量。
回复:JMP > JSL > 多次調用擬合模型的腳本加速(N > 2000)?你好@Craige_Hales ,
謝謝你的建議。 多虧了你推薦的方法,我又提高了33%的速度。
還有一些我需要完善的調整,但我開始時的總運行時間約為 450 秒,初始更改時降至 91 秒,現在降至 61 秒。
最好的事物
TS
回复:JMP > JSL > 多次調用擬合模型的腳本加速(N > 2000)?涼爽的! 我認為社區希望看到您為實現目標所做的工作,或者總結不同更改的重要性。
@DonMcCormack