<?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: Is there a faster way to loop? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Is-there-a-faster-way-to-loop/m-p/612674#M81280</link>
    <description>&lt;P&gt;&amp;nbsp;Thanks Jarmo!&amp;lt;3&lt;/img&gt;&amp;lt;3&lt;/img&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 15 Mar 2023 16:52:30 GMT</pubDate>
    <dc:creator>Jackie_</dc:creator>
    <dc:date>2023-03-15T16:52:30Z</dc:date>
    <item>
      <title>Is there a faster way to loop?</title>
      <link>https://community.jmp.com/t5/Discussions/Is-there-a-faster-way-to-loop/m-p/612450#M81257</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hello JMP community,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I am analyzing larger amounts of data, typically 350k rows.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;For each row, the code runs a loop to calculate the mean offset by "&lt;STRONG&gt;Wafer ID&lt;/STRONG&gt;". I’m looking for a faster way of doing this.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Is there a way to make the processing faster? The current script takes &lt;STRONG&gt;~1 hou&lt;/STRONG&gt;r to complete the loop.&lt;BR /&gt;&lt;/SPAN&gt;&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 );

dt1 = Data Table( "Reference Data Table.jmp" );
dt2 = Data Table("Data table");
					
									
Col_List1 = dt2 &amp;lt;&amp;lt; Get Column Names( "String" );
					
