physped.core package

Submodules

physped.core.digitizers module

physped.core.digitizers.digitize_coordinates_to_lattice(coordinates: ndarray[float], lattice_bins: ndarray[float]) ndarray[int64][source]

Digitizes the given coordinates to the specified lattice bins.

Boundary conditions: - Coordinates outside the lattice return -1. Note: it is not possible to return nan because the output is an array of integers.

Parameters:
  • coordinates – The coordinates in one dimension to be digitized.

  • lattice_bins – The bin edges in one dimension defining the

  • cells. (lattice)

Returns:

The array with integer lattice indices associated with the coordinates.

physped.core.distribution_approximator module

Module for a with distribution approximation classes.

class physped.core.distribution_approximator.DistApproximation(fit_dimensions: Tuple[str, ...], fit_parameters: Tuple[str, ...], function: Callable)[source]

Bases: object

A class for the distribution approximation of the potential.

fit_dimensions: Tuple[str, ...]
fit_parameters: Tuple[str, ...]
function: Callable
class physped.core.distribution_approximator.GaussianApproximation[source]

Bases: DistApproximation

physped.core.langevin_model module

Langevin model class.

class physped.core.langevin_model.LangevinModel(potential: PiecewisePotential, params: dict)[source]

Bases: object

Langevin model class.

This class represents a Langevin model used for simulating pedestrian trajectories. It contains methods for initializing the model, simulating trajectories, and defining stopping conditions.

potential

The piecewise potential object used

Type:

PiecewisePotential

for modeling.
params

A dictionary containing the model parameters.

Type:

dict

modelxy(state: ndarray, t) ndarray[source]

Calculate the derivatives of the Langevin model for the given state variables.

Parameters:
  • X_0 (np.ndarray) – Array of initial state variables

  • [xf

  • yf

  • uf

  • vf

  • xs

  • ys

  • us

  • vs].

Returns:

Array of derivatives [xfdot, yfdot, ufdot, vfdot, xsdot, ysdot, usdot, vsdot].

Return type:

np.ndarray

noise(X_0, t) ndarray[source]

Return noise matrix.

Returns:

A diagonal matrix representing the noise matrix. The diagonal elements correspond to the independent driving Wiener processes.

Return type:

numpy.ndarray

particle_outside_grid(xf: float, yf: float) bool[source]

Check if particle is outside the grid.

Parameters:
  • xf – The x-coordinate of the particle.

  • yf – The y-coordinate of the particle.

Returns:

Whether the particle is outside the grid.

simulate(X_0: ndarray, t_eval: ndarray = array([0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1., 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2., 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3., 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4., 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5., 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6., 6.1, 6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8, 6.9, 7., 7.1, 7.2, 7.3, 7.4, 7.5, 7.6, 7.7, 7.8, 7.9, 8., 8.1, 8.2, 8.3, 8.4, 8.5, 8.6, 8.7, 8.8, 8.9, 9., 9.1, 9.2, 9.3, 9.4, 9.5, 9.6, 9.7, 9.8, 9.9])) ndarray[source]

Simulates the Langevin model.

Parameters: - X_0: Initial state of the system as a numpy array. - t_eval: Time points at which to evaluate the solution. Defaults to np.arange(0, 10, 0.1).

Returns: - The simulated trajectory of the system as a numpy array.

physped.core.langevin_model.get_slow_derivative(name: str)[source]
physped.core.langevin_model.low_pass_filter(**kwargs) float[source]
physped.core.langevin_model.register_slow_derivative(name)[source]
physped.core.langevin_model.use_fast_dynamics(**kwargs) float[source]
physped.core.langevin_model.use_fast_dynamics2(**kwargs) float[source]
physped.core.langevin_model.use_slow_dynamics(**kwargs) float[source]

physped.core.lattice module

Module for the Latice class.

class physped.core.lattice.Lattice(bins: Dict[str, ndarray])[source]

Bases: object

compute_cell_volume() ndarray[source]

Compute the volume of each cell in the lattice.

Returns:

The volume of each cell in the lattice.

get_bin_centers() Dict[str, ndarray][source]

Return the middle of the input bins.

Returns:

The middle of the input bins.

get_lattice_shape() Tuple[int][source]

Return the shape of the lattice.

Returns:

The shape of the lattice.

physped.core.lattice_selection module

This module contains functions to select a single point or a range of values in the configuration file.

The only purpose is to let the user make a selection along the discretization lattice.

physped.core.lattice_selection.evaluate_selection_point(config: DictConfig) DictConfig[source]
physped.core.lattice_selection.evaluate_selection_range(config: DictConfig) DictConfig[source]
physped.core.lattice_selection.get_boundaries_that_enclose_the_selected_bin(bin_index: int, bins: ndarray) dict[source]
physped.core.lattice_selection.get_boundaries_that_enclose_the_selected_range(selected_range: OmegaConf, bins: dict) dict[source]
physped.core.lattice_selection.is_range_decreasing(selected_range: OmegaConf)[source]

