Static.jl

Description of internally used functions for the learning of the static parameters.

Contents

Index

Functions

ContGridModML._learn_susceptancesMethod
_learn_susceptances(
    A::SparseArrays.AbstractSparseMatrix,
    Islack::SparseArrays.AbstractSparseMatrix,
    q_proj::SparseArrays.AbstractSparseMatrix,
    disc_proj::SparseArrays.AbstractSparseMatrix,
    f_train::Array{T<:Real, 2},
    th_train::Array{T<:Real, 2},
    p::Array{T<:Real, 1},
    eve::Array{T<:Real, 2},
    comp_ix::Vector{Int64},
    n_epoch::Integer,
    n_batch::Int64;
    opt,
    bmin,
    rng,
    δ
) -> Tuple{Any, Matrix{T} where T<:Real}

Do the actual learning of the parameters.

source
ContGridModML.assemble_disc_thetaMethod
assemble_disc_theta(
    dataset::Vector{ContGridModML.DiscModel}
) -> Matrix{<:Real}

Assemble all the ground truth data into one matrix for the training and one for the test sets.

source
ContGridModML.assemble_f_staticMethod
assemble_f_static(
    model::ContGridModML.ContModel,
    dataset::Vector{ContGridModML.DiscModel},
    Af::SparseArrays.SparseMatrixCSC
) -> Matrix{Float64}

Assemble the force vectors for the static solutions.

source
ContGridModML.assemble_matrices_staticMethod
assemble_matrices_static(
    model::ContGridModML.ContModel
) -> Tuple{SparseArrays.SparseMatrixCSC{Float64, Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}}

Create all the necessary finite element matrices from a given model.

The returned matrices are

  • Af the matrix needed to create the force vector as f = Af * p_quad
  • Ak the matrix needed to create the stiffness matrix as K = A * b_quad * A'. The susceptances need to be ordered as $b_x(\mathbf{q_1}), b_y(\mathbf{q_1}), b_x(\mathbf{q_2}),\dots$
  • dim matrix with single entry for the slack bus to ensure well-posedness of the system of linear equations
  • q_coords Coordinates of the quadrature points in the same order as stored in the DoF-handler
source
ContGridModML.check_slackMethod
check_slack(
    dataset::Vector{ContGridModML.DiscModel}
) -> Bool

Check if all the slack buses in the training and test data sets are the same.

source
ContGridModML.discrete_modelsMethod
discrete_models(
    train_folder::String,
    test_folder::String,
    scale_factor::Real
) -> Tuple{Vector{ContGridModML.DiscModel}, Vector{ContGridModML.DiscModel}}

Load all the discrete models for the training and test data sets.

source
ContGridModML.get_lossesMethod
get_losses(
    train_pred::Matrix{<:Real},
    test_pred::Matrix{<:Real},
    t_train::Matrix{<:Real},
    t_test::Matrix{<:Real};
    δ
) -> Tuple{Vector{T} where T<:Real, Vector{T} where T<:Real}

Obtain the loss values for the training and test data sets.

source
ContGridModML.learn_susceptancesMethod
learn_susceptances(
;
    train_folder,
    test_folder,
    mesh_fn,
    n_epoch,
    n_batch,
    n_modes,
    n_coeffs,
    comp_ix,
    bx_init,
    by_init,
    rng,
    opt,
    bmin,
    δ
) -> ContGridModML.StaticSol{Float64}

Learn the line susceptances.

The parameters are learned by calculating the stable solution for multiple dispatches and comparing them to the results from the discrete model. The comparison points are obtained by using the liear approximation provided by the finite element method.

Arguments

  • train_fn::String = MODULE_FOLDER * "/data/ml/training_": The names of the files containing the training scenarios. The files must be labeled train_fn1.h5, train_fn2.h5, etc.
  • test_fn::String = MODULE_FOLDER * "/data/ml/test_": The names of the files containing the test scenarios. The files must be labeled test.h5, test.h5, etc.
  • grid_fn::String = MODULE_FOLDER * "/data/panta.msh": Name of the file containing the mesh
  • n_train::Int = 48: Number of training data sets
  • n_test::Int = 12: Number of test data sets
  • n_epochs::Int = 10000: Number of epochs
  • n_batches::Int = 3: Number of batches per epoch
  • tf::Real = 0.05: Duration of the heat equation diffusion for the power distribution
  • κ::Real = 0.02: Diffusion constant of the heat equation diffusion for the power distribution
  • σ::Real = 0.01: Standard deviation for the initial Gaussian distribution of the parameters
  • rng::AbstractRNG = Xoshiro(): Random number generator used to draw all random numbers
  • bmin::Real = 0.1: Minimimum value of the suscpetances
  • δ = 0.5: Parameter of the Huber loss function
source
ContGridModML.predictionMethod
prediction(
    K::SparseArrays.AbstractSparseMatrix,
    f_train::Array{T<:Real, 2},
    f_test::Array{T<:Real, 2},
    proj::SparseArrays.AbstractSparseMatrix
) -> Tuple{Any, Any}

Obtain the prediction of the stable solution for the training and test data sets.

source
ContGridModML.projectors_staticMethod
projectors_static(
    model::ContGridModML.ContModel,
    dm::ContGridModML.DiscModel
) -> Tuple{SparseArrays.SparseMatrixCSC{Float64, Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}}

Projectors of nodal values onto the discrete values and the quadrature points.

The returned matrices are

  • θ_proj project the nodal values onto the discrete nodes for comparison
  • q_proj_b project the susceptances onto the quadrature points. The susceptances need to be ordered as $b_x(\mathbf{r_1}), b_y(\mathbf{r_1}), b_x(\mathbf{r_2}),\dots$
source