How can I use "Epoch" as a variable?

27 views (last 30 days)
Eli on 26 Sep 2022
Commented: Rena Berman on 15 Nov 2022 at 15:10
one option in the ADAM-Training options is to use
'OutputFcn', 'Epoch' ...
Matlab won't recognize 'OutputFcn' as a option in my code....
I mainly need the "Epoch" as a variable, so I can use it as a input variable in one of my layers.
What is the name of the variable "Epoch" within the "trainNetwork" function?
Rena Berman
Rena Berman on 15 Nov 2022 at 15:10
(Answers Dev) Restored edit

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 26 Sep 2022
OutputFcn is defined as requiring a function handle or cell array of function handles.
For backwards compatibility, the name of a function might possibly be permitted, but in that case the function name would be searched within the base workspace, so it would need to refer to a "top-level" function -- either a built-in function or else a function that has a .m file named after it. For example if Epoch.m existed then possibly 'Epoch' might be accepted. But considering that ADAM is relatively recent, they might possibly not have bothered to program in support for function names (which have been discouraged in such contexts for over 20 years.) We recommend against using the names of functions.
If Epoch is the name of a variable that is storing a function handle, then use it without quotes, like 'OutputFcn', Epoch
If Epoch is the name of a function, then use @ with it, like 'OutputFcn', @Epoch
I mainly need the "Epoch" as a variable
OutputFcn does not support naming variables to be output, it only supports functions.
You could use 'OutputFcn', @(info)info.Epoch ... but the result is that the code will stop running on the first epoch:
To stop training early, make your output function return 1 (true). If any output function returns 1 (true), then training finishes and trainNetwork returns the latest network
(The reference to "true" tends to imply that really it tests for non-zero to terminate.)
so I can use it as a input variable in one of my layers.
OutputFcn does not permit you to import a computed value into a layer. OutputFcn just runs, and is expected to display something to the user, or plot something, or save a file or append to a shared (or global) variable; the only thing returned by an OutputFcn is whether to stop execution or not.
Walter Roberson
Walter Roberson on 30 Sep 2022
If you try
options = trainingOptions("adam", 'OutputFcn', @fprintf)
then is that rejected by your MATLAB version ?

Sign in to comment.

More Answers (0)


Find more on Historical Contests in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!