Modelling
Module for modelling materials test data.
This module provides functionalities to parameterize mechanical test data by fitting constitutive models to the data.
It includes classes to fit mathematical models to materials test data and predict material behavior. The module integrates
with the plug module for data handling.
Classes
- ModelSet: Acts as a model DataSet, used to fit, collect, and predict using constitutive models.
ModelSet
Class that acts as a model DataSet, providing functionalities to fit, collect, and predict constitutive models for material behavior.
This class is designed to fit mathematical models to mechanical test data and make predictions based on the fitted parameters. It integrates with the DataSet and DataItem classes for handling data.
Attributes:
| Name | Type | Description |
|---|---|---|
model_func |
Callable
|
A function defining the mathematical model to be fitted. It should accept an array of x-values and a tuple of variables and parameters, and return an array of y-values. |
variable_names |
List[str]
|
List of variable names that may be used in the model_func. |
param_names |
List[str]
|
List of parameter names for the model. |
bounds |
List[Tuple[float, float]]
|
Bounds for the model parameters. |
initial_guess |
Tuple[float]
|
Initial guess for the model parameters. |
sample_range |
Tuple[float, float]
|
Range of samples for fitting. |
sample_size |
int
|
Size of the sample data. |
model_id_key |
str
|
Key for the model ID. |
fitting_table |
pd.DataFrame
|
Pandas DataFrame storing the fitting results. |
Examples:
>>> import paramaterial as pam
>>> from paramaterial import DataSet, DataItem, ModelSet
>>> model_func = pam.models.linear
>>> param_names = ['E', 's_y']
>>> ms = ModelSet(model_func=model_func, param_names=param_names)
>>> ds = DataSet(info_path='info.csv', data_dir='data/')
>>> ms.fit_to(ds, x_key='strain', y_key='stress', sample_range=(0.0, 0.05), sample_size=100)
>>> prediction_ds = ms.predict(xmin=0, xmax=0.05)
Source code in paramaterial\modelling.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
fit_to(ds, x_key, y_key, sample_range=(None, None), sample_size=50, **scipy_method_kwargs)
Fits the model to a given DataSet using the specified x and y keys for the independent and dependent variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds |
DataSet
|
The DataSet containing the data to be fitted. |
required |
x_key |
str
|
The key for the independent variable (e.g., 'strain'). |
required |
y_key |
str
|
The key for the dependent variable (e.g., 'stress'). |
required |
sample_range |
Tuple[float, float]
|
The range of samples for fitting. Defaults to (None, None). |
(None, None)
|
sample_size |
int
|
The size of the sample data. Defaults to 50. |
50
|
**scipy_method_kwargs |
Additional keyword arguments to pass to the SciPy optimization method. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
None | Updates the fitting_table attribute with the fitting results. |
Examples:
>>> model_func = lambda x, args: args[0] * x + args[1] # Example linear model
>>> model_set = ModelSet(model_func, var_names=['a', 'b'], param_names=['slope', 'intercept'])
>>> ds = DataSet() # Assume this is a pre-loaded DataSet with 'strain' and 'stress' columns
>>> model_set.fit_to(ds, x_key='strain', y_key='stress')
Source code in paramaterial\modelling.py
predict(x_range=None, xmin=None, xmax=None, info_table=None, model_id_key='model_id')
Makes predictions based on the fitted model over a specified x-range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_range |
Tuple[float, float, float]
|
Range for prediction in the form (xmin, xmax, step). |
None
|
xmin |
float
|
Minimum x value for prediction. |
None
|
xmax |
float
|
Maximum x value for prediction. |
None
|
info_table |
pd.DataFrame
|
Information table containing parameters and variables. |
None
|
model_id_key |
str
|
Key for the model ID. Defaults to 'model_id'. |
'model_id'
|
Returns:
| Name | Type | Description |
|---|---|---|
DataSet | A DataSet containing the predicted values. |
Examples:
>>> x_range = (0, 10, 0.1) # Define x range for prediction
>>> predicted_ds = model_set.predict(x_range=x_range)