cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Joost
Level II

JSL - Repeats within a platform function

Names Default To Here( 1 );

// Create an Example data table
dt = currentdatatable();

// Get the names of the columns in the data table
colNames = dt << get column group( "WLS" );

nIters = 2;

Neural(
	Y( :Type ),
	X(eval(colNames)),
	Validation Method( "KFold", 5 ),
	Set Random Seed( 2 ),
	for( k=1, k <= nIters, k++, Fit( NTanH ( 2 ) ) ),
);

I am trying to fit more than 1 neural model using attached script. If instead of the for-loop I write several times Fit( NTanH(2)) it works fine, but with a for-loop I cannot get it to work. Any suggestins? Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: JSL - Repeats within a platform function

You could move the Fit(NTanH()) outside the Neural(). Below is example from scripting index:

jthi_1-1671475604873.png

Modified version from scripting index with for loop:

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Boston Housing.jmp");
obj = Neural(
	Y(:mvalue),
	X(:crim, :indus, :chas, :nox, :rooms, :age, :distance, :radial),
	Set Random Seed(2)
);

For(i = 1, i <= 2, i++,
	obj << Fit(NTanH(4));	
);

jthi_0-1671475587322.png

 

-Jarmo

View solution in original post

5 REPLIES 5
jthi
Super User

Re: JSL - Repeats within a platform function

You could move the Fit(NTanH()) outside the Neural(). Below is example from scripting index:

jthi_1-1671475604873.png

Modified version from scripting index with for loop:

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Boston Housing.jmp");
obj = Neural(
	Y(:mvalue),
	X(:crim, :indus, :chas, :nox, :rooms, :age, :distance, :radial),
	Set Random Seed(2)
);

For(i = 1, i <= 2, i++,
	obj << Fit(NTanH(4));	
);

jthi_0-1671475587322.png

 

-Jarmo
Joost
Level II

Re: JSL - Repeats within a platform function

Hi Jarmo, that was an option that I did not try and it is a solution to my problem. Works fine. Thank you!

Joost
Level II

Re: JSL - Repeats within a platform function

Hi Jarmo, Below is a working script:

Names Default To Here( 1 );
delete symbols();

dt = current data table();

colNames = dt << get column group("WLs");
exclColnames = dt <<  get excluded columns();
For( i = 1, i <= N Items( exclColnames ), i++,
	Remove From( colNames, As List( Loc( colNames, exclColnames[i] ) ) )
);

rpt = New Window( "Neural of Type", dt <<
	Neural(
		Y( :Type ),
		X( eval ( colNames ) ),
		Informative Missing( 0 ),
		Validation Method( "KFold", 5 ),
		Set Random Seed( 2 ),
		Fit( NTanH( 2 ) ),
		Fit( NTanH( 2 ) ),
		Fit( NTanH( 2 ) )
	)
);
Wait( 0 );
rpt["Neural", Outline Box( 1 ), "Validation", "Type", Table Box( 1 )] <<
Make Combined Data Table;
rpt << Close Window;

However, I want to make the Fit( NTanH(2)) flexibe. The way you demonstrated does not work here, I tried to solve it by next script (leaving out the first part):

obj =Neural(
		Y( :Type ),
		X( eval ( colNames ) ),
		Informative Missing( 0 ),
		Validation Method( "KFold", 5 ),
		Set Random Seed( 2 ),
);
for(i=1, i<=3, i++, obj << Fit( NTanH(2)));

rpt = current window();
Wait( 0 ); rpt["Neural", Outline Box( 1 ), "Validation", "Type", Table Box( 1 )] << Make Combined Data Table; rpt << Close Window;

But now I get the error message: "Cannot subscript Display Box in access or evaluation of 'rpt[ /*###*/"Neural",Outline Box(1),"Validation","Type",Table Box(1)]' , rpt[/*###*/"Neural", Outline Box( 1 ), "Validation", "Type", Table Box( 1 )]". I do not understand why I get this message, because the first script runs well.

 

Do you have a solution for this problem and can you explain why I have this problem, in order to understand JSL a bit better. Thanks!

jthi
Super User

Re: JSL - Repeats within a platform function

The code isn't finding correct references, it could be that changing rpt = Current Window(); to rpt = Current Report() is enough, but I would strongly suggest using the reference you (can) have (in my example obj)

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Boston Housing.jmp");
obj = Neural(
	Y(:mvalue),
	X(:crim, :indus, :chas, :nox, :rooms, :age, :distance, :radial),
	Set Random Seed(2),
	<< Fit(NTanH(4)),
	<< Fit(NTanH(4)),
	<< Fit(NTanH(4))
);

For(i = 1, i <= 2, i++,
	obj << Fit(NTanH(4));
);

Report(obj)[Outline Box("Neural")][Outline Box("Training")][Table Box(1)] << Make Combined Data Table;
-Jarmo
Joost
Level II

Re: JSL - Repeats within a platform function

Thanks, Jarmo, that was where I am looking for. Simple line, but hard to figure out for someone new to JSL!

Recommended Articles