In this work we showed the optimization of the spectral response of several optical elements in a silicon-based optical switch. Integrated thermal resistors induced a local heating of the components. The temperature increase, in turn, caused a thermal shift of the optical response of the component. In this manner, we aligned interleavers and micro-ring resonators to the International Telecommunication Union (ITU) channels, by using a stochastic method named Globalized Bounded Nelder-Mead (GBNM) to determine the proper temperatures. The optimization engine relied on the optical feedback from on-chip monitor photodiodes to drive these photonic elements into the wanted functioning condition. This method is suited for restoring the spectral response of optical elements impaired by fabrication inaccuracies. In the same way, it can be applied to tune in resonance active components, whose transfer function has one or more local optima. We proved the reliability of the GBNM method for the optimization of an integrated optical switch, with more than thousand optical components, each one interfaced with a thermal resistor driven by a dedicated electronic circuit. On the one hand, the GBNM guaranteed the automatic alignment of all active components on the chip, over multiple instances. On the other hand, the method allowed for the proper working of such a complex device.