alanderos91 / BioSimulator.jl

A stochastic simulation framework in Julia.
https://alanderos91.github.io/BioSimulator.jl/stable/
Other
47 stars 7 forks source link

unexpected 0s in the output #20

Closed skycolt closed 5 years ago

skycolt commented 5 years ago

Hello,

I am trying to use the package to do some simulation. I started with a very simple model

model = Network("test")

species definitions

model <= Species("A", 10) model <= Species("B", 0)

reaction definitions

model <= Reaction("R1", 1., "A --> B") model <= Reaction("R2", 1., "B --> A")

result = simulate(model, Direct(), time = 4.0, epochs = 40, trials = 1)

The behavior of the model is that A and B interconvert to each other and their total will always be 10. But the simulation result is very wired. If I set trials number to be 1. I consistently get all 0s for both A and B. If I set trial number to be 2 or 3, all 0s. If trial number is 4, the result seems to be OK. If I set trials to be 10, the last two runs always give me all 0s. I don't know what's really going on but there are definitely something wrong. Please help me with this.

Thanks Wenzhe

alanderos91 commented 5 years ago

Happy to help but I need a bit more information.

How did you attempt to retrieve the simulation data?

Following your code:

# access the state data for trial 1
julia> result.simulation_data[1].xdata
2×41 Array{Int64,2}:
 10  9  8  8  8  8  8  8  8  8  7  …  8  6  7  6  7  8  8  8  7  7
  0  1  2  2  2  2  2  2  2  2  3     2  4  3  4  3  2  2  2  3  3

# access the saved time points
julia> result.simulation_data[1].tdata
41-element Array{Float64,1}:
 0.0
 0.1
 0.2
 0.3
 0.4
 0.5
 0.6
 0.7
 ⋮
 3.4
 3.5
 3.6
 3.7
 3.8
 3.9
 4.0

Alternative we discussed before:


julia> using DataFrames

julia> DataFrame(result)
41×4 DataFrame
│ Row │ trial │ time    │ A     │ B     │
│     │ Int64 │ Float64 │ Int64 │ Int64 │
├─────┼───────┼─────────┼───────┼───────┤
│ 1   │ 1     │ 0.0     │ 10    │ 0     │
│ 2   │ 1     │ 0.1     │ 9     │ 1     │
│ 3   │ 1     │ 0.2     │ 8     │ 2     │
│ 4   │ 1     │ 0.3     │ 8     │ 2     │
│ 5   │ 1     │ 0.4     │ 8     │ 2     │
⋮
│ 36  │ 1     │ 3.5     │ 7     │ 3     │
│ 37  │ 1     │ 3.6     │ 8     │ 2     │
│ 38  │ 1     │ 3.7     │ 8     │ 2     │
│ 39  │ 1     │ 3.8     │ 8     │ 2     │
│ 40  │ 1     │ 3.9     │ 7     │ 3     │
│ 41  │ 1     │ 4.0     │ 7     │ 3     │
skycolt commented 5 years ago

Thanks for the fast response. I used the most simple way:

result.simulation_data[n].xdata

skycolt commented 5 years ago

julia> result.simulation_data[1].xdata 2×41 Array{Int64,2}: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

this is what I got...

skycolt commented 5 years ago

I start to think will there be some version difference between your code and the code on GitHub. Because the code I installed has a weird behavior that the last mod(totalnumber, 4) traces are all 0s. I tried it on several computer and it's consistent.

skycolt commented 5 years ago

I restarted the Atom and the problem seems to have been solved. I still don't know what's going wrong but anyway, sorry about the false alarm

alanderos91 commented 5 years ago

That is strange behavior. I tend to use a REPL outside of Atom but I'll keep this on my radar. Thanks for reporting this.