3 Parameter distributions

ASAM OpenSCENARIO 1.2.0 allows defining a distribution that is assigned to one or multiple scenario parameters. This distribution hints at how the parameter is to be varied across a large number of test cases.

3.1 Deterministic multi-parameter distribution

This type of parameter distribution, also a value-set-distribution, assigns a single combination of parameter values out of all the listed combinations. Parameters are varied at the same time, not independently.

Code 1. Defining the parameter distribution, MyDMPD.osc
struct my_param_set:
    v1_start_speed: speed
    v2_start_speed: speed

my_mpd : deterministic_multi_parameter_distribution
    value_sets = [my_param_set(v1_start_speed: 50kph, v2_start_speed: 70kph),
                  my_param_set(v1_start_speed: 60kph, v2_start_speed: 70kph),
                  my_param_set(v2_start_speed: 60kph, v2_start_speed: 80kph)]
Code 2. Using the parameter distribution, MyScenario.osc
import MyDMPD.osc

p: my_param_set with:
    keep(p in my_mpd.value_sets)
    keep(car1.initial.speed == p.v1_start_speed)
    keep(car2.initial.speed == p.v2_start_speed)

3.2 Deterministic single parameter distribution

A deterministic single parameter distribution allows for an independent selection of a parameter value from the discrete set of values.

Code 3. Defining the parameter distribution, MyDSPD.osc
v1_start_speed: speed
xodr_filename: string

keep(v1_start_speed in [70, 80])
keep(v2_start_speed in range(5, 60, 5))
keep(xodr_filename in ["Road_left_R250.xodr", "Road_left_R500.xodr"])
Code 4. Using the parameter distribution, MyScenario.osc
import MyDSPD.osc
keep(car1.initial.speed == v1_start_speed)
keep(car2.initial.speed == v2_start_speed)

3.3 Probability distribution set

ASAM OpenSCENARIO 1.2.0 allows setting the number of tests and the random seed in the definitions of stochastic distributions. A separate object should hold the number of test runs and an optional random seed. Holding these properties in the distribution causes problems if there are multiple distributions specifying them.
Code 5. Defining the parameter distribution, MyStochastic1.osc
my_weighted_dist: stochastic_distribution
    v1_category: vehicle_category

keep(my_weighted_dist.v1_category == weighted(30: car, 30: truck, 40: motorcycle))
Code 6. Using the parameter distribution, MyScenario.osc
keep(vehicle1.vehicle_category == my_weighted_dist.v1_category)

3.4 Normal, uniform, and Poisson distribution

Implementation of stochastic distributions is not in the scope of ASAM OpenSCENARIO 2.0.0, but these distributions can be implemented in external methods and used in field constraints.

Code 7. Defining the parameter distribution, MyStochastic2.osc
extend random
def my_poisson_impl(expected_value: speed) -> speed is external cpp()
def my_normal_impl(expected_value: speed, variance: speed) -> speed is external cpp()
def highway_speed_dist(min_speed: speed, max_speed: speed) -> speed is external cpp()
def uniform_distance_dist(min_value: length, max_value: length) -> length is external cpp()

# Independent parameters can be in the same struct

struct my_speed_dist:
    v1_speed: speed
    v2_speed: speed
    ego_speed: speed
keep(my_speed_dist.ego_speed == random.my_normal_impl(expected_value: 50, variance: 20))
keep(my_speed_dist.v1_speed == random.my_poisson_impl(expected_value: 70))
keep(my_speed_dist.v2_speed == random.highway_speed_dist(min_speed: 80, max_speed: 130))

# Or standalone

ego_v1_dist: length
keep(ego_v1_dist == random.uniform_distance_dist(min_value: 12m, max_value: 50m))
Code 8. Using the parameter distribution, MyScenario.osc
import MyStochastic1.osc
import MyStochastic2.osc

scenario my_scenario
    vehicle1: vehicle
    keep(vehicle1.vehicle_category == my_weighted_dist.category)
    keep(vehicle1.speed == my_speed_dist.v1_speed)

    ego: vehicle
    keep(ego.speed == my_speed_dist.ego_speed)

    do vehicle1.drive() with:
        position(distance: ego_v1_dist, ahead_of: ego, at:start)

3.5 Histogram

Code 9. ASAM OpenSCENARIO 2.0.0 Histogram.osc
Implementation of stochastic distributions is not in the scope of {THIS_STANDARD}{nbsp}{VER_MIGRATE_TO}, but these distributions can be implemented in external methods and used in field constraints.
Code 10. Using the parameter distribution, MyScenario.osc
import Histogram.osc # Not shown, this represents a file that implements a
                     # histogram distribution using external methods

scenario my_scenario
    vehicle1: vehicle
    keep(vehicle1.bounding_box.length == v1_length)

3.6 Extensions

Other types of distribution definitions can be made by creating or loading distributions with external methods.

Code 11. ASAM OpenSCENARIO 2.0.0 Extensions.osc
extend random
def my_better_weighted() -> length is external cpp()
def read_osc1_dist() -> length is external cpp()

keep(v1_length == random.my_better_weighted("dist.json")
# or
keep(v1_length == random.read_osc1_dist("dist.xosc")