PD control is a widely used model-free method; however, it often falls short of guaranteeing optimal performance. Optimal model-based control, such as the Linear Quadratic Regulator (LQR), can indeed achieve the desired control performance, but only for known linear systems. In this paper, we present a novel approach for designing optimal PD control for unknown mechanical systems. We utilize a conditional Generative Adversarial Network (GAN) and a Long Short-Term Memory (LSTM) neural network to approximate an optimal PD control. We employ Bayesian inference to generate PD control that can be applied at different operating points. This design mechanism ensures both stability and optimal performance. Finally, we apply this control methodology to lower limb prostheses, and the results demonstrate that the optimal PD control, using GAN and Bayesian inference, outperforms other classical controllers.