Model simulations

class balancepy.model_sim.base_model.BaseModel(mass_kg=None, height_m=None, data_exp=None, ModelName=None, config=None)

Bases: object

Base class for balancepy model simulations.

Provides a framework for parameter management, data handling, simulation, and model fitting.

Parameters:
  • mass_kg (Number, optional) – Mass of the model in kilograms. Must be provided.

  • height_m (Number, optional) – Height of the model in meters. Must be provided.

  • data_exp (balancepy.sr_data, optional) – Experimental data object containing frequency response data.

  • ModelName (str, optional) – Name of the model. If not provided, defaults to None.

  • config (dict, optional) – Configuration dictionary to override default settings. If not provided, defaults to None.

Attributes

Name

Description

ModelName

Name of the model.

mass_kg

Subject mass in kilograms.

height_m

Subject height in meters.

data_exp

Experimental data object (sr_data or None).

data_sim

Simulated data object (sr_data or None).

params

Model parameters (ParameterSet).

fit_output

Output of the fitting procedure.

dynamics

Defines the system dynamics (callable).

Methods

Name

Description

frf(freq=None)

Computes the frequency response function (FRF).

simulate_timedomain (stimulus, samplingrate_Hz)

Simulates the time domain response of the system.

objective(params_free)

Objective function for optimization.

fit(data_exp=None)

Fits the model parameters to experimental data.

plot()

Plots the experimental and simulated data, if available.

class balancepy.model_sim.parameter.Parameter(name, default, bounds=(None, None), fixed=False, unit=None, description=None)

Bases: object

Represents a single parameter in a model.

Parameters:
  • name (str) – The name of the parameter.

  • default (float) – The default value of the parameter.

  • bounds (tuple, optional) – A tuple representing the lower and upper bounds of the parameter (default is (None, None)).

  • fixed (bool, optional) – Whether the parameter is fixed (not optimized). Default is False.

  • unit (str, optional) – The unit of the parameter, if applicable.

  • description (str, optional) – A description of the parameter, if applicable.

Attributes

Name

Description

name

The name of the parameter.

value

The current value of the parameter.

default

The default value of the parameter.

bounds

The lower and upper bounds of the parameter (tuple).

fixed

Whether the parameter is fixed (not optimized).

fit_result

Result from fitting, if applicable.

confidencebounds

Confidence bounds for the parameter, if applicable.

unit

The unit of the parameter, if applicable.

description

A description of the parameter, if applicable.

class balancepy.model_sim.parameter.ParameterSet

Bases: object

Manages a collection of Parameter objects for a model.

This class enables organized handling of model parameters, including adding, accessing, updating, and retrieving parameter information such as values, bounds, units, and descriptions. It supports operations for both fixed and free parameters, making it suitable for parameter management in modeling and simulation tasks.

Methods

Name

Description

add(param)

Add a Parameter object to the set.

items()

Return (name, Parameter) pairs.

names()

List of parameter names.

defaults()

Dictionary of default values for all parameters.

units()

Dictionary of parameter units.

descriptions()

Dictionary of parameter descriptions.

values(only_free=True)

List of parameter values, optionally only for free parameters.

bounds()

List of bounds for free (not fixed) parameters.

set_values(values, only_free=True)

Set parameter values from a list, optionally only for free parameters.

set_defaults()

Reset all parameter values to their defaults.

to_value_dict( only_free=False)

Dictionary of parameter values, optionally only for free parameters.