Ottimizza il cicloCIAO,
Ho del codice JSL che richiede molto tempo per essere eseguito per set di dati più grandi.
Il codice esegue un ciclo for all'interno di un ciclo for per calcolare l'offset medio per strisce. Sto cercando un modo più veloce per farlo.
C'è un modo per velocizzare l'elaborazione? Lo script corrente impiega circa 20 minuti per completare il ciclo
Ecco lo script qui sotto:
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 );
););
ScriptingRi: Ottimizza il loopGrazie mille Jim.
Ri: Ottimizza il loopHo modificato il tuo codice per ignorare l'elaborazione se la proprietà della colonna "theMean" non era stata impostata
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 );Ri: Ottimizza il loopCIAO @txnelson ,
C'è qualche problema nella logica che hai suggerito. Se la tabella dei dati di riferimento non contiene il test che si trova nella tabella dei dati principale, eliminerà i valori di riga da quei test. Ho solo per compensare il test che sono nella tabella dei dati di riferimento. Qualsiasi aiuto sarebbe molto apprezzato

Ho allegato le tabelle dei dati di seguito. Voglio solo compensare i test specificati nella tabella di riferimento
Ri: Ottimizza il loopGrazie Jim. Funziona come fascino
Ri: Ottimizza il loop@Jacksmith12 , non sono sicuro di quale sia il condizionale dt2:Strips == dt2Strips[r] dovrebbe risolversi, ma probabilmente non sta facendo quello che vuoi che faccia.
Senza alcun dato di test su cui testare, ecco come inizierei a ottimizzarlo: il principale è prendere il dt1 << Ottieni righe Where( :Test == nome ) al di fuori del giro.
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
)
Ri: Ottimizza il loopI 2 posti in cui vedo problemi sono i
mean = dt1:Mean[dt1 << Get Rows Where( :Tests == name )];
E
measure = mean - Col Mean( If( dt2:Strips == dt2:Strips[r], Column( dt2, c ), . ) );
Ecco una soluzione per i problemi Controllali e verifica se le risposte sono corrette
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);