An Information-Theoretic Approach to Optimal Neural-Network-Based Compression