  Though federated learning (FL) well preserves clients' data privacy, many
clients are still reluctant to join FL given the communication cost and energy
consumption in their mobile devices. It is important to design pricing
compensations to motivate enough clients to join FL and distributively train
the global model. Prior pricing mechanisms for FL are static and cannot adapt
to clients' random arrival pattern over time. We propose a new dynamic pricing
solution in closed-form by constructing the Hamiltonian function to optimally
balance the client recruitment time and the model training time, without
knowing clients' actual arrivals or training costs. During the client
recruitment phase, we offer time-dependent monetary rewards per client arrival
to trade-off between the total payment and the FL model's accuracy loss. Such
reward gradually increases when we approach to the recruitment deadline or have
greater data aging, and we also extend the deadline if the clients' training
time per iteration becomes shorter. Further, we extend to consider
heterogeneous client types in training data size and training time per
iteration. We successfully extend our dynamic pricing solution and develop an
optimal algorithm of linear complexity to monotonically select client types for
FL. Finally, we also show the robustness of our solution against estimation
error of clients' data sizes and run numerical experiments to validate our
conclusion.
