Counters
OptimizationModels.Counter — Type
CounterA counter for partial evaluations of typical quantities used in solving optimization problems. These counters can be used in a number of contexts:
- Block Selection: For evaluations of objective information (e.g., objective functions, gradient functions, etc.) that only make use of a subset of the parameters.
- Batch Selection: For evaluations of objective information (e.g., objective fucntions, gradient functions, etc.) that is written as the sum of multiple components, but only a subset of the components are used.
- Block and Batch Selection: Simultaneously doing both of the above situations.
Fields
block_total::Int64, the number of parametersbatch_total::Int64, the number of additive terms in the objective functionblock_equivalent::Float64, the equivalent number ofbatch_totalevaluations given a certain number of coordinate evaluationsbatch_equivalent::Float64, the equivalent number ofblock_totalevaluations given evaluations of objective information using only a subset of the additive terms.
Constructor(s)
Counter(;block_total::Int64=1, batch_total::Int64=1)Creates a Counter object with block_equivalent and batch_equivalent set to zero. The optional block_total and batch_total are set to 1.
Incrementing Counters
OptimizationModels.increment_block! — Function
increment_block!(counter::Counter; size::Int64=1)Increments the counter.block_equivalent by size/counter.block_equivalent.
OptimizationModels.increment_batch! — Function
increment_batch!(counter::Counter; size::Int64=1)Increments the counter.batch_equivalent by size/counter.batch_equivalent.
OptimizationModels.increment! — Function
increment!(counter::Counter; batch_size::Int64=0, block_size::Int64=0)Increments the counter.block_equivalent and counter.batch_equivalent by block_size/counter.block_total and batch_size/counter.batch_total.
Resetting Counters
OptimizationModels.reset_block! — Function
reset_block!(counter::Counter)Resets the counter.block_equivalent to 0.0.
OptimizationModels.reset_batch! — Function
reset_batch!(counter::Counter)Resets the counter.batch_equivalent to 0.0.
OptimizationModels.reset! — Function
reset!(counter::Counter)Resets the counter.block_equivalent and counter.batch_equivalent to 0.
Validating Counters
Allowed counters are defined within the module as an element of
[
:obj,
:grad,
:hess,
:residual,
:jacobian,
]The following function can be used to validate a dictionary of counters.
OptimizationModels.validate_counters — Function
validate_counters(counters::Dict{Symbol, Counter})Validates that counter names are in the allowable list. Throws an error if the list is invalid. Returns nothing if valid.
Printing
Counters and dictionaries of counters can be printed using the print or println functions.