theanets/graph.py
def monitors(self, **kwargs):
        '''Return expressions that should be computed to monitor training.

        Returns
        -------
        monitors : list of (name, expression) pairs
            A list of named monitor expressions to compute for this network.
        '''
        regs = regularizers.from_kwargs(self, **kwargs)
        outputs, _ = self.build_graph(regs)
        monitors = [('err', self.losses[0](outputs))]

        def matching(pattern):
            '''Yield all matching outputs or parameters from the graph.'''
            for name, expr in util.outputs_matching(outputs, pattern):
                yield name, expr
            for name, expr in util.params_matching(self.layers, pattern):
                yield name, expr

        def parse_levels(levels):
            '''Yield named monitor callables.'''
            if isinstance(levels, dict):
                levels = levels.items()
            if isinstance(levels, (int, float)):
                levels = [levels]
            for level in levels:
                if isinstance(level, (tuple, list)):
                    label, call = level
                    yield ':{}'.format(label), call
                if isinstance(level, (int, float)):
                    def call(expr):
                        return (expr < level).mean()
                    yield '<{}'.format(level), call

        inputs = kwargs.get('monitors', {})
        if isinstance(inputs, dict):
            inputs = inputs.items()
        for pattern, levels in inputs:
            for name, expr in matching(pattern):
                for key, value in parse_levels(levels):
                    monitors.append(('{}{}'.format(name, key), value(expr)))

        return monitors
def monitors(self, **kwargs):
        '''Return expressions that should be computed to monitor training.

        Returns
        -------
        monitors : list of (name, expression) pairs
            A list of named monitor expressions to compute for this network.
        '''
        regs = regularizers.from_kwargs(self, **kwargs)
        outputs, _ = self.build_graph(regs)
        monitors = [('err', self.losses[0](outputs))]

        def matching(pattern):
            '''Yield all matching outputs or parameters from the graph.'''
            for name, expr in util.outputs_matching(outputs, pattern):
                yield name, expr
            for name, expr in util.params_matching(self.layers, pattern):
                yield name, expr

        def parse_levels(levels):
            '''Yield named monitor callables.'''
            if isinstance(levels, dict):
                levels = levels.items()
            if isinstance(levels, (int, float)):
                levels = [levels]
            for level in levels:
                if isinstance(level, (tuple, list)):
                    label, call = level
                    yield ':{}'.format(label), call
                if isinstance(level, (int, float)):
                    def call(expr):
                        return (expr < level).mean()
                    yield '<{}'.format(level), call

        inputs = kwargs.get('monitors', {})
        if isinstance(inputs, dict):
            inputs = inputs.items()
        for pattern, levels in inputs:
            for name, expr in matching(pattern):
                for key, value in parse_levels(levels):
                    monitors.append(('{}{}'.format(name, key), value(expr)))

        return monitors
def monitors ( self , * * kwargs ) : regs = regularizers . from_kwargs ( self , * * kwargs ) outputs , _ = self . build_graph ( regs ) monitors = [ ( 'err' , self . losses [ 0 ] ( outputs ) ) ] def matching ( pattern ) : '''Yield all matching outputs or parameters from the graph.''' for name , expr in util . outputs_matching ( outputs , pattern ) : yield name , expr for name , expr in util . params_matching ( self . layers , pattern ) : yield name , expr def parse_levels ( levels ) : '''Yield named monitor callables.''' if isinstance ( levels , dict ) : levels = levels . items ( ) if isinstance ( levels , ( int , float ) ) : levels = [ levels ] for level in levels : if isinstance ( level , ( tuple , list ) ) : label , call = level yield ':{}' . format ( label ) , call if isinstance ( level , ( int , float ) ) : def call ( expr ) : return ( expr < level ) . mean ( ) yield '<{}' . format ( level ) , call inputs = kwargs . get ( 'monitors' , { } ) if isinstance ( inputs , dict ) : inputs = inputs . items ( ) for pattern , levels in inputs : for name , expr in matching ( pattern ) : for key , value in parse_levels ( levels ) : monitors . append ( ( '{}{}' . format ( name , key ) , value ( expr ) ) ) return monitors
Return expressions that should be computed to monitor training.

        Returns
        -------
        monitors : list of (name, expression) pairs
            A list of named monitor expressions to compute for this network.
Return expressions that should be computed to monitor training .