Open ivergara opened 8 years ago
This should be thought with some care. Having it recomputed at every update of the parameters may be dangerous, e.g., when using the oscillator in a fitting routine. One way to avoid problems in such a case would be to have a method exposing the naked function, accepting the oscillator parameters as arguments without going through the setting of the parameters. For the time being I would keep the SW to be calcuated at the call of spectralWeight(), eventually caching the result within the object if it is calculated by numerical integration.
I agree that it might be unhandy that the spectral weight to be recomputed during a fit routine, particularly in the case of a numerical integration. In any case, nowadays computers are powerful enough not to be too much in trouble with this... but of course it's a waste. A similar situation is when sliders (be it html widgets in iPython or sliders in gtk/qt) to manipulate a parameter.
Since the spectral weight of each oscillator is an intrinsic property which is calculated from the parameters, it should be an always available attribute of any oscillator instance. Moreover, if the parameters of an oscillator change, the SW should be updated to reflect immediately such change.
This would still be true even for eventual oscillators whose SW is calculated by numerical integration.
One approach would be to implement setters for the parameters of an oscillator which invokes an update to recalculate the SW of such oscillator.