<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Need help with optimizing in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Need-help-with-optimizing/m-p/804890#M98271</link>
    <description>&lt;P&gt;You might want to use the &lt;A href="https://www.jmp.com/support/help/en/18.1/#page/jmp/debug-or-profile-scripts.shtml#" target="_self"&gt;Debugger and Profiler&lt;/A&gt; in JMP to determine where the script spends most of its time.&lt;/P&gt;</description>
    <pubDate>Thu, 10 Oct 2024 18:10:46 GMT</pubDate>
    <dc:creator>Mark_Bailey</dc:creator>
    <dc:date>2024-10-10T18:10:46Z</dc:date>
    <item>
      <title>Need help with optimizing</title>
      <link>https://community.jmp.com/t5/Discussions/Need-help-with-optimizing/m-p/804877#M98268</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to optimize the calculation. I tried both Col Formula and Loop but neither of them seem to be faster for rows &amp;gt; 10k.&lt;BR /&gt;I compared the exe speed and both of them take a very long time&lt;/P&gt;&lt;P&gt;Col Formula = 500.46s;&lt;BR /&gt;Loop = 491.70s;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to optimize using Matrix or J trans?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();

testColumn = Column( "Test_A" );

slidervalue = 6;
////UsingFormula
start = Tick Seconds();
dt &amp;lt;&amp;lt; New Column( "LL_formula",
	Numeric,
	Continuous,
	Formula(
		
						
		If( Row() &amp;lt; 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 &amp;gt;= start_row &amp;amp; matching_rows &amp;lt;= 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 &amp;lt;&amp;lt; New Column( "UL_formula",
	Numeric,
	Continuous,
	Formula(
		
		If( Row() &amp;lt; 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 &amp;gt;= start_row &amp;amp; matching_rows &amp;lt;= 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 &amp;lt;&amp;lt; New Column( "LL_loop", Numeric );
ulColX = dt &amp;lt;&amp;lt; New Column( "UL_loop", Numeric );



For Each Row(
	dt,
	If( Row() &amp;lt; 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 &amp;gt;= start_row &amp;amp; matching_rows &amp;lt;= 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() &amp;lt; 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 &amp;gt;= start_row &amp;amp; matching_rows &amp;lt;= 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 );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 18:15:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Need-help-with-optimizing/m-p/804877#M98268</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2024-10-10T18:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with optimizing</title>
      <link>https://community.jmp.com/t5/Discussions/Need-help-with-optimizing/m-p/804889#M98270</link>
      <description>&lt;P&gt;First things to try are to utilize private/invisible table with &amp;lt;&amp;lt; begin data update and &amp;lt;&amp;lt; end data update. After that has been tried, then it might be a good idea to move into other methods&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 18:00:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Need-help-with-optimizing/m-p/804889#M98270</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-10-10T18:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with optimizing</title>
      <link>https://community.jmp.com/t5/Discussions/Need-help-with-optimizing/m-p/804890#M98271</link>
      <description>&lt;P&gt;You might want to use the &lt;A href="https://www.jmp.com/support/help/en/18.1/#page/jmp/debug-or-profile-scripts.shtml#" target="_self"&gt;Debugger and Profiler&lt;/A&gt; in JMP to determine where the script spends most of its time.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 18:10:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Need-help-with-optimizing/m-p/804890#M98271</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2024-10-10T18:10:46Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with optimizing</title>
      <link>https://community.jmp.com/t5/Discussions/Need-help-with-optimizing/m-p/804891#M98272</link>
      <description>&lt;P&gt;Tried using begin/end data update and it made it worse&lt;BR /&gt;Total time :&amp;nbsp;780.73s&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();

testColumn = Column( "Test_A" );

slidervalue = 6;

///UsingLoop
start2 = Tick Seconds();

llColX = dt &amp;lt;&amp;lt; New Column( "LL_loop", Numeric );
ulColX = dt &amp;lt;&amp;lt; New Column( "UL_loop", Numeric );


dt &amp;lt;&amp;lt; show window( 0 );

dt &amp;lt;&amp;lt; begin data update;
For Each Row(
	dt,
	If( Row() &amp;lt; 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 &amp;gt;= start_row &amp;amp; matching_rows &amp;lt;= 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() &amp;lt; 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 &amp;gt;= start_row &amp;amp; matching_rows &amp;lt;= 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;
	);
	
);

dt &amp;lt;&amp;lt; end data update;
end2 = Tick Seconds();

Show( end2 - start2 );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Oct 2024 18:32:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Need-help-with-optimizing/m-p/804891#M98272</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2024-10-10T18:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with optimizing</title>
      <link>https://community.jmp.com/t5/Discussions/Need-help-with-optimizing/m-p/804893#M98274</link>
      <description>&lt;P&gt;There are still things which could be improved but this took 10-15s on my PC&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$DOWNLOADS/sample_table.jmp");

slidervalue = 6;

start2 = Tick Seconds();

ds = dt[0, "DeviceNumber"];
ss = dt[0, "SiteNumber"];
m1 = J(1, N Rows(dt), .);
m2 = J(1, N Rows(dt), .);


For Each Row(dt,
	If(Row() &amp;lt; 200,
		.
	,
		d = :DeviceNumber[Row()];
		s = :SiteNumber[Row()];
		rs = (Row() - 199)::Row();
		
		d1 = ds[rs];
		s1 = ss[rs];
		
		r = where(s1 == s | d1 == d);
		
		vals = dt[rs[r], "Test_A"];
		
		q1 = Quantile(0.25, vals);
		q3 = Quantile(0.75, vals);
		
		m1[Row()] = q1 - (q3 - q1) * (slidervalue - 0.675) / 1.35;
		m2[Row()] = q3 + (q3 - q1) * (slidervalue - 0.675) / 1.35;
	);
);

llColX = dt &amp;lt;&amp;lt; New Column("LL_loop1", Numeric, Continuous, Values(m1));
llColX = dt &amp;lt;&amp;lt; New Column("UL_loop2", Numeric, Continuous, Values(m2));

end2 = Tick Seconds();
Show(end2 - start2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Oct 2024 19:16:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Need-help-with-optimizing/m-p/804893#M98274</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-10-10T19:16:39Z</dc:date>
    </item>
  </channel>
</rss>

