Commit 3a66012a authored by Godoy, William's avatar Godoy, William

Merge branch 'linear-model' into 'master'

Linear model

See merge request !4
parents c0fed3e1 b6786836
...@@ -11,7 +11,7 @@ mutable struct Amrex <: AbstractAmrex ...@@ -11,7 +11,7 @@ mutable struct Amrex <: AbstractAmrex
Amrex(outputPrefix::String, runlogFile::String) = new( Amrex(outputPrefix::String, runlogFile::String) = new(
"Amrex", "Amrex",
outputPrefix, outputPrefix,
["max_step", "amr.check_int", "amr.plot_int", "amr.n_cell", "amr.max_level"], ["max_step", "amr.check_int", "amr.plot_int", "amr.n_cell", "amr.max_level", "caseID"],
["plots_size", "checkpoints_size"], ["plots_size", "checkpoints_size"],
runlogFile, runlogFile,
) )
......
...@@ -24,7 +24,7 @@ struct AmrexCastro <: AbstractAmrex ...@@ -24,7 +24,7 @@ struct AmrexCastro <: AbstractAmrex
"castro.max_grid_size", "castro.max_grid_size",
], ],
Dict{String,Array{String}}( Dict{String,Array{String}}(
"plots_size" => ["amr.nplot_files", "amr.ncells", "amr.max_level"], "plots_size" => ["amr.nplot_files", "amr.ncells"],
"checks_size" => [ "checks_size" => [
"amr.check_int", "amr.check_int",
"amr.ncheck_files", "amr.ncheck_files",
...@@ -67,6 +67,7 @@ function _get_input_file(extractor::AmrexCastro, outputDir::String)::String ...@@ -67,6 +67,7 @@ function _get_input_file(extractor::AmrexCastro, outputDir::String)::String
else else
end end
# print(inputFiles)
return inputFiles[1] return inputFiles[1]
end end
...@@ -75,7 +76,7 @@ end ...@@ -75,7 +76,7 @@ end
function _get_linear_model_X(extractor::AmrexCastro)::DataFrames.DataFrame function _get_linear_model_X(extractor::AmrexCastro)::DataFrames.DataFrame
# get directories runs output location # get directories runs output location
outputDirs = helper_get_prefix_directories(extractor.outputPrefix) outputDirs = helper_get_prefix_directories(extractor.outputPrefix)
# println(outputDirs) println(outputDirs)
X::DataFrames.DataFrame = DataFrames.DataFrame() X::DataFrames.DataFrame = DataFrames.DataFrame()
isXInit::Bool = false isXInit::Bool = false
...@@ -84,13 +85,15 @@ function _get_linear_model_X(extractor::AmrexCastro)::DataFrames.DataFrame ...@@ -84,13 +85,15 @@ function _get_linear_model_X(extractor::AmrexCastro)::DataFrames.DataFrame
inputFile::String = _get_input_file(extractor, outputDir) inputFile::String = _get_input_file(extractor, outputDir)
# get relevant input parameters # get relevant input parameters
parameters = _input_parser(extractor, inputFile) parameters = _input_parser(extractor, inputFile)
independent_variables = _get_independent_variables(extractor, parameters) independentVariables = _get_independent_variables(extractor, parameters)
# get outputDir name
independentVariables["caseID"] = helper_get_relative_path(outputDir)
if !isXInit if !isXInit
X = DataFrames.DataFrame(independent_variables) X = DataFrames.DataFrame(independentVariables)
isXInit = true isXInit = true
else else
DataFrames.push!(X, independent_variables) DataFrames.push!(X, independentVariables)
end end
end end
...@@ -125,21 +128,31 @@ function _run_linear_model_plots_size(extractor::AmrexCastro, X::DataFrames.Data ...@@ -125,21 +128,31 @@ function _run_linear_model_plots_size(extractor::AmrexCastro, X::DataFrames.Data
push!(plotsSizesData, [plotsSize]) push!(plotsSizesData, [plotsSize])
end end
println(plotsSizesData)
# Prepare the X independent variables in the linear model # Prepare the X independent variables in the linear model
XNames::Array{String} = extractor.outputs["plots_size"] XNames::Array{String} = extractor.outputs["plots_size"]
for XName in XNames col1 = Symbol("amr.nplot_files")
columnName = Symbol(XName) col2 = Symbol("amr.ncells")
insert!(plotsSizesData, 2 ,X[!,col1] .* X[!,col2], :new_data)
#plotsSizesData[!,col1] =
#for XName in XNames
#columnName = Symbol(XName)
# this syntax [!, symbol] does not make a copy, use [:, symbol] for copies # this syntax [!, symbol] does not make a copy, use [:, symbol] for copies
plotsSizesData[!, columnName] = X[!, columnName] #plotsSizesData[!, columnName] = X[!, columnName]
end #end
# formula from https://discourse.julialang.org/t/glm-jl-with-unknown-column-names/20692/5 # formula from https://discourse.julialang.org/t/glm-jl-with-unknown-column-names/20692/5
response = Symbol(names(plotsSizesData)[1]) response = Symbol(names(plotsSizesData)[1])
predictors = Symbol.(names(plotsSizesData)[2:end]) predictors = Symbol.(names(plotsSizesData)[2:end])
println(plotsSizesData) println(plotsSizesData)
f = @eval(GLM.@formula($response ~ (+)(1, $(predictors...)))) f = @eval(GLM.@formula($response ~ (+)( $(predictors...))))
ols = GLM.lm(f, plotsSizesData) ols = GLM.lm(f, plotsSizesData)
......
...@@ -22,6 +22,18 @@ function helper_get_prefix_directories(prefix::String)::Array{String} ...@@ -22,6 +22,18 @@ function helper_get_prefix_directories(prefix::String)::Array{String}
end end
function helper_get_relative_path(fullName::String)::String
findDelimiter = findlast("/", fullName)
# if findDelimiter == Nothing
# return fullName
# end
relativeName = string(fullName[findDelimiter[1]+1:end])
return relativeName
end
""" """
Gets the list of files inside a path that meet the prefix criteria. Gets the list of files inside a path that meet the prefix criteria.
Example: Example:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment