Table Of Contents

Previous topic

tabusearch.py

Next topic

omatrix.py

This Page

ologger.py

SIMO optimization logger

class OLogger(object):

Class for logging the performance and statistics of SIMO optimization algorithms.

def __init__(self, logger, logname, chart_path):

Initialize optimization logger

>>> from minimock import Mock
>>> logger = Mock('Logger')
>>> logname = 'MOCK'
>>> chart_path = 'optimization/test'
>>> from simo.optimization.tools.ologger import OLogger
>>> ol = OLogger(logger, logname, chart_path)

def start(self, iteration, nbranches, target):

Start logging of the optimization process

Parameters:

iteration -- current simulated iteration
branches -- branch ids for each unit
target -- optimization target, ie. "min" or "max"
>>> import numpy
>>> nbranches = {0:[0, 1], 1:[0], 2:[0, 1, 2, 3], 3:[0, 1, 2]}
>>> ol.start(1, nbranches, 'max') 
Called Logger.log_message(
    'MOCK',
    'INFO',
    'Optimization started for simulated iteration 1')
Called Logger.log_message('MOCK', 'INFO', '  total number of units: 4')
Called Logger.log_message(
    'MOCK',
    'INFO',
    '  total number of treatment schedules: 10')
Called Logger.log_message(
    'MOCK',
    'INFO',
    '  average number of treatment schedules per unit: 2.50')
Called Logger.log_message(...'MOCK',
    'INFO',
    '  total solution space size: 2.50^4')

def add_round(self, currsol, currval, bestval):

Add current iterative round parameters to the logger

Parameters:

currsol -- current solution
currcal -- current utility value
bestval -- best utility value so far
>>> currsol = numpy.zeros(4, dtype=int)
>>> ol.add_round(currsol, 1.0, 1.0)
>>> ol.add_round(currsol, 1.5, 1.5)
>>> ol.add_round(currsol, 1.2, 1.5)
>>> ol.add_round(currsol, 2.0, 2.0)
>>> ol.add_round(currsol, 1.6, 2.0)
>>> ol.add_round(currsol, 1.8, 2.0)
>>> ol._num_of_rounds
6
>>> ['%.1f' % i for i in ol._curr_values]
['1.0', '1.5', '1.2', '2.0', '1.6', '1.8']
>>> ol._best_values
[1.0, 1.5, 1.5, 2.0, 2.0, 2.0]

def add_repeat(self, iteration):

Add a single repeat of the whole optimization process

>>> ol.add_repeat()
Called Logger.log_message(
    'MOCK',
    'INFO',
    'Optimization process repeated 1 time(s)')
>>> ol.add_repeat()
Called Logger.log_message(
    'MOCK',
    'INFO',
    'Optimization process repeated 2 time(s)')

def stop(self, iteration):

Stop logging of the optimization process

Parameters:

iteration -- current simulated iteration
>>> ol.stop(5)  
Called Logger.log_message(
    'MOCK',
    'INFO',
    'Optimization process performed successfully in ... min')

def _save_stats(self, iteration):

Save the statistics of the current optimization process

>>> ol._save_stats(5) 
Called Logger.log_message('MOCK', 'INFO', 'Saving optimization log')