AI4Finance-Foundation / AI4Finance-Foundation/RLSolver

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

未关闭
#19 8 条评论 1 个 reaction 已指派 1 人 已被 @shixun404 认领 在 GitHub 查看
enhancement
主要语言
Python
星标
169
派生
36
PR 合并指标
30 天内没有已合并 PR

描述

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]
```

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。