Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Friends | List of all members
DiscreteDistribution Class Reference

Discrete Distribution. More...

#include <qle/math/discretedistribution.hpp>

+ Collaboration diagram for DiscreteDistribution:

Public Member Functions

 DiscreteDistribution (const vector< Distributionpair > &)
 
 DiscreteDistribution ()
 Default constructor with probability 1.0 at 0.0. More...
 
 DiscreteDistribution (const vector< Real > &dataPoints, const vector< Real > &probabilities)
 Construct a discrete probability distribution by giving the points and probabilities. More...
 
virtual Size size () const
 
virtual vector< Distributionpairget () const
 
virtual Distributionpair get (Size i) const
 
Real probability (Size i) const
 Return probability for data at index i. More...
 
Real data (Size i) const
 Return data at index i. More...
 
virtual ~DiscreteDistribution ()
 

Protected Attributes

vector< Distributionpairdata_
 

Friends

class MDD
 

Detailed Description

Discrete Distribution.

This class implements a one-dimensional distribution in terms of a vector of Distributionpairs.

Definition at line 61 of file discretedistribution.hpp.

Constructor & Destructor Documentation

◆ DiscreteDistribution() [1/3]

DiscreteDistribution ( const vector< Distributionpair > &  data)

Definition at line 30 of file discretedistribution.cpp.

30 : data_(data) {
31 // do checks here
32}
Real data(Size i) const
Return data at index i.
vector< Distributionpair > data_

◆ DiscreteDistribution() [2/3]

Default constructor with probability 1.0 at 0.0.

Definition at line 34 of file discretedistribution.cpp.

34: data_(1, Distributionpair(0.0, 1.0)) {}

◆ DiscreteDistribution() [3/3]

DiscreteDistribution ( const vector< Real > &  dataPoints,
const vector< Real > &  probabilities 
)

Construct a discrete probability distribution by giving the points and probabilities.

Definition at line 36 of file discretedistribution.cpp.

36 {
37 QL_REQUIRE(dataPoints.size() == probabilities.size(), "Must be the same number of data points and probabilities");
38
39 for (Size i = 0; i < dataPoints.size(); i++) {
40 data_.push_back(Distributionpair(dataPoints[i], probabilities[i]));
41 }
42}

◆ ~DiscreteDistribution()

virtual ~DiscreteDistribution ( )
virtual

Definition at line 77 of file discretedistribution.hpp.

77{}

Member Function Documentation

◆ size()

Size size ( ) const
virtual

Definition at line 44 of file discretedistribution.cpp.

44{ return data_.size(); }
+ Here is the caller graph for this function:

◆ get() [1/2]

vector< Distributionpair > get ( ) const
virtual

Definition at line 46 of file discretedistribution.cpp.

46{ return data_; }
+ Here is the caller graph for this function:

◆ get() [2/2]

Distributionpair get ( Size  i) const
virtual

Definition at line 48 of file discretedistribution.cpp.

48 {
49 // checks here
50 return data_[i];
51}

◆ probability()

Real probability ( Size  i) const

Return probability for data at index i.

Definition at line 53 of file discretedistribution.cpp.

53 {
54 // Check that index i is in bounds
55 QL_REQUIRE(0 <= i && i < data_.size(), "Asked for probability outside range of distribution");
56 return data_[i].y_;
57}

◆ data()

Real data ( Size  i) const

Return data at index i.

Definition at line 59 of file discretedistribution.cpp.

59 {
60 // Check that index i is in bounds
61 QL_REQUIRE(0 <= i && i < data_.size(), "Asked for data point outside range of distribution");
62 return data_[i].x_;
63}

Friends And Related Function Documentation

◆ MDD

friend class MDD
friend

Definition at line 79 of file discretedistribution.hpp.

Member Data Documentation

◆ data_

vector<Distributionpair> data_
protected

Definition at line 82 of file discretedistribution.hpp.