{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Phylogenetic trees" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "#3 (generic function with 1 method)" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "using TensorDec\n", "normalize_markov! = function(w,A,B,C) \n", " for i in 1:size(A,2) \n", " l = sum(A[j,i] for j in 1:size(A,1) ) \n", " A[:,i] /= l\n", " w[i] *= l\n", " end\n", " for i in 1:size(B,2) \n", " l = sum(B[j,i] for j in 1:size(B,1) ) \n", " B[:,i] /=l\n", " w[i] *= l\n", " end\n", " for i in 1:size(C,2) \n", " l = sum(C[j,i] for j in 1:size(B,1) ) \n", " C[:,i] /=l\n", " w[i] *= l\n", " end\n", " w, A,B,C\n", "end" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "([1.0 1.0 1.0 1.0], [1.0 1.0 1.0 1.0], [1.0 1.0 1.0 1.0])" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A = rand(4,4); B = rand(4,4); C = rand(4,4); w = rand(4);\n", "normalize_markov!(w,A,B,C)\n", "fill(1.,4)'*A, fill(1.,4)'*B, fill(1.,4)'*C" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4×4×4 Array{Float64,3}:\n", "[:, :, 1] =\n", " 0.259248 0.349942 0.364485 0.085319 \n", " 0.215528 0.270488 0.262803 0.0684887\n", " 0.214908 0.479766 0.506224 0.0540596\n", " 0.269875 0.450153 0.478336 0.0683525\n", "\n", "[:, :, 2] =\n", " 0.313488 0.384201 0.402716 0.115903 \n", " 0.256093 0.26977 0.265292 0.0868339\n", " 0.221668 0.521591 0.562154 0.0653809\n", " 0.300196 0.468211 0.499396 0.0853609\n", "\n", "[:, :, 3] =\n", " 0.357105 0.223798 0.198387 0.143608 \n", " 0.312446 0.211622 0.16047 0.130103 \n", " 0.13943 0.288979 0.270791 0.0376782\n", " 0.275407 0.277452 0.270645 0.0943938\n", "\n", "[:, :, 4] =\n", " 0.270442 0.247415 0.242189 0.138953 \n", " 0.224147 0.138707 0.092527 0.101356 \n", " 0.104812 0.344 0.350852 0.0728985\n", " 0.187994 0.211849 0.209937 0.0853464" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t = tensor(w,A,B,C)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "([0.718702, 10.0193, 2.8635, 2.03042], [0.158147 0.216844 0.407548 0.317121; 0.368735 0.174449 0.348307 0.0277879; 0.337246 0.298045 0.0128447 0.477643; 0.135872 0.310662 0.2313 0.177448], [0.196824 0.184114 0.632411 0.0619155; 0.549973 0.376328 0.0654333 0.386497; 0.101599 0.41063 0.0109438 0.452418; 0.151604 0.0289275 0.291212 0.0991702], [0.179996 0.35144 0.146618 0.161332; 0.125831 0.351245 0.214783 0.292323; 0.368812 0.203257 0.360999 0.0280855; 0.32536 0.0940577 0.2776 0.518259])" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wd, Ad, Bd, Cd = decompose(t)\n", "normalize_markov!(wd,Ad,Bd,Cd)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4-element Array{Float64,1}:\n", " 2.8635040860546987\n", " 10.019347309230545 \n", " 2.0304186435229035\n", " 0.7187016887591559" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4-element Array{Float64,1}:\n", " 0.718701688759023 \n", " 10.019347309230689 \n", " 2.863504086054696 \n", " 2.0304186435228844" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wd" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4×4 Array{Float64,2}:\n", " 0.407548 0.216844 0.317121 0.158147\n", " 0.348307 0.174449 0.0277879 0.368735\n", " 0.0128447 0.298045 0.477643 0.337246\n", " 0.2313 0.310662 0.177448 0.135872" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4×4 Array{Float64,2}:\n", " 0.158147 0.216844 0.407548 0.317121 \n", " 0.368735 0.174449 0.348307 0.0277879\n", " 0.337246 0.298045 0.0128447 0.477643 \n", " 0.135872 0.310662 0.2313 0.177448 " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Ad" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.8522595838390253e-14" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "using LinearAlgebra\n", "norm(t-tensor(wd,Ad,Bd,Cd))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.0.0", "language": "julia", "name": "julia-1.0" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.0.0" } }, "nbformat": 4, "nbformat_minor": 2 }