Adaptation Algorithm and Theory Based on Generalized Discrepancy