Programatically set profiler simulator distributionsI'm trying to make a Profiler with simulator options turned on and some of the inputs have random distributions. The type of distribution and parameters of that distribution are saved as table variables to be querried as necessary. But the JSL inside the Profiler() function doesn't seem to recognize if statements.
For example, this code works fine
Profiler(
Y( :a, :b ),
Profiler(
1,
Simulator(
1,
Factors(
c << Fixed( 3.5 ),
d << Random( Normal( :dist_p1, :dist_p2 ) )
),
Resimulate
)
)
)but this code doesn't load the distribution info for "d"
Profiler(
Y( :a, :b ),
Profiler(
1,
Simulator(
1,
Factors(
c << Fixed( 3.5 ),
if(
dist_type == "Normal", d << Random( Normal( :dist_p1, :dist_p2 ) ),
dist_type == "Weibull", d << Random( Weibull( :dist_p1, :dist_p2 ) )
)
),
Resimulate
)
)
)
Re: Programatically set profiler simulator distributionsI thought about this approach briefly, but in my real file it would be duplicating 100+ lines of code 9 times (3 random variables, 3 distribution types). It becomes unmanageable very quickly.
EDIT: This is in relply to David_Burnham. Still learning how to use these forums...
Re: Programatically set profiler simulator distributionsOk, if I go back to the highest level function (Profiler in this case) and wrap it with with Eval, Substitute, and Expr I can get the behavior I want. It was confusing to me because I thought that the if should be evaluated first, then used as the argument of the function it was inside of, but I can understand now why that wouldn't work.
Eval(
Substitute(
Expr(
Profiler(
Y( :a, :b ),
Simulator(
Factors(
c << Fixed( 3.5 ),
d_
),
Resimulate
)
)
),
Expr( _d_ ),
if (:dist_type == "Normal", Parse( "d << Random( Normal( :dist_p1, :dist_p2 ))" ),
:dist_type == "Weibull", Parse( "d << Random( Weibull( :dist_p2, :dist_p1 ))" )
)
)
)Re: Programatically set profiler simulator distributionsProfiler is a function. Everyhting inside the function should be function arguments required for the function to run. So you can't just stick arbitrary JSL code inside it. You need to move the conditional logic outside:
type = "Normal";
p1 = 3.0;
p2 = 0.5;
If (type == "Normal",
Profiler(
Y( :a, :b ),
Profiler(
1,
Simulator(
1,
Factors(
c << Fixed( 3.5 ),
d << Random( Normal( p1, p2 ) ),
),
Resimulate
)
)
)
);