Skip to content

Commit

Permalink
tensor collapse
Browse files Browse the repository at this point in the history
  • Loading branch information
tinybike committed Mar 18, 2015
1 parent 4acd2f6 commit 1464fc0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/JointMoments.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module JointMoments
coskewness,
cokurtosis,
center,
coalesce,
collapse,
std,
_cov,
outer
Expand Down
8 changes: 4 additions & 4 deletions src/tensors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ function center{T<:Real}(data::Matrix{T},
(cntr .* w, num_samples, num_signals)
end

# Internal sum over all tensor fibers (except first/rows)
function coalesce{T<:Real}(data::Matrix{T},
# Collapse tensor to vector: internal sum over fibers
function collapse{T<:Real}(data::Matrix{T},
order::Int;
standardize::Bool=false,
bias::Int=0)
Expand All @@ -87,8 +87,8 @@ function coalesce{T<:Real}(data::Matrix{T},
vec(sum(cntr, 2)'.^(order - 1) * cntr) / (num_samples - bias)
end

# Weighted coalescence
function coalesce{T<:Real}(data::Matrix{T},
# Weighted tensor collapse
function collapse{T<:Real}(data::Matrix{T},
w::Vector{T},
order::Int;
standardize::Bool=false,
Expand Down
10 changes: 5 additions & 5 deletions test/tensors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ ltm = _cov(data, bias=0, dense=false)
for d in (data, bigdata)
covmat = _cov(d; bias=0)
summed = sum(covmat, 2)[:]
@test all(summed - coalesce(d, 2; bias=0) .< ε)
@test all(summed - collapse(d, 2; bias=0) .< ε)

tensor = coskew(d; standardize=true, bias=0)
summed = sum(sum(tensor, 3), 2)[:]
@test all(summed - coalesce(d, 3; standardize=true, bias=0) .< ε)
@test all(summed - collapse(d, 3; standardize=true, bias=0) .< ε)

tensor = cokurt(d; standardize=true, bias=0)
summed = sum(sum(sum(tensor, 4), 3), 2)[:]
@test all(summed - coalesce(d, 4; standardize=true, bias=0) .< ε)
@test all(summed - collapse(d, 4; standardize=true, bias=0) .< ε)
end

weighted_center = [ 0.0622965 0.0422869 0.133849
Expand Down Expand Up @@ -66,9 +66,9 @@ weighted_center = [ 0.0622965 0.0422869 0.133849
-0.0503171 0.0137864 -0.0511462
-0.0149529 0.00510296 -0.00896664 ]

weighted_coalesce = [ 0.000210328
weighted_collapse = [ 0.000210328
0.000163799
0.000129309 ]

@test all(center(data, w; standardize=true, bias=0)[1] - weighted_center .< ε)
@test all(coalesce(data, w, 4; standardize=true, bias=0)[1] - weighted_coalesce .< ε)
@test all(collapse(data, w, 4; standardize=true, bias=0)[1] - weighted_collapse .< ε)

0 comments on commit 1464fc0

Please sign in to comment.