Estimating density functions: a constrained maximum likelihood approach