jeudi 22 juin 2017

best practices: program flags and efficient options

I'm implementing an iterative optimization routine, and as a diagnostic, I'd like to have the option to store and return the intermediary values (so that I can plot the convergence versus iteration). The set up is something like

def alg(args,diagnostic=False):
    for i in range(n):
        ... optimize args ...

How can I provide an option to store the history without

  1. requiring an if diagnostic == True within my iteration loop
  2. requiring an if diagnostic == True outside of the loop and having two nearly identical implementations below to call run normal mode or diagnostic mode

Aucun commentaire:

Enregistrer un commentaire