CTMCEnsemble.jl Documentation
#
CTMCEnsemble.average
— Function.
average(preds, weights=nothing; multiplicity=true)
Compute the average. multiplicity
for arithmetic mean based on mulitpiliciity.
Example
julia> average([([0.5, 0.5], [1, 2]), ([0.5, 0.5], [2, 3])])
3-element Array{Float64,1}:
0.333333
0.333333
0.333333
julia> average([([0.5, 0.5], [1, 2]), ([0.5, 0.5], [2, 3])], multiplicity=false)
3-element Array{Float64,1}:
0.25
0.5
0.25
julia> A = [0.5 0.2 0.1 0.3; 0.5 0.8 0.9 0.7]
2×4 Array{Float64,2}:
0.5 0.2 0.1 0.3
0.5 0.8 0.9 0.7
julia> B = [0.5 0.1 0.2 0.7; 0.5 0.9 0.8 0.3]
2×4 Array{Float64,2}:
0.5 0.1 0.2 0.7
0.5 0.9 0.8 0.3
julia> average([(A, [1, 2]), (B, [2, 3])])
3×4 Array{Float64,2}:
0.333333 0.129032 0.0689655 0.230769
0.333333 0.290323 0.37931 0.538462
0.333333 0.580645 0.551724 0.230769
julia> average([(A, [1, 2]), (B, [2, 3])], multiplicity=false)
3×4 Array{Float64,2}:
0.25 0.1 0.05 0.15
0.5 0.45 0.55 0.7
0.25 0.45 0.4 0.15
#
CTMCEnsemble.bordacount
— Function.
bordacount(preds, weights=nothing)
Compute the Borda count vote.
Example
julia> bordacount([([0.5, 0.5], [1, 2]), ([0.5, 0.5], [2, 3])])
3-element Array{Float64,1}:
0.25
0.5
0.25
julia> A = [0.5 0.2 0.1 0.3; 0.5 0.8 0.9 0.7]
2×4 Array{Float64,2}:
0.5 0.2 0.1 0.3
0.5 0.8 0.9 0.7
julia> B = [0.5 0.1 0.2 0.7; 0.5 0.9 0.8 0.3]
2×4 Array{Float64,2}:
0.5 0.1 0.2 0.7
0.5 0.9 0.8 0.3
julia> bordacount([(A, [1, 2]), (B, [2, 3])])
3×4 Array{Float64,2}:
0.25 0.166667 0.166667 0.166667
0.5 0.5 0.5 0.666667
0.25 0.333333 0.333333 0.166667
#
CTMCEnsemble.ctmc
— Function.
ctmc(preds, weights=nothing)
Compute stationary distribution by CTMC method.
Example
julia> ctmc([([0.5, 0.5], [1, 2]), ([0.5, 0.5], [2, 3])])
3-element Array{Float64,1}:
0.333333
0.333333
0.333333
julia> A = [0.5 0.2 0.1 0.3; 0.5 0.8 0.9 0.7]
2×4 Array{Float64,2}:
0.5 0.2 0.1 0.3
0.5 0.8 0.9 0.7
julia> B = [0.5 0.1 0.2 0.7; 0.5 0.9 0.8 0.3]
2×4 Array{Float64,2}:
0.5 0.1 0.2 0.7
0.5 0.9 0.8 0.3
julia> ctmc([(A, [1, 2]), (B, [2, 3])])
3×4 Array{Float64,2}:
0.333333 0.0243902 0.0217391 0.230769
0.333333 0.097561 0.195652 0.538462
0.333333 0.878049 0.782609 0.230769
#
CTMCEnsemble.dempstershafer_rogova
— Method.
dempstershafer_rogova(preds)
Compute the dempstershafer_rogova.
Example
julia> dempstershafer_rogova([([0.2, 0.8], [1, 2])])
2-element Array{Float64,1}:
0.0588235
0.941176
julia> dempstershafer_rogova([([0.5, 0.5], [1, 2]), ([0.5, 0.5], [2, 3])])
3-element Array{Float64,1}:
0.428571
0.142857
0.428571
julia> A = [0.5 0.2 0.1 0.3; 0.5 0.8 0.9 0.7]
2×4 Array{Float64,2}:
0.5 0.2 0.1 0.3
0.5 0.8 0.9 0.7
julia> B = [0.5 0.1 0.2 0.7; 0.5 0.9 0.8 0.3]
2×4 Array{Float64,2}:
0.5 0.1 0.2 0.7
0.5 0.9 0.8 0.3
julia> dempstershafer_rogova([(A, [1, 2]), (B, [2, 3])])
3×4 Array{Float64,2}:
0.428571 0.0503319 0.0134788 0.18598
0.142857 0.00884956 0.0519897 0.628041
0.428571 0.940819 0.934531 0.18598
#
CTMCEnsemble.powermethod
— Function.
powermethod(preds, weights=nothing; maxiter=16)
Compute stationary distribution by power method.
Example
julia> powermethod([([0.5, 0.5], [1, 2]), ([0.5, 0.5], [2, 3])], maxiter=16)
3-element Array{Float64,1}:
0.333333
0.333333
0.333333
julia> A = [0.5 0.2 0.1 0.3; 0.5 0.8 0.9 0.7]
2×4 Array{Float64,2}:
0.5 0.2 0.1 0.3
0.5 0.8 0.9 0.7
julia> B = [0.5 0.1 0.2 0.7; 0.5 0.9 0.8 0.3]
2×4 Array{Float64,2}:
0.5 0.1 0.2 0.7
0.5 0.9 0.8 0.3
julia> powermethod([(A, [1, 2]), (B, [2, 3])])
3×4 Array{Float64,2}:
0.333333 0.0244257 0.0217406 0.230769
0.333333 0.0976007 0.195655 0.538462
0.333333 0.877974 0.782604 0.230769
#
CTMCEnsemble.product
— Function.
product(preds, weights=nothing; multiplicity=true)
Compute the product. multiplicity
for geometric mean based on mulitpiliciity.
Example
julia> product([([0.5, 0.5], [1, 2]), ([0.5, 0.5], [2, 3])])
3-element Array{Float64,1}:
0.333333
0.333333
0.333333
julia> product([([0.5, 0.5], [1, 2]), ([0.5, 0.5], [2, 3])], multiplicity=false)
3-element Array{Float64,1}:
0.4
0.2
0.4
julia> A = [0.5 0.2 0.1 0.3; 0.5 0.8 0.9 0.7]
2×4 Array{Float64,2}:
0.5 0.2 0.1 0.3
0.5 0.8 0.9 0.7
julia> B = [0.5 0.1 0.2 0.7; 0.5 0.9 0.8 0.3]
2×4 Array{Float64,2}:
0.5 0.1 0.2 0.7
0.5 0.9 0.8 0.3
julia> product([(A, [1, 2]), (B, [2, 3])])
3×4 Array{Float64,2}:
0.333333 0.14463 0.0755136 0.230769
0.333333 0.204537 0.320377 0.538462
0.333333 0.650833 0.604109 0.230769
julia> product([(A, [1, 2]), (B, [2, 3])], multiplicity=false)
3×4 Array{Float64,2}:
0.4 0.169492 0.0925926 0.275229
0.2 0.0677966 0.166667 0.449541
0.4 0.762712 0.740741 0.275229
#
CTMCEnsemble.sink
— Function.
sink(preds, weights=nothing)
Compute stationary distribution by sink method.
Example
julia> sink([([0.5, 0.5], [1, 2]), ([0.5, 0.5], [2, 3])])
3-element Array{Float64,1}:
1.0
0.0
0.0
julia> A = [0.5 0.2 0.1 0.3; 0.5 0.8 0.9 0.7]
2×4 Array{Float64,2}:
0.5 0.2 0.1 0.3
0.5 0.8 0.9 0.7
julia> B = [0.5 0.1 0.2 0.7; 0.5 0.9 0.8 0.3]
2×4 Array{Float64,2}:
0.5 0.1 0.2 0.7
0.5 0.9 0.8 0.3
julia> sink([(A, [1, 2]), (B, [2, 3])])
3×4 Array{Float64,2}:
1.0 0.0 0.0 0.0
0.0 0.0 0.0 1.0
0.0 1.0 1.0 0.0
julia> sink([(A, [1, 2]), (B, [2, 3])], multiple_src=true)
3×4 Array{Float64,2}:
0.333333 0.0 0.0 0.0
0.333333 0.0 0.0 1.0
0.333333 1.0 1.0 0.0
#
CTMCEnsemble.softmax!
— Method.
softmax!(data)
Inplace softmax col-wise.
Example
julia> p = [0.49 0.09 0.71 0.07 0.28
0.73 0.48 0.01 0.96 0.51
0.87 0.09 0.76 0.63 0.39
0.37 0.65 0.89 0.31 0.42
0.6 0.49 0.19 0.21 0.77
0.56 0.32 0.27 1.0 0.92
0.5 0.83 0.99 0.4 0.81
0.34 0.03 0.83 0.07 0.62
0.93 0.75 0.15 0.37 0.21
0.25 0.19 0.83 0.69 0.64];
julia> softmax!(p)
10×5 Array{Float64,2}:
0.0907496 0.0711453 0.109493 0.063526 0.0739451
0.115365 0.10508 0.0543729 0.154694 0.0930673
0.132702 0.0711453 0.115107 0.111213 0.0825433
0.0804877 0.124552 0.131088 0.0807574 0.0850571
0.101302 0.106136 0.0650961 0.0730723 0.120702
0.0973297 0.0895435 0.0705178 0.161007 0.140235
0.0916616 0.149116 0.144874 0.0883626 0.125628
0.0781089 0.0670021 0.123454 0.063526 0.103889
0.140908 0.137651 0.0625437 0.0857511 0.0689459
0.0713862 0.0786277 0.123454 0.11809 0.105988
#
CTMCEnsemble.svdmethod
— Function.
svdmethod(preds, weights=nothing)
Compute stationary distribution by svd method.
Example
julia> svdmethod([([0.5, 0.5], [1, 2]), ([0.5, 0.5], [2, 3])])
3-element Array{Float64,1}:
0.333333
0.333333
0.333333
julia> A = [0.5 0.2 0.1 0.3; 0.5 0.8 0.9 0.7]
2×4 Array{Float64,2}:
0.5 0.2 0.1 0.3
0.5 0.8 0.9 0.7
julia> B = [0.5 0.1 0.2 0.7; 0.5 0.9 0.8 0.3]
2×4 Array{Float64,2}:
0.5 0.1 0.2 0.7
0.5 0.9 0.8 0.3
julia> svdmethod([(A, [1, 2]), (B, [2, 3])])
3×4 Array{Float64,2}:
0.333333 0.0243902 0.0217391 0.230769
0.333333 0.097561 0.195652 0.538462
0.333333 0.878049 0.782609 0.230769
#
CTMCEnsemble.top1
— Method.
top1(data, label)
Top-1 accuracy.
Example
julia> p = [0.333333 0.0243902 0.0217391 0.230769
0.333333 0.097561 0.195652 0.538462
0.333333 0.878049 0.782609 0.230769];
julia> top1(p, [1, 3, 3, 2])
1.0
#
CTMCEnsemble.top5
— Method.
top5(data, label)
Top-5 accuracy.
Example
julia> p = [0.49 0.09 0.71 0.07 0.28
0.73 0.48 0.01 0.96 0.51
0.87 0.09 0.76 0.63 0.39
0.37 0.65 0.89 0.31 0.42
0.6 0.49 0.19 0.21 0.77
0.56 0.32 0.27 1.0 0.92
0.5 0.83 0.99 0.4 0.81
0.34 0.03 0.83 0.07 0.62
0.93 0.75 0.15 0.37 0.21
0.25 0.19 0.83 0.69 0.64];
julia> top5(p, 1:5)
0.6
#
CTMCEnsemble.vote
— Function.
vote(preds, weights=nothing)
Compute the vote.
Example
julia> vote([([0.5, 0.5], [1, 2]), ([0.5, 0.5], [2, 3])])
3-element Array{Float64,1}:
0.5
0.5
0.0
julia> A = [0.5 0.2 0.1 0.3; 0.5 0.8 0.9 0.7]
2×4 Array{Float64,2}:
0.5 0.2 0.1 0.3
0.5 0.8 0.9 0.7
julia> B = [0.5 0.1 0.2 0.7; 0.5 0.9 0.8 0.3]
2×4 Array{Float64,2}:
0.5 0.1 0.2 0.7
0.5 0.9 0.8 0.3
julia> vote([(A, [1, 2]), (B, [2, 3])])
3×4 Array{Float64,2}:
0.5 0.0 0.0 0.0
0.5 0.5 0.5 1.0
0.0 0.5 0.5 0.0
#
CTMCEnsemble.build
— Function.
build(preds, weights=nothing; nclass=0)
Build the generator matrix.
Example
julia> CTMCEnsemble.build([([0.5, 0.5], [1, 2]), ([0.5, 0.5], [2, 3])])
3×3 Array{Float64,2}:
-0.5 0.5 0.0
0.5 -1.0 0.5
0.0 0.5 -0.5
#
CTMCEnsemble.chase
— Method.
chase(Q::Array, src)
Chase to the highest points from src points in the graph with weights Q. $Q_{i,j}$ is the weight going from point $j$ to $i$. Returns an array indicates the number of each point being end points.
Example
julia> G = CTMCEnsemble.build([([0.5, 0.5], [1, 2]), ([0.5, 0.5], [2, 3])]);
julia> CTMCEnsemble.chase(G, 1)
3-element Array{Float64,1}:
1.0
0.0
0.0
julia> CTMCEnsemble.chase(G, [1, 2])
3-element Array{Float64,1}:
0.5
0.5
0.0
julia> G = CTMCEnsemble.build([([0.4, 0.6], [1, 2]), ([0.4, 0.6], [2, 3])]);
julia> CTMCEnsemble.chase(G, [1, 2, 3])
3-element Array{Float64,1}:
0.0
0.0
1.0
#
CTMCEnsemble.stationdist
— Method.
stationdist(G)
Compute stationary probability distribution given generator $G$.
Example
julia> G = CTMCEnsemble.build([([0.5, 0.5], [1, 2]), ([0.5, 0.5], [2, 3])]);
julia> CTMCEnsemble.stationdist(G)
3-element Array{Float64,1}:
0.333333
0.333333
0.333333