refactored train
This commit is contained in:
+2
-12
@@ -94,23 +94,13 @@ def train(entity: Entity, batch: Mat, params: TrainingParams, status: Status, cd
|
||||
if not keep_running:
|
||||
break
|
||||
|
||||
inc_bv = np.zeros(entity.state.b_v.shape)
|
||||
inc_bh = np.zeros(entity.state.b_h.shape)
|
||||
inc_whv = np.zeros(entity.state.w_hv.shape)
|
||||
|
||||
entity.prepare()
|
||||
for epochs in range(params.num_epochs):
|
||||
# Contrastive divergence learning: calculate gradients
|
||||
dwhv, dbv, dbh, _ = cd_func(entity, mini_batch, params)
|
||||
|
||||
# Adjust weight and biases
|
||||
kl = params.learning_rate/batch.shape[0]
|
||||
inc_bv = params.momentum*inc_bv + kl*dbv
|
||||
inc_bh = params.momentum*inc_bh + kl*dbh
|
||||
inc_whv = params.momentum*inc_whv + kl*dwhv - params.weight_decay*entity.state.w_hv
|
||||
|
||||
entity.state.b_v += inc_bv
|
||||
entity.state.b_h += inc_bh
|
||||
entity.state.w_hv += inc_whv
|
||||
entity.adjust(dbv, dbh, dwhv, learning_rate=params.learning_rate/batch.shape[0], momentum=params.momentum, weight_decay=params.weight_decay)
|
||||
|
||||
# check if status update is needed
|
||||
if status.want_report(round(progress)):
|
||||
|
||||
Reference in New Issue
Block a user