The process of neural network based robotic calligraphy involves a trajectory generation process and a robotic manipulator writing process. The writing process of robotic writing cannot be expressed by mathematical expression; therefore, the conventional gradient back-propagation method cannot be directly used to optimize trajectory generation system. This paper alternatively explores the possibility of using competitive swarm optimizer (CSO) algorithm to optimize the neural network used in the robotic calligraphy system. In this paper, a variational auto-encoder network (VAE) including an encoder and a decoder is used to establish the trajectory generation model. The training of the VAE is divided into two steps. In Step 1, the decoder part of VAE network is trained by using the gradient descent method to extract the features of the input strokes. In the second step, the first encoder is used to obtain the image features directly as the input of the decoder, and the writing sequence of stroke trajectory points is obtained directly by the decoder. CSO is applied to train the decoder of VAE. Then the writing sequence is sent to the robot manipulator for writing. Experiments show that the strokes generated by this method can achieve similar but slightly different strokes from the training samples, so that the stroke writing diversity can be retained by VAE. The results also indicate the potential in autonomous action-state space exploration for other real-world applications.