-
Notifications
You must be signed in to change notification settings - Fork 270
[DO NOT MERGE] [WIP] multiobjective inspiration #105
base: main
Are you sure you want to change the base?
Conversation
| import os | ||
| import json | ||
| from nevergrad.optimization import optimizerlib | ||
| from nevergrad.functions.multiobjective.core import MultiobjectiveFunction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from nevergrad.functions import MultiobjectiveFunction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx.
| if nevergrad not in [None, 'CMA', 'DE', 'PSO', | ||
| 'TwoPointsDE', 'PortfolioDiscreteOnePlusOne', | ||
| 'DiscreteOnePlusOne', 'OnePlusOne']: | ||
| 'DiscreteOnePlusOne', 'OnePlusOne', 'random', 'loss-covering', 'hypervolume', 'domain-covering']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this mixes algorithms and selection mode, I dont get it and the docstring is not up to date.
Also, other modes dont seem to be used anyway since it loops on all selection options
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, now there is an additional "moo", in which case we loop over various Pareto sampling modes.
| gradientDecay = 0.1 | ||
|
|
||
| nImages = input.size(0) | ||
| assert nImages == 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why always 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For not mixing the different multiobjective functions.
Anyway the original code, I believe, is not good for the case nImages > 1..
| if not randomSearch: | ||
| loss.sum(dim=0).backward() | ||
|
|
||
| if nevergrad: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not modified, but: to check if it's None, always do if nevergrad is not None
| assert nImages == 1 | ||
| # assert randomSearch | ||
| thelosses = [1., 3., 3.] # These numbers should be discussed... | ||
| target = MultiobjectiveFunction(lambda x: thelosses, tuple(thelosses)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is constant? maybe use lambda x:x? and then target(losses) instead of target.compute_aggregate_loss?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When thelosses will be updated, this function will return something different. Tested with:
y=[1]
def biz(x):
print(y)
return y
biz(2)
biz(2)
y=[3]
biz(2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have though that overriding y would unlink the external y from the one used internally but indeed...
Still, this is an ugly hack you should reaaaaaaally avoid doing for both clarity and avoid extremely weird bugs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point is that Nevergrad is not equipped for Ask&Tell in multiobjective mode. I did not find a better solution for now.
|
@Brozi : |
|
|
||
| loss = -lambdaD * model.netD(noiseOut)[:, 0] | ||
| sumLoss += loss | ||
| combinedLoss[2] += loss |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can put just =
|
|
||
| if nevergrad: | ||
| for i in range(nImages): | ||
| optimizers[i].tell(inps[i], float(sumLoss[i])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could have an if nevergrad == 'moo' to avoid breaking the code when optimizing hte mono objectif
|
|
||
| else: | ||
| optimalVector = torch.where(sumLoss.view(-1, 1) < optimalLoss.view(-1, 1), | ||
| optimalVector = torch.where(combinedLoss.view(-1, 1) < optimalLoss.view(-1, 1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you probably want combinedLoss.sum(dim=0) and same thing for optimalLoss here.
Otherwise you're taking parts of varNoise and parts of optimalLoss but those parts are not related to the losses that are better.
| varNoise, optimalVector).detach() | ||
| optimalLoss = torch.where(sumLoss < optimalLoss, | ||
| sumLoss, optimalLoss).detach() | ||
| optimalLoss = torch.where(combinedLoss < optimalLoss, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, I think you should also take .sum(dim=0)
|
|
||
| print(str(iter) + " : " + formatCommand.format( | ||
| *["{:10.6f}".format(sumLoss[i].item()) | ||
| *["{:10.6f}".format(combinedLoss[i].item()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
combinedLoss[:,i]
Update inspirational_generation.py
Update inspirational_generation.py
No description provided.