Static.jl
Description of internally used functions for the learning of the static parameters.
Contents
Index
ContGridModML._learn_susceptances
ContGridModML.assemble_disc_theta
ContGridModML.assemble_f_static
ContGridModML.assemble_matrices_static
ContGridModML.check_slack
ContGridModML.discrete_models
ContGridModML.get_losses
ContGridModML.learn_susceptances
ContGridModML.prediction
ContGridModML.projectors_static
Functions
ContGridModML._learn_susceptances
— Method_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.
ContGridModML.assemble_disc_theta
— Methodassemble_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.
ContGridModML.assemble_f_static
— Methodassemble_f_static(
model::ContGridModML.ContModel,
dataset::Vector{ContGridModML.DiscModel},
Af::SparseArrays.SparseMatrixCSC
) -> Matrix{Float64}
Assemble the force vectors for the static solutions.
ContGridModML.assemble_matrices_static
— Methodassemble_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 asf = Af * p_quad
Ak
the matrix needed to create the stiffness matrix asK = 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 equationsq_coords
Coordinates of the quadrature points in the same order as stored in the DoF-handler
ContGridModML.check_slack
— Methodcheck_slack(
dataset::Vector{ContGridModML.DiscModel}
) -> Bool
Check if all the slack buses in the training and test data sets are the same.
ContGridModML.discrete_models
— Methoddiscrete_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.
ContGridModML.get_losses
— Methodget_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.
ContGridModML.learn_susceptances
— Methodlearn_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 labeledtrain_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 labeledtest.h5
,test.h5
, etc.grid_fn::String = MODULE_FOLDER * "/data/panta.msh"
: Name of the file containing the meshn_train::Int = 48
: Number of training data setsn_test::Int = 12
: Number of test data setsn_epochs::Int = 10000
: Number of epochsn_batches::Int = 3
: Number of batches per epochtf::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 parametersrng::AbstractRNG = Xoshiro()
: Random number generator used to draw all random numbersbmin::Real = 0.1
: Minimimum value of the suscpetancesδ = 0.5
: Parameter of the Huber loss function
ContGridModML.prediction
— Methodprediction(
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.
ContGridModML.projectors_static
— Methodprojectors_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 comparisonq_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$