AI4Finance-Foundation / AI4Finance-Foundation/RLSolver

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

Abierto
#19 8 comentarios 1 reacción 1 asignado Reclamado por @shixun404 Ver en GitHub
enhancement
Lenguaje dominante
Python
Estrellas
169
Forks
36
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.