tensor_methods

Tensor Methods for DS and SC
git clone git://popovic.xyz/tensor_methods.git
Log | Files | Refs

main.jl (1558B)


      1 #/usr/bin/julia
      2 
      3 include("./functions/err_lucross.jl")
      4 include("./functions/err_tsvd.jl")
      5 include("./functions/err_plot.jl")
      6 include("./functions/cs_plot.jl")
      7 
      8 using LinearAlgebra
      9 using Plots
     10 using Maxvol
     11 using TSVD
     12 using LaTeXStrings
     13 
     14 global n = 901;
     15 
     16 f(x::Number, y::Number) = 1/(1 + x^2 + y^2);
     17 g(x::Number, y::Number) = sqrt(x^2 + y^2)*(1 + 1/2*cos(15x + 22y));
     18 
     19 
     20 function main()
     21     t = [(2*(i-1)/(n-1) - 1) for i in 1:n];
     22 
     23     A = [f(t_i, t_j) for t_i in t, t_j in t];
     24     B = [g(t_i, t_j) for t_i in t, t_j in t];
     25 
     26     x_a = collect(1:rank(A));
     27     x_b = collect(1:rank(B));
     28     x_a_l = log.(x_a); x_b_l = log.(x_b);
     29 
     30     # TSVD
     31     err_a_tsvd = sort_out_values(A, x_a, get_errors_tsvd);
     32     err_b_tsvd = sort_out_values(B, x_b, get_errors_tsvd);
     33 
     34     err_plot([x_a, x_b], [err_a_tsvd, err_b_tsvd], "lu-svd-err.png")
     35 
     36 
     37     # Cross-LU without pivoting
     38     err_a_lunp = cross_lu_error(A, x_a, Val(false));
     39     err_b_lunp = cross_lu_error(B, x_b, Val(false));
     40 
     41     err_plot([x_a, x_b], [err_a_lunp, err_b_lunp], "lu-np-err.png")
     42 
     43 
     44     # Cross-LU with pivoting
     45     err_a_lup = cross_lu_error(A, x_a, Val(true));
     46     err_b_lup = cross_lu_error(B, x_b, Val(true));
     47 
     48     err_plot([x_a, x_b], [err_a_lup, err_b_lup], "lu-p-err.png")
     49 
     50     # graph restrictions by LU pivoting
     51     r_a = [1, 2, 3, 4, 5];
     52     r_b = [1, 2, 3, 4, 5, 10, 15, 20 ,30 , 40];
     53     P_A_s = [M_cross_lu_err(A, i, Val(true))[2] for i in r_a];
     54     P_B_s = [M_cross_lu_err(B, i, Val(true))[2] for i in r_b];
     55 
     56     cs_plot(t, f, P_A_s, r_a, "a")
     57     cs_plot(t, f, P_B_s, r_b, "b")
     58 
     59 end
     60 
     61 main()