Hello,
I want to optimize the calculation. I tried both Col Formula and Loop but neither of them seem to be faster for rows > 10k.
I compared the exe speed and both of them take a very long time
Col Formula = 500.46s;
Loop = 491.70s;
Is there a way to optimize using Matrix or J trans?
Names Default To Here( 1 );
dt = Current Data Table();
testColumn = Column( "Test_A" );
slidervalue = 6;
////UsingFormula
start = Tick Seconds();
dt << New Column( "LL_formula",
Numeric,
Continuous,
Formula(
If( Row() < 200, // Skip the first 200 rows
.
,
current_device = :DeviceNumber; // Get the current site number
current_site = :SiteNumber;
// Get the indices of rows that match the current SiteNumber
matching_rows = Where( :DeviceNumber == current_device | :SiteNumber == current_site );
// Determine the start and end positions for the moving window
start_row = Max( 1, Row() - 199 );
end_row = Row();
// Get the moving window data for matching rows
m = Subscript( Expr( testColumn ), matching_rows[Loc( matching_rows >= start_row & matching_rows <= end_row )] );
//m = testColumn[Max( 1, Row() - 199 ) :: Row()];
// Calculate the quantiles and IQR
q1 = Quantile( 0.25, m );
q3 = Quantile( 0.75, m );
// Calculate the lower limit using the sigma function
q1 - (q3 - q1) * (slidervalue - 0.675) / 1.35;
)
)
);
dt << New Column( "UL_formula",
Numeric,
Continuous,
Formula(
If( Row() < 200,
., // Skip the first 200 rows
// Get the moving window data for matching rows
current_device = :DeviceNumber; // Get the current site number
current_site = :SiteNumber;
// Get the indices of rows that match the current SiteNumber
matching_rows = Where( :DeviceNumber == current_device | :SiteNumber == current_site );
start_row = Max( 1, Row() - 199 );
end_row = Row();
m = Subscript( Expr( testColumn ), matching_rows[Loc( matching_rows >= start_row & matching_rows <= end_row )] );
//m = testColumn[Max( 1, Row() - 199 ) :: Row()];
// Calculate the quantiles and IQR
q1 = Quantile( 0.25, m );
q3 = Quantile( 0.75, m );
// Calculate the upper limit using the sigma function
q3 + (q3 - q1) * (slidervalue - 0.675) / 1.35;
)
)
);
end = Tick Seconds();
Show( end - start );
///UsingLoop
start2 = Tick Seconds();
llColX = dt << New Column( "LL_loop", Numeric );
ulColX = dt << New Column( "UL_loop", Numeric );
For Each Row(
dt,
If( Row() < 200,
.,
// Skip the first 200 rows
current_device = :DeviceNumber[Row()]; // Get the current site number
current_site = :SiteNumber[Row()];
// Get the indices of rows that match the current SiteNumber
matching_rows = Where( :DeviceNumber == current_device | :SiteNumber == current_site );
// Determine the start and end positions for the moving window
start_row = Max( 1, Row() - 199 );
end_row = Row();
// Get the moving window data for matching rows
m2 = Subscript( testColumn, matching_rows[Loc( matching_rows >= start_row & matching_rows <= end_row )] );
//m = testColumn[Max( 1, Row() - 199 ) :: Row()];
// Calculate the quantiles and IQR
q1 = Quantile( 0.25, m2 );
q3 = Quantile( 0.75, m2 );
// Calculate the lower limit using the sigma function
llColX[Row()] = q1 - (q3 - q1) * (slidervalue - 0.675) / 1.35;
);
If( Row() < 200,
., // Skip the first 200 rows
// Get the moving window data for matching rows
current_device = :DeviceNumber[Row()]; // Get the current site number
current_site = :SiteNumber[Row()];
// Get the indices of rows that match the current SiteNumber
matching_rows = Where( :DeviceNumber == current_device | :SiteNumber == current_site );
start_row = Max( 1, Row() - 199 );
end_row = Row();
m = Subscript( testColumn, matching_rows[Loc( matching_rows >= start_row & matching_rows <= end_row )] );
//m = testColumn[Max( 1, Row() - 199 ) :: Row()];
// Calculate the quantiles and IQR
q1 = Quantile( 0.25, m );
q3 = Quantile( 0.75, m );
// Calculate the upper limit using the sigma function
ulColX[Row()] = q3 + (q3 - q1) * (slidervalue - 0.675) / 1.35;
);
);
end2 = Tick Seconds();
Show( end2 - start2 );