YangLab-um / BiologicalOscillations.jl

A package for researchers working with biological oscillations
https://yanglab-um.github.io/BiologicalOscillations.jl/
MIT License
1 stars 2 forks source link

Add option to customize what's saved by find_oscillations #31

Closed ftavella closed 8 months ago

ftavella commented 8 months ago

Issue

Currently, find_pin_oscillations and find_grn_oscillations save the following to disk after the simulation is finished:

pin_result = Dict("model" => model,
                           "parameter_sets" => DataFrame(parameter_sets, parameter_names),
                           "equilibration_result" => DataFrame(equilibration_result),
                           "simulation_result" => DataFrame(simulation_result)
)  

where equilibration_result contains

equilibration_result = Dict(
    "parameter_index" => collect(1:1:samples),
    "equilibration_times" => equilibration_times,
    "final_velocity" => equilibration_data["final_velocity"],
    "frequency" => equilibration_data["frequency"],
    "is_steady_state" => .!filter,)
final_state = mapreduce(permutedims, vcat, equilibration_data["final_state"])
for i=1:N
    equilibration_result["final_state_$(i)"] = final_state[:,i]
end

and simulation_result contains:

simulation_result = Dict(
        "parameter_index" => collect(1:1:samples)[filter],
        "simulation_times" => simulation_times[filter],
        "is_oscillatory" => oscillatory_status,)
    final_state = mapreduce(permutedims, vcat, simulation_data["final_state"])
    for i=1:N
        frequency = Array{Float64}(undef, 0)
        power = Array{Float64}(undef, 0)
        amplitude = Array{Float64}(undef, 0)
        peak_variation = Array{Float64}(undef, 0)
        trough_variation = Array{Float64}(undef, 0)
        for j=1:sum(filter)
            push!(frequency, simulation_data["frequency_data"][j]["frequency"][i])
            push!(power, simulation_data["frequency_data"][j]["power"][i])
            push!(amplitude, simulation_data["amplitude_data"][j]["amplitude"][i])
            push!(peak_variation, simulation_data["amplitude_data"][j]["peak_variation"][i])
            push!(trough_variation, simulation_data["amplitude_data"][j]["trough_variation"][i])
        end
        simulation_result["final_state_$(i)"] = final_state[:,i]
        simulation_result["frequency_$(i)"] = frequency
        simulation_result["fft_power_$(i)"] = power
        simulation_result["amplitude_$(i)"] = amplitude
        simulation_result["peak_variation_$(i)"] = peak_variation
        simulation_result["trough_variation_$(i)"] = trough_variation
    end

Also, parameter_sets contains the information about ALL simulated parameter sets (oscillatory and non-oscillatory). Finally, the current implementation does not save the hyperparameter information by default.

Proposed solution

I propose to make the variables to save be optional via the use of hyperparameters. We can have an entry on hyperparameters called simulation_output that specifies what quantities are saved. Additionally, we should save the hyperparameters used on each call by default.

To make an effort towards generalizing the code we should also avoid calling variables pin_result or grn_result and should stick to generic names.

Additionally, to save space when saving the simulation result, we can include the option of generating parameter sets based on a random seed (and saving that seed for later reproduction of the parameter set).