Skip to content

Instantly share code, notes, and snippets.

View kikatuso's full-sized avatar

Zuzanna Skorniewska kikatuso

View GitHub Profile
@dboyliao
dboyliao / pytorch_lagrange_multi.py
Last active January 29, 2023 15:48
Simple Example: Solving Lagrange Multiplier with PyTorch
import torch
x = torch.tensor(0, requires_grad=True, dtype=torch.float64)
y = torch.tensor(0, requires_grad=True, dtype=torch.float64)
l = torch.tensor(0, requires_grad=True, dtype=torch.float64)
lr = 0.1
# min x^2+y^2 s.t x+y = 1
for i in range(100):
L = x**2 + y**2 + l*(1-x-y)