Phylogenetic trees

using TensorDec
normalize_markov! = function(w,A,B,C) 
    for i in 1:size(A,2) 
        l = sum(A[j,i] for j in 1:size(A,1) ) 
        A[:,i] /= l
        w[i] *= l
    end
    for i in 1:size(B,2) 
        l = sum(B[j,i] for j in 1:size(B,1) ) 
        B[:,i] /=l
        w[i] *= l
    end
    for i in 1:size(C,2) 
        l = sum(C[j,i] for j in 1:size(B,1) ) 
        C[:,i] /=l
        w[i] *= l
    end
    w, A,B,C
end
#3 (generic function with 1 method)
A = rand(4,4); B = rand(4,4); C = rand(4,4); w = rand(4);
normalize_markov!(w,A,B,C)
fill(1.,4)'*A, fill(1.,4)'*B, fill(1.,4)'*C
([1.0 1.0 1.0 1.0], [1.0 1.0 1.0 1.0], [1.0 1.0 1.0 1.0])
t = tensor(w,A,B,C)
4×4×4 Array{Float64,3}:
[:, :, 1] =
 0.22132   0.166737  0.254042  0.0613668
 0.092515  0.112218  0.194429  0.0814187
 0.316227  0.225333  0.297283  0.0668594
 0.309741  0.261594  0.293648  0.110342 

[:, :, 2] =
 0.0403731  0.0268474  0.0398125  0.0135116
 0.024117   0.0254106  0.0371     0.0226149
 0.0546752  0.0364448  0.0452751  0.0139016
 0.0583531  0.0540776  0.051944   0.0289579

[:, :, 3] =
 0.15016    0.0921238  0.133752  0.0523025
 0.0810969  0.0689567  0.112981  0.0703695
 0.196223   0.121267   0.146411  0.0483899
 0.180559   0.144179   0.137036  0.0674456

[:, :, 4] =
 0.119343   0.11672   0.22974   0.0601882
 0.0967337  0.124609  0.217909  0.0854228
 0.146758   0.136596  0.242653  0.0650576
 0.168666   0.191626  0.252545  0.11588
wd, Ad, Bd, Cd = decompose(t)
normalize_markov!(wd,Ad,Bd,Cd)
MethodError: no method matching decompose(::Array{Array{Float64,2},1}, ::Array{Float64,1}, ::getfield(MultivariateSeries, Symbol("##25#27")){Float64})
Closest candidates are:
  decompose(::Array{Array{C,2},1}, !Matched::Function) where C at /Users/mourrain/.julia/packages/MultivariateSeries/mJQLE/src/decompose.jl:20
  decompose(!Matched::DynamicPolynomials.Polynomial{true,C}, !Matched::Function, ::Any) where C at /Users/mourrain/Julia/TensorDec.jl/src/decompose.jl:22



Stacktrace:

 [1] #decompose#23(::Int64, ::Function, ::Array{Float64,3}, ::Function) at /Users/mourrain/Julia/TensorDec.jl/src/decompose.jl:215

 [2] decompose(::Array{Float64,3}, ::Function) at /Users/mourrain/Julia/TensorDec.jl/src/decompose.jl:210 (repeats 2 times)

 [3] top-level scope at In[4]:1
w
4-element Array{Float64,1}:
 1.3184908145711505
 1.1386144184166538
 2.8433075891450534
 2.5117767986101014
wd
UndefVarError: wd not defined



Stacktrace:

 [1] top-level scope at In[6]:1
A
4×4 Array{Float64,2}:
 0.0135068  0.32004   0.275579  0.243881   
 0.299151   0.323187  0.240813  0.000311288
 0.063392   0.252418  0.271949  0.404148   
 0.62395    0.104355  0.211659  0.35166
Ad
UndefVarError: Ad not defined



Stacktrace:

 [1] top-level scope at In[8]:1
using LinearAlgebra
norm(t-tensor(wd,Ad,Bd,Cd))
UndefVarError: wd not defined



Stacktrace:

 [1] top-level scope at In[9]:2