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

Factors in Simulator by using Variables for Monte Carlo Simulation

Hello,

I wonder to make monte carlo simulation by using the multiple dimensions listed in the data table (dt0), the N Rows of dt0 is dynamic upon user's inputs and requirements.

My question is how to use appropriate routine to add those dimensions in the Factors of Simulator?

I tried to use 'Substitute, Parse' function to make it work. But it only work when all those dimensions are listed in Factors().

Here is my scripts:

Eval(
	Substitute(
			Expr(
				myanalysis = dt << Profiler(
					Y( :Name( "TA Target" ) ),
					Profiler(
						1,
						Simulator(
							1,
							Factors( Dim A, Dim B, Dim C, Dim D, Dim E, Dim F, ),
							Responses( Name( "TA Target" ) << No Noise ),
							Resimulate
						)
					),

				)
			),
		Expr( Dim A ), Parse( "Dim A<< Random( Normal( 1, 0.01 ) )" ),
		Expr( Dim B ), Parse( "Dim B<< Random( Normal( 1, 0.01 ) )" ),
		Expr( Dim C ), Parse( "Dim C<< Random( Normal( 1, 0.01 ) )" ),
		Expr( Dim D ), Parse( "Dim D<< Random( Normal( 1, 0.01 ) )" ),
		Expr( Dim E ), Parse( "Dim E<< Random( Normal( 1, 0.01 ) )" ),
		Expr( Dim F ), Parse( "Dim F<< Random( Normal( 1, 0.01 ) )" ),

	)
);
1 ACCEPTED SOLUTION

Accepted Solutions
ian_jmp
Level X

Re: Factors in Simulator by using Variables for Monte Carlo Simulation

Yes, showing the report twice was just to illustrate that the function works.

You can just build on the coding pattern above ('SubstituteInto()' can do any number of replacements). The analysis generated is not meaningful, but the code below is an example. The 'template expression' was built by JMP (with a few subsequent edits):

 

NamesDefaultToHere(1);

dt = Open("$SAMPLE_DATA/Semiconductor Capability.jmp");

// Define a JSL function
doSimulator = 
function({x1Var, x2Var, yVar}, {Default Local},
	// Template expression
	myFit = Expr(
			fm = dt << Fit Model(
				Y( yTBD ),
				Effects( x1TBD, x2TBD ),
				Personality( "Standard Least Squares" ),
				Emphasis( "Effect Leverage" ),
				Run(
					Profiler(
						1,
						Simulator(
							1,
							Factors( 
								x1TBD << Random( Normal( 290, 50 ) ),
								x2TBD << Random( Normal( 460, 50 ) ) 									
								),
							Responses( yTBD << No Noise ),
							Resimulate
						)
					)
				)
			)
		);
	// Bake in the variablee passed to the function
	SubstituteInto(myFit, 
					Expr(x1TBD), NameExpr(x1Var),
					Expr(x2TBD), NameExpr(x2Var),
					Expr(yTBD), NameExpr(yVar)
					);
	// Do the fit
	myFit;
	// Return the reference to the fit Model object
	fm;
	);

// Try out the function . . .
f = doSimulator(Column(dt, "PNP1"), Column(dt, "PNP2"), Column(dt, "NPN1"));

View solution in original post

4 REPLIES 4
ian_jmp
Level X

Re: Factors in Simulator by using Variables for Monte Carlo Simulation

Perhaps this code might point you in the right direction:

