cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar

JSL coding for Partition of multiple segments

The following code allows the selection of multiple leaf nodes from the partition tree via the Select Rows option. But, the partition window has to be closed after the user selects the leaf nodes for file creation of good and bad populations. Is there any alternative where the Partition window does not need to be closed? or any other function in place of the onClose() which I can use?

 

dt = Open( "$SAMPLE_DATA\semiconductor capability.jmp" );
// Matrix of all rows that were selected
::wasSelected = [];

// Row state handler function
updateWasSelected = Function( {x},
	{Default Local}, 
    // 'x' is a column vector of row states that have CHANGED. We just need those that are now selected . . .
	For( i = 1, i <= N Row( x ), i++, 
        // Need to accumulate selected rows, not adding duplicates
		If( Selected( Row State( x[i] ) ) & !Contains( ::wasSelected, x[i] ),
			::wasSelected = V Concat( ::wasSelected, x[i] )
		)
	)
);

// Assign the handler to the table
rsh = dt << MakeRowStateHandler( updateWasSelected );

obj = dt << Partition(
	Y( :NPN1 ),
	X( :PNP1, :PNP2, :PNP3, :PNP4, :NPN2, :NPN3, :NPN4 ),
	Method( "Decision Tree" )
);
obj << ShowGraph( 0 );
obj << SplitBest( 4 );
obj << Show Split Count( 1 );
obj << Show Split Prob( 1 );
obj << onClose(
	If( N Rows( ::wasSelected ) > 0,
		filepath = "$Desktop";
		Try(
			dtTemp = dt << subset( invisible, rows( ::wasSelected ), selected columns( 0 ) );
			Close( dtTemp, save( filepath || "\" || "badpopulation.jmp" ) );
		,
			Print( "No rows for table!" )
		);
		dt << invert row selection;
		Try(
			dtSEG = dt << subset( invisible, selected rows( 1 ), selected columns( 0 ) );
			Close( dtSEG, save( filepath || "\" || "goodpopulation.jmp" ) );
		,
			Print( "No rows" )
		);
	);
	dt << clearRowStates;
);

 

 

1 REPLY 1
jthi
Super User

Re: JSL coding for Partition of multiple segments

You could use button for example to create new tables

Names Default To Here(1);

dt = Open("$SAMPLE_DATA\semiconductor capability.jmp");
filepath = "$Desktop";

nw = New window("part test",
	V List Box(
		obj = dt << Partition(
			Y(:NPN1), 
			X(:PNP1, :PNP2, :PNP3, :PNP4, :NPN2, :NPN3, :NPN4), 
			Method("Decision Tree")
		),
		Button box("make splits",
			make_splits_expr
		);
	)
);

obj << ShowGraph(0);
obj << SplitBest(4);
obj << Show Split Count(1);
obj << Show Split Prob(1);

make_splits_expr = Expr(
	sel_rows = dt << Get Selected Rows;
	If(N Items(sel_rows > 0),
		dtTemp = dt << subset(invisible, rows(), selected columns(0));
		Close(dtTemp, save(filepath || "\" || "badpopulation.jmp"));
		dt << invert row selection;
		sel_rows = dt << Get Selected Rows;
		dtSEG = dt << subset(invisible, selected rows(1), selected columns(0));
		Close(dtSEG, save(filepath || "\" || "goodpopulation.jmp"));
	);
	dt << Clear Selected;
);

Proper error handling and informing user what is going on is missing from this example

-Jarmo