This repository contains the code for the following paper:
Lingxiao Yuan, Harold Park*, Emma Lejeune*
Out of Distribution Generalization for Problems in Mechanics
The experiments use the following dataset. The datasets contains six benchmark out of distirbution datasets specifically for regression problems in mechanics.
envs_details
This folder contains more details of the process of how we generate and select data for OOD dataset. This information is not needed for reproducing the results from the paper.
sampling_bias_demo.ipynb: The demo of creating data distrbution dataset caused by sampling biasmake_envs_sampling_bias_MNIST.py: The demo code for generating sampling bias dataset from Mechanical MNIST datasetindex_dataset_MNIST_EMNIST.txt: The corresponding index of the OOD data in the original MNIST and EMNIST Letters
model
This folder contains the information of reproducing the results from the paper.
model.py: The two Machine Learning models (MLP and modified LeNet) for implementing all algorithmsmake_envs.py: The file loads dataset and makes a list containing data from different environmentsmain.py: The whole framework of training process using different algorithms for out of distribution problemsevaluation.py: Demo code for evaluating the trained model on covariate shift datasetsubmit_job.sh: Submit job for training models by selected hyperparameters
Below are the parameters to choose for training the model. The selected hyperparamters were given in the paper. But the results are not guaranteed to be exactly the same due to randomness.
lr: learning ratesteps: the whole epochs for training the modelpenalty_anneal_iters: the anneal step after which we add the penalty to the loss functionpenalty_weight: the weight of penalty term, this controls the strength of the penalty termalgorithm: the name of the algorithm to implemente (erm,irm,rex,iga)model: the name of the model to train(mlp,lenet)
The main.py file adapted three algorithms designed for out of distribution problems. Below are the links to these paper and the source code for the IRM algorithms that we adapted.
-
IRM:Invariant Risk Minimization
Code for IRM:https://github.com/facebookresearch/InvariantRiskMinimization, licensed under LICENCE
-
REx:Out-of-Distribution Generalization via Risk Extrapolation (REx)
-
IGA:Out-of-Distribution Generalization with Maximal Invariant Predictor
Code for implementing finite element simulation of heterogeneous material subject to large deformation due to equibiaxial extension is available on GitHub, the environmental control parameter
The Mechanical MNIST - Equibiaxial Extension Collection from which sampling bias data is created is available on OpenBU Institutional Repository at: https://open.bu.edu/handle/2144/39428
