예제 #1
0
    def display(self, report, full=False, nbins=100):  # @UnusedVariable
        """ Displays this diffeomorphism. """
        from diffeo2d import diffeo_stats
        print('getting stats')
        stats = diffeo_stats(self.d)
        angle = stats.angle
        norm = stats.norm
        
        print('getting colors')
        norm_rgb = self.get_rgb_norm()
        angle_rgb = self.get_rgb_angle()
        info_rgb = self.get_rgb_info()
        
        print('figures')
        f = report.figure(cols=6)
        f.data_rgb('norm_rgb', norm_rgb,
                    caption="Norm(D). white=0, blue=maximum (%.2f). " % np.max(norm))
        f.data_rgb('phase_rgb', angle_rgb,
                    caption="Phase(D).")
        
        if hasattr(self, 'variance_max'):
            varmax_text = '(variance max %s)' % self.variance_max
        else:
            varmax_text = ''  
        
        f.data_rgb('var_rgb', info_rgb,
                    caption='Uncertainty (green=sure, red=unknown %s)' % varmax_text)

        print('histogram of norm values')
        with f.plot('norm_hist', caption='histogram of norm values') as pylab:
            pylab.hist(norm.flat, nbins)
            
            ax = pylab.gca()
            ax.set_xlabel('pixels')
            ax2 = ax.twiny()
            new_tick_locations = ax.get_xticks()  # np.array(range(40))

            def tick_function(X):
                x = float(X * 1.0 / self.get_shape()[0])
                return '%.3f' % x

            ax2.set_xticks(new_tick_locations)
            ax2.set_xticklabels(map(tick_function, new_tick_locations))
            ax2.set_xlabel('viewport fraction (unitless)')

        print('histogram of certainty values')
        angles = np.array(angle.flat)
        valid_angles = angles[np.logical_not(np.isnan(angles))]
        if len(valid_angles) > 0:
            with f.plot('angle_hist', caption='histogram of angle values '
                        '(excluding where norm=0)') as pylab:
                pylab.hist(valid_angles, nbins)
            
        try:
            with f.plot('var_hist',
                        caption='histogram of certainty values') as pylab:
                pylab.hist(self.variance.flat, nbins)
        except:
            print('hist plot exception')
예제 #2
0
 def make_hard(dd):
     assert isinstance(dd, Diffeomorphism2D)
     if use_isomorphism_heuristics:
         stats = diffeo_stats(dd.d)
         per = np.percentile(stats.norm, norm_percentile)
         limit = per * factor
         # / 3.0
         # print('norm mean/mean: %g %g' % (np.mean(stats.norm), np.median(stats.norm)))            
         # for i in range(0, 100, 5):
         #    print(' %3d%% = %g' % (i, np.percentile(stats.norm, i)))
         # limit = np.percentile(stats.norm, info_percentile)
         # if limit <= 1:
         #    print('limit was %g' % limit)
         #    limit = 4
         variance = (stats.norm > limit).astype('float')
         logger.info('---hard choices---')
         logger.info('  per: %g pixels * %g =' % (per, factor))
         logger.info('limit: %g pixels' % limit)
         logger.info('  vis: %.1f%% ' % (100 * np.mean(variance)))
     else:
         variance = (dd.variance > info_threshold).astype('float')
     return Diffeomorphism2D(dd.d, variance)
예제 #3
0
    def display(self, report, full=False, nbins=100):  # @UnusedVariable
        """ Displays this diffeomorphism. """
        from diffeo2d import diffeo_stats
        print('getting stats')
        stats = diffeo_stats(self.d)
        angle = stats.angle
        norm = stats.norm

        print('getting colors')
        norm_rgb = self.get_rgb_norm()
        angle_rgb = self.get_rgb_angle()
        info_rgb = self.get_rgb_info()

        print('figures')
        f = report.figure(cols=6)
        f.data_rgb('norm_rgb',
                   norm_rgb,
                   caption="Norm(D). white=0, blue=maximum (%.2f). " %
                   np.max(norm))
        f.data_rgb('phase_rgb', angle_rgb, caption="Phase(D).")

        if hasattr(self, 'variance_max'):
            varmax_text = '(variance max %s)' % self.variance_max
        else:
            varmax_text = ''

        f.data_rgb('var_rgb',
                   info_rgb,
                   caption='Uncertainty (green=sure, red=unknown %s)' %
                   varmax_text)

        print('histogram of norm values')
        with f.plot('norm_hist', caption='histogram of norm values') as pylab:
            pylab.hist(norm.flat, nbins)

            ax = pylab.gca()
            ax.set_xlabel('pixels')
            ax2 = ax.twiny()
            new_tick_locations = ax.get_xticks()  # np.array(range(40))

            def tick_function(X):
                x = float(X * 1.0 / self.get_shape()[0])
                return '%.3f' % x

            ax2.set_xticks(new_tick_locations)
            ax2.set_xticklabels(map(tick_function, new_tick_locations))
            ax2.set_xlabel('viewport fraction (unitless)')

        print('histogram of certainty values')
        angles = np.array(angle.flat)
        valid_angles = angles[np.logical_not(np.isnan(angles))]
        if len(valid_angles) > 0:
            with f.plot('angle_hist',
                        caption='histogram of angle values '
                        '(excluding where norm=0)') as pylab:
                pylab.hist(valid_angles, nbins)

        try:
            with f.plot('var_hist',
                        caption='histogram of certainty values') as pylab:
                pylab.hist(self.variance.flat, nbins)
        except:
            print('hist plot exception')