Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Programatically set profiler simulator distributio...

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 13, 2017 10:44 AM
(239 views)

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

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 14, 2017 5:17 AM
(429 views)

Solution

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 ))" )
)
)
)
```

3 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 13, 2017 10:53 PM
(221 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 14, 2017 5:17 AM
(430 views)

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 ))" )
)
)
)
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 14, 2017 5:20 AM
(213 views)

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