Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add triangular distribution and related tests. #8

Closed
wants to merge 2 commits into from

Conversation

mvernacc
Copy link
Contributor

Add the triangular distribution to the set of available uncertainties.

Example usage of the new feature:

"""Demonstrate new trianguar distribution feature in Rhodium."""

import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
import rhodium as rdm
import seaborn as sns

# Triangular distrib properties
min_value = 0; max_value = 1; mode_value=0.25
scale = max_value - min_value
c = (mode_value - min_value) / scale


def identity(x):
    return x

model = rdm.Model(identity)

model.parameters = [
    rdm.Parameter('x')
]

model.responses = [
    rdm.Response('y'),
]

model.uncertainties = [
    rdm.TriangularUncertainty('x', min_value, max_value, mode_value)
]

scenarios = rdm.sample_lhs(model, nsamples=1000)

sns.distplot(scenarios['x'])

# Plot the pdf
x = np.linspace(min_value, max_value)
density = stats.triang.pdf(x, c=c, scale=scale, loc=min_value)
plt.plot(x, density, linestyle='--', color='black', label='True PDF')

plt.title('Samples from a Triangular Distribution')
plt.xlabel('Value')
plt.ylabel('Density')
plt.legend()
plt.show()

figure_1

@dhadka
Copy link
Member

dhadka commented Nov 22, 2022

Merged in #37

@dhadka dhadka closed this Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants