DeepTrackAI / deeplay

Other
4 stars 5 forks source link

Adding schedulers #118

Open BenjaminMidtvedt opened 3 months ago

BenjaminMidtvedt commented 3 months ago

This PR adds schedulers for scalar values (only floats so far) to deeplay. They can be used in place of any scalar float without any change to the forward pass. For example:

betaVAE_const = BetaVAE(beta=0.1)
betaVAE_sched = BetaVAE(beta=LinearScheduler(0, 0.1, 1000))

You can also use the methods schedule, schedule_linear, schedule_loglinear to schedule any number, even if it is not a part of the constructor:

betaVAE = BetaVAE()
betaVAE.schedule(beta=LinearScheduler(0, 0.1, 1000))
betaVAE.schedule_linear("beta", 0, 0.1, 100)
betaVAE.schedule_loglinear("beta", 0.01, 0.1, 100)

They can also trivially be used in the __init__ function:

class MyApp(Application):
    def __init__(self):
        #[...]
        self.scale= LinearScheduler(0, 0.1, 1000)

     def forward(x):
          self.model(x * self.scale)