Fitting stochastic blockmodels to graphs