HBLRWrapper.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:PersonalizedMultitaskLearning 作者: mitmedialab 项目源码 文件源码
def saveHintonPlot(self, matrix, num_tests, max_weight=None, ax=None):
        """Draw Hinton diagram for visualizing a weight matrix."""
        fig,ax = plt.subplots(1,1)

        if not max_weight:
            max_weight = 2**np.ceil(np.log(np.abs(matrix).max())/np.log(2))

        ax.patch.set_facecolor('gray')
        ax.set_aspect('equal', 'box')
        ax.xaxis.set_major_locator(plt.NullLocator())
        ax.yaxis.set_major_locator(plt.NullLocator())

        for (x, y), w in np.ndenumerate(matrix):
            color = 'white' if w > 0 else 'black'
            size = np.sqrt(np.abs(0.5*w/num_tests)) # Need to scale so that it is between 0 and 0.5
            rect = plt.Rectangle([x - size / 2, y - size / 2], size, size,
                                 facecolor=color, edgecolor=color)
            ax.add_patch(rect)

        ax.autoscale_view()
        ax.invert_yaxis()
        plt.savefig(self.figures_path + self.save_prefix + '-Hinton.eps')
        plt.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号