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
shasha_2
Level III

Need help with JSL script for multi segments partition selection

The following code helps to create new tables with good but only one selection can be chosen for bad population with the partition window open. I want the partition screen to be open but the user can select more than one leaf nodes for the bad population and rest will go to good population. Is there a way to do this?

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;
);

I want to be able to select the yellow highlighted nodes as bad population and rest as good population keeping this partition window open and change the node selection if not satisfied with the result.

shasha_2_0-1656413086285.png

Is there some way to make it happen?

1 REPLY 1
David_Burnham
Super User (Alumni)

Re: Need help with JSL script for multi segments partition selection

Here is a stab at it:

 


lstSelectedRows = {};

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")
		),
		HListBox(
			TextBox("rows selected in node = "),
			tb1 = TextBox("0"),
		),
		HListBox(
			TextBox("total rows selected = "),
			tb2 = TextBox("0")
		),
		ButtonBox("clear all selections",
			clear_selections
			, underlinestyle(1)
		),
		Button box("make splits",
			make_splits_expr
		);
	)
);

// in the partition platform from any node you can select rows
// but we need to detect this event ... do it by detecting 
// row state changes in the table


rs = dt << make row state handler(
	function({a},
		cdt = current data table();
		sel = cdt << Get Selected Rows;
		insertinto(lstSelectedRows,aslist(sel));
		tmp = [=>];
		insertInto( tmp, lstSelectedRows );
		lstSelectedRows = tmp << getKeys;  // <--- dedupe
		tb1 << settext(char(nrows(sel)));
		tb2 << settext(char(nitems(lstSelectedRows)));
	)
);

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

clear_selections = Expr(
	dt << Clear Selected;
	tb1 << settext("0");
	tb2 << settext("0");
	lstSelectedRows = {};
);

make_splits_expr = Expr(
	dt << select rows(lstSelectedRows);
	sel_rows = dt << Get Selected Rows;
	tb1 << settext(char(nrows(sel_rows)));
	If(N Items(sel_rows > 0),
		dtTemp = dt << subset(rows(), selected columns(0), output table("Selected"));
		//Close(dtTemp, save(filepath || "\" || "badpopulation.jmp"));
		dt << invert row selection;
		sel_rows = dt << Get Selected Rows;
		dtSEG = dt << subset(selected rows(1), selected columns(0), output table("Not Selected"));
		//Close(dtSEG, save(filepath || "\" || "goodpopulation.jmp"));
	);
	dt << Clear Selected;
);

I might not have understood what you are trying to do and so I wont try and explain what is going on with the code - but if it is what you are trying to do I'm happy to give you an explanation of what's going on - just let me know.  Some of the code is a bit ugly but just wanted to see if I could understand what you were trying to do.  For my own convenience, instead of saving 2 tables to the desktop I create 2 (visible tables) titled 'selected' and 'not selected'.

-Dave