Summation(
	c = 1,
	N Col( dt2 ) - 1,  
	values = [];
	name = Column( dt2, c ) &amp;lt;&amp;lt; Get Name;
	If( Contains( name, "Currents" ) | Contains( name, "Voltage" ) | Contains( name, "Resistance" ),
		rows = dt1 &amp;lt;&amp;lt; Get Rows Where( :tests == name );		
		col = Column( dt2, c );
		col mean = Col Mean( col );
		For Each Row(
			dt2,
			mean = dt1:Mean[rows];
			measure = mean - Col Mean( As Column( dt2, c ), :Wafer ID );
			values |/= col[] + measure
			;
		);
		col &amp;lt;&amp;lt; Set Values( values );
	);
	0	
	
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Jun 2023 16:28:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Is-there-a-faster-way-to-loop/m-p/612450#M81257</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2023-06-08T16:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a faster way to loop?</title>
      <link>https://community.jmp.com/t5/Discussions/Is-there-a-faster-way-to-loop/m-p/612526#M81265</link>
      <description>&lt;P&gt;Is there a specific need to have all those 350k rows if in the end you end up with 4 values each column (if I understood the code correctly), one mean per wafer per column? You could possibly use Summary to make much smaller table.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2023 14:29:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Is-there-a-faster-way-to-loop/m-p/612526#M81265</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-03-15T14:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a faster way to loop?</title>
      <link>https://community.jmp.com/t5/Discussions/Is-there-a-faster-way-to-loop/m-p/612527#M81266</link>
      <description>&lt;P&gt;Yes, Correct one mean per wafer. Yes I would like to process all at once because I'm developing a script which severs as a multi function tool for my team. Any suggestion would be appreciated jarmo&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2023 14:34:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Is-there-a-faster-way-to-loop/m-p/612527#M81266</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2023-03-15T14:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a faster way to loop?</title>
      <link>https://community.jmp.com/t5/Discussions/Is-there-a-faster-way-to-loop/m-p/612548#M81267</link>
      <description>&lt;P&gt;Using Summary (or Summarize if you don't need data table) should be fairly fast (you can join/update Summary table back to large data if needed)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt_ref = Open("$DOWNLOADS/Reference data table.jmp", invisible);
dt_dt = Open("$DOWNLOADS/Data table.jmp", invisible);
dt_dt &amp;lt;&amp;lt; clear select;
dt_ref &amp;lt;&amp;lt; clear select;

aa_means = Associative Array(Column(dt_ref, "Tests"), Column(dt_ref, "Mean"));

col_list = Filter Each({col_name}, dt_dt &amp;lt;&amp;lt; Get Column Names("String"),
	Contains({"Currents", "Voltage", "Resistance"}, Word(1, col_name));
);

dt_summary = dt_dt &amp;lt;&amp;lt; Summary(
	Group(:Wafer ID),
	Mean(Eval(col_list)),
	Freq("None"),
	Weight("None"),
	statistics column name format("column"), // this is important here
	Link to original data table(0)
);

For Each({col_name}, col_list,
	Eval(EvalExpr(
		Column(dt_summary, col_name) &amp;lt;&amp;lt; Set Each Value(
			aa_means[col_name] - AsColumn(col_name)
		);
	));
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Remember to check that the values are correct&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2023 14:49:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Is-there-a-faster-way-to-loop/m-p/612548#M81267</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-03-15T14:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a faster way to loop?</title>
      <link>https://community.jmp.com/t5/Discussions/Is-there-a-faster-way-to-loop/m-p/612585#M81269</link>
      <description>&lt;P&gt;....&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 15:47:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Is-there-a-faster-way-to-loop/m-p/612585#M81269</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2023-03-16T15:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a faster way to loop?</title>
      <link>https://community.jmp.com/t5/Discussions/Is-there-a-faster-way-to-loop/m-p/612597#M81273</link>
      <description>&lt;P&gt;Ah.. missed the col[] in your script. I'll write new version soon&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2023 15:33:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Is-there-a-faster-way-to-loop/m-p/612597#M81273</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-03-15T15:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a faster way to loop?</title>
      <link>https://community.jmp.com/t5/Discussions/Is-there-a-faster-way-to-loop/m-p/612658#M81277</link>
      <description>&lt;P&gt;Hopefully this is calculating correctly. It isn't the most simple script but it is somewhat optimized for speed (on my laptop calculation for one column took 200ms, so in total approximately 6s).&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt_ref = Open("$DOWNLOADS/Reference data table.jmp", invisible);
dt_dt = Open("$DOWNLOADS/Data table.jmp", invisible);
dt_dt &amp;lt;&amp;lt; clear select;
dt_ref &amp;lt;&amp;lt; clear select;

aa_means = Associative Array(Column(dt_ref, "Tests"), Column(dt_ref, "Mean"));

col_list = Filter Each({col_name}, dt_dt &amp;lt;&amp;lt; Get Column Names("String"),
	Contains({"Currents", "Voltage", "Resistance"}, Word(1, col_name));
);

dt_dt &amp;lt;&amp;lt; Add Row(1, At Start); 
dt_dt &amp;lt;&amp;lt; Begin Data Update;
For Each({col_name, idx}, col_list,
	start = Hp Time();
	Eval(Eval Expr(
		Column(dt_dt, col_name) &amp;lt;&amp;lt; Set Each Value(
			//AsColumn(col_name) + aa_means[col_name] - Col Mean(AsColumn(col_name), :Wafer ID);
			//Col Mean(Expr(Name Expr(AsColumn(col_name))), :Wafer ID);
			//Col Mean(:Currents A17, :Wafer ID);
			Expr(Name Expr(AsColumn(col_name)))+ Expr(aa_means[col_name]) - Col Mean(Expr(Name Expr(AsColumn(col_name))), :Wafer ID);
		);
	));
	show((Hp Time() - start)/1e6);
);
dt_dt &amp;lt;&amp;lt; Delete Row(1);
dt_dt &amp;lt;&amp;lt; End Data Update;

//Summarize(dt_dt, b = by(:WAFER ID), m = Mean(:Currents A17));
//show(b,m, Col Mean(:Currents A17));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I had to add 1 row to beginning and then remove it later to avoid some weird calculation issue when using &amp;lt;&amp;lt; Set Each Value (might be just my expressions) and that's why it has some weird commented lines in the code. I'll contact JMP support about it when I have time&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Ticket created&amp;nbsp;TS-00036082. Depending on the response I get, I will make separate post regarding Col Mean&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2023 16:57:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Is-there-a-faster-way-to-loop/m-p/612658#M81277</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-03-15T16:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a faster way to loop?</title>
      <link>https://community.jmp.com/t5/Discussions/Is-there-a-faster-way-to-loop/m-p/612674#M81280</link>
      <description>&lt;P&gt;&amp;nbsp;Thanks Jarmo!&amp;lt;3&lt;/img&gt;&amp;lt;3&lt;/img&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2023 16:52:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Is-there-a-faster-way-to-loop/m-p/612674#M81280</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2023-03-15T16:52:30Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a faster way to loop?</title>
      <link>https://community.jmp.com/t5/Discussions/Is-there-a-faster-way-to-loop/m-p/612922#M81315</link>
      <description>&lt;P&gt;Here's my attempt, the two tables at the bottom "stacked_table" and "summary_table_delta_by_wafer" might be the right shape for this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's fast at less than 1 second for the whole thing&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;(HP Time() - start) / 1000000 = 0.664238;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt_ref = Open("$DOWNLOADS/Reference data table.jmp", invisible);
dt_dt = Open("$DOWNLOADS/Data table.jmp", invisible);
dt_dt &amp;lt;&amp;lt; clear select;
dt_ref &amp;lt;&amp;lt; clear select;

start = Hp Time();

curr_col_names_list = dt_dt &amp;lt;&amp;lt; Get Column Names("string");


obj = dt_dt &amp;lt;&amp;lt; Tabulate(
		Show Control Panel( 0 ),
		Add Table(
			Column Table(
				Analysis Columns(
					eval list(curr_col_names_list)
				),
				Statistics( Mean )
			),
			Row Table( Grouping Columns( :Wafer ID ) )
		)
	);
	my_new_table = obj &amp;lt;&amp;lt; Make Into Data Table;


curr_col_names_list = my_new_table &amp;lt;&amp;lt; Get Column Names("string");

transposed_table = my_new_table &amp;lt;&amp;lt; Transpose(
	columns(
	eval list(curr_col_names_list)
	),
	Label( :Wafer ID ),
	Output Table( "transposed_table" )
);

transposed_table &amp;lt;&amp;lt; new column ("join_key"
	,char
	,formula(
		regex(:Label,"\(([^\)]+)\)", "\1")		
	)	
);


transposed_table_join = (
	transposed_table &amp;lt;&amp;lt; Join(
	With( dt_ref )
	,Match Columns( :join_key = :Tests),
	,Merge same name columns
	,output table("transposed_table_join")
	)
	);
	
// clean up
close(transposed_table,nosave);
close(my_new_table,nosave);
transposed_table_join &amp;lt;&amp;lt; delete columns(:"Match Flag", :"Label","join_key");
transposed_table_join:"Mean" &amp;lt;&amp;lt; Set Name( "Ref_Value" );

	
curr_col_names_list = transposed_table_join &amp;lt;&amp;lt; Get Column Names("string");
matches_i_dont_want_to_stack = {"Tests","Ref_Value"};
clean_col_list = Associative Array(curr_col_names_list) &amp;lt;&amp;lt; Remove(Associative Array(matches_i_dont_want_to_stack)) &amp;lt;&amp;lt; get keys;


stacked_table = transposed_table_join &amp;lt;&amp;lt; Stack(
	columns( clean_col_list ),
	Source Label Column( "Wafer_ID" ),
	Stacked Data Column( "Measured_Value" ),
	Output Table( "stacked_table" )
);


//Is this the formula you wanted on each value? A-B?
stacked_table &amp;lt;&amp;lt; new column ("delta"
	,numeric
	,continuous
	,formula(
		(:Ref_Value -:Measured_Value)	
	)	
);
//stacked table and final summary_table_delta_by_wafer seems like the useful combo here.

close(transposed_table_join,nosave);

//final output?
summary_table_delta_by_wafer = stacked_table &amp;lt;&amp;lt; Transpose(
	columns( :delta ),
	By( :Wafer_ID ),
	Label( :Tests ),
	Output Table( "summary_table_delta_by_wafer" )
);
show((Hp Time() - start)/1e6);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 08:26:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Is-there-a-faster-way-to-loop/m-p/612922#M81315</guid>
      <dc:creator>xxvvcczz</dc:creator>
      <dc:date>2023-03-16T08:26:05Z</dc:date>
    </item>
  </channel>
</rss>

