SubspaceInference.jl
The subspace inference method for Deep Neural Networks (DNN) and ordinary differential equations (ODEs) are implemented as a package named SubspaceInference.jl in Julia.
Subspace Construction
PCA based subspace construction
SubspaceInference.subspace_construction — Methodsubspace_construction(model, cost, data, opt; T = 10, c = 1, M = 3, print_freq = 1)Izmailov, P., Maddox, W. J., Kirichenko, P., Garipov, T., Vetrov, D., & Wilson, A. G. (2020, August). Subspace inference for Bayesian deep learning. In Uncertainty in Artificial Intelligence (pp. 1169-1179). PMLR.
To construct subspace from pretrained weights.
Input Arguments
model: Machine learning model. Eg: Chain(Dense(10,2)). Model should be created with Chain in Fluxcost: Cost function. Eg: L(x, y) = Flux.Losses.mse(m(x), y)data: Inputs and outputs. Eg: X = rand(10,100); Y = rand(2,100); data = DataLoader(X,Y);opt: Optimzer. Eg: opt = ADAM(0.1)
Keyword Arguments
T: Number of steps for subspace calculation. Eg: T= 1c: Moment update frequency. Eg: c = 1M: Maximum number of columns in deviation matrix. Eg: M= 2print_freq: Loss printing frequency
Outputs
W_swa: Mean weightsP: Projection Matrix
Diffusion map based subspace construction
SubspaceInference.diffusion_subspace — Methoddiffusion_subspace(model, cost, data, opt; T = 10, c = 1, M = 3, print_freq = 1)To construct subspace from pretrained weights using diffusion maps.
Input Arguments
model: Machine learning model. Eg: Chain(Dense(10,2)). Model should be created with Chain in Fluxcost: Cost function. Eg: L(x, y) = Flux.Losses.mse(m(x), y)data: Inputs and outputs. Eg: X = rand(10,100); Y = rand(2,100); data = DataLoader(X,Y);opt: Optimzer. Eg: opt = ADAM(0.1)
Keyword Arguments
T: Number of steps for subspace calculation. Eg: T= 1c: Moment update frequency. Eg: c = 1M: Maximum number of columns in deviation matrix. Eg: M= 2print_freq: Loss printing frequency
Outputs
W_swa: Mean weightsP: Projection Matrix
Autoencoder based subspace construction
SubspaceInference.auto_encoder_subspace — Methodauto_encoder_subspace(model, cost, data, opt, encoder, decoder; T = 10, c = 1, M = 3, print_freq = 1)
To construct subspace from pretrained weights using autoencoders.
Input Arguments
model: Machine learning model. Eg: Chain(Dense(10,2)). Model should be created with Chain in Fluxcost: Cost function. Eg: L(x, y) = Flux.Losses.mse(m(x), y)data: Inputs and outputs. Eg: X = rand(10,100); Y = rand(2,100); data = DataLoader(X,Y);opt: Optimzer. Eg: opt = ADAM(0.1)encoder: Encoder to generate subspace from NN or Neural ODE parametersdecoder: Decoder to generate NN or Neural ODE parameters from subspace
Keyword Arguments
T: Number of steps for subspace calculation. Eg: T= 1c: Moment update frequency. Eg: c = 1M: Maximum number of columns in deviation matrix. Eg: M= 2print_freq: Loss printing frequency
Outputs
W_swa: Mean weightsdecoder: Trained decoder to generate NN or Neural ODE parameters from subspace