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
# One can use [`SingleConfigMax`](@ref) to find one of the solution with largest set size, and it has two implementations.
95
-
# The unbounded (default) version uses [`ConfigSampler`](@ref) to sample one of the best solutions directly.
95
+
# The unbounded (default) version uses a joint type of [`CountingTropical`](@ref) and [`ConfigSampler`](@ref) in computation,
96
+
# where `CountingTropical` finds the maximum size and `ConfigSampler` samples one of the best solutions.
96
97
# The bounded version uses the binary gradient back-propagation (see our paper) to compute the gradients.
97
98
# It requires caching intermediate states, but is often faster (on CPU) because it can use [`TropicalGEMM`](https://github.com/TensorBFS/TropicalGEMM.jl) (see [Performance Tips](@ref)).
# It uses the [`ExtendedTropical`](@ref) as the tensor elements.
176
+
# One can get sets with maximum `K` sizes, by combining [`ExtendedTropical`](@ref) and the algebra in the previous section for sampling one configuration.
* The corresponding data type is inverted [`CountingTropical{Float64,<:ConfigSampler}`](@ref) if `BOUNDED` is `false`, inverted [`Tropical`](@ref) otherwise.
135
136
* Weighted graph problems is supported.
@@ -139,8 +140,9 @@ Keyword Arguments
139
140
----------------------------
140
141
* `bounded`, if it is true, use bounding trick (or boolean gradients) to reduce the working memory to store intermediate configurations.
const SetPolyNumbers{T} = Union{Polynomial{T}, TruncatedPoly{K,T} where K, CountingTropical{TV,T} where TV} where T<:AbstractSetNumber
130
-
functionadd_labels!(tensors::AbstractVector{<:AbstractArray{T}}, ixs, labels) where T <:Union{AbstractSetNumber, SetPolyNumbers}
130
+
functionadd_labels!(tensors::AbstractVector{<:AbstractArray{T}}, ixs, labels) where T <:Union{AbstractSetNumber, SetPolyNumbers, ExtendedTropical{K,T} where {K,T<:SetPolyNumbers}}
(CountingTropical(5.0, ConfigEnumerator([StaticBitVector(rand(Bool, 10)) for j=1:3])), CountingTropical(3.0, ConfigEnumerator([StaticBitVector(rand(Bool, 10)) for j=1:4])), CountingTropical(-3.0, ConfigEnumerator([StaticBitVector(rand(Bool, 10)) for j=1:5]))),
@@ -100,13 +100,13 @@ end
100
100
@test x ^0==one(x)
101
101
@test x ^2.0== x
102
102
103
-
x =ExtendedTropical{3}([1.0, 2.0, 3.0])
103
+
x =ExtendedTropical{3}(Tropical.([1.0, 2.0, 3.0]))
104
104
@test x ^1== x
105
105
@test x ^0==one(x)
106
106
@test x ^1.0== x
107
107
@test x ^0.0==one(x)
108
-
@test x ^2==ExtendedTropical{3}([2.0, 4.0, 6.0])
109
-
@test x ^2.0==ExtendedTropical{3}([2.0, 4.0, 6.0])
108
+
@test x ^2==ExtendedTropical{3}(Tropical.([2.0, 4.0, 6.0]))
109
+
@test x ^2.0==ExtendedTropical{3}(Tropical.([2.0, 4.0, 6.0]))
110
110
end
111
111
112
112
@testset"push coverage"begin
@@ -127,28 +127,28 @@ end
127
127
128
128
@testset"Truncated Tropical"begin
129
129
# +
130
-
a =ExtendedTropical{3}([1,2,3])
131
-
b =ExtendedTropical{3}([4,5,6])
132
-
c =ExtendedTropical{3}([0,1,2])
133
-
@test a + b ==ExtendedTropical{3}([4,5,6])
134
-
@test b + a ==ExtendedTropical{3}([4,5,6])
135
-
@test c + a ==ExtendedTropical{3}([2,2,3])
136
-
@test a + c ==ExtendedTropical{3}([2,2,3])
130
+
a =ExtendedTropical{3}(Tropical.([1,2,3]))
131
+
b =ExtendedTropical{3}(Tropical.([4,5,6]))
132
+
c =ExtendedTropical{3}(Tropical.([0,1,2]))
133
+
@test a + b ==ExtendedTropical{3}(Tropical.([4,5,6]))
134
+
@test b + a ==ExtendedTropical{3}(Tropical.([4,5,6]))
135
+
@test c + a ==ExtendedTropical{3}(Tropical.([2,2,3]))
136
+
@test a + c ==ExtendedTropical{3}(Tropical.([2,2,3]))
137
137
138
138
# *
139
139
functionnaive_mul(a, b)
140
140
K =length(a)
141
-
returnsort!(vec([x+y for x in a, y in b]))[end-K+1:end]
141
+
returnsort!(vec([x*y for x in a, y in b]))[end-K+1:end]
142
142
end
143
-
d =ExtendedTropical{3}([0,1,20])
143
+
d =ExtendedTropical{3}(Tropical.([0,1,20]))
144
144
@testnaive_mul(a.orders, b.orders) == (a * b).orders
0 commit comments