From Generalization Analysis to Optimization Designs for State Space Models