maximum_entropy_spatial_layout.py 1.7 KB

12345678910111213141516171819202122232425262728293031
  1. import h5py
  2. import numpy as np
  3. import scripts.spatial_layout
  4. from scripts.interneuron_placement import get_optimal_orientations_for_maximum_entropy
  5. from scripts.spatial_network.run_entropy_maximisation_orientation_map import get_orientation_map
  6. from scripts.spatial_packing_entropy.sample_spatial_layout import correlation_length, map_seed, sheet_size, NE, \
  7. data_folder, NI, long_axis, short_axis, number_of_bins, ds
  8. if __name__ == "__main__":
  9. orientation_map = get_orientation_map(correlation_length, map_seed, sheet_size, NE, data_folder=data_folder)
  10. spatial_layout = scripts.spatial_layout.SpatialLayout(orientation_map, NE, NI, long_axis, short_axis, sheet_size)
  11. _, optimal_orientations = get_optimal_orientations_for_maximum_entropy(spatial_layout.ex_positions,
  12. spatial_layout.ex_tunings,
  13. spatial_layout.in_positions, spatial_layout.long_axis,
  14. spatial_layout.short_axis, number_of_bins, trial_orientations=50)
  15. optimal_orientations = np.array(optimal_orientations)
  16. with h5py.File(data_folder + 'spatial_layouts.hdf5', "a") as f:
  17. entropy = 'max_entropy'
  18. if entropy not in f.keys():
  19. entropy_grp = f.create_group(entropy)
  20. else:
  21. entropy_grp = f[entropy]
  22. entropy_grp.create_dataset("entropy", shape=(), data=spatial_layout.get_mean_entropy(optimal_orientations, number_of_bins))
  23. entropy_grp.create_dataset("overlap", shape=(), data=spatial_layout.get_overlap(optimal_orientations, ds))
  24. entropy_grp.create_dataset("orientations", shape=(NI,), data = optimal_orientations)