Optimizar el bucleHola,
Tengo un código JSL que tarda mucho tiempo en ejecutarse para conjuntos de datos más grandes.
El código ejecuta un bucle for dentro de un bucle for para calcular el desplazamiento medio por tiras. Estoy buscando una manera más rápida de hacer esto.
¿Hay alguna manera de hacer que el procesamiento sea más rápido? El script actual tarda ~20 minutos en completar el ciclo
Aquí está el guión a continuación:
Names Default To Here( 1 );
dt1 =Data table( "Reference data table.jmp" );
dt2 = Current data table(); /// Select Data table.jmp
Col_List1 = dt2 << Get Column Names( "String" );
For( c = 1, c <= N Col( dt2 ) -1, c++,
theMatrix = [];
name = Column( Col_List1[c] ) << Get name;
if (Contains( Col_List1[c], "Currents" )| Contains( Col_List1[c], "Voltage" )| Contains( Col_List1[c], "Resistance" ),
For( r = 1, r <= N Rows( dt2 ), r++,
mean = dt1:Mean[dt1 << Get Rows Where( :Tests == name )];
measure = mean - Col Mean( If( dt2:Strips == dt2:Strips[r], Column( dt2, c ), . ) );
theMatrix = theMatrix || Column( dt2, c )[r] + measure;
);
Column( dt2, c ) << Set Values( theMatrix );
););
secuencias de comandosRe: Optimizar el bucleLos 2 lugares en los que veo problemas son los
mean = dt1:Mean[dt1 << Get Rows Where( :Tests == name )];
y
measure = mean - Col Mean( If( dt2:Strips == dt2:Strips[r], Column( dt2, c ), . ) );
Aquí hay una solución para los problemas. Revíselos y vea si las respuestas son correctas.
Names Default To Here( 1 );
start=today();
dt1 =Data table( "Reference data table.jmp" );
dt2 = Current data table(); /// Select Data table.jmp
For(i=1,i<=nrows(dt1),i++,
theTest = dt1:Tests[i];
try(column(dt2,theTest) << set property("TheMean", dt1:mean[i]));
);
Col_List1 = dt2 << Get Column Names( "String" );
For( c = 1, c <= N Col( dt2 ) -1, c++,
theMatrix = [];
name = Column( Col_List1[c] ) << Get name;
if (Contains( Col_List1[c], "Currents" )| Contains( Col_List1[c], "Voltage" )| Contains( Col_List1[c], "Resistance" ),
//For( r = 1, r <= N Rows( dt2 ), r++,
For Each Row( r=row();
//mean = dt1:Mean[dt1 << Get Rows Where( :Tests == name )];
mean = column(dt2,col_list1[c]) << get property("theMean");
//measure = mean - Col Mean( If( dt2:Strips == dt2:Strips[r], Column( dt2, c ), . ) );
measure = mean - Col Mean(as Column( dt2, c ),:Strips);
theMatrix = theMatrix || Column( dt2, c )[r] + measure;
);
Column( dt2, c ) << Set Values( theMatrix );
););
show((start-today())/60);
Re: Optimizar el bucle@Jacksmith12 , no estoy seguro de cuál es el condicional dt2:Tiras == dt2Tiras[r] se supone que debe resolverse, pero probablemente no esté haciendo lo que usted quiere que haga.
Sin ningún dato de prueba para probar, así es como comenzaría a optimizar esto: el principal es tomar el dt1 << Obtener Filas Donde( :Pruebas == nombre ) fuera del bucle.
Names Default to Here( 1 );
dt1 = Data Table( "Reference Data Table.jmp" );
dt2 = Current Data Table();
col list1 = dt2 << Get Column Names( "String" );
Summation( c = 1, N Col( dt2 ) - 1, //summation is faster that For() if you don't need to use Break() or Continue()
values = [];
name = Column( dt2, c ) << Get Name;
If( Contains( name, "Currents" ) | Contains( name, "Voltage" ) | Contains( name, "Resistance" ),
rows = dt1 << Get Rows Where( :tests == name ); // As Constant() prevents JMP from doing a lookup per row
col = Column( dt2, c );
col mean = Col Mean( col );
For Each Row( dt2,
mean = dt1:Mean[rows];
measure = mean - If( dt2:Strips == dt2:Strips /* always true */, col mean, 0 );
values |/= col[] + measure // append value to
);
col << Set Values( values )
);
0 // summation needs to end in a numeric
)
Re: Optimizar el bucleGracias Jim funciona como un encanto
Re: Optimizar el bucleHola @txnelson ,
Hay algún problema en la lógica que sugirió. Si la tabla de datos de referencia no contiene las pruebas que están en la tabla de datos principal, eliminará los valores de fila de esas pruebas. Solo para compensar las pruebas que están en la tabla de datos de referencia. Cualquier ayuda sería muy apreciada

He adjuntado las tablas de datos a continuación. Solo quiero compensar las pruebas que se especifican en la tabla de referencia.
Re: Optimizar el bucleModifiqué su código para omitir el procesamiento si la propiedad de columna "theMean" no se había establecido
Names Default To Here( 1 );
start = Today();
dt1 = Data Table( "Reference data table.jmp" );
dt2 = Current Data Table(); /// Select Data table.jmp
For( i = 1, i <= N Rows( dt1 ), i++,
theTest = dt1:Tests[i];
Try( Column( dt2, theTest ) << set property( "TheMean", dt1:mean[i] ) );
);
Col_List1 = dt2 << Get Column Names( "String" );
For( c = 1, c <= N Col( dt2 ) - 1, c++,
theMatrix = [];
name = Column( Col_List1[c] ) << Get name;
If( Contains( Col_List1[c], "Currents" ) | Contains( Col_List1[c], "Voltage" ) | Contains( Col_List1[c], "Resistance" ),
//For( r = 1, r <= N Rows( dt2 ), r++,
mean = .;
Try( mean = Column( dt2, col_list1[c] ) << get property( "theMean" ) );
// Don't process if a value for theMean does not exist
If( Is Missing( mean ) == 0,
For Each Row(
r = Row();
//mean = dt1:Mean[dt1 << Get Rows Where( :Tests == name )];
//measure = mean - Col Mean( If( dt2:Strips == dt2:Strips[r], Column( dt2, c ), . ) );
measure = mean - Col Mean( As Column( dt2, c ), :Strips );
theMatrix = theMatrix || Column( dt2, c )[r] + measure;
);
Column( dt2, c ) << Set Values( theMatrix );
);
);
);
Show( (start - Today()) / 60 );Re: Optimizar el bucleMuchas gracias Jim.