Check if the range is increasing.

Raises:

ValueError – If the range is decreasing

Parameters:

selected_range (OmegaConf) – The selection.

physped.core.lattice_selection.is_selected_range_valid(selected_range: OmegaConf) None[source]

Validate the selection.

Parameters:

selection – The selection.

physped.core.lattice_selection.is_selected_range_within_grid(selected_range: OmegaConf, grid_bins: dict) None[source]
physped.core.lattice_selection.validate_point_within_lattice(selected_point: DictConfig, grid_bins: dict) None[source]

Validate the selection.

Parameters:
  • selected_point – The selected point.

  • grid_bins – The bins of the lattice in all the dimensions.

physped.core.lattice_selection.validate_value_within_lattice(selected_value: float, bins: dict, dimension: str) None[source]

Check if the selected value is outside the lattice.

Parameters:
  • selected_value – The selected value in one of the dimensions.

  • bins – The bins of the lattice in all the dimensions.

  • dimension – The dimension of the given value.

Raises:

ValueError – If the selected value is outside the lattice.

physped.core.parametrize_potential module

Infer force fields from trajectories.

physped.core.parametrize_potential.accumulate_grids(cummulative_grids: PiecewisePotential, grids_to_add: PiecewisePotential) PiecewisePotential[source]

Accumulate grids by taking a weighted mean of the fit parameters.

The goal of this function is to sum PiecewisePotential objects.

Parameters:
  • cummulative_grids – The cumulative grids to add to.

  • grids_to_add – The grids to add to the cumulative grids.

Returns:

The updated cumulative grids.

physped.core.parametrize_potential.add_trajectories_to_histogram(histogram: ndarray, trajectories: DataFrame, groupbyindex: str) ndarray[source]

Add trajectories to a histogram.

Parameters:
  • histogram – The histogram to add the trajectories to.

  • trajectories – The trajectories to add to the histogram.

Returns:

The updated histogram.

physped.core.parametrize_potential.apply_periodic_angular_conditions(trajectories: DataFrame, lattice: Lattice) DataFrame[source]

Apply periodic angular conditions to the trajectories.

This function makes sure that the angles are within the range of the angular lattice bins.

Parameters:
  • trajectories – the trajectory data set.

  • lattice – the lattice object

Returns:

The trajectories with the angular conditions applied.

physped.core.parametrize_potential.calculate_position_based_emperic_potential(histogram_slow, config: DictConfig)[source]
physped.core.parametrize_potential.digitize_trajectories_to_grid(trajectories: DataFrame, lattice: Lattice) DataFrame[source]

Digitize trajectories to a lattice.

Adds a column to the dataframe with the trajectories that contains the slow indices

Parameters:
  • grid_bins – The bins which define the lattice.

  • trajectories – The trajectories to digitize.

Returns:

The trajectories with an extra column for the slow indices.

physped.core.parametrize_potential.extract_submatrix(matrix: ndarray, slicing_indices: List[tuple]) ndarray[source]

Extract a submatrix from a nd-matrix using periodic boundary conditions.

Periodicity is needed for the angular dimension.

Parameters:
  • matrix – The input nd-matrix to slice.

  • slicing_indices – A list of slice tuples for each dimension of the

  • nd-matrix.

Returns:

The submatrix.

physped.core.parametrize_potential.fit_probability_distributions(group: DataFrame, config: DictConfig) ndarray[source]

Fits a group of data points and returns the fit parameters.

Parameters:
  • group – The group of data points to fit the normal distribution to.

  • config – The configuration parameters.

Returns:

A matrix containing the fit parameters.

physped.core.parametrize_potential.get_boundary_coordinates_of_selection(bins, observable, values)[source]

Return the grid bounds of a given observable and value.

physped.core.parametrize_potential.get_grid_indices(piecewise_potential: PiecewisePotential, point: List[float]) ndarray[source]

Given a point (xs, ys, thetas, rs), return the associated lattice indices.

This function is 4-dimensional.

If the radial velocity is in the lowest bin, the angular velocity is automatically also added to the lowest bin. In other words, the angular velocities are not discretized for low radial velocity.

Parameters:
  • potential – The piecewise potential.

  • point – A list with slow positions and velocities (xs, ys, thetas, rs).

Returns:

A tuple of grid indices.

physped.core.parametrize_potential.learn_potential_from_trajectories(trajectories: DataFrame, config: DictConfig) PiecewisePotential[source]

Convert trajectories to a grid of histograms and parameters.

