News
We’re asking you to select a content label when starting a new topic in the Discussions area. Read more to find out why.
Choose Language Hide Translation Bar
Highlighted
fugalnc
Level II

Programatically set profiler simulator distributions

I'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
    )
  )
)

 

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
fugalnc
Level II

Re: Programatically set profiler simulator distributions

Ok, 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 ))" )
    )
  )
)

View solution in original post

0 Kudos
3 REPLIES 3
Highlighted
David_Burnham
Super User

Re: Programatically set profiler simulator distributions

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

 

-Dave
0 Kudos
Highlighted
fugalnc
Level II

Re: Programatically set profiler simulator distributions

Ok, 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 ))" )
    )
  )
)

View solution in original post

0 Kudos
Highlighted
fugalnc
Level II

Re: Programatically set profiler simulator distributions

I 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...

0 Kudos