context_start_lineno
int64
1
913
line_no
int64
16
984
repo
stringclasses
5 values
id
int64
0
416
target_function_prompt
stringlengths
201
13.6k
function_signature
stringlengths
201
13.6k
solution_position
listlengths
2
2
raw_solution
stringlengths
201
13.6k
focal_code
stringlengths
201
13.6k
function_name
stringlengths
2
38
start_line
int64
1
913
end_line
int64
16
984
file_path
stringlengths
10
52
context
stringlengths
4.52k
9.85k
538
561
QuantEcon.jl
200
function qnwnorm(n::Vector{Int}, mu::Vector, sig2::Matrix = Matrix(I, length(n), length(n))) n_n, n_mu = length(n), length(mu) if !(n_n == n_mu) error("n and mu must have same number of elements") end _nodes = Array{Vector{Float64}}(undef, n_n) _weights = Array{Vector{Float64}}(undef, n_n)...
function qnwnorm(n::Vector{Int}, mu::Vector, sig2::Matrix = Matrix(I, length(n), length(n))) n_n, n_mu = length(n), length(mu) if !(n_n == n_mu) error("n and mu must have same number of elements") end _nodes = Array{Vector{Float64}}(undef, n_n) _weights = Array{Vector{Float64}}(undef, n_n)...
[ 538, 561 ]
function qnwnorm(n::Vector{Int}, mu::Vector, sig2::Matrix = Matrix(I, length(n), length(n))) n_n, n_mu = length(n), length(mu) if !(n_n == n_mu) error("n and mu must have same number of elements") end _nodes = Array{Vector{Float64}}(undef, n_n) _weights = Array{Vector{Float64}}(undef, n_n)...
function qnwnorm(n::Vector{Int}, mu::Vector, sig2::Matrix = Matrix(I, length(n), length(n))) n_n, n_mu = length(n), length(mu) if !(n_n == n_mu) error("n and mu must have same number of elements") end _nodes = Array{Vector{Float64}}(undef, n_n) _weights = Array{Vector{Float64}}(undef, n_n)...
qnwnorm
538
561
src/quad.jl
#FILE: QuantEcon.jl/test/test_sampler.jl ##CHUNK 1 @test isapprox(mvns.Q * mvns.Q', mvns.Sigma) end @testset "check positive semi-definite zeros" begin mvns = MVNSampler(mu, zeros(n, n)) @test rand(mvns) == mu end @testset "check positive semi-definite ones" begin mvns ...
673
709
QuantEcon.jl
201
function qnwequi(n::Int, a::Vector, b::Vector, kind::AbstractString = "N") # error checking n_a, n_b = length(a), length(b) if !(n_a == n_b) error("a and b must have same number of elements") end d = n_a i = reshape(1:n, n, 1) if kind == "N" j = 2.0.^((1:d) / (d + 1)) ...
function qnwequi(n::Int, a::Vector, b::Vector, kind::AbstractString = "N") # error checking n_a, n_b = length(a), length(b) if !(n_a == n_b) error("a and b must have same number of elements") end d = n_a i = reshape(1:n, n, 1) if kind == "N" j = 2.0.^((1:d) / (d + 1)) ...
[ 673, 709 ]
function qnwequi(n::Int, a::Vector, b::Vector, kind::AbstractString = "N") # error checking n_a, n_b = length(a), length(b) if !(n_a == n_b) error("a and b must have same number of elements") end d = n_a i = reshape(1:n, n, 1) if kind == "N" j = 2.0.^((1:d) / (d + 1)) ...
function qnwequi(n::Int, a::Vector, b::Vector, kind::AbstractString = "N") # error checking n_a, n_b = length(a), length(b) if !(n_a == n_b) error("a and b must have same number of elements") end d = n_a i = reshape(1:n, n, 1) if kind == "N" j = 2.0.^((1:d) / (d + 1)) ...
qnwequi
673
709
src/quad.jl
#FILE: QuantEcon.jl/src/markov/markov_approx.jl ##CHUNK 1 Nm::Integer, n_moments::Integer=2, method::VAREstimationMethod=Even(), n_sigmas::Real=sqrt(Nm-1)) # b = zeros(2) # A = [0.9809 0.0028; 0.041 0.9648] # Sigma = [7....
795
809
QuantEcon.jl
202
function quadrect(f::Function, n, a, b, kind = "lege", args...; kwargs...) if lowercase(kind)[1] == 'l' nodes, weights = qnwlege(n, a, b) elseif lowercase(kind)[1] == 'c' nodes, weights = qnwcheb(n, a, b) elseif lowercase(kind)[1] == 't' nodes, weights = qnwtrap(n, a, b) elseif l...
function quadrect(f::Function, n, a, b, kind = "lege", args...; kwargs...) if lowercase(kind)[1] == 'l' nodes, weights = qnwlege(n, a, b) elseif lowercase(kind)[1] == 'c' nodes, weights = qnwcheb(n, a, b) elseif lowercase(kind)[1] == 't' nodes, weights = qnwtrap(n, a, b) elseif l...
[ 795, 809 ]
function quadrect(f::Function, n, a, b, kind = "lege", args...; kwargs...) if lowercase(kind)[1] == 'l' nodes, weights = qnwlege(n, a, b) elseif lowercase(kind)[1] == 'c' nodes, weights = qnwcheb(n, a, b) elseif lowercase(kind)[1] == 't' nodes, weights = qnwtrap(n, a, b) elseif l...
function quadrect(f::Function, n, a, b, kind = "lege", args...; kwargs...) if lowercase(kind)[1] == 'l' nodes, weights = qnwlege(n, a, b) elseif lowercase(kind)[1] == 'c' nodes, weights = qnwcheb(n, a, b) elseif lowercase(kind)[1] == 't' nodes, weights = qnwtrap(n, a, b) elseif l...
quadrect
795
809
src/quad.jl
#FILE: QuantEcon.jl/test/test_quad.jl ##CHUNK 1 # dim 1: num nodes, dim2: method, dim3:func data1d = Array{Float64}(undef, 6, 6, 3) kinds = ["trap", "simp", "lege", "N", "W", "H"] n_nodes = [5, 11, 21, 51, 101, 401] # number of nodes a, b = -1, 1 for (k_i, k) in enumer...
834
870
QuantEcon.jl
203
function qnwmonomial2(vcv::AbstractMatrix) n = size(vcv, 1) @assert n == size(vcv, 2) "Variance covariance matrix must be square" n_nodes = 2n^2 + 1 z0 = zeros(1, n) z1 = zeros(2n, n) # In each node, random variable i takes value either 1 or -1, and # all other variables take value 0. For e...
function qnwmonomial2(vcv::AbstractMatrix) n = size(vcv, 1) @assert n == size(vcv, 2) "Variance covariance matrix must be square" n_nodes = 2n^2 + 1 z0 = zeros(1, n) z1 = zeros(2n, n) # In each node, random variable i takes value either 1 or -1, and # all other variables take value 0. For e...
[ 834, 870 ]
function qnwmonomial2(vcv::AbstractMatrix) n = size(vcv, 1) @assert n == size(vcv, 2) "Variance covariance matrix must be square" n_nodes = 2n^2 + 1 z0 = zeros(1, n) z1 = zeros(2n, n) # In each node, random variable i takes value either 1 or -1, and # all other variables take value 0. For e...
function qnwmonomial2(vcv::AbstractMatrix) n = size(vcv, 1) @assert n == size(vcv, 2) "Variance covariance matrix must be square" n_nodes = 2n^2 + 1 z0 = zeros(1, n) z1 = zeros(2n, n) # In each node, random variable i takes value either 1 or -1, and # all other variables take value 0. For e...
qnwmonomial2
834
870
src/quad.jl
#FILE: QuantEcon.jl/test/test_mc_tools.jl ##CHUNK 1 ((i/(n-1) > p) + (i/(n-1) == p)/2)) P[i+1, i+1] = 1 - P[i+1, i] - P[i+1, i+2] end P[end, end-1], P[end, end] = ε/2, 1 - ε/2 return P end function Base.isapprox(x::Vector{Vector{<:Real}}, y::...
911
923
QuantEcon.jl
204
function qnwdist(d::Distributions.ContinuousUnivariateDistribution, N::Int, q0::Real = 0.001, qN::Real = 0.999, method::Union{T,Type{T}} = Quantile) where T z = _quadnodes(d, N, q0, qN, method) zprob = zeros(N) for i in 2:N - 1 zprob[i] = cdf(d, (z[i] + z[i + 1]) / 2) - cdf(d, (z[i] + z[i ...
function qnwdist(d::Distributions.ContinuousUnivariateDistribution, N::Int, q0::Real = 0.001, qN::Real = 0.999, method::Union{T,Type{T}} = Quantile) where T z = _quadnodes(d, N, q0, qN, method) zprob = zeros(N) for i in 2:N - 1 zprob[i] = cdf(d, (z[i] + z[i + 1]) / 2) - cdf(d, (z[i] + z[i ...
[ 911, 923 ]
function qnwdist(d::Distributions.ContinuousUnivariateDistribution, N::Int, q0::Real = 0.001, qN::Real = 0.999, method::Union{T,Type{T}} = Quantile) where T z = _quadnodes(d, N, q0, qN, method) zprob = zeros(N) for i in 2:N - 1 zprob[i] = cdf(d, (z[i] + z[i + 1]) / 2) - cdf(d, (z[i] + z[i ...
function qnwdist(d::Distributions.ContinuousUnivariateDistribution, N::Int, q0::Real = 0.001, qN::Real = 0.999, method::Union{T,Type{T}} = Quantile) where T z = _quadnodes(d, N, q0, qN, method) zprob = zeros(N) for i in 2:N - 1 zprob[i] = cdf(d, (z[i] + z[i + 1]) / 2) - cdf(d, (z[i] + z[i ...
qnwdist
911
923
src/quad.jl
#CURRENT FILE: QuantEcon.jl/src/quad.jl ##CHUNK 1 sqrt_vcv = cholesky(vcv).U R = sqrt(n + 2) .* sqrt_vcv S = sqrt((n + 2) / 2) * sqrt_vcv ϵj = [z0; z1 * R; z2 * S] ωj = vcat(2 / (n + 2) * ones(size(z0, 1)), (4 - n) / (2 * (n + 2)^2) * ones(size(z1, 1)), 1 / (n + 2)^2 * ...
43
59
QuantEcon.jl
205
function var_quadratic_sum(A::ScalarOrArray, C::ScalarOrArray, H::ScalarOrArray, bet::Real, x0::ScalarOrArray) n = size(A, 1) # coerce shapes A = reshape([A;], n, n) C = reshape([C;], n, n) H = reshape([H;], n, n) x0 = reshape([x0;], n) # solve system Q = sol...
function var_quadratic_sum(A::ScalarOrArray, C::ScalarOrArray, H::ScalarOrArray, bet::Real, x0::ScalarOrArray) n = size(A, 1) # coerce shapes A = reshape([A;], n, n) C = reshape([C;], n, n) H = reshape([H;], n, n) x0 = reshape([x0;], n) # solve system Q = sol...
[ 43, 59 ]
function var_quadratic_sum(A::ScalarOrArray, C::ScalarOrArray, H::ScalarOrArray, bet::Real, x0::ScalarOrArray) n = size(A, 1) # coerce shapes A = reshape([A;], n, n) C = reshape([C;], n, n) H = reshape([H;], n, n) x0 = reshape([x0;], n) # solve system Q = sol...
function var_quadratic_sum(A::ScalarOrArray, C::ScalarOrArray, H::ScalarOrArray, bet::Real, x0::ScalarOrArray) n = size(A, 1) # coerce shapes A = reshape([A;], n, n) C = reshape([C;], n, n) H = reshape([H;], n, n) x0 = reshape([x0;], n) # solve system Q = sol...
var_quadratic_sum
43
59
src/quadsums.jl
#FILE: QuantEcon.jl/src/matrix_eqn.jl ##CHUNK 1 - `gamma1::Matrix{Float64}` Represents the value ``X`` """ function solve_discrete_lyapunov(A::ScalarOrArray, B::ScalarOrArray, max_it::Int=50) # TODO: Implement Bartels-Stewardt n = size(A, 2) ...
119
130
QuantEcon.jl
206
function b_operator(rlq::RBLQ, P::Matrix) A, B, Q, R, bet = rlq.A, rlq.B, rlq.Q, rlq.R, rlq.bet S1 = Q + bet.*B'*P*B S2 = bet.*B'*P*A S3 = bet.*A'*P*A F = S1 \ S2 new_P = R - S2'*F + S3 return F, new_P end
function b_operator(rlq::RBLQ, P::Matrix) A, B, Q, R, bet = rlq.A, rlq.B, rlq.Q, rlq.R, rlq.bet S1 = Q + bet.*B'*P*B S2 = bet.*B'*P*A S3 = bet.*A'*P*A F = S1 \ S2 new_P = R - S2'*F + S3 return F, new_P end
[ 119, 130 ]
function b_operator(rlq::RBLQ, P::Matrix) A, B, Q, R, bet = rlq.A, rlq.B, rlq.Q, rlq.R, rlq.bet S1 = Q + bet.*B'*P*B S2 = bet.*B'*P*A S3 = bet.*A'*P*A F = S1 \ S2 new_P = R - S2'*F + S3 return F, new_P end
function b_operator(rlq::RBLQ, P::Matrix) A, B, Q, R, bet = rlq.A, rlq.B, rlq.Q, rlq.R, rlq.bet S1 = Q + bet.*B'*P*B S2 = bet.*B'*P*A S3 = bet.*A'*P*A F = S1 \ S2 new_P = R - S2'*F + S3 return F, new_P end
b_operator
119
130
src/robustlq.jl
#FILE: QuantEcon.jl/src/lqcontrol.jl ##CHUNK 1 This function updates the `P` and `d` fields on the `lq` instance in addition to returning them """ function update_values!(lq::LQ) # Simplify notation Q, R, A, B, N, C, P, d = lq.Q, lq.R, lq.A, lq.B, lq.N, lq.C, lq.P, lq.d # Some useful matrices s1 = Q +...
157
175
QuantEcon.jl
207
function robust_rule(rlq::RBLQ) A, B, C, Q, R = rlq.A, rlq.B, rlq.C, rlq.Q, rlq.R bet, theta, k, j = rlq.bet, rlq.theta, rlq.k, rlq.j # Set up LQ version # I = eye(j) Z = zeros(k, j) Ba = [B C] Qa = [Q Z Z' -bet.*I.*theta] lq = QuantEcon.LQ(Qa, R, A, Ba, bet=bet) # Solve ...
function robust_rule(rlq::RBLQ) A, B, C, Q, R = rlq.A, rlq.B, rlq.C, rlq.Q, rlq.R bet, theta, k, j = rlq.bet, rlq.theta, rlq.k, rlq.j # Set up LQ version # I = eye(j) Z = zeros(k, j) Ba = [B C] Qa = [Q Z Z' -bet.*I.*theta] lq = QuantEcon.LQ(Qa, R, A, Ba, bet=bet) # Solve ...
[ 157, 175 ]
function robust_rule(rlq::RBLQ) A, B, C, Q, R = rlq.A, rlq.B, rlq.C, rlq.Q, rlq.R bet, theta, k, j = rlq.bet, rlq.theta, rlq.k, rlq.j # Set up LQ version # I = eye(j) Z = zeros(k, j) Ba = [B C] Qa = [Q Z Z' -bet.*I.*theta] lq = QuantEcon.LQ(Qa, R, A, Ba, bet=bet) # Solve ...
function robust_rule(rlq::RBLQ) A, B, C, Q, R = rlq.A, rlq.B, rlq.C, rlq.Q, rlq.R bet, theta, k, j = rlq.bet, rlq.theta, rlq.k, rlq.j # Set up LQ version # I = eye(j) Z = zeros(k, j) Ba = [B C] Qa = [Q Z Z' -bet.*I.*theta] lq = QuantEcon.LQ(Qa, R, A, Ba, bet=bet) # Solve ...
robust_rule
157
175
src/robustlq.jl
#FILE: QuantEcon.jl/src/lqcontrol.jl ##CHUNK 1 This function updates the `P`, `d`, and `F` fields on the `lq` instance in addition to returning them """ function stationary_values!(lq::LQ) # simplify notation Q, R, A, B, N, C = lq.Q, lq.R, lq.A, lq.B, lq.N, lq.C # solve Riccati equation, obtain P A0,...
203
229
QuantEcon.jl
208
function robust_rule_simple(rlq::RBLQ, P::Matrix=zeros(Float64, rlq.n, rlq.n); max_iter=80, tol=1e-8) # Simplify notation A, B, C, Q, R = rlq.A, rlq.B, rlq.C, rlq.Q, rlq.R bet, theta, k, j = rlq.bet, rlq.theta, rlq.k, rlq.j ...
function robust_rule_simple(rlq::RBLQ, P::Matrix=zeros(Float64, rlq.n, rlq.n); max_iter=80, tol=1e-8) # Simplify notation A, B, C, Q, R = rlq.A, rlq.B, rlq.C, rlq.Q, rlq.R bet, theta, k, j = rlq.bet, rlq.theta, rlq.k, rlq.j ...
[ 203, 229 ]
function robust_rule_simple(rlq::RBLQ, P::Matrix=zeros(Float64, rlq.n, rlq.n); max_iter=80, tol=1e-8) # Simplify notation A, B, C, Q, R = rlq.A, rlq.B, rlq.C, rlq.Q, rlq.R bet, theta, k, j = rlq.bet, rlq.theta, rlq.k, rlq.j ...
function robust_rule_simple(rlq::RBLQ, P::Matrix=zeros(Float64, rlq.n, rlq.n); max_iter=80, tol=1e-8) # Simplify notation A, B, C, Q, R = rlq.A, rlq.B, rlq.C, rlq.Q, rlq.R bet, theta, k, j = rlq.bet, rlq.theta, rlq.k, rlq.j ...
robust_rule_simple
203
229
src/robustlq.jl
#FILE: QuantEcon.jl/src/lqcontrol.jl ##CHUNK 1 This function updates the `P` and `d` fields on the `lq` instance in addition to returning them """ function update_values!(lq::LQ) # Simplify notation Q, R, A, B, N, C, P, d = lq.Q, lq.R, lq.A, lq.B, lq.N, lq.C, lq.P, lq.d # Some useful matrices s1 = Q +...
245
260
QuantEcon.jl
209
function F_to_K(rlq::RBLQ, F::Matrix) # simplify notation R, Q, A, B, C = rlq.R, rlq.Q, rlq.A, rlq.B, rlq.C bet, theta = rlq.bet, rlq.theta # set up lq Q2 = bet * theta R2 = - R - F'*Q*F A2 = A - B*F B2 = C lq = QuantEcon.LQ(Q2, R2, A2, B2, bet=bet) neg_P, neg_K, d = stationary...
function F_to_K(rlq::RBLQ, F::Matrix) # simplify notation R, Q, A, B, C = rlq.R, rlq.Q, rlq.A, rlq.B, rlq.C bet, theta = rlq.bet, rlq.theta # set up lq Q2 = bet * theta R2 = - R - F'*Q*F A2 = A - B*F B2 = C lq = QuantEcon.LQ(Q2, R2, A2, B2, bet=bet) neg_P, neg_K, d = stationary...
[ 245, 260 ]
function F_to_K(rlq::RBLQ, F::Matrix) # simplify notation R, Q, A, B, C = rlq.R, rlq.Q, rlq.A, rlq.B, rlq.C bet, theta = rlq.bet, rlq.theta # set up lq Q2 = bet * theta R2 = - R - F'*Q*F A2 = A - B*F B2 = C lq = QuantEcon.LQ(Q2, R2, A2, B2, bet=bet) neg_P, neg_K, d = stationary...
function F_to_K(rlq::RBLQ, F::Matrix) # simplify notation R, Q, A, B, C = rlq.R, rlq.Q, rlq.A, rlq.B, rlq.C bet, theta = rlq.bet, rlq.theta # set up lq Q2 = bet * theta R2 = - R - F'*Q*F A2 = A - B*F B2 = C lq = QuantEcon.LQ(Q2, R2, A2, B2, bet=bet) neg_P, neg_K, d = stationary...
F_to_K
245
260
src/robustlq.jl
#FILE: QuantEcon.jl/src/lqcontrol.jl ##CHUNK 1 This function updates the `P`, `d`, and `F` fields on the `lq` instance in addition to returning them """ function stationary_values!(lq::LQ) # simplify notation Q, R, A, B, N, C = lq.Q, lq.R, lq.A, lq.B, lq.N, lq.C # solve Riccati equation, obtain P A0,...
276
286
QuantEcon.jl
210
function K_to_F(rlq::RBLQ, K::Matrix) R, Q, A, B, C = rlq.R, rlq.Q, rlq.A, rlq.B, rlq.C bet, theta = rlq.bet, rlq.theta A1, B1, Q1, R1 = A+C*K, B, Q, R-bet*theta.*K'*K lq = QuantEcon.LQ(Q1, R1, A1, B1, bet=bet) P, F, d = stationary_values(lq) return F, P end
function K_to_F(rlq::RBLQ, K::Matrix) R, Q, A, B, C = rlq.R, rlq.Q, rlq.A, rlq.B, rlq.C bet, theta = rlq.bet, rlq.theta A1, B1, Q1, R1 = A+C*K, B, Q, R-bet*theta.*K'*K lq = QuantEcon.LQ(Q1, R1, A1, B1, bet=bet) P, F, d = stationary_values(lq) return F, P end
[ 276, 286 ]
function K_to_F(rlq::RBLQ, K::Matrix) R, Q, A, B, C = rlq.R, rlq.Q, rlq.A, rlq.B, rlq.C bet, theta = rlq.bet, rlq.theta A1, B1, Q1, R1 = A+C*K, B, Q, R-bet*theta.*K'*K lq = QuantEcon.LQ(Q1, R1, A1, B1, bet=bet) P, F, d = stationary_values(lq) return F, P end
function K_to_F(rlq::RBLQ, K::Matrix) R, Q, A, B, C = rlq.R, rlq.Q, rlq.A, rlq.B, rlq.C bet, theta = rlq.bet, rlq.theta A1, B1, Q1, R1 = A+C*K, B, Q, R-bet*theta.*K'*K lq = QuantEcon.LQ(Q1, R1, A1, B1, bet=bet) P, F, d = stationary_values(lq) return F, P end
K_to_F
276
286
src/robustlq.jl
#FILE: QuantEcon.jl/src/lqcontrol.jl ##CHUNK 1 This function updates the `P`, `d`, and `F` fields on the `lq` instance in addition to returning them """ function stationary_values!(lq::LQ) # simplify notation Q, R, A, B, N, C = lq.Q, lq.R, lq.A, lq.B, lq.N, lq.C # solve Riccati equation, obtain P A0,...
331
350
QuantEcon.jl
211
function evaluate_F(rlq::RBLQ, F::Matrix) R, Q, A, B, C = rlq.R, rlq.Q, rlq.A, rlq.B, rlq.C bet, theta, j = rlq.bet, rlq.theta, rlq.j # Solve for policies and costs using agent 2's problem K_F, P_F = F_to_K(rlq, F) # I = eye(j) H = inv(I - C'*P_F*C./theta) d_F = log(det(H)) # compute O...
function evaluate_F(rlq::RBLQ, F::Matrix) R, Q, A, B, C = rlq.R, rlq.Q, rlq.A, rlq.B, rlq.C bet, theta, j = rlq.bet, rlq.theta, rlq.j # Solve for policies and costs using agent 2's problem K_F, P_F = F_to_K(rlq, F) # I = eye(j) H = inv(I - C'*P_F*C./theta) d_F = log(det(H)) # compute O...
[ 331, 350 ]
function evaluate_F(rlq::RBLQ, F::Matrix) R, Q, A, B, C = rlq.R, rlq.Q, rlq.A, rlq.B, rlq.C bet, theta, j = rlq.bet, rlq.theta, rlq.j # Solve for policies and costs using agent 2's problem K_F, P_F = F_to_K(rlq, F) # I = eye(j) H = inv(I - C'*P_F*C./theta) d_F = log(det(H)) # compute O...
function evaluate_F(rlq::RBLQ, F::Matrix) R, Q, A, B, C = rlq.R, rlq.Q, rlq.A, rlq.B, rlq.C bet, theta, j = rlq.bet, rlq.theta, rlq.j # Solve for policies and costs using agent 2's problem K_F, P_F = F_to_K(rlq, F) # I = eye(j) H = inv(I - C'*P_F*C./theta) d_F = log(det(H)) # compute O...
evaluate_F
331
350
src/robustlq.jl
#FILE: QuantEcon.jl/src/lqcontrol.jl ##CHUNK 1 A0, B0 = sqrt(lq.bet) * A, sqrt(lq.bet) * B P = solve_discrete_riccati(A0, B0, R, Q, N) # Compute F s1 = Q .+ lq.bet * (B' * P * B) s2 = lq.bet * (B' * P * A) .+ N F = s1 \ s2 # Compute d d = lq.bet * tr(P * C * C') / (1 - lq.bet) # B...
17
55
QuantEcon.jl
212
function MVNSampler(mu::Vector{TM}, Sigma::Matrix{TS}) where {TM<:Real,TS<:Real} ATOL1, RTOL1 = 1e-8, 1e-8 ATOL2, RTOL2 = 1e-8, 1e-14 n = length(mu) if size(Sigma) != (n, n) # Check Sigma is n x n throw(ArgumentError( "Sigma must be 2 dimensional and square matrix of same length to...
function MVNSampler(mu::Vector{TM}, Sigma::Matrix{TS}) where {TM<:Real,TS<:Real} ATOL1, RTOL1 = 1e-8, 1e-8 ATOL2, RTOL2 = 1e-8, 1e-14 n = length(mu) if size(Sigma) != (n, n) # Check Sigma is n x n throw(ArgumentError( "Sigma must be 2 dimensional and square matrix of same length to...
[ 17, 55 ]
function MVNSampler(mu::Vector{TM}, Sigma::Matrix{TS}) where {TM<:Real,TS<:Real} ATOL1, RTOL1 = 1e-8, 1e-8 ATOL2, RTOL2 = 1e-8, 1e-14 n = length(mu) if size(Sigma) != (n, n) # Check Sigma is n x n throw(ArgumentError( "Sigma must be 2 dimensional and square matrix of same length to...
function MVNSampler(mu::Vector{TM}, Sigma::Matrix{TS}) where {TM<:Real,TS<:Real} ATOL1, RTOL1 = 1e-8, 1e-8 ATOL2, RTOL2 = 1e-8, 1e-14 n = length(mu) if size(Sigma) != (n, n) # Check Sigma is n x n throw(ArgumentError( "Sigma must be 2 dimensional and square matrix of same length to...
MVNSampler
17
55
src/sampler.jl
#FILE: QuantEcon.jl/src/markov/markov_approx.jl ##CHUNK 1 Nm::Integer, n_moments::Integer=2, method::VAREstimationMethod=Even(), n_sigmas::Real=sqrt(Nm-1)) # b = zeros(2) # A = [0.9809 0.0028; 0.041 0.9648] # Sigma = [7....
40
68
QuantEcon.jl
213
function gridmake!(out, arrays::Union{AbstractVector,AbstractMatrix}...) lens = Int[size(e, 1) for e in arrays] n = sum(_i -> size(_i, 2), arrays) l = prod(lens) @assert size(out) == (l, n) reverse!(lens) repititions = cumprod(vcat(1, lens[1:end-1])) reverse!(repititions) reverse!(lens...
function gridmake!(out, arrays::Union{AbstractVector,AbstractMatrix}...) lens = Int[size(e, 1) for e in arrays] n = sum(_i -> size(_i, 2), arrays) l = prod(lens) @assert size(out) == (l, n) reverse!(lens) repititions = cumprod(vcat(1, lens[1:end-1])) reverse!(repititions) reverse!(lens...
[ 40, 68 ]
function gridmake!(out, arrays::Union{AbstractVector,AbstractMatrix}...) lens = Int[size(e, 1) for e in arrays] n = sum(_i -> size(_i, 2), arrays) l = prod(lens) @assert size(out) == (l, n) reverse!(lens) repititions = cumprod(vcat(1, lens[1:end-1])) reverse!(repititions) reverse!(lens...
function gridmake!(out, arrays::Union{AbstractVector,AbstractMatrix}...) lens = Int[size(e, 1) for e in arrays] n = sum(_i -> size(_i, 2), arrays) l = prod(lens) @assert size(out) == (l, n) reverse!(lens) repititions = cumprod(vcat(1, lens[1:end-1])) reverse!(repititions) reverse!(lens...
gridmake!
40
68
src/util.jl
#FILE: QuantEcon.jl/src/markov/ddp.jl ##CHUNK 1 end end @doc doc""" Define Matrix Multiplication between 3-dimensional matrix and a vector Matrix multiplication over the last dimension of ``A`` """ function *(A::AbstractArray{T,3}, v::AbstractVector) where T shape = size(A) size(v, 1) == shape[end] || er...
138
148
QuantEcon.jl
214
function is_stable(A::AbstractMatrix) # Check for stability by testing that eigenvalues are less than 1 stable = true d = eigvals(A) if maximum(abs, d) > 1.0 stable = false end return stable end
function is_stable(A::AbstractMatrix) # Check for stability by testing that eigenvalues are less than 1 stable = true d = eigvals(A) if maximum(abs, d) > 1.0 stable = false end return stable end
[ 138, 148 ]
function is_stable(A::AbstractMatrix) # Check for stability by testing that eigenvalues are less than 1 stable = true d = eigvals(A) if maximum(abs, d) > 1.0 stable = false end return stable end
function is_stable(A::AbstractMatrix) # Check for stability by testing that eigenvalues are less than 1 stable = true d = eigvals(A) if maximum(abs, d) > 1.0 stable = false end return stable end
is_stable
138
148
src/util.jl
#FILE: QuantEcon.jl/src/lss.jl ##CHUNK 1 #### Arguments - `lss::LSS` The linear state space system #### Returns - `stable::Bool` Whether or not the system is stable """ function is_stable(lss::LSS) # Get version of A without constant row/column A = remove_constants(lss) # Check for stability stab...
224
242
QuantEcon.jl
215
function Base.iterate(sg::SimplexGrid, state) m = sg.m x, h = state x[1] >= sg.n && return nothing h -= 1 val = x[h+1] x[h+1] = 0 x[m] = val - 1 x[h] += 1 if val != 1 h = m end return x, (x, h) end
function Base.iterate(sg::SimplexGrid, state) m = sg.m x, h = state x[1] >= sg.n && return nothing h -= 1 val = x[h+1] x[h+1] = 0 x[m] = val - 1 x[h] += 1 if val != 1 h = m end return x, (x, h) end
[ 224, 242 ]
function Base.iterate(sg::SimplexGrid, state) m = sg.m x, h = state x[1] >= sg.n && return nothing h -= 1 val = x[h+1] x[h+1] = 0 x[m] = val - 1 x[h] += 1 if val != 1 h = m end return x, (x, h) end
function Base.iterate(sg::SimplexGrid, state) m = sg.m x, h = state x[1] >= sg.n && return nothing h -= 1 val = x[h+1] x[h+1] = 0 x[m] = val - 1 x[h] += 1 if val != 1 h = m end return x, (x, h) end
Base.iterate
224
242
src/util.jl
#FILE: QuantEcon.jl/src/markov/markov_approx.jl ##CHUNK 1 if any(!in(x, X) for x in states) error("One of the states does not appear in history X") end # Count states and store in dictionary nstates = length(states) d = Dict{T, Int}(zip(states, 1:nstates)) # Counter matrix and dictiona...
287
298
QuantEcon.jl
216
function simplex_grid(m, n) # Get number of elements in array and allocate L = num_compositions(m, n) out = Matrix{Int}(undef, m, L) sg = SimplexGrid(m, n) for (i, x) in enumerate(sg) copyto!(out, m*(i-1) + 1, x, 1, m) end return out end
function simplex_grid(m, n) # Get number of elements in array and allocate L = num_compositions(m, n) out = Matrix{Int}(undef, m, L) sg = SimplexGrid(m, n) for (i, x) in enumerate(sg) copyto!(out, m*(i-1) + 1, x, 1, m) end return out end
[ 287, 298 ]
function simplex_grid(m, n) # Get number of elements in array and allocate L = num_compositions(m, n) out = Matrix{Int}(undef, m, L) sg = SimplexGrid(m, n) for (i, x) in enumerate(sg) copyto!(out, m*(i-1) + 1, x, 1, m) end return out end
function simplex_grid(m, n) # Get number of elements in array and allocate L = num_compositions(m, n) out = Matrix{Int}(undef, m, L) sg = SimplexGrid(m, n) for (i, x) in enumerate(sg) copyto!(out, m*(i-1) + 1, x, 1, m) end return out end
simplex_grid
287
298
src/util.jl
#FILE: QuantEcon.jl/other/ddpsolve.jl ##CHUNK 1 ind = n * x + (1-n:0) fstar = f[ind] pstar = P[ind, :] return pstar, fstar, ind end function expandg(g) # Only need if I supply "transfunc". Not doing so n, m = size(g) P = sparse(1:n*m, g(:), 1, n*m, n) return P end function diagmult(a...
320
337
QuantEcon.jl
217
function simplex_index(x, m, n) # If only one element then only one point in simplex if m==1 return 1 end decumsum = reverse(cumsum(reverse(x[2:end]))) idx = binomial(n+m-1, m-1) for i in 1:m-1 if decumsum[i] == 0 break end idx -= num_compositions(m ...
function simplex_index(x, m, n) # If only one element then only one point in simplex if m==1 return 1 end decumsum = reverse(cumsum(reverse(x[2:end]))) idx = binomial(n+m-1, m-1) for i in 1:m-1 if decumsum[i] == 0 break end idx -= num_compositions(m ...
[ 320, 337 ]
function simplex_index(x, m, n) # If only one element then only one point in simplex if m==1 return 1 end decumsum = reverse(cumsum(reverse(x[2:end]))) idx = binomial(n+m-1, m-1) for i in 1:m-1 if decumsum[i] == 0 break end idx -= num_compositions(m ...
function simplex_index(x, m, n) # If only one element then only one point in simplex if m==1 return 1 end decumsum = reverse(cumsum(reverse(x[2:end]))) idx = binomial(n+m-1, m-1) for i in 1:m-1 if decumsum[i] == 0 break end idx -= num_compositions(m ...
simplex_index
320
337
src/util.jl
#FILE: QuantEcon.jl/src/markov/mc_tools.jl ##CHUNK 1 @inbounds for k in 1:n-1 scale = sum(A[k, k+1:n]) if scale <= zero(T) # There is one (and only one) recurrent class contained in # {1, ..., k}; # compute the solution associated with that recurrent class. ...
376
396
QuantEcon.jl
218
function next_k_array!(a::Vector{<:Integer}) k = length(a) if k == 1 || a[1] + 1 < a[2] a[1] += 1 return a end a[1] = 1 i = 2 x = a[i] + 1 while i < k && x == a[i+1] i += 1 a[i-1] = i - 1 x = a[i] + 1 end a[i] = x return a end
function next_k_array!(a::Vector{<:Integer}) k = length(a) if k == 1 || a[1] + 1 < a[2] a[1] += 1 return a end a[1] = 1 i = 2 x = a[i] + 1 while i < k && x == a[i+1] i += 1 a[i-1] = i - 1 x = a[i] + 1 end a[i] = x return a end
[ 376, 396 ]
function next_k_array!(a::Vector{<:Integer}) k = length(a) if k == 1 || a[1] + 1 < a[2] a[1] += 1 return a end a[1] = 1 i = 2 x = a[i] + 1 while i < k && x == a[i+1] i += 1 a[i-1] = i - 1 x = a[i] + 1 end a[i] = x return a end
function next_k_array!(a::Vector{<:Integer}) k = length(a) if k == 1 || a[1] + 1 < a[2] a[1] += 1 return a end a[1] = 1 i = 2 x = a[i] + 1 while i < k && x == a[i+1] i += 1 a[i-1] = i - 1 x = a[i] + 1 end a[i] = x return a end
next_k_array!
376
396
src/util.jl
#FILE: QuantEcon.jl/src/markov/random_mc.jl ##CHUNK 1 k == 1 && return ones((k, m)) # if k >= 2 x = Matrix{Float64}(undef, k, m) r = rand(rng, k-1, m) x[1:end .- 1, :] = sort(r, dims = 1) for j in 1:m x[end, j] = 1 - x[end-1, j] for i in k-1:-1:2 x[i, j] -= x[i-1, ...
424
436
QuantEcon.jl
219
function k_array_rank(T::Type{<:Integer}, a::Vector{<:Integer}) if T != BigInt binomial(BigInt(a[end]), BigInt(length(a))) ≤ typemax(T) || throw(InexactError(:Binomial, T, a[end])) end k = length(a) idx = one(T) for i = 1:k idx += binomial(T(a[i])-one(T), T(i)) end r...
function k_array_rank(T::Type{<:Integer}, a::Vector{<:Integer}) if T != BigInt binomial(BigInt(a[end]), BigInt(length(a))) ≤ typemax(T) || throw(InexactError(:Binomial, T, a[end])) end k = length(a) idx = one(T) for i = 1:k idx += binomial(T(a[i])-one(T), T(i)) end r...
[ 424, 436 ]
function k_array_rank(T::Type{<:Integer}, a::Vector{<:Integer}) if T != BigInt binomial(BigInt(a[end]), BigInt(length(a))) ≤ typemax(T) || throw(InexactError(:Binomial, T, a[end])) end k = length(a) idx = one(T) for i = 1:k idx += binomial(T(a[i])-one(T), T(i)) end r...
function k_array_rank(T::Type{<:Integer}, a::Vector{<:Integer}) if T != BigInt binomial(BigInt(a[end]), BigInt(length(a))) ≤ typemax(T) || throw(InexactError(:Binomial, T, a[end])) end k = length(a) idx = one(T) for i = 1:k idx += binomial(T(a[i])-one(T), T(i)) end r...
k_array_rank
424
436
src/util.jl
#FILE: QuantEcon.jl/other/ddpsolve.jl ##CHUNK 1 # TODO: the stdlib function findmax(arr, dim) should do this now function indvalmax(a::Matrix{T}, dim::Integer=2) where T out_size = dim == 2 ? size(a, 1) : size(a, 2) out_v = Array(T, out_size) out_i = Array(Int64, out_size) if dim == 2 for i=1:o...
121
143
QuantEcon.jl
220
function divide_bracket(f::Function, x1::T, x2::T, n::Int=50) where T<:Number x1 <= x2 || throw(ArgumentError("x1 must be less than x2")) xs = range(x1, stop=x2, length=n) dx = xs[2] - xs[1] x1b = T[] x2b = T[] f1 = f(x1) for x in xs[2:end] f2 = f(x) if f1*f2 <= 0.0 ...
function divide_bracket(f::Function, x1::T, x2::T, n::Int=50) where T<:Number x1 <= x2 || throw(ArgumentError("x1 must be less than x2")) xs = range(x1, stop=x2, length=n) dx = xs[2] - xs[1] x1b = T[] x2b = T[] f1 = f(x1) for x in xs[2:end] f2 = f(x) if f1*f2 <= 0.0 ...
[ 121, 143 ]
function divide_bracket(f::Function, x1::T, x2::T, n::Int=50) where T<:Number x1 <= x2 || throw(ArgumentError("x1 must be less than x2")) xs = range(x1, stop=x2, length=n) dx = xs[2] - xs[1] x1b = T[] x2b = T[] f1 = f(x1) for x in xs[2:end] f2 = f(x) if f1*f2 <= 0.0 ...
function divide_bracket(f::Function, x1::T, x2::T, n::Int=50) where T<:Number x1 <= x2 || throw(ArgumentError("x1 must be less than x2")) xs = range(x1, stop=x2, length=n) dx = xs[2] - xs[1] x1b = T[] x2b = T[] f1 = f(x1) for x in xs[2:end] f2 = f(x) if f1*f2 <= 0.0 ...
divide_bracket
121
143
src/zeros.jl
#CURRENT FILE: QuantEcon.jl/src/zeros.jl ##CHUNK 1 end if abs(f1) < abs(f2) x1 += fac*(x1 - x2) f1 = f(x1) else x2 += fac*(x2 - x1) f2 = f(x2) end end throw(ConvergenceError("failed to find bracket in $ntry iterations")) end expa...
550
562
QuantEcon.jl
221
function backward_induction(ddp::DiscreteDP{T}, J::Integer, v_term::AbstractVector{<:Real}= zeros(num_states(ddp))) where {T} n = num_states(ddp) S = typeof(zero(T)/one(T)) vs = Matrix{S}(undef, n, J+1) vs[:,end] = v_term sigmas = Matrix{Int}(u...
function backward_induction(ddp::DiscreteDP{T}, J::Integer, v_term::AbstractVector{<:Real}= zeros(num_states(ddp))) where {T} n = num_states(ddp) S = typeof(zero(T)/one(T)) vs = Matrix{S}(undef, n, J+1) vs[:,end] = v_term sigmas = Matrix{Int}(u...
[ 550, 562 ]
function backward_induction(ddp::DiscreteDP{T}, J::Integer, v_term::AbstractVector{<:Real}= zeros(num_states(ddp))) where {T} n = num_states(ddp) S = typeof(zero(T)/one(T)) vs = Matrix{S}(undef, n, J+1) vs[:,end] = v_term sigmas = Matrix{Int}(u...
function backward_induction(ddp::DiscreteDP{T}, J::Integer, v_term::AbstractVector{<:Real}= zeros(num_states(ddp))) where {T} n = num_states(ddp) S = typeof(zero(T)/one(T)) vs = Matrix{S}(undef, n, J+1) vs[:,end] = v_term sigmas = Matrix{Int}(u...
backward_induction
550
562
src/markov/ddp.jl
#CURRENT FILE: QuantEcon.jl/src/markov/ddp.jl ##CHUNK 1 ``` for ``j= J, \\ldots, 1``, where the terminal value function ``v_{J+1}`` is exogenously given by `v_term`. # Parameters - `ddp::DiscreteDP{T}` : Object that contains the Model Parameters - `J::Integer`: Number of decision periods - `v_term::AbstractVector{<...
699
716
QuantEcon.jl
222
function s_wise_max!( a_indices::AbstractVector, a_indptr::AbstractVector, vals::AbstractVector, out::AbstractVector ) n = length(out) for i in 1:n if a_indptr[i] != a_indptr[i+1] m = a_indptr[i] for j in a_indptr[i]+1:(a_indptr[i+1]-1) if vals...
function s_wise_max!( a_indices::AbstractVector, a_indptr::AbstractVector, vals::AbstractVector, out::AbstractVector ) n = length(out) for i in 1:n if a_indptr[i] != a_indptr[i+1] m = a_indptr[i] for j in a_indptr[i]+1:(a_indptr[i+1]-1) if vals...
[ 699, 716 ]
function s_wise_max!( a_indices::AbstractVector, a_indptr::AbstractVector, vals::AbstractVector, out::AbstractVector ) n = length(out) for i in 1:n if a_indptr[i] != a_indptr[i+1] m = a_indptr[i] for j in a_indptr[i]+1:(a_indptr[i+1]-1) if vals...
function s_wise_max!( a_indices::AbstractVector, a_indptr::AbstractVector, vals::AbstractVector, out::AbstractVector ) n = length(out) for i in 1:n if a_indptr[i] != a_indptr[i+1] m = a_indptr[i] for j in a_indptr[i]+1:(a_indptr[i+1]-1) if vals...
s_wise_max!
699
716
src/markov/ddp.jl
#FILE: QuantEcon.jl/other/ddpsolve.jl ##CHUNK 1 # TODO: the stdlib function findmax(arr, dim) should do this now function indvalmax(a::Matrix{T}, dim::Integer=2) where T out_size = dim == 2 ? size(a, 1) : size(a, 2) out_v = Array(T, out_size) out_i = Array(Int64, out_size) if dim == 2 for i=1:o...
757
772
QuantEcon.jl
223
function _has_sorted_sa_indices( s_indices::AbstractVector, a_indices::AbstractVector ) L = length(s_indices) for i in 1:L-1 if s_indices[i] > s_indices[i+1] return false end if s_indices[i] == s_indices[i+1] if a_indices[i] >= a_indices[i+1] ...
function _has_sorted_sa_indices( s_indices::AbstractVector, a_indices::AbstractVector ) L = length(s_indices) for i in 1:L-1 if s_indices[i] > s_indices[i+1] return false end if s_indices[i] == s_indices[i+1] if a_indices[i] >= a_indices[i+1] ...
[ 757, 772 ]
function _has_sorted_sa_indices( s_indices::AbstractVector, a_indices::AbstractVector ) L = length(s_indices) for i in 1:L-1 if s_indices[i] > s_indices[i+1] return false end if s_indices[i] == s_indices[i+1] if a_indices[i] >= a_indices[i+1] ...
function _has_sorted_sa_indices( s_indices::AbstractVector, a_indices::AbstractVector ) L = length(s_indices) for i in 1:L-1 if s_indices[i] > s_indices[i+1] return false end if s_indices[i] == s_indices[i+1] if a_indices[i] >= a_indices[i+1] ...
_has_sorted_sa_indices
757
772
src/markov/ddp.jl
#CURRENT FILE: QuantEcon.jl/src/markov/ddp.jl ##CHUNK 1 if a_indptr[i] != a_indptr[i+1] m = a_indptr[i] for j in a_indptr[i]+1:(a_indptr[i+1]-1) if vals[j] > vals[m] m = j end end out[i] = vals[m] out...
185
217
QuantEcon.jl
224
function estimate_mc_discrete(X::Vector{T}, states::Vector{T}) where T # Get length of simulation capT = length(X) # Make sure all of the passed in states appear in X... If not # throw an error if any(!in(x, X) for x in states) error("One of the states does not appear in history X") end...
function estimate_mc_discrete(X::Vector{T}, states::Vector{T}) where T # Get length of simulation capT = length(X) # Make sure all of the passed in states appear in X... If not # throw an error if any(!in(x, X) for x in states) error("One of the states does not appear in history X") end...
[ 185, 217 ]
function estimate_mc_discrete(X::Vector{T}, states::Vector{T}) where T # Get length of simulation capT = length(X) # Make sure all of the passed in states appear in X... If not # throw an error if any(!in(x, X) for x in states) error("One of the states does not appear in history X") end...
function estimate_mc_discrete(X::Vector{T}, states::Vector{T}) where T # Get length of simulation capT = length(X) # Make sure all of the passed in states appear in X... If not # throw an error if any(!in(x, X) for x in states) error("One of the states does not appear in history X") end...
estimate_mc_discrete
185
217
src/markov/markov_approx.jl
#FILE: QuantEcon.jl/src/markov/ddp.jl ##CHUNK 1 num_states, num_actions = size(R) if size(Q) != (num_states, num_actions, num_states) throw(ArgumentError("shapes of R and Q must be (n,m) and (n,m,n)")) end # check feasibility R_max = s_wise_max(R) if any(R_max .== ...
298
425
QuantEcon.jl
225
function discrete_var(b::Union{Real, AbstractVector}, B::Union{Real, AbstractMatrix}, Psi::Union{Real, AbstractMatrix}, Nm::Integer, n_moments::Integer=2, method::VAREstimationMethod=Even(), ...
function discrete_var(b::Union{Real, AbstractVector}, B::Union{Real, AbstractMatrix}, Psi::Union{Real, AbstractMatrix}, Nm::Integer, n_moments::Integer=2, method::VAREstimationMethod=Even(), ...
[ 298, 425 ]
function discrete_var(b::Union{Real, AbstractVector}, B::Union{Real, AbstractMatrix}, Psi::Union{Real, AbstractMatrix}, Nm::Integer, n_moments::Integer=2, method::VAREstimationMethod=Even(), ...
function discrete_var(b::Union{Real, AbstractVector}, B::Union{Real, AbstractMatrix}, Psi::Union{Real, AbstractMatrix}, Nm::Integer, n_moments::Integer=2, method::VAREstimationMethod=Even(), ...
discrete_var
298
425
src/markov/markov_approx.jl
#FILE: QuantEcon.jl/src/sampler.jl ##CHUNK 1 struct MVNSampler{TM<:Real,TS<:Real,TQ<:BlasReal} mu::Vector{TM} Sigma::Matrix{TS} Q::Matrix{TQ} end function MVNSampler(mu::Vector{TM}, Sigma::Matrix{TS}) where {TM<:Real,TS<:Real} ATOL1, RTOL1 = 1e-8, 1e-8 ATOL2, RTOL2 = 1e-8, 1e-14 n = length(mu)...
494
506
QuantEcon.jl
226
function standardize_var(b::AbstractVector, B::AbstractMatrix, Psi::AbstractMatrix, M::Integer) C1 = cholesky(Psi).L mu = ((I - B)\ I)*b A1 = C1\(B*C1) # unconditional variance Sigma1 = reshape(((I-kron(A1,A1))\I)*vec(Matrix(I, M, M)),M,M) U, _ = min_var_trace(Sigma1) ...
function standardize_var(b::AbstractVector, B::AbstractMatrix, Psi::AbstractMatrix, M::Integer) C1 = cholesky(Psi).L mu = ((I - B)\ I)*b A1 = C1\(B*C1) # unconditional variance Sigma1 = reshape(((I-kron(A1,A1))\I)*vec(Matrix(I, M, M)),M,M) U, _ = min_var_trace(Sigma1) ...
[ 494, 506 ]
function standardize_var(b::AbstractVector, B::AbstractMatrix, Psi::AbstractMatrix, M::Integer) C1 = cholesky(Psi).L mu = ((I - B)\ I)*b A1 = C1\(B*C1) # unconditional variance Sigma1 = reshape(((I-kron(A1,A1))\I)*vec(Matrix(I, M, M)),M,M) U, _ = min_var_trace(Sigma1) ...
function standardize_var(b::AbstractVector, B::AbstractMatrix, Psi::AbstractMatrix, M::Integer) C1 = cholesky(Psi).L mu = ((I - B)\ I)*b A1 = C1\(B*C1) # unconditional variance Sigma1 = reshape(((I-kron(A1,A1))\I)*vec(Matrix(I, M, M)),M,M) U, _ = min_var_trace(Sigma1) ...
standardize_var
494
506
src/markov/markov_approx.jl
#FILE: QuantEcon.jl/other/regression.jl ##CHUNK 1 U, S, V = svd(X1, thin=true) S_inv = diagm(0 => 1.0 ./ S) B1 = V*S_inv * U' * Y1 B = de_normalize(X, Y, B1) else U, S, V = svd(X, thin=true) S_inv = diagm(1.0 ./ S) B = V * S_inv * U' * Y end return B e...
720
759
QuantEcon.jl
227
function discrete_approximation(D::AbstractVector, T::Function, Tbar::AbstractVector, q::AbstractVector=ones(length(D))/length(D), # Default prior weights lambda0::AbstractVector=zeros(Tbar)) # Input error checking N = length(D) Tx = T(D)...
function discrete_approximation(D::AbstractVector, T::Function, Tbar::AbstractVector, q::AbstractVector=ones(length(D))/length(D), # Default prior weights lambda0::AbstractVector=zeros(Tbar)) # Input error checking N = length(D) Tx = T(D)...
[ 720, 759 ]
function discrete_approximation(D::AbstractVector, T::Function, Tbar::AbstractVector, q::AbstractVector=ones(length(D))/length(D), # Default prior weights lambda0::AbstractVector=zeros(Tbar)) # Input error checking N = length(D) Tx = T(D)...
function discrete_approximation(D::AbstractVector, T::Function, Tbar::AbstractVector, q::AbstractVector=ones(length(D))/length(D), # Default prior weights lambda0::AbstractVector=zeros(Tbar)) # Input error checking N = length(D) Tx = T(D)...
discrete_approximation
720
759
src/markov/markov_approx.jl
#FILE: QuantEcon.jl/src/robustlq.jl ##CHUNK 1 """ function robust_rule_simple(rlq::RBLQ, P::Matrix=zeros(Float64, rlq.n, rlq.n); max_iter=80, tol=1e-8) # Simplify notation A, B, C, Q, R = rlq.A, rlq.B, rlq.C, rlq.Q, rlq.R b...
871
892
QuantEcon.jl
228
function min_var_trace(A::AbstractMatrix) ==(size(A)...) || throw(ArgumentError("input matrix must be square")) K = size(A, 1) # size of A d = tr(A)/K # diagonal of U'*A*U should be closest to d function obj(X, grad) X = reshape(X, K, K) return (norm(diag(X'*A*X) .- d)) end fun...
function min_var_trace(A::AbstractMatrix) ==(size(A)...) || throw(ArgumentError("input matrix must be square")) K = size(A, 1) # size of A d = tr(A)/K # diagonal of U'*A*U should be closest to d function obj(X, grad) X = reshape(X, K, K) return (norm(diag(X'*A*X) .- d)) end fun...
[ 871, 892 ]
function min_var_trace(A::AbstractMatrix) ==(size(A)...) || throw(ArgumentError("input matrix must be square")) K = size(A, 1) # size of A d = tr(A)/K # diagonal of U'*A*U should be closest to d function obj(X, grad) X = reshape(X, K, K) return (norm(diag(X'*A*X) .- d)) end fun...
function min_var_trace(A::AbstractMatrix) ==(size(A)...) || throw(ArgumentError("input matrix must be square")) K = size(A, 1) # size of A d = tr(A)/K # diagonal of U'*A*U should be closest to d function obj(X, grad) X = reshape(X, K, K) return (norm(diag(X'*A*X) .- d)) end fun...
min_var_trace
871
892
src/markov/markov_approx.jl
#FILE: QuantEcon.jl/src/quadsums.jl ##CHUNK 1 """ function var_quadratic_sum(A::ScalarOrArray, C::ScalarOrArray, H::ScalarOrArray, bet::Real, x0::ScalarOrArray) n = size(A, 1) # coerce shapes A = reshape([A;], n, n) C = reshape([C;], n, n) H = reshape([H;], n, n) x0 ...
35
51
QuantEcon.jl
229
function MarkovChain{T,TM,TV}(p::AbstractMatrix, state_values) where {T,TM,TV} n, m = size(p) n != m && throw(DimensionMismatch("stochastic matrix must be square")) minimum(p) <0 && throw(ArgumentError("stochastic matrix must have nonnegative elements")) !check...
function MarkovChain{T,TM,TV}(p::AbstractMatrix, state_values) where {T,TM,TV} n, m = size(p) n != m && throw(DimensionMismatch("stochastic matrix must be square")) minimum(p) <0 && throw(ArgumentError("stochastic matrix must have nonnegative elements")) !check...
[ 35, 51 ]
function MarkovChain{T,TM,TV}(p::AbstractMatrix, state_values) where {T,TM,TV} n, m = size(p) n != m && throw(DimensionMismatch("stochastic matrix must be square")) minimum(p) <0 && throw(ArgumentError("stochastic matrix must have nonnegative elements")) !check...
function MarkovChain{T,TM,TV}(p::AbstractMatrix, state_values) where {T,TM,TV} n, m = size(p) n != m && throw(DimensionMismatch("stochastic matrix must be square")) minimum(p) <0 && throw(ArgumentError("stochastic matrix must have nonnegative elements")) !check...
MarkovChain{T,TM,TV}
35
51
src/markov/mc_tools.jl
#FILE: QuantEcon.jl/src/markov/random_mc.jl ##CHUNK 1 return transpose(p) end random_stochastic_matrix(n::Integer, k::Integer=n) = random_stochastic_matrix(Random.GLOBAL_RNG, n, k) """ _random_stochastic_matrix([rng], n, m; k=n) Generate a "non-square column stochstic matrix" of shape `(n, m)`, which co...
117
147
QuantEcon.jl
230
function gth_solve!(A::Matrix{T}) where T<:Real n = size(A, 1) x = zeros(T, n) @inbounds for k in 1:n-1 scale = sum(A[k, k+1:n]) if scale <= zero(T) # There is one (and only one) recurrent class contained in # {1, ..., k}; # compute the solution associate...
function gth_solve!(A::Matrix{T}) where T<:Real n = size(A, 1) x = zeros(T, n) @inbounds for k in 1:n-1 scale = sum(A[k, k+1:n]) if scale <= zero(T) # There is one (and only one) recurrent class contained in # {1, ..., k}; # compute the solution associate...
[ 117, 147 ]
function gth_solve!(A::Matrix{T}) where T<:Real n = size(A, 1) x = zeros(T, n) @inbounds for k in 1:n-1 scale = sum(A[k, k+1:n]) if scale <= zero(T) # There is one (and only one) recurrent class contained in # {1, ..., k}; # compute the solution associate...
function gth_solve!(A::Matrix{T}) where T<:Real n = size(A, 1) x = zeros(T, n) @inbounds for k in 1:n-1 scale = sum(A[k, k+1:n]) if scale <= zero(T) # There is one (and only one) recurrent class contained in # {1, ..., k}; # compute the solution associate...
gth_solve!
117
147
src/markov/mc_tools.jl
#FILE: QuantEcon.jl/src/markov/random_mc.jl ##CHUNK 1 k == 1 && return ones((k, m)) # if k >= 2 x = Matrix{Float64}(undef, k, m) r = rand(rng, k-1, m) x[1:end .- 1, :] = sort(r, dims = 1) for j in 1:m x[end, j] = 1 - x[end-1, j] for i in k-1:-1:2 x[i, j] -= x[i-1, ...
219
230
QuantEcon.jl
231
function period(mc::MarkovChain) g = DiGraph(mc.p) recurrent = attracting_components(g) d = 1 for r in recurrent pd = period(g[r]) d *= div(pd, gcd(pd, d)) end return d end
function period(mc::MarkovChain) g = DiGraph(mc.p) recurrent = attracting_components(g) d = 1 for r in recurrent pd = period(g[r]) d *= div(pd, gcd(pd, d)) end return d end
[ 219, 230 ]
function period(mc::MarkovChain) g = DiGraph(mc.p) recurrent = attracting_components(g) d = 1 for r in recurrent pd = period(g[r]) d *= div(pd, gcd(pd, d)) end return d end
function period(mc::MarkovChain) g = DiGraph(mc.p) recurrent = attracting_components(g) d = 1 for r in recurrent pd = period(g[r]) d *= div(pd, gcd(pd, d)) end return d end
period
219
230
src/markov/mc_tools.jl
#FILE: QuantEcon.jl/src/quad.jl ##CHUNK 1 # Recurrance relation for Laguerre polynomials p3 = p2 p2 = p1 p1 = ((2j - 1 + a - z) * p2 - (j - 1 + a) * p3) ./ j end pp = (n * p1 - (n + a) * p2) ./ z z1 = z z = z...
275
285
QuantEcon.jl
232
function todense(T::Type, S::SparseMatrixCSC) A = zeros(T, S.m, S.n) for Sj in 1:S.n for Sk in nzrange(S, Sj) Si = S.rowval[Sk] Sv = S.nzval[Sk] A[Si, Sj] = Sv end end return A end
function todense(T::Type, S::SparseMatrixCSC) A = zeros(T, S.m, S.n) for Sj in 1:S.n for Sk in nzrange(S, Sj) Si = S.rowval[Sk] Sv = S.nzval[Sk] A[Si, Sj] = Sv end end return A end
[ 275, 285 ]
function todense(T::Type, S::SparseMatrixCSC) A = zeros(T, S.m, S.n) for Sj in 1:S.n for Sk in nzrange(S, Sj) Si = S.rowval[Sk] Sv = S.nzval[Sk] A[Si, Sj] = Sv end end return A end
function todense(T::Type, S::SparseMatrixCSC) A = zeros(T, S.m, S.n) for Sj in 1:S.n for Sk in nzrange(S, Sj) Si = S.rowval[Sk] Sv = S.nzval[Sk] A[Si, Sj] = Sv end end return A end
todense
275
285
src/markov/mc_tools.jl
#FILE: QuantEcon.jl/src/markov/ddp.jl ##CHUNK 1 while(s_indices[idx] == s) idx += 1 end out[s+1] = idx end # need this +1 to be consistent with Julia's sparse pointers: # colptr[i]:(colptr[i+1]-1) out[num_states+1] = length(s_indices)+1 out end function _find_ind...
81
92
QuantEcon.jl
233
function random_stochastic_matrix(rng::AbstractRNG, n::Integer, k::Integer=n) if !(n > 0) throw(ArgumentError("n must be a positive integer")) end if !(k > 0 && k <= n) throw(ArgumentError("k must be an integer with 0 < k <= n")) end p = _random_stochastic_matrix(rng, n, n, k=k) ...
function random_stochastic_matrix(rng::AbstractRNG, n::Integer, k::Integer=n) if !(n > 0) throw(ArgumentError("n must be a positive integer")) end if !(k > 0 && k <= n) throw(ArgumentError("k must be an integer with 0 < k <= n")) end p = _random_stochastic_matrix(rng, n, n, k=k) ...
[ 81, 92 ]
function random_stochastic_matrix(rng::AbstractRNG, n::Integer, k::Integer=n) if !(n > 0) throw(ArgumentError("n must be a positive integer")) end if !(k > 0 && k <= n) throw(ArgumentError("k must be an integer with 0 < k <= n")) end p = _random_stochastic_matrix(rng, n, n, k=k) ...
function random_stochastic_matrix(rng::AbstractRNG, n::Integer, k::Integer=n) if !(n > 0) throw(ArgumentError("n must be a positive integer")) end if !(k > 0 && k <= n) throw(ArgumentError("k must be an integer with 0 < k <= n")) end p = _random_stochastic_matrix(rng, n, n, k=k) ...
random_stochastic_matrix
81
92
src/markov/random_mc.jl
#FILE: QuantEcon.jl/test/test_random_mc.jl ##CHUNK 1 @testset "Test random_stochastic_matrix" begin n, k = 5, 3 Ps = (random_stochastic_matrix(n), random_stochastic_matrix(n, k)) for P in Ps @test all(P .>= 0) == true @test all(x->isapprox(sum(x), 1), ...
117
138
QuantEcon.jl
234
function _random_stochastic_matrix(rng::AbstractRNG, n::Integer, m::Integer; k::Integer=n) probvecs = random_probvec(rng, k, m) k == n && return probvecs # if k < n # Randomly sample row indices for each column for nonzero values row_indices = Vector{Int}(undef, ...
function _random_stochastic_matrix(rng::AbstractRNG, n::Integer, m::Integer; k::Integer=n) probvecs = random_probvec(rng, k, m) k == n && return probvecs # if k < n # Randomly sample row indices for each column for nonzero values row_indices = Vector{Int}(undef, ...
[ 117, 138 ]
function _random_stochastic_matrix(rng::AbstractRNG, n::Integer, m::Integer; k::Integer=n) probvecs = random_probvec(rng, k, m) k == n && return probvecs # if k < n # Randomly sample row indices for each column for nonzero values row_indices = Vector{Int}(undef, ...
function _random_stochastic_matrix(rng::AbstractRNG, n::Integer, m::Integer; k::Integer=n) probvecs = random_probvec(rng, k, m) k == n && return probvecs # if k < n # Randomly sample row indices for each column for nonzero values row_indices = Vector{Int}(undef, ...
_random_stochastic_matrix
117
138
src/markov/random_mc.jl
#CURRENT FILE: QuantEcon.jl/src/markov/random_mc.jl ##CHUNK 1 - `m::Integer` : Number of probability vectors. # Returns - `a::Array` : Matrix of shape `(k, m)`, or Vector of shape `(k,)` if `m` is not specified, containing probability vector(s) as column(s). """ function random_probvec(rng::AbstractRNG, k::Integer,...
169
184
QuantEcon.jl
235
function random_discrete_dp(rng::AbstractRNG, num_states::Integer, num_actions::Integer, beta::Real=rand(rng); k::Integer=num_states, scale::Real=1) L = num_states * num_action...
function random_discrete_dp(rng::AbstractRNG, num_states::Integer, num_actions::Integer, beta::Real=rand(rng); k::Integer=num_states, scale::Real=1) L = num_states * num_action...
[ 169, 184 ]
function random_discrete_dp(rng::AbstractRNG, num_states::Integer, num_actions::Integer, beta::Real=rand(rng); k::Integer=num_states, scale::Real=1) L = num_states * num_action...
function random_discrete_dp(rng::AbstractRNG, num_states::Integer, num_actions::Integer, beta::Real=rand(rng); k::Integer=num_states, scale::Real=1) L = num_states * num_action...
random_discrete_dp
169
184
src/markov/random_mc.jl
#FILE: QuantEcon.jl/test/test_random_mc.jl ##CHUNK 1 # k > n @test_throws ArgumentError random_markov_chain(2, 3) end @testset "Test random_discrete_dp" begin num_states, num_actions = 5, 4 num_sa = num_states * num_actions k = 3 ddp = random_discrete_dp(num_stat...
210
227
QuantEcon.jl
236
function random_probvec(rng::AbstractRNG, k::Integer, m::Integer) k == 1 && return ones((k, m)) # if k >= 2 x = Matrix{Float64}(undef, k, m) r = rand(rng, k-1, m) x[1:end .- 1, :] = sort(r, dims = 1) for j in 1:m x[end, j] = 1 - x[end-1, j] for i in k-1:-1:2 x[i, j...
function random_probvec(rng::AbstractRNG, k::Integer, m::Integer) k == 1 && return ones((k, m)) # if k >= 2 x = Matrix{Float64}(undef, k, m) r = rand(rng, k-1, m) x[1:end .- 1, :] = sort(r, dims = 1) for j in 1:m x[end, j] = 1 - x[end-1, j] for i in k-1:-1:2 x[i, j...
[ 210, 227 ]
function random_probvec(rng::AbstractRNG, k::Integer, m::Integer) k == 1 && return ones((k, m)) # if k >= 2 x = Matrix{Float64}(undef, k, m) r = rand(rng, k-1, m) x[1:end .- 1, :] = sort(r, dims = 1) for j in 1:m x[end, j] = 1 - x[end-1, j] for i in k-1:-1:2 x[i, j...
function random_probvec(rng::AbstractRNG, k::Integer, m::Integer) k == 1 && return ones((k, m)) # if k >= 2 x = Matrix{Float64}(undef, k, m) r = rand(rng, k-1, m) x[1:end .- 1, :] = sort(r, dims = 1) for j in 1:m x[end, j] = 1 - x[end-1, j] for i in k-1:-1:2 x[i, j...
random_probvec
210
227
src/markov/random_mc.jl
#FILE: QuantEcon.jl/src/lqnash.jl ##CHUNK 1 function nnash(a, b1, b2, r1, r2, q1, q2, s1, s2, w1, w2, m1, m2; beta::Float64=1.0, tol::Float64=1e-8, max_iter::Int=1000) # Apply discounting a, b1, b2 = map(x->sqrt(beta) * x, Any[a, b1, b2]) dd = 10 its = 0 n = size(a, 1) # NOTE: i...
25
40
StatsBase.jl
237
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}) # add counts of integers from x that fall within levels to r checkbounds(r, axes(levels)...) m0 = first(levels) m1 = last(levels) b = m0 - firstindex(levels) # firstindex(levels) == 1 because levels::U...
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}) # add counts of integers from x that fall within levels to r checkbounds(r, axes(levels)...) m0 = first(levels) m1 = last(levels) b = m0 - firstindex(levels) # firstindex(levels) == 1 because levels::U...
[ 25, 40 ]
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}) # add counts of integers from x that fall within levels to r checkbounds(r, axes(levels)...) m0 = first(levels) m1 = last(levels) b = m0 - firstindex(levels) # firstindex(levels) == 1 because levels::U...
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}) # add counts of integers from x that fall within levels to r checkbounds(r, axes(levels)...) m0 = first(levels) m1 = last(levels) b = m0 - firstindex(levels) # firstindex(levels) == 1 because levels::U...
addcounts!
25
40
src/counts.jl
#FILE: StatsBase.jl/src/scalarstats.jl ##CHUNK 1 Return all modes (most common numbers) of an array, optionally over a specified range `r` or weighted via vector `wv`. """ function modes(a::AbstractArray{T}, r::UnitRange{T}) where T<:Integer r0 = r[1] r1 = r[end] n = length(r) cnts = zeros(Int, n) #...
42
63
StatsBase.jl
238
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}, wv::AbstractWeights) # add wv weighted counts of integers from x that fall within levels to r length(x) == length(wv) || throw(DimensionMismatch("x and wv must have the same length, got $(length(x)) and $(l...
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}, wv::AbstractWeights) # add wv weighted counts of integers from x that fall within levels to r length(x) == length(wv) || throw(DimensionMismatch("x and wv must have the same length, got $(length(x)) and $(l...
[ 42, 63 ]
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}, wv::AbstractWeights) # add wv weighted counts of integers from x that fall within levels to r length(x) == length(wv) || throw(DimensionMismatch("x and wv must have the same length, got $(length(x)) and $(l...
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}, wv::AbstractWeights) # add wv weighted counts of integers from x that fall within levels to r length(x) == length(wv) || throw(DimensionMismatch("x and wv must have the same length, got $(length(x)) and $(l...
addcounts!
42
63
src/counts.jl
#CURRENT FILE: StatsBase.jl/src/counts.jl ##CHUNK 1 If a weighting vector `wv` is specified, the sum of weights is used rather than the raw counts. """ function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}) # add counts of integers from x that fall within levels to r ...
121
145
StatsBase.jl
239
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, levels::NTuple{2,UnitRange{<:Integer}}) # add counts of pairs from zip(x,y) to r xlevels, ylevels = levels checkbounds(r, axes(xlevels, 1), axes(ylevels, 1)) mx0 = first(xlevels) mx1 = last(xlevels) ...
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, levels::NTuple{2,UnitRange{<:Integer}}) # add counts of pairs from zip(x,y) to r xlevels, ylevels = levels checkbounds(r, axes(xlevels, 1), axes(ylevels, 1)) mx0 = first(xlevels) mx1 = last(xlevels) ...
[ 121, 145 ]
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, levels::NTuple{2,UnitRange{<:Integer}}) # add counts of pairs from zip(x,y) to r xlevels, ylevels = levels checkbounds(r, axes(xlevels, 1), axes(ylevels, 1)) mx0 = first(xlevels) mx1 = last(xlevels) ...
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, levels::NTuple{2,UnitRange{<:Integer}}) # add counts of pairs from zip(x,y) to r xlevels, ylevels = levels checkbounds(r, axes(xlevels, 1), axes(ylevels, 1)) mx0 = first(xlevels) mx1 = last(xlevels) ...
addcounts!
121
145
src/counts.jl
#FILE: StatsBase.jl/src/signalcorr.jl ##CHUNK 1 for j = 1 : ns demean_col!(zy, y, j, demean) sc = sqrt(xx * dot(zy, zy)) for k = 1 : m r[k,j] = _crossdot(zx, zy, lx, lags[k]) / sc end end return r end function crosscor!(r::AbstractArray{<:Real,3}, x::AbstractMatr...
147
179
StatsBase.jl
240
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, levels::NTuple{2,UnitRange{<:Integer}}, wv::AbstractWeights) # add counts of pairs from zip(x,y) to r length(x) == length(y) == length(wv) || throw(DimensionMismatch("x, y, and wv must ha...
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, levels::NTuple{2,UnitRange{<:Integer}}, wv::AbstractWeights) # add counts of pairs from zip(x,y) to r length(x) == length(y) == length(wv) || throw(DimensionMismatch("x, y, and wv must ha...
[ 147, 179 ]
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, levels::NTuple{2,UnitRange{<:Integer}}, wv::AbstractWeights) # add counts of pairs from zip(x,y) to r length(x) == length(y) == length(wv) || throw(DimensionMismatch("x, y, and wv must ha...
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, levels::NTuple{2,UnitRange{<:Integer}}, wv::AbstractWeights) # add counts of pairs from zip(x,y) to r length(x) == length(y) == length(wv) || throw(DimensionMismatch("x, y, and wv must ha...
addcounts!
147
179
src/counts.jl
#FILE: StatsBase.jl/src/signalcorr.jl ##CHUNK 1 for j = 1 : ns demean_col!(zy, y, j, demean) sc = sqrt(xx * dot(zy, zy)) for k = 1 : m r[k,j] = _crossdot(zx, zy, lx, lags[k]) / sc end end return r end function crosscor!(r::AbstractArray{<:Real,3}, x::AbstractMatr...
272
283
StatsBase.jl
241
function _addcounts!(::Type{T}, cm::Dict, x; alg = :auto) where T # if it's safe to be sorted using radixsort then it should be faster # albeit using more RAM if radixsort_safe(T) && (alg == :auto || alg == :radixsort) addcounts_radixsort!(cm, x) elseif alg == :radixsort throw(ArgumentEr...
function _addcounts!(::Type{T}, cm::Dict, x; alg = :auto) where T # if it's safe to be sorted using radixsort then it should be faster # albeit using more RAM if radixsort_safe(T) && (alg == :auto || alg == :radixsort) addcounts_radixsort!(cm, x) elseif alg == :radixsort throw(ArgumentEr...
[ 272, 283 ]
function _addcounts!(::Type{T}, cm::Dict, x; alg = :auto) where T # if it's safe to be sorted using radixsort then it should be faster # albeit using more RAM if radixsort_safe(T) && (alg == :auto || alg == :radixsort) addcounts_radixsort!(cm, x) elseif alg == :radixsort throw(ArgumentEr...
function _addcounts!(::Type{T}, cm::Dict, x; alg = :auto) where T # if it's safe to be sorted using radixsort then it should be faster # albeit using more RAM if radixsort_safe(T) && (alg == :auto || alg == :radixsort) addcounts_radixsort!(cm, x) elseif alg == :radixsort throw(ArgumentEr...
_addcounts!
272
283
src/counts.jl
#CURRENT FILE: StatsBase.jl/src/counts.jl ##CHUNK 1 If a weighting vector `wv` is specified, the sum of the weights is used rather than the raw counts. `alg` is only allowed for unweighted counting and can be one of: - `:auto` (default): if `StatsBase.radixsort_safe(eltype(x)) == true` then use `:...
286
296
StatsBase.jl
242
function addcounts_dict!(cm::Dict{T}, x) where T for v in x index = ht_keyindex2!(cm, v) if index > 0 @inbounds cm.vals[index] += 1 else @inbounds Base._setindex!(cm, 1, v, -index) end end return cm end
function addcounts_dict!(cm::Dict{T}, x) where T for v in x index = ht_keyindex2!(cm, v) if index > 0 @inbounds cm.vals[index] += 1 else @inbounds Base._setindex!(cm, 1, v, -index) end end return cm end
[ 286, 296 ]
function addcounts_dict!(cm::Dict{T}, x) where T for v in x index = ht_keyindex2!(cm, v) if index > 0 @inbounds cm.vals[index] += 1 else @inbounds Base._setindex!(cm, 1, v, -index) end end return cm end
function addcounts_dict!(cm::Dict{T}, x) where T for v in x index = ht_keyindex2!(cm, v) if index > 0 @inbounds cm.vals[index] += 1 else @inbounds Base._setindex!(cm, 1, v, -index) end end return cm end
addcounts_dict!
286
296
src/counts.jl
#FILE: StatsBase.jl/src/scalarstats.jl ##CHUNK 1 for i = 1:length(a) @inbounds x = a[i] if r0 <= x <= r1 @inbounds c = (cnts[x - r0 + 1] += 1) if c > mc mc = c end end end # find all values corresponding to maximum count ms = T[...
350
370
StatsBase.jl
243
function _addcounts_radix_sort_loop!(cm::Dict{T}, sx::AbstractVector{T}) where T isempty(sx) && return cm last_sx = first(sx) start_i = firstindex(sx) # now the data is sorted: can just run through and accumulate values before # adding into the Dict @inbounds for i in start_i+1:lastindex(sx) ...
function _addcounts_radix_sort_loop!(cm::Dict{T}, sx::AbstractVector{T}) where T isempty(sx) && return cm last_sx = first(sx) start_i = firstindex(sx) # now the data is sorted: can just run through and accumulate values before # adding into the Dict @inbounds for i in start_i+1:lastindex(sx) ...
[ 350, 370 ]
function _addcounts_radix_sort_loop!(cm::Dict{T}, sx::AbstractVector{T}) where T isempty(sx) && return cm last_sx = first(sx) start_i = firstindex(sx) # now the data is sorted: can just run through and accumulate values before # adding into the Dict @inbounds for i in start_i+1:lastindex(sx) ...
function _addcounts_radix_sort_loop!(cm::Dict{T}, sx::AbstractVector{T}) where T isempty(sx) && return cm last_sx = first(sx) start_i = firstindex(sx) # now the data is sorted: can just run through and accumulate values before # adding into the Dict @inbounds for i in start_i+1:lastindex(sx) ...
_addcounts_radix_sort_loop!
350
370
src/counts.jl
#FILE: StatsBase.jl/src/ranking.jl ##CHUNK 1 for e in 2:n # e is pass-by-end index of current range cx = x[p[e]] if cx != v # fill average rank to s : e-1 ar = (s + e - 1) / 2 for i = s : e-1 rks[p[i]] = ar ...
389
405
StatsBase.jl
244
function addcounts!(cm::Dict{T}, x::AbstractArray{T}, wv::AbstractVector{W}) where {T,W<:Real} # add wv weighted counts of integers from x to cm length(x) == length(wv) || throw(DimensionMismatch("x and wv must have the same length, got $(length(x)) and $(length(wv))")) xv = vec(x) # discard shape...
function addcounts!(cm::Dict{T}, x::AbstractArray{T}, wv::AbstractVector{W}) where {T,W<:Real} # add wv weighted counts of integers from x to cm length(x) == length(wv) || throw(DimensionMismatch("x and wv must have the same length, got $(length(x)) and $(length(wv))")) xv = vec(x) # discard shape...
[ 389, 405 ]
function addcounts!(cm::Dict{T}, x::AbstractArray{T}, wv::AbstractVector{W}) where {T,W<:Real} # add wv weighted counts of integers from x to cm length(x) == length(wv) || throw(DimensionMismatch("x and wv must have the same length, got $(length(x)) and $(length(wv))")) xv = vec(x) # discard shape...
function addcounts!(cm::Dict{T}, x::AbstractArray{T}, wv::AbstractVector{W}) where {T,W<:Real} # add wv weighted counts of integers from x to cm length(x) == length(wv) || throw(DimensionMismatch("x and wv must have the same length, got $(length(x)) and $(length(wv))")) xv = vec(x) # discard shape...
addcounts!
389
405
src/counts.jl
#FILE: StatsBase.jl/src/weights.jl ##CHUNK 1 end) @inbounds (@nref $N R j) += f((@nref $N A i) - (@nref $N means j)) * wi end return R end end _wsum!(R::AbstractArray, A::AbstractArray, w::AbstractVector, dim::Int, init::Bool) = _wsum_general!(R, identity, A, w, d...
5
16
StatsBase.jl
245
function _symmetrize!(a::DenseMatrix) m, n = size(a) m == n || error("a must be a square matrix.") for j = 1:n @inbounds for i = j+1:n vl = a[i,j] vr = a[j,i] a[i,j] = a[j,i] = middle(vl, vr) end end return a end
function _symmetrize!(a::DenseMatrix) m, n = size(a) m == n || error("a must be a square matrix.") for j = 1:n @inbounds for i = j+1:n vl = a[i,j] vr = a[j,i] a[i,j] = a[j,i] = middle(vl, vr) end end return a end
[ 5, 16 ]
function _symmetrize!(a::DenseMatrix) m, n = size(a) m == n || error("a must be a square matrix.") for j = 1:n @inbounds for i = j+1:n vl = a[i,j] vr = a[j,i] a[i,j] = a[j,i] = middle(vl, vr) end end return a end
function _symmetrize!(a::DenseMatrix) m, n = size(a) m == n || error("a must be a square matrix.") for j = 1:n @inbounds for i = j+1:n vl = a[i,j] vr = a[j,i] a[i,j] = a[j,i] = middle(vl, vr) end end return a end
_symmetrize!
5
16
src/cov.jl
#FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 n = length(a) k = length(x) k <= n || error("length(x) should not exceed length(a)") i = 0 j = 0 while k > 1 u = rand(rng) q = (n - k) / n while q > u # skip i += 1 n -= 1 q *= (n - k) / n...
142
157
StatsBase.jl
246
function cov2cor!(C::AbstractMatrix, s::AbstractArray = map(sqrt, view(C, diagind(C)))) Base.require_one_based_indexing(C, s) n = length(s) size(C) == (n, n) || throw(DimensionMismatch("inconsistent dimensions")) for j = 1:n sj = s[j] for i = 1:(j-1) C[i,j] = adjoint(C[j,i]) ...
function cov2cor!(C::AbstractMatrix, s::AbstractArray = map(sqrt, view(C, diagind(C)))) Base.require_one_based_indexing(C, s) n = length(s) size(C) == (n, n) || throw(DimensionMismatch("inconsistent dimensions")) for j = 1:n sj = s[j] for i = 1:(j-1) C[i,j] = adjoint(C[j,i]) ...
[ 142, 157 ]
function cov2cor!(C::AbstractMatrix, s::AbstractArray = map(sqrt, view(C, diagind(C)))) Base.require_one_based_indexing(C, s) n = length(s) size(C) == (n, n) || throw(DimensionMismatch("inconsistent dimensions")) for j = 1:n sj = s[j] for i = 1:(j-1) C[i,j] = adjoint(C[j,i]) ...
function cov2cor!(C::AbstractMatrix, s::AbstractArray = map(sqrt, view(C, diagind(C)))) Base.require_one_based_indexing(C, s) n = length(s) size(C) == (n, n) || throw(DimensionMismatch("inconsistent dimensions")) for j = 1:n sj = s[j] for i = 1:(j-1) C[i,j] = adjoint(C[j,i]) ...
cov2cor!
142
157
src/cov.jl
#FILE: StatsBase.jl/src/rankcorr.jl ##CHUNK 1 C = Matrix{Float64}(I, n, 1) any(isnan, y) && return fill!(C, NaN) yrank = tiedrank(y) for j = 1:n Xj = view(X, :, j) if any(isnan, Xj) C[j,1] = NaN else Xjrank = tiedrank(Xj) C[j,1] = cor(Xjrank, y...
162
184
StatsBase.jl
247
function cov2cor!(C::Union{Symmetric{<:Real},Hermitian}, s::AbstractArray) n = length(s) size(C) == (n, n) || throw(DimensionMismatch("inconsistent dimensions")) A = parent(C) if C.uplo === 'U' for j = 1:n sj = s[j] for i = 1:(j-1) A[i,j] = _clampcor(A[i,j...
function cov2cor!(C::Union{Symmetric{<:Real},Hermitian}, s::AbstractArray) n = length(s) size(C) == (n, n) || throw(DimensionMismatch("inconsistent dimensions")) A = parent(C) if C.uplo === 'U' for j = 1:n sj = s[j] for i = 1:(j-1) A[i,j] = _clampcor(A[i,j...
[ 162, 184 ]
function cov2cor!(C::Union{Symmetric{<:Real},Hermitian}, s::AbstractArray) n = length(s) size(C) == (n, n) || throw(DimensionMismatch("inconsistent dimensions")) A = parent(C) if C.uplo === 'U' for j = 1:n sj = s[j] for i = 1:(j-1) A[i,j] = _clampcor(A[i,j...
function cov2cor!(C::Union{Symmetric{<:Real},Hermitian}, s::AbstractArray) n = length(s) size(C) == (n, n) || throw(DimensionMismatch("inconsistent dimensions")) A = parent(C) if C.uplo === 'U' for j = 1:n sj = s[j] for i = 1:(j-1) A[i,j] = _clampcor(A[i,j...
cov2cor!
162
184
src/cov.jl
#FILE: StatsBase.jl/src/pairwise.jl ##CHUNK 1 function _pairwise!(::Val{:none}, f, dest::AbstractMatrix, x, y, symmetric::Bool) @inbounds for (i, xi) in enumerate(x), (j, yj) in enumerate(y) symmetric && i > j && continue # For performance, diagonal is special-cased if f === cor && eltype(d...
204
219
StatsBase.jl
248
function cor2cov!(C::AbstractMatrix, s::AbstractArray) Base.require_one_based_indexing(C, s) n = length(s) size(C) == (n, n) || throw(DimensionMismatch("inconsistent dimensions")) for j in 1:n sj = s[j] for i in 1:(j-1) C[i,j] = adjoint(C[j,i]) end C[j,j] = sj...
function cor2cov!(C::AbstractMatrix, s::AbstractArray) Base.require_one_based_indexing(C, s) n = length(s) size(C) == (n, n) || throw(DimensionMismatch("inconsistent dimensions")) for j in 1:n sj = s[j] for i in 1:(j-1) C[i,j] = adjoint(C[j,i]) end C[j,j] = sj...
[ 204, 219 ]
function cor2cov!(C::AbstractMatrix, s::AbstractArray) Base.require_one_based_indexing(C, s) n = length(s) size(C) == (n, n) || throw(DimensionMismatch("inconsistent dimensions")) for j in 1:n sj = s[j] for i in 1:(j-1) C[i,j] = adjoint(C[j,i]) end C[j,j] = sj...
function cor2cov!(C::AbstractMatrix, s::AbstractArray) Base.require_one_based_indexing(C, s) n = length(s) size(C) == (n, n) || throw(DimensionMismatch("inconsistent dimensions")) for j in 1:n sj = s[j] for i in 1:(j-1) C[i,j] = adjoint(C[j,i]) end C[j,j] = sj...
cor2cov!
204
219
src/cov.jl
#FILE: StatsBase.jl/src/rankcorr.jl ##CHUNK 1 n = length(x) n == length(y) || throw(DimensionMismatch("vectors must have same length")) (any(isnan, x) || any(isnan, y)) && return NaN return cor(tiedrank(x), tiedrank(y)) end function corspearman(X::AbstractMatrix{<:Real}, y::AbstractVector{<:Real}) ...
222
244
StatsBase.jl
249
function cor2cov!(C::Union{Symmetric{<:Real},Hermitian}, s::AbstractArray) n = length(s) size(C) == (n, n) || throw(DimensionMismatch("inconsistent dimensions")) A = parent(C) if C.uplo === 'U' for j in 1:n sj = s[j] for i in 1:(j-1) A[i,j] *= s[i] * sj ...
function cor2cov!(C::Union{Symmetric{<:Real},Hermitian}, s::AbstractArray) n = length(s) size(C) == (n, n) || throw(DimensionMismatch("inconsistent dimensions")) A = parent(C) if C.uplo === 'U' for j in 1:n sj = s[j] for i in 1:(j-1) A[i,j] *= s[i] * sj ...
[ 222, 244 ]
function cor2cov!(C::Union{Symmetric{<:Real},Hermitian}, s::AbstractArray) n = length(s) size(C) == (n, n) || throw(DimensionMismatch("inconsistent dimensions")) A = parent(C) if C.uplo === 'U' for j in 1:n sj = s[j] for i in 1:(j-1) A[i,j] *= s[i] * sj ...
function cor2cov!(C::Union{Symmetric{<:Real},Hermitian}, s::AbstractArray) n = length(s) size(C) == (n, n) || throw(DimensionMismatch("inconsistent dimensions")) A = parent(C) if C.uplo === 'U' for j in 1:n sj = s[j] for i in 1:(j-1) A[i,j] *= s[i] * sj ...
cor2cov!
222
244
src/cov.jl
#FILE: StatsBase.jl/src/toeplitzsolvers.jl ##CHUNK 1 # Symmetric Toeplitz solver function durbin!(r::AbstractVector{T}, y::AbstractVector{T}) where T<:BlasReal n = length(r) n <= length(y) || throw(DimensionMismatch("Auxiliary vector cannot be shorter than data vector")) y[1] = -r[1] β = one(T) α = ...
11
21
StatsBase.jl
250
function counteq(a::AbstractArray, b::AbstractArray) n = length(a) length(b) == n || throw(DimensionMismatch("Inconsistent lengths.")) c = 0 for i in eachindex(a, b) @inbounds if a[i] == b[i] c += 1 end end return c end
function counteq(a::AbstractArray, b::AbstractArray) n = length(a) length(b) == n || throw(DimensionMismatch("Inconsistent lengths.")) c = 0 for i in eachindex(a, b) @inbounds if a[i] == b[i] c += 1 end end return c end
[ 11, 21 ]
function counteq(a::AbstractArray, b::AbstractArray) n = length(a) length(b) == n || throw(DimensionMismatch("Inconsistent lengths.")) c = 0 for i in eachindex(a, b) @inbounds if a[i] == b[i] c += 1 end end return c end
function counteq(a::AbstractArray, b::AbstractArray) n = length(a) length(b) == n || throw(DimensionMismatch("Inconsistent lengths.")) c = 0 for i in eachindex(a, b) @inbounds if a[i] == b[i] c += 1 end end return c end
counteq
11
21
src/deviation.jl
#FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 n = length(a) length(wv) == n || throw(DimensionMismatch("Inconsistent lengths.")) k = length(x) w = Vector{Float64}(undef, n) copyto!(w, wv) for i = 1:k u = rand(rng) * wsum j = 1 c = w[1] while c < u && j < n ...
30
40
StatsBase.jl
251
function countne(a::AbstractArray, b::AbstractArray) n = length(a) length(b) == n || throw(DimensionMismatch("Inconsistent lengths.")) c = 0 for i in eachindex(a, b) @inbounds if a[i] != b[i] c += 1 end end return c end
function countne(a::AbstractArray, b::AbstractArray) n = length(a) length(b) == n || throw(DimensionMismatch("Inconsistent lengths.")) c = 0 for i in eachindex(a, b) @inbounds if a[i] != b[i] c += 1 end end return c end
[ 30, 40 ]
function countne(a::AbstractArray, b::AbstractArray) n = length(a) length(b) == n || throw(DimensionMismatch("Inconsistent lengths.")) c = 0 for i in eachindex(a, b) @inbounds if a[i] != b[i] c += 1 end end return c end
function countne(a::AbstractArray, b::AbstractArray) n = length(a) length(b) == n || throw(DimensionMismatch("Inconsistent lengths.")) c = 0 for i in eachindex(a, b) @inbounds if a[i] != b[i] c += 1 end end return c end
countne
30
40
src/deviation.jl
#FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 n = length(a) length(wv) == n || throw(DimensionMismatch("Inconsistent lengths.")) k = length(x) w = Vector{Float64}(undef, n) copyto!(w, wv) for i = 1:k u = rand(rng) * wsum j = 1 c = w[1] while c < u && j < n ...
96
107
StatsBase.jl
252
function Linfdist(a::AbstractArray{T}, b::AbstractArray{T}) where T<:Number n = length(a) length(b) == n || throw(DimensionMismatch("Input dimension mismatch")) r = 0.0 for i in eachindex(a, b) @inbounds v = abs(a[i] - b[i]) if r < v r = v end end return r end
function Linfdist(a::AbstractArray{T}, b::AbstractArray{T}) where T<:Number n = length(a) length(b) == n || throw(DimensionMismatch("Input dimension mismatch")) r = 0.0 for i in eachindex(a, b) @inbounds v = abs(a[i] - b[i]) if r < v r = v end end return r end
[ 96, 107 ]
function Linfdist(a::AbstractArray{T}, b::AbstractArray{T}) where T<:Number n = length(a) length(b) == n || throw(DimensionMismatch("Input dimension mismatch")) r = 0.0 for i in eachindex(a, b) @inbounds v = abs(a[i] - b[i]) if r < v r = v end end return r end
function Linfdist(a::AbstractArray{T}, b::AbstractArray{T}) where T<:Number n = length(a) length(b) == n || throw(DimensionMismatch("Input dimension mismatch")) r = 0.0 for i in eachindex(a, b) @inbounds v = abs(a[i] - b[i]) if r < v r = v end end return r end
Linfdist
96
107
src/deviation.jl
#FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 n = length(a) k = length(x) k <= n || error("length(x) should not exceed length(a)") i = 0 j = 0 while k > 1 u = rand(rng) q = (n - k) / n while q > u # skip i += 1 n -= 1 q *= (n - k) / n...
118
131
StatsBase.jl
253
function gkldiv(a::AbstractArray{T}, b::AbstractArray{T}) where T<:AbstractFloat n = length(a) r = 0.0 for i in eachindex(a, b) @inbounds ai = a[i] @inbounds bi = b[i] if ai > 0 r += (ai * log(ai / bi) - ai + bi) else r += bi end end re...
function gkldiv(a::AbstractArray{T}, b::AbstractArray{T}) where T<:AbstractFloat n = length(a) r = 0.0 for i in eachindex(a, b) @inbounds ai = a[i] @inbounds bi = b[i] if ai > 0 r += (ai * log(ai / bi) - ai + bi) else r += bi end end re...
[ 118, 131 ]
function gkldiv(a::AbstractArray{T}, b::AbstractArray{T}) where T<:AbstractFloat n = length(a) r = 0.0 for i in eachindex(a, b) @inbounds ai = a[i] @inbounds bi = b[i] if ai > 0 r += (ai * log(ai / bi) - ai + bi) else r += bi end end re...
function gkldiv(a::AbstractArray{T}, b::AbstractArray{T}) where T<:AbstractFloat n = length(a) r = 0.0 for i in eachindex(a, b) @inbounds ai = a[i] @inbounds bi = b[i] if ai > 0 r += (ai * log(ai / bi) - ai + bi) else r += bi end end re...
gkldiv
118
131
src/deviation.jl
#FILE: StatsBase.jl/src/scalarstats.jl ##CHUNK 1 ) # return zero for empty arrays pzero = zero(eltype(p)) qzero = zero(eltype(q)) return xlogy(pzero, zero(pzero / qzero)) end # use pairwise summation (https://github.com/JuliaLang/julia/pull/31020) broadcasted = Broad...
19
42
StatsBase.jl
254
function (ecdf::ECDF)(v::AbstractVector{<:Real}) evenweights = isempty(ecdf.weights) weightsum = evenweights ? length(ecdf.sorted_values) : sum(ecdf.weights) ord = sortperm(v) m = length(v) r = similar(ecdf.sorted_values, m) r0 = zero(weightsum) i = 1 for (j, x) in enumerate(ecdf.sorted_...
function (ecdf::ECDF)(v::AbstractVector{<:Real}) evenweights = isempty(ecdf.weights) weightsum = evenweights ? length(ecdf.sorted_values) : sum(ecdf.weights) ord = sortperm(v) m = length(v) r = similar(ecdf.sorted_values, m) r0 = zero(weightsum) i = 1 for (j, x) in enumerate(ecdf.sorted_...
[ 19, 42 ]
function (ecdf::ECDF)(v::AbstractVector{<:Real}) evenweights = isempty(ecdf.weights) weightsum = evenweights ? length(ecdf.sorted_values) : sum(ecdf.weights) ord = sortperm(v) m = length(v) r = similar(ecdf.sorted_values, m) r0 = zero(weightsum) i = 1 for (j, x) in enumerate(ecdf.sorted_...
function (ecdf::ECDF)(v::AbstractVector{<:Real}) evenweights = isempty(ecdf.weights) weightsum = evenweights ? length(ecdf.sorted_values) : sum(ecdf.weights) ord = sortperm(v) m = length(v) r = similar(ecdf.sorted_values, m) r0 = zero(weightsum) i = 1 for (j, x) in enumerate(ecdf.sorted_...
unknown_function
19
42
src/empirical.jl
#FILE: StatsBase.jl/test/empirical.jl ##CHUNK 1 @test extrema(fnecdf) == (minimum(fnecdf), maximum(fnecdf)) == extrema(x) fnecdf = ecdf([0.5]) @test fnecdf([zeros(5000); ones(5000)]) == [zeros(5000); ones(5000)] @test extrema(fnecdf) == (minimum(fnecdf), maximum(fnecdf)) == (0.5, 0.5) @test isnan(ec...
21
50
StatsBase.jl
255
function rle(v::AbstractVector{T}) where T n = length(v) vals = T[] lens = Int[] n>0 || return (vals,lens) cv = v[1] cl = 1 i = 2 @inbounds while i <= n vi = v[i] if isequal(vi, cv) cl += 1 else push!(vals, cv) push!(lens, cl...
function rle(v::AbstractVector{T}) where T n = length(v) vals = T[] lens = Int[] n>0 || return (vals,lens) cv = v[1] cl = 1 i = 2 @inbounds while i <= n vi = v[i] if isequal(vi, cv) cl += 1 else push!(vals, cv) push!(lens, cl...
[ 21, 50 ]
function rle(v::AbstractVector{T}) where T n = length(v) vals = T[] lens = Int[] n>0 || return (vals,lens) cv = v[1] cl = 1 i = 2 @inbounds while i <= n vi = v[i] if isequal(vi, cv) cl += 1 else push!(vals, cv) push!(lens, cl...
function rle(v::AbstractVector{T}) where T n = length(v) vals = T[] lens = Int[] n>0 || return (vals,lens) cv = v[1] cl = 1 i = 2 @inbounds while i <= n vi = v[i] if isequal(vi, cv) cl += 1 else push!(vals, cv) push!(lens, cl...
rle
21
50
src/misc.jl
#FILE: StatsBase.jl/src/counts.jl ##CHUNK 1 checkbounds(r, axes(xlevels, 1), axes(ylevels, 1)) mx0 = first(xlevels) mx1 = last(xlevels) my0 = first(ylevels) my1 = last(ylevels) bx = mx0 - 1 by = my0 - 1 for i in eachindex(xv, yv, wv) xi = xv[i] yi = yv[i] if (m...
60
80
StatsBase.jl
256
function inverse_rle(vals::AbstractVector{T}, lens::AbstractVector{<:Integer}) where T m = length(vals) mlens = length(lens) mlens == m || throw(DimensionMismatch( "number of vals ($m) does not match the number of lens ($mlens)")) n = sum(lens) n >= 0 || throw(ArgumentError("...
function inverse_rle(vals::AbstractVector{T}, lens::AbstractVector{<:Integer}) where T m = length(vals) mlens = length(lens) mlens == m || throw(DimensionMismatch( "number of vals ($m) does not match the number of lens ($mlens)")) n = sum(lens) n >= 0 || throw(ArgumentError("...
[ 60, 80 ]
function inverse_rle(vals::AbstractVector{T}, lens::AbstractVector{<:Integer}) where T m = length(vals) mlens = length(lens) mlens == m || throw(DimensionMismatch( "number of vals ($m) does not match the number of lens ($mlens)")) n = sum(lens) n >= 0 || throw(ArgumentError("...
function inverse_rle(vals::AbstractVector{T}, lens::AbstractVector{<:Integer}) where T m = length(vals) mlens = length(lens) mlens == m || throw(DimensionMismatch( "number of vals ($m) does not match the number of lens ($mlens)")) n = sum(lens) n >= 0 || throw(ArgumentError("...
inverse_rle
60
80
src/misc.jl
#FILE: StatsBase.jl/src/signalcorr.jl ##CHUNK 1 end return r end function crosscov!(r::AbstractMatrix{<:Real}, x::AbstractVector{<:Real}, y::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true) lx = length(x) ns = size(y, 2) m = length(lags) (size(y, 1) == lx && size(r) =...
107
118
StatsBase.jl
257
function levelsmap(a::AbstractArray{T}) where T d = Dict{T,Int}() index = 1 for i = 1 : length(a) @inbounds k = a[i] if !haskey(d, k) d[k] = index index += 1 end end return d end
function levelsmap(a::AbstractArray{T}) where T d = Dict{T,Int}() index = 1 for i = 1 : length(a) @inbounds k = a[i] if !haskey(d, k) d[k] = index index += 1 end end return d end
[ 107, 118 ]
function levelsmap(a::AbstractArray{T}) where T d = Dict{T,Int}() index = 1 for i = 1 : length(a) @inbounds k = a[i] if !haskey(d, k) d[k] = index index += 1 end end return d end
function levelsmap(a::AbstractArray{T}) where T d = Dict{T,Int}() index = 1 for i = 1 : length(a) @inbounds k = a[i] if !haskey(d, k) d[k] = index index += 1 end end return d end
levelsmap
107
118
src/misc.jl
#FILE: StatsBase.jl/src/counts.jl ##CHUNK 1 end function _addcounts!(::Type{T}, cm::Dict{T}, x; alg = :ignored) where T <: Union{UInt8, UInt16, Int8, Int16} counts = zeros(Int, 2^(8sizeof(T))) @inbounds for xi in x counts[Int(xi) - typemin(T) + 1] += 1 end for (i, c) in zip(typemin(T):typemax...
168
180
StatsBase.jl
258
function _indicatormat_dense(x::AbstractArray{T}, c::AbstractArray{T}) where T d = indexmap(c) m = length(c) n = length(x) r = zeros(Bool, m, n) o = 0 @inbounds for i = 1 : n xi = x[i] r[o + d[xi]] = true o += m end return r end
function _indicatormat_dense(x::AbstractArray{T}, c::AbstractArray{T}) where T d = indexmap(c) m = length(c) n = length(x) r = zeros(Bool, m, n) o = 0 @inbounds for i = 1 : n xi = x[i] r[o + d[xi]] = true o += m end return r end
[ 168, 180 ]
function _indicatormat_dense(x::AbstractArray{T}, c::AbstractArray{T}) where T d = indexmap(c) m = length(c) n = length(x) r = zeros(Bool, m, n) o = 0 @inbounds for i = 1 : n xi = x[i] r[o + d[xi]] = true o += m end return r end
function _indicatormat_dense(x::AbstractArray{T}, c::AbstractArray{T}) where T d = indexmap(c) m = length(c) n = length(x) r = zeros(Bool, m, n) o = 0 @inbounds for i = 1 : n xi = x[i] r[o + d[xi]] = true o += m end return r end
_indicatormat_dense
168
180
src/misc.jl
#FILE: StatsBase.jl/src/weights.jl ##CHUNK 1 j_d = i_d end) @inbounds (@nref $N R j) += f(@nref $N A i) * wi end return R end end @generated function _wsum_centralize!(R::AbstractArray{RT}, f::supertype(typeof(abs)), ...
184
194
StatsBase.jl
259
function _indicatormat_sparse(x::AbstractArray{T}, c::AbstractArray{T}) where T d = indexmap(c) m = length(c) n = length(x) rinds = Vector{Int}(undef, n) @inbounds for i = 1 : n rinds[i] = d[x[i]] end return sparse(rinds, 1:n, true, m, n) end
function _indicatormat_sparse(x::AbstractArray{T}, c::AbstractArray{T}) where T d = indexmap(c) m = length(c) n = length(x) rinds = Vector{Int}(undef, n) @inbounds for i = 1 : n rinds[i] = d[x[i]] end return sparse(rinds, 1:n, true, m, n) end
[ 184, 194 ]
function _indicatormat_sparse(x::AbstractArray{T}, c::AbstractArray{T}) where T d = indexmap(c) m = length(c) n = length(x) rinds = Vector{Int}(undef, n) @inbounds for i = 1 : n rinds[i] = d[x[i]] end return sparse(rinds, 1:n, true, m, n) end
function _indicatormat_sparse(x::AbstractArray{T}, c::AbstractArray{T}) where T d = indexmap(c) m = length(c) n = length(x) rinds = Vector{Int}(undef, n) @inbounds for i = 1 : n rinds[i] = d[x[i]] end return sparse(rinds, 1:n, true, m, n) end
_indicatormat_sparse
184
194
src/misc.jl
#FILE: StatsBase.jl/src/weights.jl ##CHUNK 1 j_d = i_d end) @inbounds (@nref $N R j) += f(@nref $N A i) * wi end return R end end @generated function _wsum_centralize!(R::AbstractArray{RT}, f::supertype(typeof(abs)), ...
34
56
StatsBase.jl
260
function var!(R::AbstractArray, A::AbstractArray{<:Real}, w::AbstractWeights, dims::Int; mean=nothing, corrected::Union{Bool, Nothing}=nothing) corrected = depcheck(:var!, :corrected, corrected) if mean == 0 mean = Base.reducedim_initarray(A, dims, 0, eltype(R)) elseif mean === nothin...
function var!(R::AbstractArray, A::AbstractArray{<:Real}, w::AbstractWeights, dims::Int; mean=nothing, corrected::Union{Bool, Nothing}=nothing) corrected = depcheck(:var!, :corrected, corrected) if mean == 0 mean = Base.reducedim_initarray(A, dims, 0, eltype(R)) elseif mean === nothin...
[ 34, 56 ]
function var!(R::AbstractArray, A::AbstractArray{<:Real}, w::AbstractWeights, dims::Int; mean=nothing, corrected::Union{Bool, Nothing}=nothing) corrected = depcheck(:var!, :corrected, corrected) if mean == 0 mean = Base.reducedim_initarray(A, dims, 0, eltype(R)) elseif mean === nothin...
function var!(R::AbstractArray, A::AbstractArray{<:Real}, w::AbstractWeights, dims::Int; mean=nothing, corrected::Union{Bool, Nothing}=nothing) corrected = depcheck(:var!, :corrected, corrected) if mean == 0 mean = Base.reducedim_initarray(A, dims, 0, eltype(R)) elseif mean === nothin...
var!
34
56
src/moments.jl
#FILE: StatsBase.jl/src/cov.jl ##CHUNK 1 function cov(sc::SimpleCovariance, X::AbstractMatrix; dims::Int=1, mean=nothing) dims ∈ (1, 2) || throw(ArgumentError("Argument dims can only be 1 or 2 (given: $dims)")) if mean === nothing return cov(X; dims=dims, corrected=sc.corrected) else return ...
281
295
StatsBase.jl
261
function skewness(v::AbstractArray{<:Real}, m::Real) n = length(v) cm2 = 0.0 # empirical 2nd centered moment (variance) cm3 = 0.0 # empirical 3rd centered moment for i = 1:n @inbounds z = v[i] - m z2 = z * z cm2 += z2 cm3 += z2 * z end cm3 /= n cm2 /= n ...
function skewness(v::AbstractArray{<:Real}, m::Real) n = length(v) cm2 = 0.0 # empirical 2nd centered moment (variance) cm3 = 0.0 # empirical 3rd centered moment for i = 1:n @inbounds z = v[i] - m z2 = z * z cm2 += z2 cm3 += z2 * z end cm3 /= n cm2 /= n ...
[ 281, 295 ]
function skewness(v::AbstractArray{<:Real}, m::Real) n = length(v) cm2 = 0.0 # empirical 2nd centered moment (variance) cm3 = 0.0 # empirical 3rd centered moment for i = 1:n @inbounds z = v[i] - m z2 = z * z cm2 += z2 cm3 += z2 * z end cm3 /= n cm2 /= n ...
function skewness(v::AbstractArray{<:Real}, m::Real) n = length(v) cm2 = 0.0 # empirical 2nd centered moment (variance) cm3 = 0.0 # empirical 3rd centered moment for i = 1:n @inbounds z = v[i] - m z2 = z * z cm2 += z2 cm3 += z2 * z end cm3 /= n cm2 /= n ...
skewness
281
295
src/moments.jl
#CURRENT FILE: StatsBase.jl/src/moments.jl ##CHUNK 1 function skewness(v::AbstractArray{<:Real}, wv::AbstractWeights, m::Real) n = length(v) length(wv) == n || throw(DimensionMismatch("Inconsistent array lengths.")) cm2 = 0.0 # empirical 2nd centered moment (variance) cm3 = 0.0 # empirical 3rd cent...
297
315
StatsBase.jl
262
function skewness(v::AbstractArray{<:Real}, wv::AbstractWeights, m::Real) n = length(v) length(wv) == n || throw(DimensionMismatch("Inconsistent array lengths.")) cm2 = 0.0 # empirical 2nd centered moment (variance) cm3 = 0.0 # empirical 3rd centered moment @inbounds for i = 1:n x_i = v...
function skewness(v::AbstractArray{<:Real}, wv::AbstractWeights, m::Real) n = length(v) length(wv) == n || throw(DimensionMismatch("Inconsistent array lengths.")) cm2 = 0.0 # empirical 2nd centered moment (variance) cm3 = 0.0 # empirical 3rd centered moment @inbounds for i = 1:n x_i = v...
[ 297, 315 ]
function skewness(v::AbstractArray{<:Real}, wv::AbstractWeights, m::Real) n = length(v) length(wv) == n || throw(DimensionMismatch("Inconsistent array lengths.")) cm2 = 0.0 # empirical 2nd centered moment (variance) cm3 = 0.0 # empirical 3rd centered moment @inbounds for i = 1:n x_i = v...
function skewness(v::AbstractArray{<:Real}, wv::AbstractWeights, m::Real) n = length(v) length(wv) == n || throw(DimensionMismatch("Inconsistent array lengths.")) cm2 = 0.0 # empirical 2nd centered moment (variance) cm3 = 0.0 # empirical 3rd centered moment @inbounds for i = 1:n x_i = v...
skewness
297
315
src/moments.jl
#FILE: StatsBase.jl/test/cov.jl ##CHUNK 1 X = randn(3, 8) Z1 = X .- mean(X, dims = 1) Z2 = X .- mean(X, dims = 2) w1 = rand(3) w2 = rand(8) # varcorrection is negative if sum of weights is smaller than 1 if f === fweights w1[1] += 1 w2[1] += 1 end wv1 = f(w1) ...
328
341
StatsBase.jl
263
function kurtosis(v::AbstractArray{<:Real}, m::Real) n = length(v) cm2 = 0.0 # empirical 2nd centered moment (variance) cm4 = 0.0 # empirical 4th centered moment for i = 1:n @inbounds z = v[i] - m z2 = z * z cm2 += z2 cm4 += z2 * z2 end cm4 /= n cm2 /= n ...
function kurtosis(v::AbstractArray{<:Real}, m::Real) n = length(v) cm2 = 0.0 # empirical 2nd centered moment (variance) cm4 = 0.0 # empirical 4th centered moment for i = 1:n @inbounds z = v[i] - m z2 = z * z cm2 += z2 cm4 += z2 * z2 end cm4 /= n cm2 /= n ...
[ 328, 341 ]
function kurtosis(v::AbstractArray{<:Real}, m::Real) n = length(v) cm2 = 0.0 # empirical 2nd centered moment (variance) cm4 = 0.0 # empirical 4th centered moment for i = 1:n @inbounds z = v[i] - m z2 = z * z cm2 += z2 cm4 += z2 * z2 end cm4 /= n cm2 /= n ...
function kurtosis(v::AbstractArray{<:Real}, m::Real) n = length(v) cm2 = 0.0 # empirical 2nd centered moment (variance) cm4 = 0.0 # empirical 4th centered moment for i = 1:n @inbounds z = v[i] - m z2 = z * z cm2 += z2 cm4 += z2 * z2 end cm4 /= n cm2 /= n ...
kurtosis
328
341
src/moments.jl
#FILE: StatsBase.jl/src/scalarstats.jl ##CHUNK 1 elseif normalize m * mad_constant else m end end # Interquartile range """ iqr(x) Compute the interquartile range (IQR) of collection `x`, i.e. the 75th percentile minus the 25th percentile. """ iqr(x) = (q = quantile(x, [.25, .75]); q[2...
343
362
StatsBase.jl
264
function kurtosis(v::AbstractArray{<:Real}, wv::AbstractWeights, m::Real) n = length(v) length(wv) == n || throw(DimensionMismatch("Inconsistent array lengths.")) cm2 = 0.0 # empirical 2nd centered moment (variance) cm4 = 0.0 # empirical 4th centered moment @inbounds for i = 1 : n x_i = v...
function kurtosis(v::AbstractArray{<:Real}, wv::AbstractWeights, m::Real) n = length(v) length(wv) == n || throw(DimensionMismatch("Inconsistent array lengths.")) cm2 = 0.0 # empirical 2nd centered moment (variance) cm4 = 0.0 # empirical 4th centered moment @inbounds for i = 1 : n x_i = v...
[ 343, 362 ]
function kurtosis(v::AbstractArray{<:Real}, wv::AbstractWeights, m::Real) n = length(v) length(wv) == n || throw(DimensionMismatch("Inconsistent array lengths.")) cm2 = 0.0 # empirical 2nd centered moment (variance) cm4 = 0.0 # empirical 4th centered moment @inbounds for i = 1 : n x_i = v...
function kurtosis(v::AbstractArray{<:Real}, wv::AbstractWeights, m::Real) n = length(v) length(wv) == n || throw(DimensionMismatch("Inconsistent array lengths.")) cm2 = 0.0 # empirical 2nd centered moment (variance) cm4 = 0.0 # empirical 4th centered moment @inbounds for i = 1 : n x_i = v...
kurtosis
343
362
src/moments.jl
#FILE: StatsBase.jl/src/scalarstats.jl ##CHUNK 1 function sem(x::AbstractArray, weights::ProbabilityWeights; mean=nothing) if isempty(x) # Return the NaN of the type that we would get for a nonempty x return var(x, weights; mean=mean, corrected=true) / 0 else _mean = mean === nothing ? S...
381
400
StatsBase.jl
265
function cumulant(v::AbstractArray{<:Real}, krange::Union{Integer, AbstractRange{<:Integer}}, wv::AbstractWeights, m::Real=mean(v, wv)) if minimum(krange) <= 0 throw(ArgumentError("Cumulant orders must be strictly positive.")) end k = maximum(krange) cmoms = zeros(typeof(m), k)...
function cumulant(v::AbstractArray{<:Real}, krange::Union{Integer, AbstractRange{<:Integer}}, wv::AbstractWeights, m::Real=mean(v, wv)) if minimum(krange) <= 0 throw(ArgumentError("Cumulant orders must be strictly positive.")) end k = maximum(krange) cmoms = zeros(typeof(m), k)...
[ 381, 400 ]
function cumulant(v::AbstractArray{<:Real}, krange::Union{Integer, AbstractRange{<:Integer}}, wv::AbstractWeights, m::Real=mean(v, wv)) if minimum(krange) <= 0 throw(ArgumentError("Cumulant orders must be strictly positive.")) end k = maximum(krange) cmoms = zeros(typeof(m), k)...
function cumulant(v::AbstractArray{<:Real}, krange::Union{Integer, AbstractRange{<:Integer}}, wv::AbstractWeights, m::Real=mean(v, wv)) if minimum(krange) <= 0 throw(ArgumentError("Cumulant orders must be strictly positive.")) end k = maximum(krange) cmoms = zeros(typeof(m), k)...
cumulant
381
400
src/moments.jl
#CURRENT FILE: StatsBase.jl/src/moments.jl ##CHUNK 1 w_i = wv[i] z = x_i - m z2 = z * z z2w = z2 * w_i cm2 += z2w cm4 += z2w * z2 end sw = sum(wv) cm4 /= sw cm2 /= sw return (cm4 / (cm2 * cm2)) - 3.0 end kurtosis(v::AbstractArray{<:Real}) = kurtosis(v...
1
20
StatsBase.jl
266
function _pairwise!(::Val{:none}, f, dest::AbstractMatrix, x, y, symmetric::Bool) @inbounds for (i, xi) in enumerate(x), (j, yj) in enumerate(y) symmetric && i > j && continue # For performance, diagonal is special-cased if f === cor && eltype(dest) !== Union{} && i == j && xi === yj ...
function _pairwise!(::Val{:none}, f, dest::AbstractMatrix, x, y, symmetric::Bool) @inbounds for (i, xi) in enumerate(x), (j, yj) in enumerate(y) symmetric && i > j && continue # For performance, diagonal is special-cased if f === cor && eltype(dest) !== Union{} && i == j && xi === yj ...
[ 1, 20 ]
function _pairwise!(::Val{:none}, f, dest::AbstractMatrix, x, y, symmetric::Bool) @inbounds for (i, xi) in enumerate(x), (j, yj) in enumerate(y) symmetric && i > j && continue # For performance, diagonal is special-cased if f === cor && eltype(dest) !== Union{} && i == j && xi === yj ...
function _pairwise!(::Val{:none}, f, dest::AbstractMatrix, x, y, symmetric::Bool) @inbounds for (i, xi) in enumerate(x), (j, yj) in enumerate(y) symmetric && i > j && continue # For performance, diagonal is special-cased if f === cor && eltype(dest) !== Union{} && i == j && xi === yj ...
_pairwise!
1
20
src/pairwise.jl
#FILE: StatsBase.jl/src/rankcorr.jl ##CHUNK 1 n = length(x) n == length(y) || throw(DimensionMismatch("vectors must have same length")) (any(isnan, x) || any(isnan, y)) && return NaN return cor(tiedrank(x), tiedrank(y)) end function corspearman(X::AbstractMatrix{<:Real}, y::AbstractVector{<:Real}) ...
49
80
StatsBase.jl
267
function _pairwise!(::Val{:pairwise}, f, dest::AbstractMatrix, x, y, symmetric::Bool) check_vectors(x, y, :pairwise) @inbounds for (j, yj) in enumerate(y) ynminds = .!ismissing.(yj) @inbounds for (i, xi) in enumerate(x) symmetric && i > j && continue if xi === yj ...
function _pairwise!(::Val{:pairwise}, f, dest::AbstractMatrix, x, y, symmetric::Bool) check_vectors(x, y, :pairwise) @inbounds for (j, yj) in enumerate(y) ynminds = .!ismissing.(yj) @inbounds for (i, xi) in enumerate(x) symmetric && i > j && continue if xi === yj ...
[ 49, 80 ]
function _pairwise!(::Val{:pairwise}, f, dest::AbstractMatrix, x, y, symmetric::Bool) check_vectors(x, y, :pairwise) @inbounds for (j, yj) in enumerate(y) ynminds = .!ismissing.(yj) @inbounds for (i, xi) in enumerate(x) symmetric && i > j && continue if xi === yj ...
function _pairwise!(::Val{:pairwise}, f, dest::AbstractMatrix, x, y, symmetric::Bool) check_vectors(x, y, :pairwise) @inbounds for (j, yj) in enumerate(y) ynminds = .!ismissing.(yj) @inbounds for (i, xi) in enumerate(x) symmetric && i > j && continue if xi === yj ...
_pairwise!
49
80
src/pairwise.jl
#FILE: StatsBase.jl/src/rankcorr.jl ##CHUNK 1 n = length(x) n == length(y) || throw(DimensionMismatch("vectors must have same length")) (any(isnan, x) || any(isnan, y)) && return NaN return cor(tiedrank(x), tiedrank(y)) end function corspearman(X::AbstractMatrix{<:Real}, y::AbstractVector{<:Real}) ...
82
103
StatsBase.jl
268
function _pairwise!(::Val{:listwise}, f, dest::AbstractMatrix, x, y, symmetric::Bool) check_vectors(x, y, :listwise) nminds = .!ismissing.(first(x)) @inbounds for xi in Iterators.drop(x, 1) nminds .&= .!ismissing.(xi) end if x !== y @inbounds for yj in y nminds .&= .!ismi...
function _pairwise!(::Val{:listwise}, f, dest::AbstractMatrix, x, y, symmetric::Bool) check_vectors(x, y, :listwise) nminds = .!ismissing.(first(x)) @inbounds for xi in Iterators.drop(x, 1) nminds .&= .!ismissing.(xi) end if x !== y @inbounds for yj in y nminds .&= .!ismi...
[ 82, 103 ]
function _pairwise!(::Val{:listwise}, f, dest::AbstractMatrix, x, y, symmetric::Bool) check_vectors(x, y, :listwise) nminds = .!ismissing.(first(x)) @inbounds for xi in Iterators.drop(x, 1) nminds .&= .!ismissing.(xi) end if x !== y @inbounds for yj in y nminds .&= .!ismi...
function _pairwise!(::Val{:listwise}, f, dest::AbstractMatrix, x, y, symmetric::Bool) check_vectors(x, y, :listwise) nminds = .!ismissing.(first(x)) @inbounds for xi in Iterators.drop(x, 1) nminds .&= .!ismissing.(xi) end if x !== y @inbounds for yj in y nminds .&= .!ismi...
_pairwise!
82
103
src/pairwise.jl
#CURRENT FILE: StatsBase.jl/src/pairwise.jl ##CHUNK 1 function _pairwise!(f, dest::AbstractMatrix, x, y; symmetric::Bool=false, skipmissing::Symbol=:none) if !(skipmissing in (:none, :pairwise, :listwise)) throw(ArgumentError("skipmissing must be one of :none, :pairwise or :listwise"))...
105
122
StatsBase.jl
269
function _pairwise!(f, dest::AbstractMatrix, x, y; symmetric::Bool=false, skipmissing::Symbol=:none) if !(skipmissing in (:none, :pairwise, :listwise)) throw(ArgumentError("skipmissing must be one of :none, :pairwise or :listwise")) end x′ = x isa Union{AbstractArray, Tuple, Nam...
function _pairwise!(f, dest::AbstractMatrix, x, y; symmetric::Bool=false, skipmissing::Symbol=:none) if !(skipmissing in (:none, :pairwise, :listwise)) throw(ArgumentError("skipmissing must be one of :none, :pairwise or :listwise")) end x′ = x isa Union{AbstractArray, Tuple, Nam...
[ 105, 122 ]
function _pairwise!(f, dest::AbstractMatrix, x, y; symmetric::Bool=false, skipmissing::Symbol=:none) if !(skipmissing in (:none, :pairwise, :listwise)) throw(ArgumentError("skipmissing must be one of :none, :pairwise or :listwise")) end x′ = x isa Union{AbstractArray, Tuple, Nam...
function _pairwise!(f, dest::AbstractMatrix, x, y; symmetric::Bool=false, skipmissing::Symbol=:none) if !(skipmissing in (:none, :pairwise, :listwise)) throw(ArgumentError("skipmissing must be one of :none, :pairwise or :listwise")) end x′ = x isa Union{AbstractArray, Tuple, Nam...
_pairwise!
105
122
src/pairwise.jl
#FILE: StatsBase.jl/test/pairwise.jl ##CHUNK 1 length(xm), length(ym)), xm, ym, skipmissing=:something) # variable with only missings xm = [fill(missing, 10), rand(10)] ym = [rand(10), rand(10)] ...
16
26
StatsBase.jl
270
function _partialcor(x::AbstractVector, μx, y::AbstractVector, μy, Z::AbstractMatrix) p = size(Z, 2) p == 1 && return _partialcor(x, μx, y, μy, vec(Z)) z₀ = view(Z, :, 1) Zmz₀ = view(Z, :, 2:p) μz₀ = mean(z₀) rxz = _partialcor(x, μx, z₀, μz₀, Zmz₀) rzy = _partialcor(z₀, μz₀, y, μy, Zmz...
function _partialcor(x::AbstractVector, μx, y::AbstractVector, μy, Z::AbstractMatrix) p = size(Z, 2) p == 1 && return _partialcor(x, μx, y, μy, vec(Z)) z₀ = view(Z, :, 1) Zmz₀ = view(Z, :, 2:p) μz₀ = mean(z₀) rxz = _partialcor(x, μx, z₀, μz₀, Zmz₀) rzy = _partialcor(z₀, μz₀, y, μy, Zmz...
[ 16, 26 ]
function _partialcor(x::AbstractVector, μx, y::AbstractVector, μy, Z::AbstractMatrix) p = size(Z, 2) p == 1 && return _partialcor(x, μx, y, μy, vec(Z)) z₀ = view(Z, :, 1) Zmz₀ = view(Z, :, 2:p) μz₀ = mean(z₀) rxz = _partialcor(x, μx, z₀, μz₀, Zmz₀) rzy = _partialcor(z₀, μz₀, y, μy, Zmz...
function _partialcor(x::AbstractVector, μx, y::AbstractVector, μy, Z::AbstractMatrix) p = size(Z, 2) p == 1 && return _partialcor(x, μx, y, μy, vec(Z)) z₀ = view(Z, :, 1) Zmz₀ = view(Z, :, 2:p) μz₀ = mean(z₀) rxz = _partialcor(x, μx, z₀, μz₀, Zmz₀) rzy = _partialcor(z₀, μz₀, y, μy, Zmz...
_partialcor
16
26
src/partialcor.jl
#FILE: StatsBase.jl/src/signalcorr.jl ##CHUNK 1 ns = size(y, 2) m = length(lags) (size(y, 1) == lx && size(r) == (m, ns)) || throw(DimensionMismatch()) check_lags(lx, lags) T = typeof(zero(eltype(x)) / 1) zx::Vector{T} = demean ? x .- mean(x) : x S = typeof(zero(eltype(y)) / 1) zy = Vec...
28
62
StatsBase.jl
271
function _partialcor(x::AbstractVector, μx, y::AbstractVector, μy, z::AbstractVector) μz = mean(z) # Initialize all of the accumulators to 0 of the appropriate types Σxx = abs2(zero(eltype(x)) - zero(μx)) Σyy = abs2(zero(eltype(y)) - zero(μy)) Σzz = abs2(zero(eltype(z)) - zero(μz)) Σxy = zero(Σ...
function _partialcor(x::AbstractVector, μx, y::AbstractVector, μy, z::AbstractVector) μz = mean(z) # Initialize all of the accumulators to 0 of the appropriate types Σxx = abs2(zero(eltype(x)) - zero(μx)) Σyy = abs2(zero(eltype(y)) - zero(μy)) Σzz = abs2(zero(eltype(z)) - zero(μz)) Σxy = zero(Σ...
[ 28, 62 ]
function _partialcor(x::AbstractVector, μx, y::AbstractVector, μy, z::AbstractVector) μz = mean(z) # Initialize all of the accumulators to 0 of the appropriate types Σxx = abs2(zero(eltype(x)) - zero(μx)) Σyy = abs2(zero(eltype(y)) - zero(μy)) Σzz = abs2(zero(eltype(z)) - zero(μz)) Σxy = zero(Σ...
function _partialcor(x::AbstractVector, μx, y::AbstractVector, μy, z::AbstractVector) μz = mean(z) # Initialize all of the accumulators to 0 of the appropriate types Σxx = abs2(zero(eltype(x)) - zero(μx)) Σyy = abs2(zero(eltype(y)) - zero(μy)) Σzz = abs2(zero(eltype(z)) - zero(μz)) Σxy = zero(Σ...
_partialcor
28
62
src/partialcor.jl
#FILE: StatsBase.jl/src/signalcorr.jl ##CHUNK 1 ns = size(y, 2) m = length(lags) (size(y, 1) == lx && size(r) == (m, ns)) || throw(DimensionMismatch()) check_lags(lx, lags) T = typeof(zero(eltype(x)) / 1) zx::Vector{T} = demean ? x .- mean(x) : x S = typeof(zero(eltype(y)) / 1) zy = Vec...
27
44
StatsBase.jl
272
function corspearman(X::AbstractMatrix{<:Real}, y::AbstractVector{<:Real}) size(X, 1) == length(y) || throw(DimensionMismatch("X and y have inconsistent dimensions")) n = size(X, 2) C = Matrix{Float64}(I, n, 1) any(isnan, y) && return fill!(C, NaN) yrank = tiedrank(y) for j = 1:n ...
function corspearman(X::AbstractMatrix{<:Real}, y::AbstractVector{<:Real}) size(X, 1) == length(y) || throw(DimensionMismatch("X and y have inconsistent dimensions")) n = size(X, 2) C = Matrix{Float64}(I, n, 1) any(isnan, y) && return fill!(C, NaN) yrank = tiedrank(y) for j = 1:n ...
[ 27, 44 ]
function corspearman(X::AbstractMatrix{<:Real}, y::AbstractVector{<:Real}) size(X, 1) == length(y) || throw(DimensionMismatch("X and y have inconsistent dimensions")) n = size(X, 2) C = Matrix{Float64}(I, n, 1) any(isnan, y) && return fill!(C, NaN) yrank = tiedrank(y) for j = 1:n ...
function corspearman(X::AbstractMatrix{<:Real}, y::AbstractVector{<:Real}) size(X, 1) == length(y) || throw(DimensionMismatch("X and y have inconsistent dimensions")) n = size(X, 2) C = Matrix{Float64}(I, n, 1) any(isnan, y) && return fill!(C, NaN) yrank = tiedrank(y) for j = 1:n ...
corspearman
27
44
src/rankcorr.jl
#CURRENT FILE: StatsBase.jl/src/rankcorr.jl ##CHUNK 1 n = size(Y, 2) C = Matrix{Float64}(I, 1, n) any(isnan, x) && return fill!(C, NaN) xrank = tiedrank(x) for j = 1:n Yj = view(Y, :, j) if any(isnan, Yj) C[1,j] = NaN else Yjrank = tiedrank(Yj) ...
46
63
StatsBase.jl
273
function corspearman(x::AbstractVector{<:Real}, Y::AbstractMatrix{<:Real}) size(Y, 1) == length(x) || throw(DimensionMismatch("x and Y have inconsistent dimensions")) n = size(Y, 2) C = Matrix{Float64}(I, 1, n) any(isnan, x) && return fill!(C, NaN) xrank = tiedrank(x) for j = 1:n ...
function corspearman(x::AbstractVector{<:Real}, Y::AbstractMatrix{<:Real}) size(Y, 1) == length(x) || throw(DimensionMismatch("x and Y have inconsistent dimensions")) n = size(Y, 2) C = Matrix{Float64}(I, 1, n) any(isnan, x) && return fill!(C, NaN) xrank = tiedrank(x) for j = 1:n ...
[ 46, 63 ]
function corspearman(x::AbstractVector{<:Real}, Y::AbstractMatrix{<:Real}) size(Y, 1) == length(x) || throw(DimensionMismatch("x and Y have inconsistent dimensions")) n = size(Y, 2) C = Matrix{Float64}(I, 1, n) any(isnan, x) && return fill!(C, NaN) xrank = tiedrank(x) for j = 1:n ...
function corspearman(x::AbstractVector{<:Real}, Y::AbstractMatrix{<:Real}) size(Y, 1) == length(x) || throw(DimensionMismatch("x and Y have inconsistent dimensions")) n = size(Y, 2) C = Matrix{Float64}(I, 1, n) any(isnan, x) && return fill!(C, NaN) xrank = tiedrank(x) for j = 1:n ...
corspearman
46
63
src/rankcorr.jl
#CURRENT FILE: StatsBase.jl/src/rankcorr.jl ##CHUNK 1 C = Matrix{Float64}(I, n, 1) any(isnan, y) && return fill!(C, NaN) yrank = tiedrank(y) for j = 1:n Xj = view(X, :, j) if any(isnan, Xj) C[j,1] = NaN else Xjrank = tiedrank(Xj) C[j,1] = cor(X...
65
90
StatsBase.jl
274
function corspearman(X::AbstractMatrix{<:Real}) n = size(X, 2) C = Matrix{Float64}(I, n, n) anynan = Vector{Bool}(undef, n) for j = 1:n Xj = view(X, :, j) anynan[j] = any(isnan, Xj) if anynan[j] C[:,j] .= NaN C[j,:] .= NaN C[j,j] = 1 ...
function corspearman(X::AbstractMatrix{<:Real}) n = size(X, 2) C = Matrix{Float64}(I, n, n) anynan = Vector{Bool}(undef, n) for j = 1:n Xj = view(X, :, j) anynan[j] = any(isnan, Xj) if anynan[j] C[:,j] .= NaN C[j,:] .= NaN C[j,j] = 1 ...
[ 65, 90 ]
function corspearman(X::AbstractMatrix{<:Real}) n = size(X, 2) C = Matrix{Float64}(I, n, n) anynan = Vector{Bool}(undef, n) for j = 1:n Xj = view(X, :, j) anynan[j] = any(isnan, Xj) if anynan[j] C[:,j] .= NaN C[j,:] .= NaN C[j,j] = 1 ...
function corspearman(X::AbstractMatrix{<:Real}) n = size(X, 2) C = Matrix{Float64}(I, n, n) anynan = Vector{Bool}(undef, n) for j = 1:n Xj = view(X, :, j) anynan[j] = any(isnan, Xj) if anynan[j] C[:,j] .= NaN C[j,:] .= NaN C[j,j] = 1 ...
corspearman
65
90
src/rankcorr.jl
#FILE: StatsBase.jl/src/cov.jl ##CHUNK 1 """ function cov2cor!(C::AbstractMatrix, s::AbstractArray = map(sqrt, view(C, diagind(C)))) Base.require_one_based_indexing(C, s) n = length(s) size(C) == (n, n) || throw(DimensionMismatch("inconsistent dimensions")) for j = 1:n sj = s[j] for i = ...
92
116
StatsBase.jl
275
function corspearman(X::AbstractMatrix{<:Real}, Y::AbstractMatrix{<:Real}) size(X, 1) == size(Y, 1) || throw(ArgumentError("number of rows in each array must match")) nr = size(X, 2) nc = size(Y, 2) C = Matrix{Float64}(undef, nr, nc) for j = 1:nr Xj = view(X, :, j) if any(isn...
function corspearman(X::AbstractMatrix{<:Real}, Y::AbstractMatrix{<:Real}) size(X, 1) == size(Y, 1) || throw(ArgumentError("number of rows in each array must match")) nr = size(X, 2) nc = size(Y, 2) C = Matrix{Float64}(undef, nr, nc) for j = 1:nr Xj = view(X, :, j) if any(isn...
[ 92, 116 ]
function corspearman(X::AbstractMatrix{<:Real}, Y::AbstractMatrix{<:Real}) size(X, 1) == size(Y, 1) || throw(ArgumentError("number of rows in each array must match")) nr = size(X, 2) nc = size(Y, 2) C = Matrix{Float64}(undef, nr, nc) for j = 1:nr Xj = view(X, :, j) if any(isn...
function corspearman(X::AbstractMatrix{<:Real}, Y::AbstractMatrix{<:Real}) size(X, 1) == size(Y, 1) || throw(ArgumentError("number of rows in each array must match")) nr = size(X, 2) nc = size(Y, 2) C = Matrix{Float64}(undef, nr, nc) for j = 1:nr Xj = view(X, :, j) if any(isn...
corspearman
92
116
src/rankcorr.jl
#FILE: StatsBase.jl/src/cov.jl ##CHUNK 1 """ function cov2cor!(C::AbstractMatrix, s::AbstractArray = map(sqrt, view(C, diagind(C)))) Base.require_one_based_indexing(C, s) n = length(s) size(C) == (n, n) || throw(DimensionMismatch("inconsistent dimensions")) for j = 1:n sj = s[j] for i = ...
189
200
StatsBase.jl
276
function corkendall(X::AbstractMatrix{<:Real}) n = size(X, 2) C = Matrix{Float64}(I, n, n) for j = 2:n permx = sortperm(X[:,j]) for i = 1:j - 1 C[j,i] = corkendall!(X[:,j], X[:,i], permx) C[i,j] = C[j,i] end end return C end
function corkendall(X::AbstractMatrix{<:Real}) n = size(X, 2) C = Matrix{Float64}(I, n, n) for j = 2:n permx = sortperm(X[:,j]) for i = 1:j - 1 C[j,i] = corkendall!(X[:,j], X[:,i], permx) C[i,j] = C[j,i] end end return C end
[ 189, 200 ]
function corkendall(X::AbstractMatrix{<:Real}) n = size(X, 2) C = Matrix{Float64}(I, n, n) for j = 2:n permx = sortperm(X[:,j]) for i = 1:j - 1 C[j,i] = corkendall!(X[:,j], X[:,i], permx) C[i,j] = C[j,i] end end return C end
function corkendall(X::AbstractMatrix{<:Real}) n = size(X, 2) C = Matrix{Float64}(I, n, n) for j = 2:n permx = sortperm(X[:,j]) for i = 1:j - 1 C[j,i] = corkendall!(X[:,j], X[:,i], permx) C[i,j] = C[j,i] end end return C end
corkendall
189
200
src/rankcorr.jl
#FILE: StatsBase.jl/test/rankcorr.jl ##CHUNK 1 # AbstractMatrix{<:Real} @test corkendall(X) ≈ [c11 c12; c12 c22] @test c11 == 1.0 @test c22 == 1.0 @test c12 == 3/sqrt(20) # Finished testing for overflow, so redefine n for speedier tests n = 100 @test corkendall(repeat(X, n), repeat(X, n)) ≈ [c11 c12; c12 c22] @te...
202
213
StatsBase.jl
277
function corkendall(X::AbstractMatrix{<:Real}, Y::AbstractMatrix{<:Real}) nr = size(X, 2) nc = size(Y, 2) C = Matrix{Float64}(undef, nr, nc) for j = 1:nr permx = sortperm(X[:,j]) for i = 1:nc C[j,i] = corkendall!(X[:,j], Y[:,i], permx) end end return C end
function corkendall(X::AbstractMatrix{<:Real}, Y::AbstractMatrix{<:Real}) nr = size(X, 2) nc = size(Y, 2) C = Matrix{Float64}(undef, nr, nc) for j = 1:nr permx = sortperm(X[:,j]) for i = 1:nc C[j,i] = corkendall!(X[:,j], Y[:,i], permx) end end return C end
[ 202, 213 ]
function corkendall(X::AbstractMatrix{<:Real}, Y::AbstractMatrix{<:Real}) nr = size(X, 2) nc = size(Y, 2) C = Matrix{Float64}(undef, nr, nc) for j = 1:nr permx = sortperm(X[:,j]) for i = 1:nc C[j,i] = corkendall!(X[:,j], Y[:,i], permx) end end return C end
function corkendall(X::AbstractMatrix{<:Real}, Y::AbstractMatrix{<:Real}) nr = size(X, 2) nc = size(Y, 2) C = Matrix{Float64}(undef, nr, nc) for j = 1:nr permx = sortperm(X[:,j]) for i = 1:nc C[j,i] = corkendall!(X[:,j], Y[:,i], permx) end end return C end
corkendall
202
213
src/rankcorr.jl
#FILE: StatsBase.jl/test/rankcorr.jl ##CHUNK 1 # AbstractMatrix{<:Real} @test corkendall(X) ≈ [c11 c12; c12 c22] @test c11 == 1.0 @test c22 == 1.0 @test c12 == 3/sqrt(20) # Finished testing for overflow, so redefine n for speedier tests n = 100 @test corkendall(repeat(X, n), repeat(X, n)) ≈ [c11 c12; c12 c22] @te...
254
293
StatsBase.jl
278
function merge_sort!(v::AbstractVector, lo::Integer, hi::Integer, t::AbstractVector=similar(v, 0)) # Use of widen below prevents possible overflow errors when # length(v) exceeds 2^16 (32 bit) or 2^32 (64 bit) nswaps = widen(0) @inbounds if lo < hi hi - lo <= SMALL_THRESHOLD && return insertion_...
function merge_sort!(v::AbstractVector, lo::Integer, hi::Integer, t::AbstractVector=similar(v, 0)) # Use of widen below prevents possible overflow errors when # length(v) exceeds 2^16 (32 bit) or 2^32 (64 bit) nswaps = widen(0) @inbounds if lo < hi hi - lo <= SMALL_THRESHOLD && return insertion_...
[ 254, 293 ]
function merge_sort!(v::AbstractVector, lo::Integer, hi::Integer, t::AbstractVector=similar(v, 0)) # Use of widen below prevents possible overflow errors when # length(v) exceeds 2^16 (32 bit) or 2^32 (64 bit) nswaps = widen(0) @inbounds if lo < hi hi - lo <= SMALL_THRESHOLD && return insertion_...
function merge_sort!(v::AbstractVector, lo::Integer, hi::Integer, t::AbstractVector=similar(v, 0)) # Use of widen below prevents possible overflow errors when # length(v) exceeds 2^16 (32 bit) or 2^32 (64 bit) nswaps = widen(0) @inbounds if lo < hi hi - lo <= SMALL_THRESHOLD && return insertion_...
merge_sort!
254
293
src/rankcorr.jl
#FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 # set threshold @inbounds threshold = pq[1].first @inbounds for i in s+1:n w = wv.values[i] w < 0 && error("Negative weight found in weight vector at index $i") w > 0 || continue key = w/randexp(rng) # if key is larger t...
306
324
StatsBase.jl
279
function insertion_sort!(v::AbstractVector, lo::Integer, hi::Integer) if lo == hi return widen(0) end nswaps = widen(0) @inbounds for i = lo + 1:hi j = i x = v[i] while j > lo if x < v[j - 1] nswaps += 1 v[j] = v[j - 1] j -=...
function insertion_sort!(v::AbstractVector, lo::Integer, hi::Integer) if lo == hi return widen(0) end nswaps = widen(0) @inbounds for i = lo + 1:hi j = i x = v[i] while j > lo if x < v[j - 1] nswaps += 1 v[j] = v[j - 1] j -=...
[ 306, 324 ]
function insertion_sort!(v::AbstractVector, lo::Integer, hi::Integer) if lo == hi return widen(0) end nswaps = widen(0) @inbounds for i = lo + 1:hi j = i x = v[i] while j > lo if x < v[j - 1] nswaps += 1 v[j] = v[j - 1] j -=...
function insertion_sort!(v::AbstractVector, lo::Integer, hi::Integer) if lo == hi return widen(0) end nswaps = widen(0) @inbounds for i = lo + 1:hi j = i x = v[i] while j > lo if x < v[j - 1] nswaps += 1 v[j] = v[j - 1] j -=...
insertion_sort!
306
324
src/rankcorr.jl
#FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 k = length(x) k > 0 || return x # initialize priority queue pq = Vector{Pair{Float64,Int}}(undef, k) i = 0 s = 0 @inbounds for _s in 1:n s = _s w = wv.values[s] w < 0 && error("Negative weight found in weight vector at in...
60
80
StatsBase.jl
280
function _competerank!(rks::AbstractArray, x::AbstractArray, p::AbstractArray{<:Integer}) n = _check_randparams(rks, x, p) @inbounds if n > 0 p1 = p[1] v = x[p1] rks[p1] = k = 1 for i in 2:n pi = p[i] xi = x[pi] if xi != v v =...
function _competerank!(rks::AbstractArray, x::AbstractArray, p::AbstractArray{<:Integer}) n = _check_randparams(rks, x, p) @inbounds if n > 0 p1 = p[1] v = x[p1] rks[p1] = k = 1 for i in 2:n pi = p[i] xi = x[pi] if xi != v v =...
[ 60, 80 ]
function _competerank!(rks::AbstractArray, x::AbstractArray, p::AbstractArray{<:Integer}) n = _check_randparams(rks, x, p) @inbounds if n > 0 p1 = p[1] v = x[p1] rks[p1] = k = 1 for i in 2:n pi = p[i] xi = x[pi] if xi != v v =...
function _competerank!(rks::AbstractArray, x::AbstractArray, p::AbstractArray{<:Integer}) n = _check_randparams(rks, x, p) @inbounds if n > 0 p1 = p[1] v = x[p1] rks[p1] = k = 1 for i in 2:n pi = p[i] xi = x[pi] if xi != v v =...
_competerank!
60
80
src/ranking.jl
#FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 k <= n || error("length(x) should not exceed length(a)") inds = Vector{Int}(undef, n) for i = 1:n @inbounds inds[i] = i end @inbounds for i = 1:k j = rand(rng, i:n) t = inds[j] inds[j] = inds[i] inds[i] = t ...
97
117
StatsBase.jl
281
function _denserank!(rks::AbstractArray, x::AbstractArray, p::AbstractArray{<:Integer}) n = _check_randparams(rks, x, p) @inbounds if n > 0 p1 = p[1] v = x[p1] rks[p1] = k = 1 for i in 2:n pi = p[i] xi = x[pi] if xi != v v = x...
function _denserank!(rks::AbstractArray, x::AbstractArray, p::AbstractArray{<:Integer}) n = _check_randparams(rks, x, p) @inbounds if n > 0 p1 = p[1] v = x[p1] rks[p1] = k = 1 for i in 2:n pi = p[i] xi = x[pi] if xi != v v = x...
[ 97, 117 ]
function _denserank!(rks::AbstractArray, x::AbstractArray, p::AbstractArray{<:Integer}) n = _check_randparams(rks, x, p) @inbounds if n > 0 p1 = p[1] v = x[p1] rks[p1] = k = 1 for i in 2:n pi = p[i] xi = x[pi] if xi != v v = x...
function _denserank!(rks::AbstractArray, x::AbstractArray, p::AbstractArray{<:Integer}) n = _check_randparams(rks, x, p) @inbounds if n > 0 p1 = p[1] v = x[p1] rks[p1] = k = 1 for i in 2:n pi = p[i] xi = x[pi] if xi != v v = x...
_denserank!
97
117
src/ranking.jl
#FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 k <= n || error("length(x) should not exceed length(a)") inds = Vector{Int}(undef, n) for i = 1:n @inbounds inds[i] = i end @inbounds for i = 1:k j = rand(rng, i:n) t = inds[j] inds[j] = inds[i] inds[i] = t ...
134
163
StatsBase.jl
282
function _tiedrank!(rks::AbstractArray, x::AbstractArray, p::AbstractArray{<:Integer}) n = _check_randparams(rks, x, p) @inbounds if n > 0 v = x[p[1]] s = 1 # starting index of current range for e in 2:n # e is pass-by-end index of current range cx = x[p[e]] if...
function _tiedrank!(rks::AbstractArray, x::AbstractArray, p::AbstractArray{<:Integer}) n = _check_randparams(rks, x, p) @inbounds if n > 0 v = x[p[1]] s = 1 # starting index of current range for e in 2:n # e is pass-by-end index of current range cx = x[p[e]] if...
[ 134, 163 ]
function _tiedrank!(rks::AbstractArray, x::AbstractArray, p::AbstractArray{<:Integer}) n = _check_randparams(rks, x, p) @inbounds if n > 0 v = x[p[1]] s = 1 # starting index of current range for e in 2:n # e is pass-by-end index of current range cx = x[p[e]] if...
function _tiedrank!(rks::AbstractArray, x::AbstractArray, p::AbstractArray{<:Integer}) n = _check_randparams(rks, x, p) @inbounds if n > 0 v = x[p[1]] s = 1 # starting index of current range for e in 2:n # e is pass-by-end index of current range cx = x[p[e]] if...
_tiedrank!
134
163
src/ranking.jl
#FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 # set threshold @inbounds threshold = pq[1].first @inbounds for i in s+1:n w = wv.values[i] w < 0 && error("Negative weight found in weight vector at index $i") w > 0 || continue key = w/randexp(rng) # if key is larger t...
53
78
StatsBase.jl
283
function cronbachalpha(covmatrix::AbstractMatrix{<:Real}) if !isposdef(covmatrix) throw(ArgumentError("Covariance matrix must be positive definite. " * "Maybe you passed the data matrix instead of its covariance matrix? " * "If so, call `cronbachalpha(...
function cronbachalpha(covmatrix::AbstractMatrix{<:Real}) if !isposdef(covmatrix) throw(ArgumentError("Covariance matrix must be positive definite. " * "Maybe you passed the data matrix instead of its covariance matrix? " * "If so, call `cronbachalpha(...
[ 53, 78 ]
function cronbachalpha(covmatrix::AbstractMatrix{<:Real}) if !isposdef(covmatrix) throw(ArgumentError("Covariance matrix must be positive definite. " * "Maybe you passed the data matrix instead of its covariance matrix? " * "If so, call `cronbachalpha(...
function cronbachalpha(covmatrix::AbstractMatrix{<:Real}) if !isposdef(covmatrix) throw(ArgumentError("Covariance matrix must be positive definite. " * "Maybe you passed the data matrix instead of its covariance matrix? " * "If so, call `cronbachalpha(...
cronbachalpha
53
78
src/reliability.jl
#FILE: StatsBase.jl/src/signalcorr.jl ##CHUNK 1 z::Vector{T} = demean ? x .- mean(x) : x for k = 1 : m # foreach lag value r[k] = _autodot(z, lx, lags[k]) / lx end return r end function autocov!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool...
123
136
StatsBase.jl
284
function trimvar(x::AbstractVector; prop::Real=0.0, count::Integer=0) n = length(x) n > 0 || throw(ArgumentError("x can not be empty.")) if count == 0 0 <= prop < 0.5 || throw(ArgumentError("prop must satisfy 0 ≤ prop < 0.5.")) count = floor(Int, n * prop) else 0 <= count < n/2 ...
function trimvar(x::AbstractVector; prop::Real=0.0, count::Integer=0) n = length(x) n > 0 || throw(ArgumentError("x can not be empty.")) if count == 0 0 <= prop < 0.5 || throw(ArgumentError("prop must satisfy 0 ≤ prop < 0.5.")) count = floor(Int, n * prop) else 0 <= count < n/2 ...
[ 123, 136 ]
function trimvar(x::AbstractVector; prop::Real=0.0, count::Integer=0) n = length(x) n > 0 || throw(ArgumentError("x can not be empty.")) if count == 0 0 <= prop < 0.5 || throw(ArgumentError("prop must satisfy 0 ≤ prop < 0.5.")) count = floor(Int, n * prop) else 0 <= count < n/2 ...
function trimvar(x::AbstractVector; prop::Real=0.0, count::Integer=0) n = length(x) n > 0 || throw(ArgumentError("x can not be empty.")) if count == 0 0 <= prop < 0.5 || throw(ArgumentError("prop must satisfy 0 ≤ prop < 0.5.")) count = floor(Int, n * prop) else 0 <= count < n/2 ...
trimvar
123
136
src/robust.jl
#FILE: StatsBase.jl/test/counts.jl ##CHUNK 1 @test addcounts!(fill(0.0, 1, 5), reshape(x, 10, 50, 10), 1:5, w) ≈ c0 # Perhaps this should not be allowed @test x == x0 @test w == w0 end @testset "2D integer counts" begin x = rand(1:4, n) y = rand(1:5, n) w = weights(rand(n)) x0 = deepcopy(...
14
29
StatsBase.jl
285
function direct_sample!(rng::AbstractRNG, a::UnitRange, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) s = Sampler(rng, 1:length(a)) b = a[1] - 1 if b == 0 for i = 1:length(x) @inbounds x[i] = rand(rng, s)...
function direct_sample!(rng::AbstractRNG, a::UnitRange, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) s = Sampler(rng, 1:length(a)) b = a[1] - 1 if b == 0 for i = 1:length(x) @inbounds x[i] = rand(rng, s)...
[ 14, 29 ]
function direct_sample!(rng::AbstractRNG, a::UnitRange, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) s = Sampler(rng, 1:length(a)) b = a[1] - 1 if b == 0 for i = 1:length(x) @inbounds x[i] = rand(rng, s)...
function direct_sample!(rng::AbstractRNG, a::UnitRange, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) s = Sampler(rng, 1:length(a)) b = a[1] - 1 if b == 0 for i = 1:length(x) @inbounds x[i] = rand(rng, s)...
direct_sample!
14
29
src/sampling.jl
#CURRENT FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) n = length(a) k = length(x) ...
40
50
StatsBase.jl
286
function direct_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) s = Sampl...
function direct_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) s = Sampl...
[ 40, 50 ]
function direct_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) s = Sampl...
function direct_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) s = Sampl...
direct_sample!
40
50
src/sampling.jl
#CURRENT FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 """ function knuths_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray; initshuffle::Bool=true) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x...
65
87
StatsBase.jl
287
function sample_ordered!(sampler!, rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) ...
function sample_ordered!(sampler!, rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) ...
[ 65, 87 ]
function sample_ordered!(sampler!, rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) ...
function sample_ordered!(sampler!, rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) ...
sample_ordered!
65
87
src/sampling.jl
#FILE: StatsBase.jl/src/pairwise.jl ##CHUNK 1 [view(yi, nminds′) for yi in y], symmetric) end function _pairwise!(f, dest::AbstractMatrix, x, y; symmetric::Bool=false, skipmissing::Symbol=:none) if !(skipmissing in (:none, :pairwise, :listwise)) ...
143
176
StatsBase.jl
288
function knuths_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray; initshuffle::Bool=true) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not ...
function knuths_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray; initshuffle::Bool=true) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not ...
[ 143, 176 ]
function knuths_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray; initshuffle::Bool=true) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not ...
function knuths_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray; initshuffle::Bool=true) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not ...
knuths_sample!
143
176
src/sampling.jl
#CURRENT FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 """ direct_sample!([rng], a::AbstractArray, x::AbstractArray) Direct sampling: for each `j` in `1:k`, randomly pick `i` from `1:n`, and set `x[j] = a[i]`, with `n=length(a)` and `k=length(x)`. This algorithm consumes `k` random numbers. """ function direct_sa...
204
226
StatsBase.jl
289
function fisher_yates_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) n =...
function fisher_yates_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) n =...
[ 204, 226 ]
function fisher_yates_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) n =...
function fisher_yates_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) n =...
fisher_yates_sample!
204
226
src/sampling.jl
#CURRENT FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 """ direct_sample!([rng], a::AbstractArray, x::AbstractArray) Direct sampling: for each `j` in `1:k`, randomly pick `i` from `1:n`, and set `x[j] = a[i]`, with `n=length(a)` and `k=length(x)`. This algorithm consumes `k` random numbers. """ function direct_sa...
244
272
StatsBase.jl
290
function self_avoid_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) n = l...
function self_avoid_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) n = l...
[ 244, 272 ]
function self_avoid_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) n = l...
function self_avoid_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) n = l...
self_avoid_sample!
244
272
src/sampling.jl
#CURRENT FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 """ direct_sample!([rng], a::AbstractArray, x::AbstractArray) Direct sampling: for each `j` in `1:k`, randomly pick `i` from `1:n`, and set `x[j] = a[i]`, with `n=length(a)` and `k=length(x)`. This algorithm consumes `k` random numbers. """ function direct_sa...
286
315
StatsBase.jl
291
function seqsample_a!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) n = length(...
function seqsample_a!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) n = length(...
[ 286, 315 ]
function seqsample_a!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) n = length(...
function seqsample_a!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) n = length(...
seqsample_a!
286
315
src/sampling.jl
#CURRENT FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 However, if `k` is large and approaches ``n``, the rejection rate would increase drastically, resulting in poorer performance. """ function self_avoid_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || th...
328
361
StatsBase.jl
292
function seqsample_c!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) n = length(...
function seqsample_c!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) n = length(...
[ 328, 361 ]
function seqsample_c!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) n = length(...
function seqsample_c!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) n = length(...
seqsample_c!
328
361
src/sampling.jl
#CURRENT FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 However, if `k` is large and approaches ``n``, the rejection rate would increase drastically, resulting in poorer performance. """ function self_avoid_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray) 1 == firstindex(a) == firstindex(x) || th...
488
525
StatsBase.jl
293
function sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray; replace::Bool=true, ordered::Bool=false) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) n = length(a) k = length(x) k == 0 && return x if replace # w...
function sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray; replace::Bool=true, ordered::Bool=false) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) n = length(a) k = length(x) k == 0 && return x if replace # w...
[ 488, 525 ]
function sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray; replace::Bool=true, ordered::Bool=false) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) n = length(a) k = length(x) k == 0 && return x if replace # w...
function sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray; replace::Bool=true, ordered::Bool=false) 1 == firstindex(a) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) n = length(a) k = length(x) k == 0 && return x if replace # w...
sample!
488
525
src/sampling.jl
#CURRENT FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 if replace if ordered sample_ordered!(rng, a, wv, x) do rng, a, wv, x sample!(rng, a, wv, x; replace=true, ordered=false) end else if n < 40 direct_sample!(rng, a, wv, x) ...
586
600
StatsBase.jl
294
function sample(rng::AbstractRNG, wv::AbstractWeights) 1 == firstindex(wv) || throw(ArgumentError("non 1-based arrays are not supported")) wsum = sum(wv) isfinite(wsum) || throw(ArgumentError("only finite weights are supported")) t = rand(rng) * wsum n = length(wv) i = 1 cw = wv[1] ...
function sample(rng::AbstractRNG, wv::AbstractWeights) 1 == firstindex(wv) || throw(ArgumentError("non 1-based arrays are not supported")) wsum = sum(wv) isfinite(wsum) || throw(ArgumentError("only finite weights are supported")) t = rand(rng) * wsum n = length(wv) i = 1 cw = wv[1] ...
[ 586, 600 ]
function sample(rng::AbstractRNG, wv::AbstractWeights) 1 == firstindex(wv) || throw(ArgumentError("non 1-based arrays are not supported")) wsum = sum(wv) isfinite(wsum) || throw(ArgumentError("only finite weights are supported")) t = rand(rng) * wsum n = length(wv) i = 1 cw = wv[1] ...
function sample(rng::AbstractRNG, wv::AbstractWeights) 1 == firstindex(wv) || throw(ArgumentError("non 1-based arrays are not supported")) wsum = sum(wv) isfinite(wsum) || throw(ArgumentError("only finite weights are supported")) t = rand(rng) * wsum n = length(wv) i = 1 cw = wv[1] ...
sample
586
600
src/sampling.jl
#FILE: StatsBase.jl/src/weights.jl ##CHUNK 1 @propagate_inbounds function Base.getindex(wv::W, i::AbstractArray) where W <: AbstractWeights @boundscheck checkbounds(wv, i) @inbounds v = wv.values[i] W(v, sum(v)) end Base.getindex(wv::W, ::Colon) where {W <: AbstractWeights} = W(copy(wv.values), sum(wv)) ...
618
632
StatsBase.jl
295
function direct_sample!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) Base.mightalias(x, wv) && throw(ArgumentError("output array x must n...
function direct_sample!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) Base.mightalias(x, wv) && throw(ArgumentError("output array x must n...
[ 618, 632 ]
function direct_sample!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) Base.mightalias(x, wv) && throw(ArgumentError("output array x must n...
function direct_sample!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) Base.mightalias(x, wv) && throw(ArgumentError("output array x must n...
direct_sample!
618
632
src/sampling.jl
#CURRENT FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 when the corresponding sample is picked. Noting `k=length(x)` and `n=length(a)`, this algorithm consumes ``O(k)`` random numbers, and has overall time complexity ``O(n k)``. """ function naive_wsample_norep!(rng::AbstractRNG, a::AbstractArray, ...
649
666
StatsBase.jl
296
function alias_sample!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) 1 == firstindex(a) == firstindex(wv) || throw(ArgumentError("non 1-based arrays are not suppo...
function alias_sample!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) 1 == firstindex(a) == firstindex(wv) || throw(ArgumentError("non 1-based arrays are not suppo...
[ 649, 666 ]
function alias_sample!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) 1 == firstindex(a) == firstindex(wv) || throw(ArgumentError("non 1-based arrays are not suppo...
function alias_sample!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) 1 == firstindex(a) == firstindex(wv) || throw(ArgumentError("non 1-based arrays are not suppo...
alias_sample!
649
666
src/sampling.jl
#FILE: StatsBase.jl/src/deprecates.jl ##CHUNK 1 a::AbstractVector{Float64}, alias::AbstractVector{Int}) Base.depwarn("make_alias_table! is both internal and deprecated, use AliasTables.jl instead", :make_alias_table!) # Arguments: # # w [in]: ...
681
711
StatsBase.jl
297
function naive_wsample_norep!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) Base.mightalias(x, wv) && throw(ArgumentError("output ar...
function naive_wsample_norep!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) Base.mightalias(x, wv) && throw(ArgumentError("output ar...
[ 681, 711 ]
function naive_wsample_norep!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) Base.mightalias(x, wv) && throw(ArgumentError("output ar...
function naive_wsample_norep!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) Base.mightalias(x, wv) && throw(ArgumentError("output ar...
naive_wsample_norep!
681
711
src/sampling.jl
#CURRENT FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) Base.mightalias(x, wv) && throw(ArgumentError("output array x must not share memory with weights array wv")) 1 == firstindex(a) == fi...
728
753
StatsBase.jl
298
function efraimidis_a_wsample_norep!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) Base.mightalias(x, wv) && throw(ArgumentEr...
function efraimidis_a_wsample_norep!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) Base.mightalias(x, wv) && throw(ArgumentEr...
[ 728, 753 ]
function efraimidis_a_wsample_norep!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) Base.mightalias(x, wv) && throw(ArgumentEr...
function efraimidis_a_wsample_norep!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) Base.mightalias(x, wv) && throw(ArgumentEr...
efraimidis_a_wsample_norep!
728
753
src/sampling.jl
#CURRENT FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 throw(ArgumentError("output array x must not share memory with input array a")) Base.mightalias(x, wv) && throw(ArgumentError("output array x must not share memory with weights array wv")) 1 == firstindex(a) == firstindex(wv) == firstindex(x)...
770
826
StatsBase.jl
299
function efraimidis_ares_wsample_norep!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) Base.mightalias(x, wv) && throw(Argu...
function efraimidis_ares_wsample_norep!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) Base.mightalias(x, wv) && throw(Argu...
[ 770, 826 ]
function efraimidis_ares_wsample_norep!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) Base.mightalias(x, wv) && throw(Argu...
function efraimidis_ares_wsample_norep!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray) Base.mightalias(a, x) && throw(ArgumentError("output array x must not share memory with input array a")) Base.mightalias(x, wv) && throw(Argu...
efraimidis_ares_wsample_norep!
770
826
src/sampling.jl
#CURRENT FILE: StatsBase.jl/src/sampling.jl ##CHUNK 1 Base.mightalias(x, wv) && throw(ArgumentError("output array x must not share memory with weights array wv")) 1 == firstindex(a) == firstindex(wv) == firstindex(x) || throw(ArgumentError("non 1-based arrays are not supported")) isfinite(su...