AI4Finance-Foundation / AI4Finance-Foundation/RLSolver

Generative Meta-Learning for Large-Scale Non-Convex Optimization (RL)

Đang mở
#19 8 bình luận 1 reaction 1 người được giao Được @shixun404 nhận Xem trên GitHub
enhancement
Ngôn ngữ chính
Python
Star
169
Fork
36
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Hello!

You can find it here: https://github.com/kayuksel/generative-opt

Just change the following lines for combinatorial optimization.

I also implemented Fast CMA-ES and Tabu Search in PyTorch.

Here is Fast CMA-ES: https://github.com/kayuksel/torch-tsp-es/

Let me know if Tabu Search would also be helpful, I can share.

Please to don't forget to contribute back, and cite when possible.

Sincerely,
Kamer

```
class Generator(nn.Module):
def __init__(self, noise_dim = 0):
super(Generator, self).__init__()
def block(in_feat, out_feat):
return [nn.Linear(in_feat, out_feat), nn.Tanh()]
self.model = nn.Sequential(
*block(noise_dim+args.cnndim, 512), *block(512, 1024), nn.Linear(1024, len(assets)))
init_weights(self)
self.extract = Extractor(args.cnndim)
def forward(self, x):
mu = self.model(self.extract(x))
return torch.bernoulli(mu.sigmoid())

actor = Generator(args.noise).to(device)
opt = torch.optim.AdamW(filter(lambda p: p.requires_grad, actor.parameters()), lr=1e-3)

best_reward = None

for epoch in range(args.iter):
torch.cuda.empty_cache()
weights = actor(torch.randn((args.batch, args.noise)).to(device))
weights = weights / weights.sum(dim=1).reshape(-1, 1)

loss = calculate_reward(weights.clone(), valid_data[:-test_size], index[:-test_size], True)
opt.zero_grad()
loss.mean().backward()
nn.utils.clip_grad_norm_(actor.parameters(), 1.0)
opt.step()

with torch.no_grad():
weights = weights[rewards.argmin()]
test_reward = calculate_reward(weights.unsqueeze(0),
valid_data[-test_size:], index[-test_size:])[0]
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.