You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/performancetips.md
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -93,6 +93,48 @@ Benchmark shows the performance of `TropicalGEMM` is close to the theoretical op
93
93
It is a sum-product expression tree to store [`ConfigEnumerator`](@ref) in a lazy style, configurations can be extracted by depth first searching the tree with the `Base.collect` method. Although it is space efficient, it is in general not easy to extract information from it.
94
94
This tree structure supports directed sampling so that one can get some statistic properties from it with an intermediate effort.
95
95
96
+
For example, if we want to check some property of an intermediate scale graph, one can type
97
+
```julia
98
+
julia> graph =random_regular_graph(70, 3)
99
+
100
+
julia> problem =IndependentSet(graph; optimizer=TreeSA());
101
+
102
+
julia> tree =solve(problem, ConfigsAll(; tree_storage=true))[];
103
+
16633909006371
104
+
```
105
+
If one wants to store these configurations, he will need a hard disk of size 256 TB!
106
+
However, this sum-product binary tree structure supports efficient and unbiased direct sampling.
107
+
108
+
```julia
109
+
samples =generate_samples(tree, 1000);
110
+
```
111
+
112
+
With these samples, one can already compute useful properties like distribution of hamming distance (see [`hamming_distribution`](@ref)).
# A patch to make `Polynomial{ConfigEnumerator}` work
583
661
function Base.:*(a::Int, y::AbstractSetNumber)
584
662
a ==0&&returnzero(y)
@@ -611,7 +689,8 @@ end
611
689
612
690
# utilities for creating onehot vectors
613
691
onehotv(::Type{ConfigEnumerator{N,S,C}}, i::Integer, v) where {N,S,C} =ConfigEnumerator([onehotv(StaticElementVector{N,S,C}, i, v)])
614
-
onehotv(::Type{TreeConfigEnumerator{N,S,C}}, i::Integer, v) where {N,S,C} =TreeConfigEnumerator(onehotv(StaticElementVector{N,S,C}, i, v))
692
+
# we treat `v == 0` specially because we want the final result not containing one leaves.
693
+
onehotv(::Type{TreeConfigEnumerator{N,S,C}}, i::Integer, v) where {N,S,C} = v ==0?one(TreeConfigEnumerator{N,S,C}) :TreeConfigEnumerator(onehotv(StaticElementVector{N,S,C}, i, v))
615
694
onehotv(::Type{ConfigSampler{N,S,C}}, i::Integer, v) where {N,S,C} =ConfigSampler(onehotv(StaticElementVector{N,S,C}, i, v))
616
695
# just to make matrix transpose work
617
696
Base.transpose(c::ConfigEnumerator) = c
@@ -620,7 +699,7 @@ Base.transpose(c::TreeConfigEnumerator) = c
620
699
function Base.copy(c::TreeConfigEnumerator{N,S,C}) where {N,S,C}
621
700
if c.tag == LEAF
622
701
TreeConfigEnumerator(c.data)
623
-
elseif c.tag == ZERO
702
+
elseif c.tag == ZERO|| c.tag == ONE
624
703
TreeConfigEnumerator{N,S,C}(c.tag)
625
704
else
626
705
TreeConfigEnumerator(c.tag, c.left, c.right)
@@ -635,9 +714,9 @@ end
635
714
636
715
# to handle power of polynomials
637
716
function Base.:^(x::TreeConfigEnumerator, y::Real)
638
-
if y <=0
717
+
if y ==0
639
718
returnone(x)
640
-
elseif x.tag == LEAF
719
+
elseif x.tag == LEAF|| x.tag == ONE || x.tag == ZERO
641
720
return x
642
721
else
643
722
error("pow of non-leaf nodes is forbidden!")
@@ -688,6 +767,19 @@ function _x(::Type{T}; invert) where {T<:AbstractSetNumber}
688
767
invert ?pre_invert_exponent(ret) : ret
689
768
end
690
769
770
+
function_onehotv(::Type{Polynomial{BS,X}}, x, v) where {BS,X}
771
+
Polynomial{BS,X}([onehotv(BS, x, v)])
772
+
end
773
+
function_onehotv(::Type{TruncatedPoly{K,BS,OS}}, x, v) where {K,BS,OS}
774
+
TruncatedPoly{K,BS,OS}(ntuple(i->i != K ?zero(BS) :onehotv(BS, x, v), K),zero(OS))
775
+
end
776
+
function_onehotv(::Type{CountingTropical{TV,BS}}, x, v) where {TV,BS}
function_onehotv(::Type{BS}, x, v) where {BS<:AbstractSetNumber}
103
-
onehotv(BS, x, v)
113
+
functionhamming_distribution!(out::AbstractVector, s1::AbstractVector{StaticElementVector{N,S,C}}, s2::AbstractVector{StaticElementVector{N,S,C}}) where {N,S,C}
0 commit comments