We can't use an ensemble average directly for the entropy, because it doesn't make sense to talk about the entropy of a microstate. But we can talk about the entropy of the ensemble since the many copies can be in many different microstates. So we define the entropy of the system as the entropy of the ensemble divided by the number of copies, , in the ensemble: .
The ensemble has copies in the th microstate, so the number of ways of arranging these is
So, using Stirling's approximation,
For a system in contact with a heat bath, is given by the Boltzmann distribution, so