The following answers are taken directly from the 802.11 standard (2012 version).
The PTK is generated as follows: $$\mathrm{PTK} \gets \operatorname{\mathrm{PRF-X}(PMK, ``pairwise \ key \ expansion", \\ min(AA, SPA) || max(AA,SPA)|| \\ min(ANonce, SNonce) || max(ANonce, SNonce)) } $$ where $\operatorname{\mathrm{PRF-X}}$ for$\mathrm{AA}$ and $X = 128,192,256,384,512$$\mathrm{SPA}$ are the MAC addresses of the Authenticator and Supplicant, respectively. The pseudorandom function $\operatorname{\mathrm{PRF-X}}$ is defined as follows for $X = 128,192,256,384,512$:
PRF-X(K,A,B): for i = 0 to (X + 159) / 160: Z = Z || HMAC-SHA1(K, A || 0 || B || i) return LeftBits(Z,0,X)
PRF-X(K,A,B): for i = 0 to (X + 159) / 160: Z = Z ||The MICs are computed using either HMAC-SHA1(K, A || 0 || B || i) return LeftBits-128 or AES-CMAC-128 (Z,0,Xwhich one to use is negotiated during the handshake).
The GTK is simply chosen at random by the AP.