Search Spaces

Search spaces are divided in two main types: Atomic Search Spaces and Mixed Spaces.

Atomic search spaces are those defined by themselves.


julia> using SearchSpaces
julia> subtypes(SearchSpaces.AtomicSearchSpace)4-element Vector{Any}: BitArraySpace BoxConstrainedSpace CombinationSpace PermutationSpace

Bit Array Space

SearchSpaces.BitArraySpaceType
BitArraySpace(;dim)

Define a search space delimited by bit arrays.

Example

julia> space = BitArraySpace(4)
BitArraySpace(4)

julia> rand(space, 7)
7-element Vector{Vector{Bool}}:
 [0, 1, 1, 0]
 [0, 0, 0, 1]
 [1, 1, 1, 0]
 [0, 0, 0, 1]
 [0, 1, 0, 1]
 [1, 1, 1, 0]
 [1, 0, 0, 0]
source

Box-Constrained Space (Hyperrectangle)

SearchSpaces.BoxConstrainedSpaceType
BoxConstrainedSpace(;lb, ub, rigid=true)

Define a search space delimited by box constraints.

Example

julia> space = BoxConstrainedSpace(lb = zeros(Int, 5), ub = ones(Int, 5))
BoxConstrainedSpace{Int64}([0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], 5, true)

julia> cardinality(space)
32
source

Combination Space

SearchSpaces.CombinationSpaceType
CombinationSpace(values; k)
CombinationSpace(k)

Define a search space defined by the combinations (with replacement) of size k.

Example

julia> space = CombinationSpace(3)
CombinationSpace{UnitRange{Int64}}(1:3, 3)

julia> rand(space)
3-element Vector{Int64}:
 1
 1
 2

julia> rand(space,7)
7-element Vector{Vector{Int64}}:
 [1, 1, 1]
 [2, 1, 1]
 [2, 2, 1]
 [2, 3, 3]
 [1, 3, 1]
 [2, 1, 2]
 [2, 3, 1]

julia> rand(CombinationSpace([:apple, :orange, :onion, :garlic]))
4-element Vector{Symbol}:
 :apple
 :orange
 :orange
 :apple
source

$k$-Permutation Space

SearchSpaces.PermutationSpaceType
PermutationSpace(values; k)
PermutationSpace(k)

Define a search space defined by permuting the values of size k (k-permutations).

julia> space = PermutationSpace([:red, :green, :blue])
PermutationSpace{Vector{Symbol}}([:red, :green, :blue], 3)

julia> rand(space, 5)
5-element Vector{Vector{Symbol}}:
 [:blue, :green, :red]
 [:red, :blue, :green]
 [:blue, :green, :red]
 [:green, :blue, :red]
 [:red, :blue, :green]

julia> GridSampler(PermutationSpace(3)) |> collect
6-element Vector{Any}:
 [1, 2, 3]
 [1, 3, 2]
 [2, 1, 3]
 [2, 3, 1]
 [3, 1, 2]
 [3, 2, 1]
source

Category Space

SearchSpaces.CategorySpaceFunction
CategorySpace(categories)

Define a search space given by the provided categories (Vector).

Example

julia> space = CategorySpace([:soft, :medium, :high]);

julia> rand(space)
:soft

julia> cardinality(space)
3
source

Mixed Space

SearchSpaces.MixedSpaceType
MixedSpace([itr])

Construct a search space.

Example

julia> space = MixedSpace( :X => BoxConstrainedSpace(lb = [-1.0, -3.0], ub = [10.0, 10.0]),
                          :Y => PermutationSpace(10),
                          :Z => BitArraySpace(dim = 10)
                          ) 
MixedSpace defined by 3 subspaces:
X => BoxConstrainedSpace{Float64}([-1.0, -3.0], [10.0, 10.0], [11.0, 13.0], 2, true)
Y => PermutationSpace{Vector{Int64}}([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 10)
Z => BitArraySpace(10)


julia> rand(space)
Dict{Symbol, Vector} with 3 entries:
  :Z => Bool[0, 1, 0, 0, 0, 0, 0, 1, 1, 0]
  :X => [0.367973, 4.62101]
  :Y => [4, 3, 9, 1, 7, 2, 10, 8, 5, 6]

See also ×

source
SearchSpaces.:×Function
A × B

Return the mixed space using Cartesian product.

Example

julia> bounds = BoxConstrainedSpace(lb = zeros(Int, 5), ub = ones(Int, 5));

julia> permutations = PermutationSpace([:red, :green, :blue]);

julia> bits = BitArraySpace(3);

julia> mixed = bounds × permutations × bits
MixedSpace defined by 3 subspaces:
S3 => BitArraySpace(3)
S2 => PermutationSpace{Vector{Symbol}}([:red, :green, :blue], 3)
S1 => BoxConstrainedSpace{Int64}([0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], 5, true)

julia> cardinality(mixed)
1536

julia> rand(mixed)
Dict{Symbol, Vector} with 3 entries:
  :S2 => [:red, :blue, :green]
  :S1 => [0, 1, 0, 0, 1]
  :S3 => Bool[1, 1, 0]
source