em_optimizer
em_optimizer
¤
EM
¤
Bases: Optimizer
Expectation Maximization optimizer for torch backend.
WARNING: This optimizer should be used by calling the model ONLY on the training data. Doing something like:
ll=model(train_data)
model(random_data)
ll.sum().backward()
optim.step()
Will cause the cached input used for the update to be random_data instead of train_data
Also, it should be noted that this is a maximiser, so it should be trained with log-likelihood and not negative log log-likelihood.
Source code in cirkit/backend/torch/em_optimizer.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
pc = pc
instance-attribute
¤
__init__(pc, lr, pseudocount, alpha=1e-08)
¤
Initialize the optimizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pc
|
TorchCircuit
|
Compiled circuit to optimized. |
required |
lr
|
float
|
Learning rate / Step size. |
required |
pseudocount
|
float
|
Pseudocount for laplace smoothing (when implemented). |
required |
alpha
|
float
|
Minimal value for clamping gradients. |
1e-08
|
Raises:
| Type | Description |
|---|---|
ValueError
|
Raised if the step size is not between 0 and 1. |
Source code in cirkit/backend/torch/em_optimizer.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
step(closure=None)
¤
Update parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
closure
|
Callable | None
|
Not used, present for compatibility. |
None
|
Source code in cirkit/backend/torch/em_optimizer.py
66 67 68 69 70 71 72 73 74 75 76 77 | |
zero_grad(set_to_none=True)
¤
Source code in cirkit/backend/torch/em_optimizer.py
79 80 | |