A Generalized Weighted Optimization Method for Computational Learning and Inversion