NamesDefaultToHere(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

// Define a JSL function
doSimulator = 
function({xVar, yVar}, {Default Local},
	// Template expression
	myFit = Expr(
			fm = dt << Fit Model(
				Y( yTBD ),
				Effects( xTBD ),
				Personality( "Standard Least Squares" ),
				Emphasis( "Effect Leverage" ),
				Run(
					Profiler(
						1,
						Simulator(
							1,
							Factors( xTBD << Random( Normal( 80, 10 ) ) ),
							Responses( yTBD << No Noise ),
							Resimulate
						)
					)
				)
			)
		);
	// Bake in the variablee passed to the function
	SubstituteInto(myFit, Expr(xTBD), NameExpr(xVar), Expr(yTBD), NameExpr(yVar));
	// Do the fit
	myFit;
	// Return the reference to the fit Model object
	fm;
	);

// Try out the function . . .
fhw = doSimulator(Column(dt, "height"), Column(dt, "weight"));
fwh = doSimulator(Column(dt, "weight"), Column(dt, "height"));
Adam_Xu
Level III

Re: Factors in Simulator by using Variables for Monte Carlo Simulation

Thank you so much, Ian!

It seems like the function works. However, with the scripts by following your advice, multiple profilers will be generated w/ only one Factor displayed in each profiler. I wonder to know how to display all Factors in one Profiler report. Do you have any comment? Appreciate it.

 

Here is my revised scripts:

doSimulator=Function(
		{xVar, MeanVar, SigmaVar}, {Default Local},
		myFP=Expr(
			myProfiler=dt<<Profiler(
				Y( :Name( "TA Target" ) ),
				Profiler(
					1,
					Simulator(
						1,
						Factors(
							xTBD<<Random( Normal( MeanTBD, SigmaTBD ) ),
						),
						Responses( Name( "TA Target" ) << No Noise ),
						Resimulate
					),
				);
			);
		);
		SubstituteInto(myFP, Expr(xTBD), Name Expr(xVar), Expr(MeanTBD), Name Expr(MeanVar), Expr(SigmaTBD), Name Expr(SigmaVar) );
		myFP;
		myProfiler;
	);
	
	For(i=1, i<=dimN, i++,
		cdimna=Col Stored Value(dt0,:Dim #, i);
		cdimme=Col Stored Value(dt0,:Mean,i);
		cdimsi=Col Stored Value(dt0,:Sigma,i);
		doSimulator(cdimna, cdimme, cdimsi);
	);
ian_jmp
Level X

Re: Factors in Simulator by using Variables for Monte Carlo Simulation

Yes, showing the report twice was just to illustrate that the function works.

You can just build on the coding pattern above ('SubstituteInto()' can do any number of replacements). The analysis generated is not meaningful, but the code below is an example. The 'template expression' was built by JMP (with a few subsequent edits):

 

NamesDefaultToHere(1);

dt = Open("$SAMPLE_DATA/Semiconductor Capability.jmp");

// Define a JSL function
doSimulator = 
function({x1Var, x2Var, yVar}, {Default Local},
	// Template expression
	myFit = Expr(
			fm = dt << Fit Model(
				Y( yTBD ),
				Effects( x1TBD, x2TBD ),
				Personality( "Standard Least Squares" ),
				Emphasis( "Effect Leverage" ),
				Run(
					Profiler(
						1,
						Simulator(
							1,
							Factors( 
								x1TBD << Random( Normal( 290, 50 ) ),
								x2TBD << Random( Normal( 460, 50 ) ) 									
								),
							Responses( yTBD << No Noise ),
							Resimulate
						)
					)
				)
			)
		);
	// Bake in the variablee passed to the function
	SubstituteInto(myFit, 
					Expr(x1TBD), NameExpr(x1Var),
					Expr(x2TBD), NameExpr(x2Var),
					Expr(yTBD), NameExpr(yVar)
					);
	// Do the fit
	myFit;
	// Return the reference to the fit Model object
	fm;
	);

// Try out the function . . .
f = doSimulator(Column(dt, "PNP1"), Column(dt, "PNP2"), Column(dt, "NPN1"));
Adam_Xu
Level III

Re: Factors in Simulator by using Variables for Monte Carlo Simulation

Thank you, Ian!

Maybe this is the most promising and feasible method by adding lots of variables in function list to get the Monte Carlo simulation by scripts based on current version of JMP.