diff --git a/CHANGELOG.md b/CHANGELOG.md index 52b58a1..24f79f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # AutomationLabsSystems Changelog +## v0.1.8 + +* Remove dependencies AutomationLabsIdentification, MLJ, MLJMultivariateStatsInterface. +* Remove design_models.jl. +* Add type models for removing the AutomationLabsIdentification dependency. +* proceed_system_model_evaluation types modifications. + ## v0.1.7 * Add dict for return for _extract_model_from_machine functions. diff --git a/Project.toml b/Project.toml index 245cdfe..025d38e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,33 +1,30 @@ name = "AutomationLabsSystems" uuid = "6d3dfdf0-e107-48c6-a6ff-eced1a5a9334" authors = ["Pierre BLAUD and contributors"] -version = "0.1.7" +version = "0.1.8" [deps] -AutomationLabsIdentification = "48ff5a6f-d08b-4053-9585-6a9e3e078386" ControlSystems = "a6e380b2-a6ca-5380-bf3e-84a91bcd477e" Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043" -MLJ = "add582a8-e3ab-11e8-2d5e-e98b27df1bc7" -MLJMultivariateStatsInterface = "1b6a4a23-ba22-4f51-9698-8599985d3728" MathematicalSystems = "d14a8603-c872-5ed3-9ece-53e0e82e39da" NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" [compat] -AutomationLabsIdentification = "0.2" ControlSystems = "1.6" Flux = "0.13" ForwardDiff = "0.10" LazySets = "2" -MLJ = "0.19" -MLJMultivariateStatsInterface = "0.5" MathematicalSystems = "0.13" NNlib = "0.8" julia = "1" [extras] +AutomationLabsIdentification = "48ff5a6f-d08b-4053-9585-6a9e3e078386" +MLJ = "add582a8-e3ab-11e8-2d5e-e98b27df1bc7" +MLJMultivariateStatsInterface = "1b6a4a23-ba22-4f51-9698-8599985d3728" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test"] +test = ["Test", "AutomationLabsIdentification", "MLJ", "MLJMultivariateStatsInterface"] diff --git a/src/AutomationLabsSystems.jl b/src/AutomationLabsSystems.jl index 518cbda..6cfeec4 100644 --- a/src/AutomationLabsSystems.jl +++ b/src/AutomationLabsSystems.jl @@ -9,15 +9,13 @@ module AutomationLabsSystems import MathematicalSystems -import AutomationLabsIdentification -import MLJ -import MLJMultivariateStatsInterface import LazySets import Flux import ForwardDiff import NNlib import ControlSystems +# Export methods export proceed_system export proceed_system_linearization @@ -26,7 +24,6 @@ export proceed_system_model_evaluation # Load files include("types/types.jl") -include("sub/design_models.jl") include("sub/design_systems.jl") include("main/main_systems.jl") diff --git a/src/main/main_systems.jl b/src/main/main_systems.jl index 1a3123e..a90e966 100644 --- a/src/main/main_systems.jl +++ b/src/main/main_systems.jl @@ -202,44 +202,57 @@ function proceed_system_model_evaluation( sublayers_name = collect(keys(system.f)) if sublayers_name[1] == :fnn_input - model_type = AutomationLabsIdentification.Fnn() + #model_type = AutomationLabsIdentification.Fnn() + model_type = Fnn() elseif sublayers_name[1] == :icnn_input - model_type = AutomationLabsIdentification.Icnn() + #model_type = AutomationLabsIdentification.Icnn() + model_type = Icnn() + elseif sublayers_name[1] == :resnet_input - model_type = AutomationLabsIdentification.ResNet() + #model_type = AutomationLabsIdentification.ResNet() + model_type = ResNet() elseif sublayers_name[1] == :polynet_input - model_type = AutomationLabsIdentification.PolyNet() + #model_type = AutomationLabsIdentification.PolyNet() + model_type = PolyNet() elseif sublayers_name[1] == :densenet_input - model_type = AutomationLabsIdentification.DenseNet() + #model_type = AutomationLabsIdentification.DenseNet() + model_type = DenseNet() elseif sublayers_name[1] == :rbf_input - model_type = AutomationLabsIdentification.Rbf() + #model_type = AutomationLabsIdentification.Rbf() + model_type = Rbf() elseif sublayers_name[1] == :neuralode_inner - model_type = AutomationLabsIdentification.NeuralODE() + #model_type = AutomationLabsIdentification.NeuralODE() + model_type = NeuralODE() elseif sublayers_name[1] == :rknn1_identity - model_type = AutomationLabsIdentification.Rknn1() + #model_type = AutomationLabsIdentification.Rknn1() + model_type = Rknn1() elseif sublayers_name[1] == :rknn2_identity - model_type = AutomationLabsIdentification.Rknn2() + #model_type = AutomationLabsIdentification.Rknn2() + model_type = Rknn2() elseif sublayers_name[1] == :rknn4_identity - model_type = AutomationLabsIdentification.Rknn4() + #model_type = AutomationLabsIdentification.Rknn4() + model_type = Rknn4() elseif sublayers_name[1] == :rnn_input - model_type = AutomationLabsIdentification.Rnn() + #model_type = AutomationLabsIdentification.Rnn() + model_type = Rnn() elseif sublayers_name[1] == :lstm_input - model_type = AutomationLabsIdentification.Lstm() + #model_type = AutomationLabsIdentification.Lstm() + model_type = Lstm() elseif sublayers_name[1] == :gru_input - model_type = AutomationLabsIdentification.Gru() - + #model_type = AutomationLabsIdentification.Gru() + model_type = Gru() end return model_type diff --git a/src/sub/design_models.jl b/src/sub/design_models.jl deleted file mode 100644 index 7dadcaf..0000000 --- a/src/sub/design_models.jl +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright (c) 2022: Pierre Blaud and contributors -######################################################## -# This Source Code Form is subject to the terms of the # -# Mozilla Public License, v. 2.0. If a copy of the MPL # -# was not distributed with this file, # -# You can obtain one at https://mozilla.org/MPL/2.0/. # -######################################################## - -#to do find a better way to get the AutomationLabsIdentification type -function _get_mlj_model_type( - machine_mlj::MLJ.Machine{MLJMultivariateStatsInterface.MultitargetLinearRegressor,true}, -) - - return machine_mlj.model -end - -function _get_mlj_model_type(machine_mlj) - - return MLJ.fitted_params(MLJ.fitted_params(machine_mlj).machine).best_model.builder -end - -""" - _extract_model_from_machine -A function for design the system (model and constraints) with MathematicalSystems from linear model. -""" -function _extract_model_from_machine( - model_type::Union{ - AutomationLabsIdentification.Fnn, - AutomationLabsIdentification.Icnn, - AutomationLabsIdentification.ResNet, - AutomationLabsIdentification.DenseNet, - AutomationLabsIdentification.Rbf, - AutomationLabsIdentification.PolyNet, - AutomationLabsIdentification.NeuralODE, - AutomationLabsIdentification.Rknn1, - AutomationLabsIdentification.Rknn2, - AutomationLabsIdentification.Rknn4, - AutomationLabsIdentification.Rnn, - AutomationLabsIdentification.Lstm, - AutomationLabsIdentification.Gru, - }, - machine_mlj, -) - - # Extract best model from the machine - f = MLJ.fitted_params(MLJ.fitted_params(machine_mlj).machine).best_fitted_params[1] - - result = Dict(:f => f) - - return result -end - -""" - _extract_model_from_machine -A function for design the system (model and constraints) with MathematicalSystems for system from a tune model with mlj. -""" -function _extract_model_from_machine( - model_type::MLJMultivariateStatsInterface.MultitargetLinearRegressor, - machine_mlj, -) - - # Extract model from the machine - AB_t = MLJ.fitted_params(machine_mlj).coefficients - nbr_state = size(AB_t, 2) - - AB = copy(AB_t') - A = AB[:, 1:nbr_state] - B = AB[:, nbr_state+1:end] - - result = Dict(:A => A, :B => B) - # Set the system - return result -end diff --git a/src/types/types.jl b/src/types/types.jl index be95bd7..be41609 100644 --- a/src/types/types.jl +++ b/src/types/types.jl @@ -71,3 +71,88 @@ struct DiscreteNonLinearModel <: AbstractModel nbr_state::Int nbr_input::Int end + +#This is a type reformulation to avoid AutomationLabsIdentification types deps +""" + Fnn +An feedforward neural network architecture type for dynamical system identification problem [ref]. +""" +struct Fnn <: AbstractModel end + +""" + Rbf +An radial basis neural network architecture type for dynamical system identification problem [ref]. +""" +struct Rbf <: AbstractModel end + +""" + Icnn +An input convex neural network architecture type for dynamical system identification problem [ref]. +""" +struct Icnn <: AbstractModel end + +""" + ResNet +An residual layer network architecture type for dynamical system identification problem [ref]. +""" +struct ResNet <: AbstractModel end + +""" + PolyNet +An poly-inception network architecture type for dynamical system identification problem [ref]. +""" +struct PolyNet <: AbstractModel end + +""" + DenseNet +An densely connected network architecture type for dynamical system identification problem [ref]. +""" +struct DenseNet <: AbstractModel end + +""" +NeuralODE +An neural neural network ODE architecture type for dynamical system identification problem [ref]. +""" +struct NeuralODE <: AbstractModel end + +""" + Rknn1 +A runge-kutta neural neural network 1 architecture type for dynamical system identification problem [ref]. +""" +struct Rknn1 <: AbstractModel end + +""" + Rknn2 +A runge-kutta neural neural network 2 architecture type for dynamical system identification problem [ref]. +""" +struct Rknn2 <: AbstractModel end + +""" + Rknn4 +A runge-kutta neural neural network 4 architecture type for dynamical system identification problem [ref]. +""" +struct Rknn4 <: AbstractModel end + +""" + linear +An linear (Wv --> Ax + Bu) architecture type for dynamical system identification problem [ref]. +""" +struct Linear <: AbstractModel end + +""" + Rnn +A recurrent neural network architecture type for dynamical system identification problem [ref]. +""" +struct Rnn <: AbstractModel end + +""" + lstm +A long short-term memory recurrent neural network architecture type for dynamical system identification problem [ref]. +""" +struct Lstm <: AbstractModel end + +""" + gru +A gated recurrent unit recurrent neural network architecture type for dynamical system identification problem [ref]. +""" +struct Gru <: AbstractModel end \ No newline at end of file diff --git a/test/system_evaluation_test.jl b/test/system_evaluation_test.jl index 91036a5..4aba9f6 100644 --- a/test/system_evaluation_test.jl +++ b/test/system_evaluation_test.jl @@ -16,9 +16,6 @@ using MLJ using Flux using MLJMultivariateStatsInterface -import AutomationLabsSystems: _get_mlj_model_type -import AutomationLabsSystems: _extract_model_from_machine - ### Discrete ### @testset "Model evaluation fnn, resnet, ..." begin @@ -37,20 +34,20 @@ import AutomationLabsSystems: _extract_model_from_machine gru = machine("./models_saved/gru_train_result.jls") linear = machine("./models_saved/linear_regressor_train_result.jls") - fnn_type = _get_mlj_model_type(fnn) - icnn_type = _get_mlj_model_type(icnn) - resnet_type = _get_mlj_model_type(resnet) - polynet_type = _get_mlj_model_type(polynet) - densenet_type = _get_mlj_model_type(densenet) - rbf_type = _get_mlj_model_type(rbf) - neuralode_type = _get_mlj_model_type(neuralode) - rknn1_type = _get_mlj_model_type(rknn1) - rknn2_type = _get_mlj_model_type(rknn2) - rknn4_type = _get_mlj_model_type(rknn4) - rnn_type = _get_mlj_model_type(rnn) - lstm_type = _get_mlj_model_type(lstm) - gru_type = _get_mlj_model_type(gru) - linear_type = _get_mlj_model_type(linear) + fnn_type = AutomationLabsIdentification.get_mlj_model_type(fnn) + icnn_type = AutomationLabsIdentification.get_mlj_model_type(icnn) + resnet_type = AutomationLabsIdentification.get_mlj_model_type(resnet) + polynet_type = AutomationLabsIdentification.get_mlj_model_type(polynet) + densenet_type = AutomationLabsIdentification.get_mlj_model_type(densenet) + rbf_type = AutomationLabsIdentification.get_mlj_model_type(rbf) + neuralode_type = AutomationLabsIdentification.get_mlj_model_type(neuralode) + rknn1_type = AutomationLabsIdentification.get_mlj_model_type(rknn1) + rknn2_type = AutomationLabsIdentification.get_mlj_model_type(rknn2) + rknn4_type = AutomationLabsIdentification.get_mlj_model_type(rknn4) + rnn_type = AutomationLabsIdentification.get_mlj_model_type(rnn) + lstm_type = AutomationLabsIdentification.get_mlj_model_type(lstm) + gru_type = AutomationLabsIdentification.get_mlj_model_type(gru) + linear_type = AutomationLabsIdentification.get_mlj_model_type(linear) @test typeof(fnn_type) == typeof(AutomationLabsIdentification.Fnn()) @test typeof(icnn_type) == typeof(AutomationLabsIdentification.Icnn()) @@ -68,20 +65,20 @@ import AutomationLabsSystems: _extract_model_from_machine @test typeof(linear_type) == typeof(MLJMultivariateStatsInterface.MultitargetLinearRegressor(bias = false)) - f_fnn = _extract_model_from_machine(fnn_type, fnn) - f_icnn = _extract_model_from_machine(icnn_type, icnn) - f_resnet = _extract_model_from_machine(resnet_type, resnet) - f_polynet = _extract_model_from_machine(polynet_type, polynet) - f_densenet = _extract_model_from_machine(densenet_type, densenet) - f_rbf = _extract_model_from_machine(rbf_type, rbf) - f_neuralode = _extract_model_from_machine(neuralode_type, neuralode) - f_rknn1 = _extract_model_from_machine(rknn1_type, rknn1) - f_rknn2 = _extract_model_from_machine(rknn2_type, rknn2) - f_rknn4 = _extract_model_from_machine(rknn4_type, rknn4) - f_rnn = _extract_model_from_machine(rnn_type, rnn) - f_lstm = _extract_model_from_machine(lstm_type, lstm) - f_gru = _extract_model_from_machine(gru_type, gru) - f_linear = _extract_model_from_machine(linear_type, linear) + f_fnn = AutomationLabsIdentification.extract_model_from_machine(fnn_type, fnn) + f_icnn = AutomationLabsIdentification.extract_model_from_machine(icnn_type, icnn) + f_resnet = AutomationLabsIdentification.extract_model_from_machine(resnet_type, resnet) + f_polynet = AutomationLabsIdentification.extract_model_from_machine(polynet_type, polynet) + f_densenet = AutomationLabsIdentification.extract_model_from_machine(densenet_type, densenet) + f_rbf = AutomationLabsIdentification.extract_model_from_machine(rbf_type, rbf) + f_neuralode = AutomationLabsIdentification.extract_model_from_machine(neuralode_type, neuralode) + f_rknn1 = AutomationLabsIdentification.extract_model_from_machine(rknn1_type, rknn1) + f_rknn2 = AutomationLabsIdentification.extract_model_from_machine(rknn2_type, rknn2) + f_rknn4 = AutomationLabsIdentification.extract_model_from_machine(rknn4_type, rknn4) + f_rnn = AutomationLabsIdentification.extract_model_from_machine(rnn_type, rnn) + f_lstm = AutomationLabsIdentification.extract_model_from_machine(lstm_type, lstm) + f_gru = AutomationLabsIdentification.extract_model_from_machine(gru_type, gru) + f_linear = AutomationLabsIdentification.extract_model_from_machine(linear_type, linear) nbr_state = 4 nbr_input = 2 @@ -116,19 +113,19 @@ import AutomationLabsSystems: _extract_model_from_machine lstm_type_2 = proceed_system_model_evaluation(sys_lstm) gru_type_2 = proceed_system_model_evaluation(sys_gru) - @test typeof(fnn_type) == typeof(fnn_type_2) - @test typeof(icnn_type) == typeof(icnn_type_2) - @test typeof(resnet_type) == typeof(resnet_type_2) - @test typeof(polynet_type) == typeof(polynet_type_2) - @test typeof(densenet_type) == typeof(densenet_type_2) - @test typeof(rbf_type) == typeof(rbf_type_2) - @test typeof(neuralode_type) == typeof(neuralode_type_2) - @test typeof(rknn1_type) == typeof(rknn1_type_2) - @test typeof(rknn2_type) == typeof(rknn2_type_2) - @test typeof(rknn4_type) == typeof(rknn4_type_2) - @test typeof(rnn_type) == typeof(rnn_type_2) - @test typeof(lstm_type) == typeof(lstm_type_2) - @test typeof(gru_type) == typeof(gru_type_2) + @test AutomationLabsSystems.Fnn == typeof(fnn_type_2) + @test AutomationLabsSystems.Icnn == typeof(icnn_type_2) + @test AutomationLabsSystems.ResNet == typeof(resnet_type_2) + @test AutomationLabsSystems.PolyNet == typeof(polynet_type_2) + @test AutomationLabsSystems.DenseNet == typeof(densenet_type_2) + @test AutomationLabsSystems.Rbf == typeof(rbf_type_2) + @test AutomationLabsSystems.NeuralODE == typeof(neuralode_type_2) + @test AutomationLabsSystems.Rknn1 == typeof(rknn1_type_2) + @test AutomationLabsSystems.Rknn2 == typeof(rknn2_type_2) + @test AutomationLabsSystems.Rknn4 == typeof(rknn4_type_2) + @test AutomationLabsSystems.Rnn == typeof(rnn_type_2) + @test AutomationLabsSystems.Lstm == typeof(lstm_type_2) + @test AutomationLabsSystems.Gru == typeof(gru_type_2) end