API references
Built-in Samplers
SearchSpaces.GridSampler — TypeGridSampler(searchspace; npartitions)Return an iterator over the given searchspace.
The npartitions controls the number of partitions for each axis when searchspace isa BoxConstrainedSpace (3 by default).
Examples
julia> for x in GridSampler(PermutationSpace([:red, :green, :blue]))
@show x
end
x = [:red, :green, :blue]
x = [:red, :blue, :green]
x = [:green, :red, :blue]
x = [:green, :blue, :red]
x = [:blue, :red, :green]
x = [:blue, :green, :red]
julia> for x in GridSampler(BoxConstrainedSpace(lb=[-1.0, -1], ub=[1, 0.0]), npartitions=3)
@show x
end
x = [-1.0, -1.0]
x = [0.0, -1.0]
x = [1.0, -1.0]
x = [-1.0, -0.5]
x = [0.0, -0.5]
x = [1.0, -0.5]
x = [-1.0, 0.0]
x = [0.0, 0.0]
x = [1.0, 0.0]
julia> mixed = MixedSpace(
:W => CategorySpace([:red, :green, :blue]),
:X => PermutationSpace(2),
:Y => BitArrays(2),
);
julia> collect(GridSampler(mixed))
24-element Vector{Any}:
Dict{Symbol, Any}(:W => :red, :X => [1, 2], :Y => Bool[0, 0])
Dict{Symbol, Any}(:W => :green, :X => [1, 2], :Y => Bool[0, 0])
Dict{Symbol, Any}(:W => :blue, :X => [1, 2], :Y => Bool[0, 0])
Dict{Symbol, Any}(:W => :red, :X => [2, 1], :Y => Bool[0, 0])
Dict{Symbol, Any}(:W => :green, :X => [2, 1], :Y => Bool[0, 0])
Dict{Symbol, Any}(:W => :blue, :X => [2, 1], :Y => Bool[0, 0])
⋮
Dict{Symbol, Any}(:W => :blue, :X => [2, 1], :Y => Bool[0, 1])
Dict{Symbol, Any}(:W => :red, :X => [1, 2], :Y => Bool[1, 1])
Dict{Symbol, Any}(:W => :green, :X => [1, 2], :Y => Bool[1, 1])
Dict{Symbol, Any}(:W => :blue, :X => [1, 2], :Y => Bool[1, 1])
Dict{Symbol, Any}(:W => :red, :X => [2, 1], :Y => Bool[1, 1])
Dict{Symbol, Any}(:W => :green, :X => [2, 1], :Y => Bool[1, 1])
Dict{Symbol, Any}(:W => :blue, :X => [2, 1], :Y => Bool[1, 1])SearchSpaces.RandomSampler — TypeRandomSampler(searchspace;rng)Define a random iterator for the search space.
Miscellaneous
SearchSpaces.cardinality — Functioncardinality(searchspace)Cardinality of the search space.
Example
julia> cardinality(PermutationSpace(5))
120
julia> cardinality(BoxConstrainedSpace(lb = zeros(2), ub = ones(2)))
Inf
julia> cardinality(BoxConstrainedSpace(lb = zeros(Int, 2), ub = ones(Int,2)))
4
julia> mixed = MixedSpace(
:W => CategorySpace([:red, :green, :blue]),
:X => PermutationSpace(3),
:Y => BitArraySpace(3),
);
julia> cardinality(mixed)
144SearchSpaces.isinbounds — Functionisinbounds(item, searchspace) --> BoolDetermine whether an item is in the given searchspace.
SearchSpaces.ispermutation — Functionispermutation(item, searchspace) --> BoolDetermine whether an item is in the given searchspace.
SearchSpaces.isinspace — Functionisinspace(item, searchspace) --> BoolDetermine whether an item is in the given searchspace.
See also in.
SearchSpaces.Variable — TypeVariable(name, searchspace)A structure to define a variable in the search space: searchspace.
SearchSpaces.@var — Macro@var x in searchspaceA macro to define a Variable for in the given search space.
SearchSpaces.BitArraySpace — MethodBitArraySpace(;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]SearchSpaces.BoxConstrainedSpace — MethodBoxConstrainedSpace(;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)
32SearchSpaces.CombinationSpace — MethodCombinationSpace(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
:appleSearchSpaces.MixedSpace — MethodMixedSpace([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 ×
SearchSpaces.PermutationSpace — MethodPermutationSpace(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]SearchSpaces.Sampler — MethodSampler(sampler, searchspace)Crate an iterator for the sampler for the given searchspace.
Base.in — Methodin(item, searchspace) -> BoolDetermine whether an item is in the given searchspace.
Base.rand — Methodrand([rng=GLOBAL_RNG], searchspace, [d])Pick a random element or array of random elements from the search space specified by searchspace.
Examples
julia> searchspace = BoxConstrainedSpace(lb=[-10, 1, 100], ub = [10, 2, 1000]);
julia> rand(searchspace)
3-element Vector{Int64}:
1
1
606
julia> rand(searchspace, 3)
3-element Vector{Vector{Int64}}:
[0, 1, 440]
[9, 1, 897]
[3, 2, 498]Another example using MixedSpace:
julia> mixed = MixedSpace(
:W => CategorySpace([:red, :green, :blue]),
:X => PermutationSpace(3),
:Y => BitArrays(3),
:Z => BoxConstrainedSpace(lb = zeros(2), ub = ones(2))
);
julia> rand(mixed)
Dict{Symbol, Any} with 4 entries:
:Z => [0.775912, 0.467882]
:W => :red
:X => [3, 1, 2]
:Y => Bool[1, 0, 1]SearchSpaces.:.. — Method..(a, b)Define a interval between a and b (inclusive).
Example
julia> my_interval = (-π..π)
julia> rand(my_interval, 5)
5-element Vector{Float64}:
0.5111482297554093
1.1984728844571544
1.3279941255812906
2.3429444282250502
3.0495310142685526See also BoxConstrainedSpace
SearchSpaces.:× — MethodA × BReturn 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]SearchSpaces.CategorySpace — MethodCategorySpace(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)
3SearchSpaces.cardinality — Methodcardinality(searchspace)Cardinality of the search space.
Example
julia> cardinality(PermutationSpace(5))
120
julia> cardinality(BoxConstrainedSpace(lb = zeros(2), ub = ones(2)))
Inf
julia> cardinality(BoxConstrainedSpace(lb = zeros(Int, 2), ub = ones(Int,2)))
4
julia> mixed = MixedSpace(
:W => CategorySpace([:red, :green, :blue]),
:X => PermutationSpace(3),
:Y => BitArraySpace(3),
);
julia> cardinality(mixed)
144SearchSpaces.get_iterator — Methodget_iterator(searchspace, [npartitions=3])Get the iterator for the GridSampler.
SearchSpaces.isinbounds — Methodisinbounds(item, searchspace) --> BoolDetermine whether an item is in the given searchspace.
SearchSpaces.isinspace — Methodisinspace(item, searchspace) --> BoolDetermine whether an item is in the given searchspace.
See also in.
SearchSpaces.ispermutation — Methodispermutation(item, searchspace) --> BoolDetermine whether an item is in the given searchspace.
SearchSpaces.@var — Macro@var x in searchspaceA macro to define a Variable for in the given search space.