Record values
To record values during the iterations of a solver run, there are in general two possibilities. On the one hand, the high-level interfaces provide a record=
keyword, that accepts several different inputs. For more details see How to record.
For example recording the gradient from the GradientDescentOptions
is automatically available, as explained in the gradient_descent
solver.
Record Options
Manopt.RecordAction
— TypeRecordAction
A RecordAction
is a small functor to record values. The usual call is given by (p,o,i) -> s
that performs the record based on a Problem
p
, Options
o
and the current iterate i
.
By convention i<=0
is interpreted as "For Initialization only", i.e. only initialize internal values, but not trigger any record, the same holds for i=typemin(Inf)
which is used to indicate stop
, i.e. that the record is called from within stop_solver!
which returns true afterwards.
Fields (assumed by subtypes to exist)
recorded_values
anArray
of the recorded values.
Manopt.RecordChange
— TypeRecordChange <: RecordAction
debug for the amount of change of the iterate (stored in o.x
of the Options
) during the last iteration.
Additional Fields
storage
aStoreOptionsAction
to store (at least)o.x
to use this as the last value (to compute the changeinvretr
- (default_inverse_retraction_method(manifold)
) the inverse retraction to be used for approximating distance.
Additional constructor keyword parameters
manifold
(DefaultManifold(1)
) manifold whose default inverse retraction should be used
for approximating the distance.
Manopt.RecordCost
— TypeRecordCost <: RecordAction
record the current cost function value, see get_cost
.
Manopt.RecordEntry
— TypeRecordEntry{T} <: RecordAction
record a certain fields entry of type {T} during the iterates
Fields
recorded_values
– the recorded Iteratesfield
– Symbol the entry can be accessed with withinOptions
Manopt.RecordEntryChange
— TypeRecordEntryChange{T} <: RecordAction
record a certain entries change during iterates
Additional Fields
recorded_values
– the recorded Iteratesfield
– Symbol the field can be accessed with withinOptions
distance
– function (p,o,x1,x2) to compute the change/distance between two values of the entrystorage
– aStoreOptionsAction
to store (at least)getproperty(o, d.field)
Manopt.RecordEvery
— TypeRecordEvery <: RecordAction
record only every $i$th iteration. Otherwise (optionally, but activated by default) just update internal tracking values.
This method does not perform any record itself but relies on it's childrens methods
Manopt.RecordGroup
— TypeRecordGroup <: RecordAction
group a set of RecordAction
s into one action, where the internal RecordAction
s act independently, but the results can be collected in a grouped fashion, i.e. tuples per calls of this group. The enries can be later addressed either by index or semantic Symbols
Constructors
RecordGroup(g::Array{<:RecordAction, 1})
construct a group consisting of an Array of RecordAction
s g
,
RecordGroup(g, symbols)
Examples
r = RecordGroup([RecordIteration(), RecordCost()])
A RecordGroup to record the current iteration and the cost. The cost can then be accessed using get_record(r,2)
or r[2]
.
r = RecordGroup([RecordIteration(), RecordCost()], Dict(:Cost => 2))
A RecordGroup to record the current iteration and the cost, wich can then be accesed using get_record(:Cost)
or r[:Cost]
.
r = RecordGroup([RecordIteration(), :Cost => RecordCost()])
A RecordGroup identical to the previous constructor, just a little easier to use.
Manopt.RecordIterate
— TypeRecordIterate <: RecordAction
record the iterate
Constructors
RecordIterate(x0)
initialize the iterate record array to the type of x0
, e.g. your initial data.
RecordIterate(P)
initialize the iterate record array to the data type T
.
Manopt.RecordIteration
— TypeRecordIteration <: RecordAction
record the current iteration
Manopt.RecordOptions
— TypeRecordOptions <: Options
append to any Options
the decorator with record functionality, Internally a Dict
ionary is kept that stores a RecordAction
for several concurrent modes using a Symbol
as reference. The default mode is :Iteration
, which is used to store information that is recorded during the iterations. RecordActions might be added to :Start
or :Stop
to record values at the beginning or for the stopping time point, respectively
The original options can still be accessed using the get_options
function.
Fields
options
– the options that are extended by debug informationrecordDictionary
– aDict{Symbol,RecordAction}
to keep track of all different recorded values
Constructors
RecordOptions(o,dR)
construct record decorated Options
, where dR
can be
- a
RecordAction
, then it is stored within the dictionary at:Iteration
- an
Array
ofRecordAction
s, then it is stored as arecordDictionary
(@ref) within the dictionary at:All
. - a
Dict{Symbol,RecordAction}
.
Manopt.RecordTime
— TypeRecordTime <: RecordAction
record the time elapsed during the current iteration.
The three possible modes are
:cumulative
record times without resetting the timer:iterative
record times with resetting the timer:total
record a time only at the end of an algorithm (seestop_solver!
)
The default is :cumulative
, and any non-listed symbol default to using this mode.
Constructor
RecordTime(; mode::Symbol=:cumulative)
Base.getindex
— Methodgetindex(r::RecordGroup, s::Symbol)
r[s]
getindex(r::RecordGroup, sT::NTuple{N,Symbol})
r[sT]
getindex(r::RecordGroup, i)
r[i]
return an array of recorded values with respect to the s
, the symbols from the tuple sT
or the index i
. See get_record
for details.
Base.getindex
— Methodget_index(ro::RecordOptions, s::Symbol)
ro[s]
Get the recorded values for reording type s
, see get_record
for details.
get_index(ro::RecordOptions, s::Symbol, i...)
ro[s, i...]
Acces the recording type of type s
and call its RecordAction
with [i...]
.
Manopt.RecordActionFactory
— MethodRecordActionFactory(s)
create a RecordAction
where
- a
RecordAction
is passed through - a [
Symbol
] createsRecordEntry
of that symbol, with the exceptions of:Change
- to recorde the change of the iterates ino.x
`:Iterate
- to record the iterate:Iteration
- to record the current iteration numner:Cost
- to record the current cost function value:Time
- to record the total time taken after every iteration:IterativeTime
– to record the times taken for each iteration.
Manopt.RecordFactory
— MethodRecordFactory(o::Options, a)
given an array of Symbol
s and RecordAction
s and Ints
- The symbol
:Cost
creates aRecordCost
- The symbol
:iteration
creates aRecordIteration
- The symbol
:Change
creates aRecordChange
- any other symbol creates a
RecordEntry
of the corresponding field inOptions
- any
RecordAction
is directly included - an semantic pair
:symbol => RecordAction
is directly included - an Integer
k
introduces that record is only performed everyk
th iteration
Manopt.get_record
— Functionget_record(o::Options, [,s=:Iteration])
get_record(o::RecordOptions, [,s=:Iteration])
return the recorded values from within the RecordOptions
o
that where recorded with respect to the Symbol s
as an Array
. The default refers to any recordings during an :Iteration
.
When called with arbitrary Options
, this method looks for the RecordOptions
decorator and calls get_record
on the decorator.
Manopt.get_record
— Methodget_record(r::RecordAction)
return the recorded values stored within a RecordAction
r
.
Manopt.get_record
— Methodget_record(r::RecordGroup)
return an array of tuples, where each tuple is a recorded set, e.g. per iteration / record call.
get_record(r::RecordGruop, i::Int)
return an array of values corresponding to the i
th entry in this record group
get_record(r::RecordGruop, s::Symbol)
return an array of recorded values with respect to the s
, see RecordGroup
.
get_record(r::RecordGroup, s1::Symbol, s2::Symbol,...)
return an array of tuples, where each tuple is a recorded set corresponding to the symbols s1, s2,...
per iteration / record call.
Manopt.get_record_action
— Functionget_record_action(o::Options, s::Symbol)
return the action contained in the (first) RecordOptions
decorator within the Options
o
.
Manopt.get_record_options
— Methodget_record_options(o::Options)
return the RecordOptions
among the decorators from the Options
o
Manopt.has_record
— Methodhas_record(o::Options)
check whether the Options
o
are decorated with RecordOptions
Manopt.record_or_reset!
— Methodrecord_or_reset!(r,v,i)
either record (i>0
and not Inf
) the value v
within the RecordAction
r
or reset (i<0
) the internal storage, where v
has to match the internal value type of the corresponding Recordaction.
see recording values for details on the decorated solver.
Further specific RecordAction
s can be found when specific types of Options
define them on their corresponding site.
Technical Details: The Record Solver
Manopt.initialize_solver!
— Methodinitialize_solver!(p,o)
Initialize the solver to the optimization Problem
by initializing the encapsulated options
from within the RecordOptions
o
.
Manopt.step_solver!
— Methodstep_solver!(p,o,iter)
Do one iteration step (the iter
th) for Problem
p
by modifying the values in the Options
o.options
and record the result(s).
Manopt.stop_solver!
— Methodstop_solver!(p,o,i)
determine whether the solver for Problem
p
and the RecordOptions
o
should stop at iteration i
. If so, do a (final) record to :All
and :Stop
.