Creating a Custom Distribution ​
A custom distribution can be generated by employing the OwnDistributions
class. This class allows the assignment of discrete labels (integers greater than or equal to zero) and the probability of each label occurring.
parameters (dict)
: A dictionary in which the keys represent the labels and the values represent their associated probabilities. All keys must be integers greater than or equal to zero, and the sum of the values must be equal to 1.
Below is an example illustrating how to create an instance of OwnDistributions
:
python
from phitter import simulation
# Parameters for the custom distribution
parameters = {0: 0.1, 1: 0.2, 3: 0.7}
# Create an "OwnDistributions" instance
simulation_own_distribution = simulation.OwnDistributions(parameters=parameters)
Simulating Labels ​
Once an instance of OwnDistributions
has been created, the method .ppf
can be used to simulate a label based on a specified probability.
probability (float)
: A probability value (between 0 and 1) used for sampling the label.
Below is an example of how to generate a label using a random probability:
python
import random
prob = random.random()
label = simulation_own_distribution.ppf(probability=prob)
This process produces a single label from the user-defined distribution, drawn according to the probability specified by prob
.