Commit 35cb4161 authored by Johannes Blaschke's avatar Johannes Blaschke
Browse files

correct implementation of the `left` and `right` fluxes

parent c25a94e0
Loading
Loading
Loading
Loading
+25 −119
Original line number Diff line number Diff line
%% Cell type:code id: tags:

``` julia
include("src/fp.jl")
```

%% Output

    Main.FP

%% Cell type:code id: tags:

``` julia
using .FP
```

%% Cell type:code id: tags:

``` julia
f = FluxArray{Float64}(10)
N = 10
```

%% Output

    FluxArray{Float64}([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, 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], Distributions.Normal{Float64}(μ=0.0, σ=1.0))
    10

%% Cell type:code id: tags:

``` julia
f.total[1] = 2
n = zeros(N);
f = FluxArray{Float64}(N);
```

%% Output

    2

%% Cell type:code id: tags:

``` julia
f
n[Integer(length(n)/2)] = 1
```

%% Output

    FluxArray{Float64}([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.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], Distributions.Normal{Float64}(μ=0.0, σ=1.0))
    1

%% Cell type:code id: tags:

``` julia
size(f)
fill_fr!(f);
fill_lr!(f, n);
```

%% Output

    11

%% Cell type:code id: tags:

``` julia
f.total
f.left
```

%% Output

    11-element Array{Float64,1}:
     2.0
     0.0
    10-element Array{Float64,1}:
     0.0
     0.0
     0.0
     0.0
     0.4837357890990863
     0.0
     0.0
     0.0
     0.0
     0.0

%% Cell type:code id: tags:

``` julia
reset!(f, 0.)
```

%% Cell type:code id: tags:

``` julia
f.total
f.right
```

%% Output

    11-element Array{Float64,1}:
     0.0
     0.0
    10-element Array{Float64,1}:
     0.0
     0.0
     0.0
     0.0
     0.5162642109009137
     0.0
     0.0
     0.0
     0.0
     0.0

%% Cell type:code id: tags:

``` julia
fill_fr!(f)
```

%% Output

    10-element Array{Float64,1}:
     0.3719488756174305
     0.7078439875853346
     0.14686744039919186
     0.7371645339687076
     0.28061514908409957
     0.06665763097169641
     0.3619721310699473
     0.5156590411935236
     0.9600217110629821
     0.0028426574179554187

%% Cell type:code id: tags:

``` julia
f.fr
f.left .+ f.right
```

%% Output

    10-element Array{Float64,1}:
     0.3719488756174305
     0.7078439875853346
     0.14686744039919186
     0.7371645339687076
     0.28061514908409957
     0.06665763097169641
     0.3619721310699473
     0.5156590411935236
     0.9600217110629821
     0.0028426574179554187

%% Cell type:code id: tags:

``` julia
fill_lr!(f)
```

%% Output

    10-element Array{Float64,1}:
      0.15640224893447258
     -0.8567724114538633
     -0.03319116142866772
     -0.015849254780078256
      0.8756940245445292
      0.05592573265792126
     -0.43241475945139746
     -0.3858741762658584
      0.31423851240411305
     -0.0027535889452761316

%% Cell type:code id: tags:

``` julia
f.left
```

%% Output

    10-element Array{Float64,1}:
     -0.225580551433496
     -0.4954587637915302
      0.43257977013920135
      0.6598113417294635
     -0.8498029315267405
      0.7326503841221602
     -0.415898912958631
      1.8333641220723385
      0.034033453904415645
     -1.9254946253093828

%% Cell type:code id: tags:

``` julia
f.right
```

%% Output

    10-element Array{Float64,1}:
      0.42049394200976353
     -1.2103972435742056
     -0.22599400751080537
     -0.021500294777815575
      3.1206227725149867
      0.8389997040499078
     -1.1946078781624154
     -0.7483126357539075
      0.32732438108735384
     -0.9686671801826372
     0.0
     0.0
     0.0
     0.0
     1.0
     0.0
     0.0
     0.0
     0.0
     0.0

%% Cell type:code id: tags:

``` julia
```
+6 −4
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ import Base.size
import Random.rand!
import Distributions.Normal

struct FluxArray{T}
mutable struct FluxArray{T}
    #
    # FluxArrays store flux data as Struct-of-Arrays. These arrays are allocated
    # and initialized (to zero) by the constructor (each array has length `n+1`
@@ -59,9 +59,11 @@ function fill_fr!(flx::FluxArray{T}) where T
    rand!(flx.fr);
end

function fill_lr!(flx::FluxArray{T}) where T
    rand!(flx.distribution, flx.left)  .* (1 .- flx.fr)
    rand!(flx.distribution, flx.right) .* flx.fr
function fill_lr!(flx::FluxArray{T}, n::Array{T}) where T
    #rand!(flx.distribution, flx.left)  .* (1 .- flx.fr);
    #rand!(flx.distribution, flx.right) .* flx.fr;
    flx.left  = n .* (1 .- flx.fr);
    flx.right = n .* flx.fr;
end