Parameters:
  • trajectories – A DataFrame of trajectories.

  • grid_bins – A dictionary of grid values for each dimension.

Returns:

A dictionary of DiscreteGrid objects for storing histograms and parameters.

physped.core.parametrize_potential.make_grid_selection(piecewise_potential, selection)[source]

Make selection.

physped.core.parametrize_potential.parameterize_trajectories(parametrization: ndarray, trajectories: DataFrame, config: DictConfig)[source]

Fit trajectories to the lattice.

Fit the fast dynamics conditioned to the slow dynamics.

Parameters:
  • parametrization – The initialized, empty, parametrization matrix.

  • trajectories – The trajectories to fit.

  • config – The configuration parameters.

Returns:

The updated parametrization matrix.

physped.core.parametrize_potential.selection_to_bounds(bins, selection_coordinates, dimension)[source]

physped.core.pedestrian_initializer module

physped.core.pedestrian_initializer.get_initial_dynamics(config: dict) ndarray[source]
physped.core.pedestrian_initializer.initialize_pedestrians(initial_dynamics: ndarray) ndarray[source]

Add time, step, and Pid to the initial dynamics

Parameters:
  • initial_dynamics – The initial dynamics of the pedestrians expressed as

  • [xf

  • yf

  • uf

  • vf

  • xs

  • ys

  • us

  • vs]

Returns:

The initial dynamics with the time, step, and Pid added [xf, yf, uf, vf, xs, ys, us, vs, t, k, Pid]

physped.core.pedestrian_initializer.sample_dynamics_from_trajectories(trajectories: DataFrame, n_trajs: int, state_n: int) ndarray[source]

physped.core.pedestrian_simulator module

physped.core.pedestrian_simulator.check_restarting_conditions(traj, n_frames_back, piecewise_potential)[source]
physped.core.pedestrian_simulator.heatmap_zero_at_slow_state(piecewise_potential: PiecewisePotential, slow_state) bool[source]

Check if the heatmap is zero at the given position.

If the heatmap is zero it indicates that the spatial position was never visited by a pedestrian in the input data.

Parameters:
  • piecewise_potential – The piecewise potential object.

  • position – The position to check.

Returns:

True if the heatmap is zero at the given position, False otherwise.

physped.core.pedestrian_simulator.read_simulated_trajectories_from_file(config)[source]
physped.core.pedestrian_simulator.simulate_pedestrians(piecewise_potential: PiecewisePotential, config: dict) DataFrame[source]
physped.core.pedestrian_simulator.simulate_trajectory_piece(model: LangevinModel, starting_state: ndarray, evaluation_time: ndarray, no_traj_piece: int) DataFrame[source]

physped.core.piecewise_potential module

Module for the PiecewisePotential class.

class physped.core.piecewise_potential.PiecewisePotential(lattice: Lattice, dist_approximation: DistApproximation)[source]

Bases: object

initialize_parametrization()[source]

Initialize the potential parametrization.

We initialize the parametrization with the following shape: (lattice_shape, len(fit_dimensions), len(fit_parameters)) Such that the potential is parameterized in each lattice site for every fit dimension by the number of free fit parameters.

reparametrize_to_curvature(config: DictConfig)[source]

Reparametrize the potential.

From (mu, var) to (mu, curvature). Implements equations 15 and 16 from the paper.

Parameters:

config – The configuration.

Raises:

ValueError – If the fit parameters are not mu and sigma

physped.core.slow_dynamics module

physped.core.slow_dynamics.compute_slow_dynamics(preprocessed_trajectories, config)[source]
physped.core.slow_dynamics.compute_slow_position(df: DataFrame, config: DictConfig) DataFrame[source]
physped.core.slow_dynamics.compute_slow_velocity(df: DataFrame, config: DictConfig) DataFrame[source]
physped.core.slow_dynamics.get_slow_algorithm(name: str)[source]
physped.core.slow_dynamics.integrate_slow_velocity(df: DataFrame, **kwargs)[source]
physped.core.slow_dynamics.integrate_slow_velocity_single_path(x0: float, us: Series, dt: float) list[source]

Compute slow dynamics by integrating the slow velocity

physped.core.slow_dynamics.low_pass_filter_all_paths(df: DataFrame, **kwargs)[source]
physped.core.slow_dynamics.low_pass_filter_single_path(fast: Series, tau: float, dt: float) list[source]

Compute slow dynamics of single trajectory with low pass filter.

physped.core.slow_dynamics.register_slow_algorithm(name: str)[source]
physped.core.slow_dynamics.savgol_smoothing(df: DataFrame, **kwargs)[source]
physped.core.slow_dynamics.use_fast_dynamics(df: DataFrame, **kwargs)[source]

Module contents