def test_lifetime_sparsity_values(self): feat_maps = np.zeros([10, 1, 1, 3]) feat_maps[:5, :, :, 1] = 1.0 feat_maps[..., 2] = 1.0 sparsity = lifetime_sparsity(feat_maps) self.assertAlmostEqual(sparsity[0], 1.0) self.assertAlmostEqual(sparsity[1], 0.55, places=1) self.assertAlmostEqual(sparsity[2], 0.0)
# mean acts, mean sparsity, and number active plt.errorbar(x = list(range(mean_acts.size)), y = mean_acts, yerr = se_acts) plt.xlabel('Neuron Index') plt.ylabel('Mean Activation +/- 1 SE') plt.savefig(os.path.join(args.save_dir, 'mean_activations_line.png'), bbox_inches = 'tight') plt.close() seaborn.boxplot(y = mean_acts) plt.ylabel('Mean Activation') plt.savefig(os.path.join(args.save_dir, 'mean_activations_box.png'), bbox_inches = 'tight') plt.close() logging.info('PLOTTING LIFETIME SPARSITY') lifetime = lifetime_sparsity(acts) lifetime.sort() plt.plot(lifetime[::-1]) plt.xlabel('Neuron Index') plt.ylabel('Lifetime Sparsity') plt.savefig(os.path.join(args.save_dir, 'lifetime_sparsity_line.png'), bbox_inches = 'tight') plt.close() seaborn.boxplot(y = lifetime) plt.ylabel('Lifetime Sparsity') plt.savefig(os.path.join(args.save_dir, 'lifetime_sparsity_box.png'), bbox_inches = 'tight') plt.close() logging.info('PLOTTING POPULATION SPARSITY')
def test_lifetime_sparsity_shape_hw_equal_1(self): feat_maps = np.zeros([10, 1, 1, 7]) sparsity = lifetime_sparsity(feat_maps) self.assertEqual(sparsity.size, 7)