HerbSearch.jl Documentation
HerbSearch.AbstractBFSIterator — Type
AbstractBFSIterator <: TopDownIteratorThis is the supertype for all breadth-first search iterators. It inherits all stop-criteria and traversal mechanisms from TopDownIterator.
HerbSearch.AbstractDFSIterator — Type
AbstractDFSIterator <: TopDownIteratorThis is the supertype for all depth-first search iterators. It inherits all stop-criteria and from TopDownIterator, but the traversal mechanism is implemented to perform a depth-first search.
HerbSearch.AbstractMHSearchIterator — Type
AbstractMHSearchIterator <: StochasticSearchIteratorThis is the supertype for all Metropolis Hastings (MH) search iterators. It inherits all behaviour from StochasticSearchIterator.
HerbSearch.AbstractSASearchIterator — Type
AbstractSASearchIterator <: StochasticSearchIteratorThis is the supertype for all SA search iterators.
HerbSearch.AbstractVLSNSearchIterator — Type
AbstractVLSNSearchIterator <: StochasticSearchIteratorThis is the supertype for all VLSN search iterators.
HerbSearch.BFSIterator — Type
@programiterator BFSIterator() <: TopDownIteratorCreates a breadth-first search iterator for traversing given a grammar, starting from the given symbol. The iterator returns trees in the grammar in increasing order of size.
HerbSearch.DFSIterator — Type
@programiterator DFSIterator() <: AbstractDFSIteratorCreates a depth-first search iterator for traversing a given a grammar, starting from a given symbol. The iterator returns trees in the grammar in decreasing order of size.
HerbSearch.ExpandFailureReason — Type
@enum ExpandFailureReason limit_reached=1 already_complete=2Representation of the different reasons why expanding a partial tree failed. Currently, there are two possible causes of the expansion failing:
limit_reached: The depth limit or the size limit of the partial tree would be violated by the expansionalready_complete: There is no hole left in the tree, so nothing can be expanded.
HerbSearch.GeneticSearchIterator — Type
GeneticSearchIterator{FitnessFunction,CrossOverFunction,MutationFunction,SelectParentsFunction,EvaluationFunction} <: ProgramIteratorDefines an ProgramIterator using genetic search.
Consists of:
examples::Vector{<:IOExample}: a collection of examples defining the specificationevaluation_function::EvaluationFunction: interpreter to evaluate the individual programspopulation_size::Int64: number of inviduals in the populationmutation_probability::Float64: probability of mutation for each individualmaximum_initial_population_depth::Int64: maximum depth of trees when population is initialized
end
HerbSearch.MHSearchIterator — Type
MHSearchIterator(examples::AbstractArray{<:IOExample}, cost_function::Function, evaluation_function::Function=HerbInterpret.execute_on_input)The MHSearchIterator generates programs using the Metropolis-Hastings algorithm. The search behaviour has the following characteristics:
- It uses
random_fill_proposefor theproposefunction. - The
accept function isprobabilistic`. - The
temperatureof the algorithm remains constant over time, ensuring a stable acceptance probability.
Arguments
examples::AbstractArray{<:IOExample}: An array of input-output examples used to guide the search.cost_function::Function: A function to evaluate the cost of the proposed programs.evaluation_function::Function=HerbInterpret.execute_on_input: A function that evaluates the generated program generated and produces an output. Defaults toHerbInterpret.execute_on_input.
Returns
An iterator to generate programs according to the Metropolis Hastings algorithm.
HerbSearch.MLFSIterator — Type
@programiterator MLFSIterator() <: TopDownIteratorIterator that enumerates expressions in the grammar in decreasing order of probability (Only use this iterator with probabilistic grammars). Inherits all stop-criteria from TopDownIterator.
HerbSearch.ProgramIterator — Type
abstract type ProgramIteratorAbstract iterator type for all search strategies.
See @programiterator for details on constructing iterators or defining new strategies.
HerbSearch.RandomIterator — Type
@programiterator RandomIterator() <: TopDownIteratorIterates trees in the grammar in a random order.
HerbSearch.SASearchIterator — Type
SASearchIterator(spec, cost_function, initial_temperature=1, temperature_decreasing_factor = 0.99, evaluation_function::Function=HerbInterpret.execute_on_input)Returns an enumerator that runs according to the Simulated Annealing Search algorithm.
spec: array of examplescost_function: cost function to evaluate the programs proposedinitial_temperature: the starting temperature of the algorithmtemperature_decreasing_factor: the decreasing factor of the temperature of the timeevaluation_function: evaluation function that evaluates the program generated and produces an output
The propose function is random_fill_propose (the same as for Metropolis Hastings). The accept function is probabilistic but takes into account the tempeerature too.
HerbSearch.StochasticSearchIterator — Type
abstract type StochasticSearchIterator <: ProgramIteratorA unified abstract type for the stochastic search algorithms Metropolis Hastings, Very Large Scale Neighbourhood and Simulated Annealing. Iterators are customisable by overloading the followign functions:
neighbourhoodproposetemperatureaccept.
Fields
examples::Vector{IOExample}example used to check the programcost_function::Function. Returns the cost of the current program. It receives a list of tuples for (expected, found) and gives back a cost.initial_temperature::Real= 1evaluation_function::Function that evaluates the julia expressions
An iterator over all possible expressions of a grammar up to maxdepth with start symbol sym. Also inherits all stop criteria like `maxdepthfromProgramIterator`.
HerbSearch.SynthResult — Type
@enum SynthResult optimal_program=1 suboptimal_program=2Representation of the possible results of the synth procedure. At the moment there are two possible outcomes:
optimal_program: The synthesized program satisfies the entire program specification.suboptimal_program: The synthesized program does not satisfy the entire program specification, but got the best score from the evaluator.
HerbSearch.TopDownIterator — Type
mutable struct TopDownIterator <: ProgramIteratorEnumerates a context-free grammar starting at Symbol sym with respect to the grammar up to a given depth and a given size. The exploration is done using the given priority function for derivations, and the expand function for discovered nodes. Concrete iterators may overload the following methods:
- priority_function
- derivation_heuristic
- hole_heuristic
HerbSearch.UniformIterator — Type
mutable struct UniformIteratorInner iterator that enumerates all candidate programs of a uniform tree.
solver: the uniform solver.outeriter: outer iterator that is responsible for producing uniform trees. This field is used to dispatch on thederivation_heuristic.unvisited_branches: for each search-node from the root to the current search-node, a list of unviisted branches.nsolutions: number of solutions found so far.
HerbSearch.UniformIterator — Method
UniformIterator(solver::UniformSolver, outeriter::ProgramIterator)Constructs a new UniformIterator that traverses solutions of the UniformSolver and is an inner iterator of an outer ProgramIterator.
HerbSearch.VLSNSearchIterator — Type
VLSNSearchIterator(spec, cost_function, enumeration_depth = 2, evaluation_function::Function=HerbInterpret.execute_on_input) = StochasticSearchIterator(Returns an iterator that runs according to the Very Large Scale Neighbourhood Search algorithm.
spec: array of examplescost_function: cost function to evaluate the proposed programsvlsn_neighbourhood_depth: the enumeration depth to search for a best program at a timeevaluation_function: evaluation function that evaluates the program generated and produces an output
The propose function consists of all possible programs of the given enumeration_depth. The accept function accepts the program with the lowest cost according to the cost_function. The temperature value of the algorithm remains constant over time.
HerbSearch.@programiterator — Macro
@programiteratorCreate a new type T<:ProgramIterator that includes the common fields of ProgramIterators and some useful constructors.
Fields
- solver
- start_symbol
- initial_node
- grammar
- max_depth
- max_size
Syntax accepted by the macro is as follows (anything enclosed in square brackets is optional):
@programiterator [mutable] <IteratorName>(
<arg₁>,
...,
<argₙ>
) [<: <SupertypeIterator>]The mutable keyword determines whether the declared struct is mutable. SupertypeIterator must be an abstract type <:ProgramIterator. If no supertype is given, the new iterator extends ProgramIterator directly. Each <argᵢ> may be (almost) any expression valid in a struct declaration, and they must be comma separated.
An inner constructor must always be given using the extended function <name>(...) ... end syntax.
Example
julia> abstract type SomeIteratorFamily<:ProgramIterator end
julia> @programiterator mutable SomeCustomIterator(a_param::Int) <: SomeIteratorFamily;Base.collect — Method
function Base.collect(iter::TopDownIterator)Return an array of all programs in the TopDownIterator.
Base.iterate — Method
Base.iterate(iter::GeneticSearchIterator, current_state::GeneticIteratorState)Iterates the search space using a genetic algorithm. Takes the iterator and the current state to mutate and crossover random inviduals. Returns the best program-so-far and the state of the iterator.
Base.iterate — Method
Base.iterate(iter::GeneticSearchIterator)Iterates the search space using a genetic algorithm. First generates a population sampling random programs. Returns the best program-so-far, and the state of the iterator.
Base.iterate — Method
Base.iterate(iter::StochasticSearchIterator, current_state::IteratorState)The algorithm that constructs the iterator of StochasticSearchIterator. It has the following structure:
- get a random node location -> location,dict = neighbourhood(current_program)
- call propose on the current program getting a list of full programs
- iterate through all the proposals and check if the proposed program is "better" than the previous one
- "accept" the new program by calling the
accept - return the new next_program
Base.iterate — Method
Base.iterate(iter::TopDownIterator, pq::DataStructures.PriorityQueue)Describes the iteration for a given TopDownIterator and a PriorityQueue over the grammar without enqueueing new items to the priority queue. Recursively returns the result for the priority queue.
Base.iterate — Method
Base.iterate(iter::TopDownIterator)Describes the iteration for a given TopDownIterator over the grammar. The iteration constructs a PriorityQueue first and then prunes it propagating the active constraints. Recursively returns the result for the priority queue.
Base.length — Method
Base.length(iter::ProgramIterator)Counts and returns the number of possible programs without storing all the programs.
Base.length — Method
Base.length(iter::UniformIterator)Counts and returns the number of programs without storing all the programs. !!! warning: modifies and exhausts the iterator
HerbConstraints.get_grammar — Method
HerbConstraints.get_grammar(pi::ProgramIterator)HerbConstraints.get_max_depth — Method
HerbConstraints.get_max_depth(pi::ProgramIterator)Get the maximum depth of the programs that the program iterator will return.
HerbConstraints.get_max_size — Method
HerbConstraints.get_max_size(pi::ProgramIterator)Get the maximum size of the programs that the program iterator will return.
HerbConstraints.get_starting_symbol — Method
HerbConstraints.get_starting_symbol(pi::ProgramIterator)Get the starting symbol of the iterator.
Example
Given an iterator that is initialized with :Int as the starting symbol, the root of each of the programs returned from the iterator will have the same type, and this will match the symbol returned by get_starting_symbol.
julia> g = @csgrammar begin
Int = length(List)
Int = Int + Int
List = x
end;
julia> it = BFSIterator(g, :Int; max_depth=4);
julia> programs = rulenode2expr.((freeze_state(p) for p in it), (g,))
5-element Vector{Expr}:
:(length(x))
:(length(x) + length(x))
:(length(x) + (length(x) + length(x)))
:((length(x) + length(x)) + length(x))
:((length(x) + length(x)) + (length(x) + length(x)))
julia> get_starting_symbol(it)
:IntNote that all of the programs will return an Int, matching the type returned by get_starting_symbol(it).
HerbSearch._calculate_cost — Method
_calculate_cost(program::RuleNode, cost_function::Function, spec::AbstractVector{IOExample}, grammar::AbstractGrammar, evaluation_function::Function)Returns the cost of the program using the examples and the cost_function. It first convert the program to an expression and evaluates it on all the examples.
HerbSearch._extract_name_from_argument — Method
_extract_name_from_argument(ex)Extracts the name of a field declaration, otherwise throws an ArgumentError. A field declaration is either a simple field name with possible a type attached to it or a keyword argument.
Example
x::Int -> x hello -> hello x = 4 -> x x::Int = 3 -> x
HerbSearch._find_next_complete_tree — Method
_find_next_complete_tree(solver::Solver, pq::PriorityQueue, iter::TopDownIterator)::Union{Tuple{RuleNode, Tuple{Vector{AbstractRuleNode}, PriorityQueue}}, Nothing}Takes a priority queue and returns the smallest AST from the grammar it can obtain from the queue or by (repeatedly) expanding trees that are in the queue. Returns nothing if there are no trees left within the depth limit.
HerbSearch._is_field_decl — Method
_is_field_decl(ex)Check if extractname(ex) returns a name.
HerbSearch._is_kwdef — Method
is_kwdeg(ex)Checks if a field declaration is a keyword argument or not. This is called when filtering if the user arguments to the program iteartor are keyword arguments or not.
HerbSearch._processkwarg! — Method
_processkwarg!(keywords::Vector{Expr}, ex::Union{Expr,Symbol})Checks if ex has a default value specified, if so it returns only the field declaration, and pushes ex to keywords. Otherwise it returns ex
HerbSearch.accept — Method
accept(::StochasticSearchIterator, current_cost::Real, next_cost::Real, temperature::Real)Based on the current program and possible cost and temperature a program is accepted or not. Usually we would always want to accept better programs but we might get stuck if we do so. That is why some implementations of the accept function accept with a probability costs that are worse. cost means how different are the outcomes of the program compared to the correct outcomes. The lower the cost the better the program performs on the examples. The cost is provided by the cost_function
HerbSearch.best_accept — Method
best_accept(current_cost::Real, next_cost::Real, temperature::Real)Returns true if the cost of the proposed program is smaller than the cost of the current program. Otherwise, returns false.
Arguments
current_cost::Real: the cost of the current program.next_cost::Real: the cost of the proposed program.temperature::Real: the temperature; not used.
HerbSearch.calculate_cost — Method
calculate_cost(iter::T, program::Union{RuleNode, StateHole}) where T <: StochasticSearchIteratorWrapper around _calculate_cost.
HerbSearch.const_temperature — Method
const_temperature(current_temperature::Real)Returns the temperature unchanged. This function is used by Metropolis Hastings and Very Large Neighbourhood Search algorithms.
Arguments
current_temperature::Real: the current temperature of the search.
HerbSearch.constructNeighbourhood — Method
constructNeighbourhood(current_program::RuleNode, grammar::AbstractGrammar)The neighbourhood node location is chosen at random. The dictionary is nothing.
Arguments
current_program::RuleNode: the current program.grammar::AbstractGrammar: the grammar.
HerbSearch.constructNeighbourhoodRuleSubset — Method
constructNeighbourhoodRuleSubset(current_program::RuleNode, grammar::AbstractGrammar)The neighbourhood node location is chosen at random. The dictionary is contains one entry with key "rule_subset" and value of type Vector{Any} being a random subset of grammar rules.
Arguments
current_program::RuleNode: the current program.grammar::AbstractGrammar: the grammar.
HerbSearch.cross_over — Method
cross_over(::GeneticSearchIterator, parent_1::RuleNode, parent_2::RuleNode)Combines the program from two parent individuals to create one or more offspring individuals.
HerbSearch.crossover_swap_children_1 — Method
crossover_swap_children_1(parent_1::RuleNode, parent_2::RuleNode)Performs a random crossover of two parents of type RuleNode. The subprograms are swapped and only one altered parent program is returned.
HerbSearch.crossover_swap_children_2 — Method
crossover_swap_children_2(parent_1::RuleNode, parent_2::RuleNode)Performs a random crossover of two parents of type RuleNode. The subprograms are swapped and both altered parent programs are returned.
HerbSearch.decreasing_temperature — Method
decreasing_temperature(percentage::Real)Returns a function that produces a temperature decreased by percentage%. This function is used by the Simmulated Annealing algorithm.
Arguments
percentage::Real: the percentage to decrease the temperature by.
HerbSearch.default_fitness — Method
default_fitness(program, results)Defines the default fitness function taking the program and its results. Results are a vector of tuples, where each tuple is in the form Tuple{expected_output, actual_output}. As we are looking for individuals with the highest fitness function, the error is inverted.
HerbSearch.derivation_heuristic — Method
derivation_heuristic(iter::MLFSIterator, domain::Vector{Int})Defines derivation_heuristic for the iterator type MLFSIterator. Sorts the indices within a domain, that is grammar rules, by decreasing log_probabilities.
This will invert the enumeration order if probabilities are equal.
HerbSearch.derivation_heuristic — Method
function derivation_heuristic(::RandomIterator, indices::Vector{Int})Randomly shuffles the rules.
HerbSearch.derivation_heuristic — Method
function derivation_heuristic(::TopDownIterator, indices::Vector{Int})Returns a sorted sublist of the indices, based on which rules are most promising to fill a hole. The underlying solver can change the order within a Hole's domain. We sort the domain to make the enumeration order explicit and more predictable.
HerbSearch.enumerate_neighbours_propose — Method
enumerate_neighbours_propose(enumeration_depth::Int64)The return function is a function that produces a list with all the subprograms with depth at most enumeration_depth.
HerbSearch.evaluate — Method
evaluate(problem::Problem{Vector{IOExample}}, expr::Any, tab::SymbolTable; allow_evaluation_errors::Bool=false)Evaluate the expression on the examples.
Optional parameters:
- `shortcircuit` - Whether to stop evaluating after finding single example fails, to speed up the [synth](@ref) procedure. If true, the returned score is an underapproximation of the actual score.
- `allow_evaluation_errors` - Whether the search should continue if an exception is thrown in the evaluation or throw the errorReturns a score in the interval [0, 1]
HerbSearch.fitness — Method
fitness(::GeneticSearchIterator, program, results)Assigns a numerical value (fitness score) to each individual based on how closely it meets the desired objective.
HerbSearch.generate_branches — Method
Returns a vector of disjoint branches to expand the search tree at its current state. Example:
# pseudo code
Hole(domain=[2, 4, 5], children=[
Hole(domain=[1, 6]),
Hole(domain=[1, 6])
])If we split on the first hole, this function will create three branches.
(firsthole, 2)(firsthole, 4)(firsthole, 5)
HerbSearch.get_best_program — Method
get_best_program(population::Array{RuleNode}, iter::GeneticSearchIterator)::RuleNodeReturns the best program within the population with respect to the fitness function.
HerbSearch.get_solver — Method
get_solver(pi::ProgramIterator)Get the program iterator solver.
HerbSearch.heuristic_leftmost — Method
heuristic_leftmost(node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference}Defines a heuristic over holes, where the left-most hole always gets considered first. Returns a HoleReference once a hole is found. This is the default option for enumerators.
HerbSearch.heuristic_random — Method
heuristic_random(node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference}Defines a heuristic over holes, where random holes get chosen randomly using random exploration. Returns a HoleReference once a hole is found.
HerbSearch.heuristic_rightmost — Method
heuristic_rightmost(node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference}Defines a heuristic over holes, where the right-most hole always gets considered first. Returns a HoleReference once a hole is found.
HerbSearch.heuristic_smallest_domain — Method
heuristic_smallest_domain(node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference}Defines a heuristic over all available holes in the unfinished AST, by considering the size of their respective domains. A domain here describes the number of possible derivations with respect to the constraints. Returns a HoleReference once a hole is found.
HerbSearch.hole_heuristic — Method
hole_heuristic(::TopDownIterator, node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference}Defines a heuristic over variable shaped holes. Returns a HoleReference once a hole is found.
HerbSearch.mean_squared_error — Method
mean_squared_error(results::AbstractVector{Tuple{<:Number,<:Number}})Returns the mean squared error of results.
Arguments
results<:AbstractVector{<:Tuple{Number,Number}}: the vector of tuples, where each tuple is in the formTuple{expected_output, actual_output}.
HerbSearch.misclassification — Method
misclassification(results::AbstractVector{Tuple{<:Number,<:Number}})Returns the amount of misclassified examples, i.e. how many tuples with non-matching entries are there in results.
Arguments
results<:AbstractVector{<:Tuple{Number,Number}}: the vector of tuples, where each tuple is in the formTuple{expected_output, actual_output}.
HerbSearch.mutate! — Function
mutate!(::GeneticSearchIterator, program::RuleNode, grammar::AbstractGrammar, max_depth::Int = 2)Mutates the program of an invididual.
HerbSearch.mutate_random! — Function
mutate_random!(program::RuleNode, grammar::AbstractGrammar, max_depth::Int64 = 2)Mutates the given program by inserting a randomly generated sub-program at a random location.
HerbSearch.neighbourhood — Method
neighbourhood(iter::StochasticSearchIterator, current_program::RuleNode)Returns a node location from the neighbourhood of the current program.
HerbSearch.next_solution! — Method
next_solution!(iter::UniformIterator)::Union{RuleNode, StateHole, Nothing}Searches for the next unvisited solution. Returns nothing if all solutions have been found already.
HerbSearch.priority_function — Method
priority_function(::AbstractDFSIterator, g::AbstractGrammar, tree::AbstractRuleNode, parent_value::Union{Real, Tuple{Vararg{Real}}}, isrequeued::Bool)Assigns priority such that the search tree is traversed like in a DFS manner.
HerbSearch.priority_function — Method
priority_function(::MLFSIterator, grammar::AbstractGrammar, current_program::AbstractRuleNode, parent_value::Union{Real, Tuple{Vararg{Real}}}, isrequeued::Bool)Calculates the priority function of the MLFSIterator. The priority value of a tree is then the maxrulenodelog_probability within the represented uniform tree. The value is negated as lower priority values are popped earlier.
HerbSearch.priority_function — Method
priority_function(::RandomIterator, g::AbstractGrammar, tree::AbstractRuleNode, parent_value::Union{Real, Tuple{Vararg{Real}}}, isrequeued::Bool)Assigns a random priority to each state.
HerbSearch.priority_function — Method
priority_function(::TopDownIterator, g::AbstractGrammar, tree::AbstractRuleNode, parent_value::Union{Real, Tuple{Vararg{Real}}}, isrequeued::Bool)Assigns a priority value to a tree that needs to be considered later in the search. Trees with the lowest priority value are considered first.
- ``: The first argument is a dispatch argument and is only used to dispatch to the correct priority function
g: The grammar used for enumerationtree: The tree that is about to be stored in the priority queueparent_value: The priority value of the parentSolverStateisrequeued: The same tree shape will be requeued. The next time this tree shape is considered, theUniformSolverwill produce the next complete program deriving from this shape.
HerbSearch.probabilistic_accept — Method
probabilistic_accept(current_cost::Real, next_cost::Real, temperature::Real)Probabilistically decides whether to accept the new program (next) based on the ratio of costs (smaller is better) between the previous and new program. Returns True if the new program is accepted, False otherwise.
Arguments
current_cost::Real: the cost of the current program.next_cost::Real: the cost of the proposed program.temperature::Real: the temperature; not used.
HerbSearch.probabilistic_accept_with_temperature — Method
probabilistic_accept_with_temperature(current_cost::Real, next_cost::Real, temperature::Real)Returns true if the cost of the proposed program is smaller than the cost of the current program. Otherwise, returns true with the probability equal to:
\[1 / (1 + exp(delta / temperature))\]
In any other case, returns false.
Arguments
current_cost::Real: the cost of the current program.next_cost::Real: the cost of the proposed program.temperature::Real: the temperature of the search.
HerbSearch.probabilistic_accept_with_temperature_fraction — Method
probabilistic_accept_with_temperature_fraction(current_cost::Real, program_to_consider_cost::Real, temperature::Real)Probabilistically decides whether to accept the new program (next) based on the ratio of costs (smaller is better) between the previous and new program multiplied by the temperature. Returns True if the new program is accepted, False otherwise.
Arguments
current_cost::Real: the cost of the current program.next_cost::Real: the cost of the proposed program.temperature::Real: the current temperature
HerbSearch.propose — Method
propose(iter::StochasticSearchIterator, path::Vector{Int}, dict::Union{Nothing,Dict{String,Any}})Proposes a list of programs to fill in the location provided by path and the dict.
HerbSearch.random_fill_propose — Function
random_fill_propose(solver::Solver, path::Vector{Int}, dict::Union{Nothing,Dict{String,Any}}, nr_random=5)Returns a list with only one proposed, completely random, subprogram.
Arguments
solver::solver: solverpath::Vector{Int}: path to the location to be filled.dict::Dict{String, Any}: the dictionary with additional arguments; not used.nr_random=1 : the number of random subprograms to be generated.
HerbSearch.select_chromosome — Method
select_chromosome(population::Array{RuleNode}, fitness_array::Array{<:Real})::RuleNodeSelects a chromosome (individual) from the population based on a fitness array. The function uses a fitness-proportionate selection strategy, often referred to as "roulette wheel" selection. Assumes fitness_array to be normalized already.
HerbSearch.select_fitness_proportional_parents — Method
select_fitness_proportional_parents(population::Array{RuleNode}, fitness_array::Array{<:Real})::Tuple{RuleNode,RuleNode}Selects two parent chromosomes (individuals) from a population based on fitness-proportionate selection. The selected parents can be used for genetic crossover in the next steps of the algorithm.
HerbSearch.select_parents — Method
select_parents(::GeneticSearchIterator, population::Array{RuleNode}, fitness_array::Array{<:Real})Selects two parents for the crossover.
HerbSearch.set_stateholes! — Method
function set_stateholes!(iter::UniformIterator, node::Union{StateHole, RuleNode})::Vector{StateHole}Does a dfs to retrieve all unfilled state holes in the program tree and stores them in the stateholes vector.
HerbSearch.synth — Method
synth(problem::Problem, iterator::ProgramIterator; shortcircuit::Bool=true, allow_evaluation_errors::Bool=false, mod::Module=Main)::Union{Tuple{RuleNode, SynthResult}, Nothing}Synthesize a program that satisfies the maximum number of examples in the problem. - problem - The problem definition with IO examples - iterator - The iterator that will be used - shortcircuit - Whether to stop evaluating after finding a single example that fails, to speed up the synth procedure. If true, the returned score is an underapproximation of the actual score. - allowevaluationerrors - Whether the search should crash if an exception is thrown in the evaluation - maxtime - Maximum time that the iterator will run - maxenumerations - Maximum number of iterations that the iterator will run - mod - A module containing definitions for the functions in the grammar that do not exist in Main
Returns a tuple of the rulenode representing the solution program and a synthresult that indicates if that program is optimal. synth uses evaluate which returns a score in the interval [0, 1] and checks whether that score reaches 1. If not it will return the best program so far, with the proper flag
HerbSearch.temperature — Method
temperature(::StochasticSearchIterator, current_temperature::Real)Returns the new temperature based on the current temperature. A higher temperature means that the algorithm will explore more.
HerbSearch.validate_iterator — Method
validate_iterator(iter)Validates the parameters of the iterator
StatsBase.sample — Function
sample(root::RuleNode, typ::Symbol, grammar::AbstractGrammar, maxdepth::Int=typemax(Int))Uniformly samples a random node from the tree limited to maxdepth.
StatsBase.sample — Function
StatsBase.sample(::Type{NodeLoc}, root::RuleNode, typ::Symbol, grammar::AbstractGrammar, maxdepth::Int=typemax(Int))Uniformly selects a random node in the tree of a given type, specified using its parent such that the subtree can be replaced. Returns a NodeLoc.
StatsBase.sample — Function
sample(root::RuleNode, typ::Symbol, grammar::AbstractGrammar,
maxdepth::Int=typemax(Int))Uniformly selects a random node of the given return type typ limited by maxdepth.
StatsBase.sample — Function
sample(::Type{NodeLoc}, root::RuleNode, maxdepth::Int=typemax(Int))Uniformly selects a random node in the tree no deeper than maxdepth using reservoir sampling. Returns a NodeLoc that specifies the location using its parent so that the subtree can be replaced.
The HerbSearch package takes care of all operations related to searching for the desired program. This includes
- the functionality to sample a certain program given a grammar,
- the implementation of several heuristic functions,
- searching for a program that satisfies the specification, and
- implementations of several search algorithms in terms of how they enumerate the search space
- Breadth-First Search
- Depth-First Search
- Metropolis Hastings
- Very Large Scale Neighbourhood Search
- Simulated Annealing
- Genetic Search
Index
HerbConstraints.AbstractGrammarConstraintHerbConstraints.AbstractLocalConstraintHerbConstraints.AbstractStateManagerHerbConstraints.ContainsHerbConstraints.ContainsSubtreeHerbConstraints.DomainRuleNodeHerbConstraints.ForbiddenHerbConstraints.ForbiddenSequenceHerbConstraints.GenericSolverHerbConstraints.GenericSolverHerbConstraints.GenericSolverHerbConstraints.LessThanOrEqualHardFailHerbConstraints.LessThanOrEqualResultHerbConstraints.LessThanOrEqualSoftFailHerbConstraints.LessThanOrEqualSuccessHerbConstraints.LessThanOrEqualSuccessEqualityHerbConstraints.LessThanOrEqualSuccessLessThanHerbConstraints.LessThanOrEqualSuccessWithHolesHerbConstraints.LocalContainsHerbConstraints.LocalContainsSubtreeHerbConstraints.LocalContainsSubtreeHerbConstraints.LocalForbiddenHerbConstraints.LocalForbiddenSequenceHerbConstraints.LocalOrderedHerbConstraints.LocalUniqueHerbConstraints.MakeEqualHardFailHerbConstraints.MakeEqualResultHerbConstraints.MakeEqualSoftFailHerbConstraints.MakeEqualSuccessHerbConstraints.OrderedHerbConstraints.PatternMatchHardFailHerbConstraints.PatternMatchResultHerbConstraints.PatternMatchSoftFailHerbConstraints.PatternMatchSuccessHerbConstraints.PatternMatchSuccessWhenHoleAssignedToHerbConstraints.SolverHerbConstraints.SolverStateHerbConstraints.StateHoleHerbConstraints.StateHoleHerbConstraints.StateHoleHerbConstraints.StateIntHerbConstraints.StateIntBackupHerbConstraints.StateManagerHerbConstraints.StateSparseSetHerbConstraints.StateSparseSetHerbConstraints.StateStackHerbConstraints.StateStackHerbConstraints.StateStackHerbConstraints.UniformSolverHerbConstraints.UniformSolverHerbConstraints.UniqueHerbConstraints.VarNodeHerbCore.AbstractConstraintHerbCore.AbstractGrammarHerbCore.AbstractHoleHerbCore.AbstractRuleNodeHerbCore.AbstractUniformHoleHerbCore.HoleHerbCore.HoleReferenceHerbCore.RuleNodeHerbCore.RuleNodeHerbCore.RuleNodeHerbCore.UniformHoleHerbGrammar.ContextSensitiveGrammarHerbGrammar.NodeLocHerbGrammar.SymbolTableHerbSearch.AbstractBFSIteratorHerbSearch.AbstractDFSIteratorHerbSearch.AbstractMHSearchIteratorHerbSearch.AbstractSASearchIteratorHerbSearch.AbstractVLSNSearchIteratorHerbSearch.BFSIteratorHerbSearch.DFSIteratorHerbSearch.ExpandFailureReasonHerbSearch.GeneticSearchIteratorHerbSearch.MHSearchIteratorHerbSearch.MLFSIteratorHerbSearch.ProgramIteratorHerbSearch.RandomIteratorHerbSearch.SASearchIteratorHerbSearch.StochasticSearchIteratorHerbSearch.SynthResultHerbSearch.TopDownIteratorHerbSearch.UniformIteratorHerbSearch.UniformIteratorHerbSearch.VLSNSearchIteratorHerbSpecification.AbstractDependentTypeSpecificationHerbSpecification.AgdaSpecificationHerbSpecification.IOExampleHerbSpecification.MetricProblemHerbSpecification.ProblemHerbSpecification.SMTSpecificationHerbSpecification.TraceBase.collectBase.collectBase.findallBase.findfirstBase.findlastBase.getBase.getindexBase.getindexBase.inBase.inBase.insert!Base.islessBase.iterateBase.iterateBase.iterateBase.iterateBase.iterateBase.lengthBase.lengthBase.lengthBase.lengthBase.push!Base.randBase.randBase.randBase.showBase.sizeBase.sizeBase.sumHerbConstraints._containsHerbConstraints._count_occurrencesHerbConstraints._count_occurrencesHerbConstraints._count_occurrences!HerbConstraints._exchange_positions!HerbConstraints._update_bounds_val_removed!HerbConstraints._update_max_val_removed!HerbConstraints._update_min_val_removed!HerbConstraints.annotation2constraintHerbConstraints.are_disjointHerbConstraints.are_disjointHerbConstraints.backup!HerbConstraints.check_treeHerbConstraints.check_treeHerbConstraints.check_treeHerbConstraints.check_treeHerbConstraints.check_treeHerbConstraints.check_treeHerbConstraints.contains_varnodeHerbConstraints.deactivate!HerbConstraints.deactivate!HerbConstraints.decrement!HerbConstraints.fix_point!HerbConstraints.freeze_stateHerbConstraints.get_grammarHerbConstraints.get_grammarHerbConstraints.get_grammarHerbConstraints.get_hole_at_locationHerbConstraints.get_hole_at_locationHerbConstraints.get_intersectionHerbConstraints.get_max_depthHerbConstraints.get_max_depthHerbConstraints.get_max_sizeHerbConstraints.get_max_sizeHerbConstraints.get_nodesHerbConstraints.get_nodes_on_pathHerbConstraints.get_priorityHerbConstraints.get_starting_symbolHerbConstraints.get_starting_symbolHerbConstraints.get_stateHerbConstraints.get_treeHerbConstraints.get_treeHerbConstraints.get_tree_sizeHerbConstraints.get_valueHerbConstraints.increment!HerbConstraints.is_subdomainHerbConstraints.is_subdomainHerbConstraints.isfeasibleHerbConstraints.isfeasibleHerbConstraints.load_state!HerbConstraints.make_equal!HerbConstraints.make_less_than_or_equal!HerbConstraints.make_less_than_or_equal!HerbConstraints.make_less_than_or_equal!HerbConstraints.new_state!HerbConstraints.notify_new_nodeHerbConstraints.notify_new_nodesHerbConstraints.notify_new_nodesHerbConstraints.notify_tree_manipulationHerbConstraints.notify_tree_manipulationHerbConstraints.partitionHerbConstraints.pattern_matchHerbConstraints.pattern_matchHerbConstraints.pattern_matchHerbConstraints.pattern_matchHerbConstraints.pattern_matchHerbConstraints.pattern_matchHerbConstraints.post!HerbConstraints.post!HerbConstraints.propagate!HerbConstraints.propagate!HerbConstraints.propagate!HerbConstraints.propagate!HerbConstraints.propagate!HerbConstraints.propagate!HerbConstraints.propagate!HerbConstraints.remove!HerbConstraints.remove!HerbConstraints.remove!HerbConstraints.remove!HerbConstraints.remove!HerbConstraints.remove_above!HerbConstraints.remove_above!HerbConstraints.remove_above!HerbConstraints.remove_all_but!HerbConstraints.remove_all_but!HerbConstraints.remove_all_but!HerbConstraints.remove_all_but!HerbConstraints.remove_all_but!HerbConstraints.remove_all_but!HerbConstraints.remove_below!HerbConstraints.remove_below!HerbConstraints.remove_below!HerbConstraints.remove_node!HerbConstraints.restore!HerbConstraints.restore!HerbConstraints.restore!HerbConstraints.save_state!HerbConstraints.save_state!HerbConstraints.save_state!HerbConstraints.schedule!HerbConstraints.set_infeasible!HerbConstraints.set_infeasible!HerbConstraints.set_value!HerbConstraints.shouldscheduleHerbConstraints.shouldscheduleHerbConstraints.simplify_hole!HerbConstraints.substitute!HerbCore.contains_holeHerbCore.contains_holeHerbCore.contains_indexHerbCore.contains_nonuniform_holeHerbCore.depthHerbCore.get_childrenHerbCore.get_node_at_locationHerbCore.get_node_at_locationHerbCore.get_node_at_locationHerbCore.get_node_at_locationHerbCore.get_pathHerbCore.get_pathHerbCore.get_pathHerbCore.get_ruleHerbCore.get_ruleHerbCore.get_rulesequenceHerbCore.hasdynamicvalueHerbCore.have_same_shapeHerbCore.is_domain_validHerbCore.isfilledHerbCore.isfilledHerbCore.issameHerbCore.isuniformHerbCore.node_depthHerbCore.number_of_holesHerbCore.rulesoftypeHerbCore.rulesoftypeHerbCore.rulesonleftHerbCore.swap_nodeHerbCore.swap_nodeHerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbCore.update_rule_indices!HerbGrammar.add_rule!HerbGrammar.add_rule!HerbGrammar.add_rule!HerbGrammar.addconstraint!HerbGrammar.child_typesHerbGrammar.child_typesHerbGrammar.cleanup_removed_rules!HerbGrammar.clearconstraints!HerbGrammar.containedinHerbGrammar.contains_returntypeHerbGrammar.expr2csgrammarHerbGrammar.expr2pcsgrammarHerbGrammar.expr2rulenodeHerbGrammar.expr2rulenodeHerbGrammar.expr2rulenodeHerbGrammar.expr2rulenodeHerbGrammar.get_childtypesHerbGrammar.get_domainHerbGrammar.get_domainHerbGrammar.get_rulesequenceHerbGrammar.grammar2symboltableHerbGrammar.init_probabilities!HerbGrammar.iscompleteHerbGrammar.isevalHerbGrammar.isevalHerbGrammar.isevalHerbGrammar.isprobabilisticHerbGrammar.isterminalHerbGrammar.isterminalHerbGrammar.isterminalHerbGrammar.isvariableHerbGrammar.isvariableHerbGrammar.isvariableHerbGrammar.isvariableHerbGrammar.log_probabilityHerbGrammar.max_arityHerbGrammar.max_rulenode_log_probabilityHerbGrammar.merge_grammars!HerbGrammar.mindepthHerbGrammar.mindepth_mapHerbGrammar.nchildrenHerbGrammar.nchildrenHerbGrammar.nonterminalsHerbGrammar.normalize!HerbGrammar.parse_probabilistic_ruleHerbGrammar.probabilityHerbGrammar.read_csgHerbGrammar.read_pcsgHerbGrammar.remove_rule!HerbGrammar.return_typeHerbGrammar.return_typeHerbGrammar.return_typeHerbGrammar.root_node_locHerbGrammar.rulenode2exprHerbGrammar.rulenode_log_probabilityHerbGrammar.rulesonleftHerbGrammar.store_csgHerbGrammar.subsequenceofHerbGrammar.swap_nodeHerbGrammar.swap_nodeHerbInterpret.evaluate_programHerbInterpret.execute_on_inputHerbInterpret.execute_on_inputHerbInterpret.execute_on_inputHerbInterpret.execute_on_inputHerbInterpret.interpretHerbSearch._calculate_costHerbSearch._extract_name_from_argumentHerbSearch._find_next_complete_treeHerbSearch._is_field_declHerbSearch._is_kwdefHerbSearch._processkwarg!HerbSearch.acceptHerbSearch.best_acceptHerbSearch.calculate_costHerbSearch.const_temperatureHerbSearch.constructNeighbourhoodHerbSearch.constructNeighbourhoodRuleSubsetHerbSearch.cross_overHerbSearch.crossover_swap_children_1HerbSearch.crossover_swap_children_2HerbSearch.decreasing_temperatureHerbSearch.default_fitnessHerbSearch.derivation_heuristicHerbSearch.derivation_heuristicHerbSearch.derivation_heuristicHerbSearch.enumerate_neighbours_proposeHerbSearch.evaluateHerbSearch.fitnessHerbSearch.generate_branchesHerbSearch.get_best_programHerbSearch.get_solverHerbSearch.heuristic_leftmostHerbSearch.heuristic_randomHerbSearch.heuristic_rightmostHerbSearch.heuristic_smallest_domainHerbSearch.hole_heuristicHerbSearch.mean_squared_errorHerbSearch.misclassificationHerbSearch.mutate!HerbSearch.mutate_random!HerbSearch.neighbourhoodHerbSearch.next_solution!HerbSearch.priority_functionHerbSearch.priority_functionHerbSearch.priority_functionHerbSearch.priority_functionHerbSearch.probabilistic_acceptHerbSearch.probabilistic_accept_with_temperatureHerbSearch.probabilistic_accept_with_temperature_fractionHerbSearch.proposeHerbSearch.random_fill_proposeHerbSearch.select_chromosomeHerbSearch.select_fitness_proportional_parentsHerbSearch.select_parentsHerbSearch.set_stateholes!HerbSearch.synthHerbSearch.temperatureHerbSearch.validate_iteratorStatsBase.sampleStatsBase.sampleStatsBase.sampleStatsBase.sampleHerbConstraints.@csgrammar_annotatedHerbCore.@rulenodeHerbGrammar.@cfgrammarHerbGrammar.@csgrammarHerbGrammar.@pcsgrammarHerbSearch.@programiterator