**M. Johansson and K. Rasmussen
**

We extend earlier work [K. Rasmussen et al., Phys. Rev. Lett. 84, 3740 (2000)] on the statistical mechanics of the cubic one-dimensional discrete nonlinear Schroedinger (DNLS) equation to a more general class of models, including higher dimensionalities and nonlinearities of arbitrary degree. These extensions are physically motivated e.g. by the desire to describe situations with an excitation threshold for creation of localized excitations, as well as by recent suggestions for non-cubic DNLS models to describe Bose-Einstein condensates in deep optical lattices, taking into account the effective condensate dimensionality. Considering ensembles of initial conditions with given values of the two conserved quantities, norm and Hamiltonian, we calculate analytically the boundary of the 'normal' Gibbsian regime corresponding to infinite temperature, and perform numerical simulations to illuminate the nature of the localization dynamics outside this regime for various cases. Furthermore, we show quantitatively how this DNLS localization transition manifests itself for small-amplitude oscillations in generic Klein-Gordon lattices of weakly coupled anharmonic oscillators (in which energy is the only conserved quantity), and determine conditions for existence of persistent energy localization over large time scales.