JMP> JSL> Aceleración de scripts para múltiples llamadas al modelo de ajuste (N> 2000)?Hola, comunidad de JMP:
El tamaño de mis conjuntos de datos es cada vez mayor y los scripts básicos que creé hace un tiempo (ver más abajo) no se mantienen al día desde el punto de vista de la velocidad.
Agradecería mucho escuchar ideas sobre cómo optimizar este tipo de script para mejorar la velocidad. Por ejemplo, sospecho que operaciones como "Concatenar" son relativamente lentas y podría tener sentido trabajar con matrices para este tipo de operación.
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;
Todos los comentarios son bienvenidos.
Mejor,
TS
ScriptingRe: JMP> JSL> Aceleración de scripts para múltiples llamadas para ajustar el modelo (N> 2000)?Hola, comunidad de JMP:
He experimentado con matrices como receptáculos para agregar colecciones largas de tablas de salida de análisis, y hasta ahora he acelerado mi tiempo de ejecución en ~ 5 veces (ver más abajo). El único inconveniente menor es que tuve que reconstruir las anotaciones para las tablas de salida capturadas porque (obviamente) las matrices no contienen texto.
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;
Re: JMP> JSL> Aceleración de scripts para múltiples llamadas para ajustar el modelo (N> 2000)?¡5X suena genial!
También puede haber una opción invisible para la plataforma que podría ayudar.
(Pruebe el generador de perfiles JSL, la siguiente sugerencia puede estar fuera de lugar. No tiene sentido hacer algo más rápido que use <1% del tiempo ...)
Si aún no es suficiente, las dos últimas declaraciones del ciclo pueden ser el siguiente lugar para buscar. Creo que su JSL está reasignando las matrices 2000 veces en tamaños progresivamente más grandes. Si puede preasignar las matrices (usando la función J (nr, nc, initvalue)) y almacenarlas en ellas con algo como mtx_lsm [a :: b, 0] = temp_mtx_lsm [0,0], ahorrará algo de tiempo .
Editar: esto es potencialmente un problema N ^ 2 porque no solo se reasigna, también copia los datos; Pasar de una ejecución de 1000 a una ejecución de 2000 copiará 4 veces (no 2 veces) la cantidad de datos.
Re: JMP> JSL> Aceleración de scripts para múltiples llamadas para ajustar el modelo (N> 2000)?Hola @Craige_Hales ,
Gracias por la sugerencia. Gracias al método que me recomendó, he mejorado la velocidad en otro 33%.
Todavía hay algunos ajustes que necesito perfeccionar, pero comencé con un tiempo de ejecución total de aproximadamente 450 segundos, bajé a 91 segundos con mis cambios iniciales, y bajé a 61 segundos ahora.
Mejor
TS
Re: JMP> JSL> Aceleración de scripts para múltiples llamadas para ajustar el modelo (N> 2000)?¡Frio! Creo que a la comunidad le gustaría ver qué hiciste para llegar allí, o tal vez resumir la importancia de los diferentes cambios.
@DonMcCormack