[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [IMP-users] Visualizing entire scoring function (Optimization)



On 8/19/15 8:25 AM, Hughes, Katelyn Jean wrote:
Is there currently a way to return every score generated by the
scoring function (or the function itself) during the optimization
stage?
It would be tricky to record every call to the scoring function (I think 
the only way to do it would be to subclass ScoringFunction). But if 
you're only interested in a single score per optimizer step (not quite 
the same thing, since a step may involve multiple scores) then it's 
pretty straightforward. Simply make an OptimizerState that records the 
score. OptimizerStates get called by Optimizers once per accepted step. 
You can get the score from the Optimizer itself by calling its 
get_last_score() method. For example,
o = IMP.core.ConjugateGradients(m)
o.set_scoring_function(sf)

class ReportOptimizerState(IMP.OptimizerState):
    def __init__(self, *args, **keys):
        self.scores = []
        IMP.OptimizerState.__init__(self, *args, **keys)

    def do_update(self, i):
        score = self.get_optimizer().get_last_score()
        self.scores.append(score)

r = ReportOptimizerState(m, "reporter")
o.add_optimizer_state(r)
o.optimize(50)
print(r.scores)

	Ben
--
ben@salilab.org                      http://salilab.org/~ben/
"It is a capital mistake to theorize before one has data."
	- Sir Arthur Conan Doyle