Skip to content

Add normal distribution #44

Description

@mikkokotila

from scipy import stats
import numpy as np

def bounded_normal(min_val, max_val, size=None):
# Set mean to the center of the range
mean = (min_val + max_val) / 2

# Set standard deviation to cover most of the range
# A common heuristic is to make 3 standard deviations cover the range
std = (max_val - min_val) / 6

# Calculate the corresponding normalized bounds
a = (min_val - mean) / std
b = (max_val - mean) / std

# Use scipy's truncated normal distribution
return stats.truncnorm.rvs(a, b, loc=mean, scale=std, size=size)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions