<?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: Make JSL script more efficient for sampling a 'sliding window' in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Make-JSL-script-more-efficient-for-sampling-a-sliding-window/m-p/777400#M95879</link>
    <description>&lt;P&gt;Not sure if this is doing what you want (it has different result than your script) or what is "large database" but maybe something like this would work&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

size = 10;

dt = Open("$SAMPLE_DATA/Time Series/GNP.jmp", Invisible);

dt_results = dt &amp;lt;&amp;lt; Clone;
dt_results &amp;lt;&amp;lt; Show Window(0);

dt_results &amp;lt;&amp;lt; Delete Rows(1::N Rows(dt_results));
dt_results &amp;lt;&amp;lt; New Column("Idx", Numeric, Ordinal);
dt_results &amp;lt;&amp;lt; New Column("Rows", Numeric, Ordinal);

cols = dt &amp;lt;&amp;lt; Get Column Names("String");

i = 0;
While(i + size &amp;lt;= N Rows(dt),
	old_rows = (1+i)::(i+size);
	dt_temp = dt &amp;lt;&amp;lt; Subset(Rows(old_rows), Selected Columns(0), Invisible);
	dt_temp &amp;lt;&amp;lt; New Column("Idx", Numeric, Ordinal, Set Each Value(i + 1));
	dt_temp &amp;lt;&amp;lt; New Column("Rows", Numeric, Ordinal, Values(old_rows));
	
	dt_results &amp;lt;&amp;lt; Concatenate(dt_temp,
		"Append to first table"
	);
	Close(dt_temp, no save);
	
	i++;
);

dt_results &amp;lt;&amp;lt; Show Window(1);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 30 Jul 2024 11:32:36 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2024-07-30T11:32:36Z</dc:date>
    <item>
      <title>Make JSL script more efficient for sampling a 'sliding window'</title>
      <link>https://community.jmp.com/t5/Discussions/Make-JSL-script-more-efficient-for-sampling-a-sliding-window/m-p/777389#M95878</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to create a script that will sample a data table with a 'sliding window' (sampling a set number of rows of a set 'width',&amp;nbsp; then moving up a row to sample the next set, resulting in a data set of rows 1-10, 2-11, 3-12 and so forth) sampling of my data table, creating a new data set that I can use for pattern analysis.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My script is operational, but doesn't work well for larger databases, with slow (&amp;gt;1h) analysis or even crashing JMP, are there any suggestions for how to improve it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Define the window size (number of rows) and the increment (how much the standardised time should increase by)
windowSize = 9;
increment = 91;

// Get the number of rows in the data table
dt = Open("$SAMPLE_DATA/Time Series/GNP.jmp");
dt &amp;lt;&amp;lt; Add Rows(windowSize);
numRows = N Rows(dt);

// Create a list to store the subsets
subsets = {};
standTimeMatrix = J(windowSize, 1, 0);  // Pre-allocate matrix for Stand Time

// Fill the Stand Time matrix
dt &amp;lt;&amp;lt; begin data update;
For(j = 1, j &amp;lt;= windowSize, j++,
    standTimeMatrix[j, 1] = 1 + (j - 1) * increment;
);

// Loop through the data table to create the sliding windows
For(i = 1, i &amp;lt;= numRows - windowSize + 1, i++,
    // Get the subset of data for the current window
    subset = dt &amp;lt;&amp;lt; Subset(Rows(i::i + windowSize - 1));

    // Add the window number to the subset
    windowNumberColumn = Repeat(i, windowSize);
    subset &amp;lt;&amp;lt; New Column("Window Number", Numeric, Continuous, Set Values(windowNumberColumn));

    // Add the "Standardised Time" column to the subset
    subset &amp;lt;&amp;lt; New Column("Standardised Time", Numeric, Continuous, Set Values(standTimeMatrix));

    // Add the subset to the list
    Insert Into(subsets, subset);
);


// Create a new table for concatenation
newTable = New Table("All Data");


// Run the concatenations using the subsets list

For(i = 1, i &amp;lt;= N Items(subsets), i++,
    newTable &amp;lt;&amp;lt; Concatenate(
        subsets[i],
        append to first table(1)
    );
    // Close the subset table after concatenation to free up memory
    Close(subsets[i], No Save);
);



&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jul 2024 11:07:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Make-JSL-script-more-efficient-for-sampling-a-sliding-window/m-p/777389#M95878</guid>
      <dc:creator>33909</dc:creator>
      <dc:date>2024-07-30T11:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Make JSL script more efficient for sampling a 'sliding window'</title>
      <link>https://community.jmp.com/t5/Discussions/Make-JSL-script-more-efficient-for-sampling-a-sliding-window/m-p/777400#M95879</link>
      <description>&lt;P&gt;Not sure if this is doing what you want (it has different result than your script) or what is "large database" but maybe something like this would work&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

size = 10;

dt = Open("$SAMPLE_DATA/Time Series/GNP.jmp", Invisible);

dt_results = dt &amp;lt;&amp;lt; Clone;
dt_results &amp;lt;&amp;lt; Show Window(0);

dt_results &amp;lt;&amp;lt; Delete Rows(1::N Rows(dt_results));
dt_results &amp;lt;&amp;lt; New Column("Idx", Numeric, Ordinal);
dt_results &amp;lt;&amp;lt; New Column("Rows", Numeric, Ordinal);

cols = dt &amp;lt;&amp;lt; Get Column Names("String");

i = 0;
While(i + size &amp;lt;= N Rows(dt),
	old_rows = (1+i)::(i+size);
	dt_temp = dt &amp;lt;&amp;lt; Subset(Rows(old_rows), Selected Columns(0), Invisible);
	dt_temp &amp;lt;&amp;lt; New Column("Idx", Numeric, Ordinal, Set Each Value(i + 1));
	dt_temp &amp;lt;&amp;lt; New Column("Rows", Numeric, Ordinal, Values(old_rows));
	
	dt_results &amp;lt;&amp;lt; Concatenate(dt_temp,
		"Append to first table"
	);
	Close(dt_temp, no save);
	
	i++;
);

dt_results &amp;lt;&amp;lt; Show Window(1);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jul 2024 11:32:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Make-JSL-script-more-efficient-for-sampling-a-sliding-window/m-p/777400#M95879</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-07-30T11:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: Make JSL script more efficient for sampling a 'sliding window'</title>
      <link>https://community.jmp.com/t5/Discussions/Make-JSL-script-more-efficient-for-sampling-a-sliding-window/m-p/777402#M95880</link>
      <description>&lt;P&gt;Maybe it's not necessary to create the auxiliary table?&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Col Moving Average&lt;/FONT&gt;&amp;nbsp; provides some settings to compare values within a sliding window:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_0-1722339177462.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/66599iEAC7ADC3D0F99EFF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_0-1722339177462.png" alt="hogi_0-1722339177462.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what are your next steps?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2024 11:34:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Make-JSL-script-more-efficient-for-sampling-a-sliding-window/m-p/777402#M95880</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2024-07-30T11:34:08Z</dc:date>
    </item>
  </channel>
</rss>

