Advertisement
Guest User

Untitled

a guest
May 14th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 1.06 KB | None | 0 0
  1. function BB_est(x, sims, prob)
  2.     X = center_data(x)
  3.     n = size(X, 1)
  4.     p = size(X, 2)
  5.     prob = convert(Float64, prob)
  6.     offdiag = (p * (p - 1)) / 2
  7.  
  8.     loop_max = convert(Int64, offdiag)
  9.  
  10.     temp = Exponential(1)
  11.     sims= convert(Int64, sims)
  12.     exp_drw = rand(temp, sims, n)
  13.  
  14.     dir_weights = exp_drw ./sum(exp_drw, 2)
  15.  
  16.    A = zeros(sims, offdiag)
  17.    B = zeros((1, offdiag))
  18.    C = zeros(sims, p)
  19.    mat_point = zeros(p,p)
  20.    mat_sig = zeros(p, p)
  21.    idx = tril(trues(size(mat_point)), -1);
  22.  
  23.    for i = 1:sims
  24.     t = dir_weights[i, 1:n]
  25.     d = X .* sqrt.(t)
  26.     bb_cov = (d' * d)
  27.    inv_cov =  inv(bb_cov)
  28.    d = diag(inv_cov)
  29.    inv_cov[diagind(inv_cov)] = 0
  30.  
  31.    test = inv_cov[idx]
  32.    rmv_0 = filter!(x->x≠ 0,test)
  33.    A[i,:] = rmv_0
  34.    C[i,:] = d
  35.    end
  36.  
  37.    for i in 1:loop_max
  38.    temp1 = post_prob(A[:,i])
  39.    B[1,i] = ifelse(temp1 > prob, 1, 0)
  40. end
  41.  
  42.    mat_sig[idx] = B
  43.    mat_point[idx] = mean(A, 1)
  44.    mat_point[diagind(mat_point)] = mean(C, 1)
  45.    force_sym(mat_sig), force_sym(mat_point), A, B
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement