Skip to content

laser.core.demographics.pyramid

laser.core.demographics.pyramid

A class for generating samples from a distribution using the Vose alias method.

laser.core.demographics.pyramid.AliasedDistribution(counts)

A class to generate samples from a distribution using the Vose alias method.

laser.core.demographics.pyramid.AliasedDistribution.sample(count=1, dtype=np.int32)

Generate samples from the distribution.

Parameters:

Name Type Description Default
count int

The number of samples to generate. Default is 1.

1

Returns:

Type Description
int

int or numpy.ndarray: A single integer if count is 1, otherwise an array of integers representing the generated samples.

laser.core.demographics.pyramid.load_pyramid_csv(file, verbose=False)

Load a CSV file with population pyramid data and return it as a NumPy array.

The CSV file is expected to have the following schema:

  • The first line is a header: "Age,M,F"
  • Subsequent lines contain age ranges and population counts for males and females:

1
2
3
"low-high,#males,#females"
...
"max+,#males,#females"
Where low, high, males, females, and max are integer values >= 0.

The function processes the CSV file to create a NumPy array with the following columns:

  • Start age of the range
  • End age of the range
  • Number of males
  • Number of females

Parameters:

Name Type Description Default
file Path

The path to the CSV file.

required
verbose bool

If True, prints the file reading status. Default is False.

False

Returns:

Type Description
ndarray

np.ndarray: A NumPy array with the processed population pyramid data.