Drake
normal_distribution< drake::symbolic::Expression > Class Template Reference

Detailed Description

template<>
class std::normal_distribution< drake::symbolic::Expression >

Provides std::normal_distribution, N(μ, σ), for symbolic expressions.

When operator() is called, it returns a symbolic expression μ + σ * v where v is a symbolic random variable associated with the standard normal (Gaussian) distribution.

It keeps a shared pointer to the vector of symbolic random variables that has been created for the following purposes:

  • When reset() is called, it rewinds index_ to zero so that the next operator (re)-uses the first symbolic random variable.
    random_device rd;
    RandomGenerator g{rd()};
    std::normal_distribution<Expression> d(0.0, 1.0);
    const Expression e1{d(g)};
    const Expression e2{d(g)};
    d.reset();
    const Expression e3{d(g)};
    EXPECT_FALSE(e1.EqualTo(e2));
    EXPECT_TRUE(e1.EqualTo(e3));
  • When an instance of this class is copied, the original and copied distributions share the vector of symbolic random variables. We want to make sure that the two generate identical sequences of elements.
    random_device rd;
    RandomGenerator g{rd()};
    std::normal_distribution<Expression> d1(0.0, 1.0);
    std::normal_distribution<Expression> d2(d1);
    const Expression e1_1{d1(g)};
    const Expression e1_2{d1(g)};
    const Expression e2_1{d2(g)};
    const Expression e2_2{d2(g)};
    EXPECT_TRUE(e1_1.EqualTo(e2_1));
    EXPECT_TRUE(e1_2.EqualTo(e2_2));

#include <drake/common/symbolic_expression.h>

Public Types

using RealType = drake::symbolic::Expression
 
using result_type = RealType
 

Public Member Functions

 normal_distribution (RealType mean, RealType stddev=1.0)
 Constructs a new distribution object with mean and stddev. More...
 
 normal_distribution ()
 Constructs a new distribution object with mean = 0.0 and stddev = 1.0. More...
 
void reset ()
 Resets the internal state of the distribution object. More...
 
result_type operator() ()
 Generates a symbolic expression representing a random value that is distributed according to the associated probability function. More...
 
template<class Generator >
result_type operator() (Generator &)
 Generates a symbolic expression representing a random value that is distributed according to the associated probability function. More...
 
RealType mean () const
 Returns the mean μ distribution parameter. More...
 
RealType stddev () const
 Returns the deviation σ distribution parameter. More...
 
result_type min () const
 Returns the minimum potentially generated value. More...
 
result_type max () const
 Returns the maximum potentially generated value.o. More...
 
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 normal_distribution (const normal_distribution &)=default
 
normal_distributionoperator= (const normal_distribution &)=default
 
 normal_distribution (normal_distribution &&)=default
 
normal_distributionoperator= (normal_distribution &&)=default
 

Friends

bool operator== (const normal_distribution< drake::symbolic::Expression > &lhs, const normal_distribution< drake::symbolic::Expression > &rhs)
 

Member Typedef Documentation

◆ RealType

◆ result_type

Constructor & Destructor Documentation

◆ normal_distribution() [1/4]

normal_distribution ( RealType  mean,
RealType  stddev = 1.0 
)
explicit

Constructs a new distribution object with mean and stddev.

Exceptions
std::exceptionif stddev is a non-positive constant expression.

◆ normal_distribution() [2/4]

normal_distribution ( )

Constructs a new distribution object with mean = 0.0 and stddev = 1.0.

◆ normal_distribution() [3/4]

normal_distribution ( const normal_distribution< drake::symbolic::Expression > &  )
default

◆ normal_distribution() [4/4]

normal_distribution ( normal_distribution< drake::symbolic::Expression > &&  )
default

Member Function Documentation

◆ max()

result_type max ( ) const

Returns the maximum potentially generated value.o.

◆ mean()

RealType mean ( ) const

Returns the mean μ distribution parameter.

◆ min()

result_type min ( ) const

Returns the minimum potentially generated value.

Note
In libstdc++ std::normal_distribution<> defines min() and max() to return -DBL_MAX and DBL_MAX while the one in libc++ returns -INFINITY and INFINITY. We follows libc++ and return -INFINITY and INFINITY.

◆ operator()() [1/2]

result_type operator() ( )

Generates a symbolic expression representing a random value that is distributed according to the associated probability function.

◆ operator()() [2/2]

result_type operator() ( Generator &  )

Generates a symbolic expression representing a random value that is distributed according to the associated probability function.

Note
We provide this method, which takes a random generator, for compatibility with the std::normal_distribution::operator().

◆ operator=() [1/2]

◆ operator=() [2/2]

◆ reset()

void reset ( )

Resets the internal state of the distribution object.

◆ stddev()

RealType stddev ( ) const

Returns the deviation σ distribution parameter.

Friends And Related Function Documentation

◆ operator==

bool operator== ( const normal_distribution< drake::symbolic::Expression > &  lhs,
const normal_distribution< drake::symbolic::Expression > &  rhs 
)
friend

The documentation for this class was generated from the following file: