Download tasks/bicycle_studio/solution/reference/scalarization.py from Tokenwave-AI/REE: direct link, hf CLI and curl.
- Browser
- Download file 687 Bytes
-
https://huggingface.co/datasets/Tokenwave-AI/REE/resolve/main/tasks/bicycle_studio/solution/reference/scalarization.py
- Command line
-
hf download hf://datasets/Tokenwave-AI/REE/tasks/bicycle_studio/solution/reference/scalarization.py
-
curl -L -o scalarization.py https://huggingface.co/datasets/Tokenwave-AI/REE/resolve/main/tasks/bicycle_studio/solution/reference/scalarization.py
687 Bytes
| import numpy as np | |
| import torch | |
| from torch import Tensor | |
| ''' | |
| numpy evaluation may have some problems, please check. | |
| Here, an interesting thing is that, PBI and COSMOS are not MOO agg functions. | |
| I.e., the optimas may not be Pareto optimal. | |
| ''' | |
| def tche(f_arr, w, z=0): | |
| if type(f_arr) == Tensor: | |
| idx = torch.argmax(w * (f_arr - z), axis=1) | |
| return f_arr[torch.arange(f_arr.shape[0]), idx] | |
| # return [0] | |
| elif type(f_arr) == np.ndarray: | |
| idx = np.argmax(w * (f_arr - z), axis=1) | |
| return f_arr[np.arange(f_arr.shape[0]), idx] | |
| # return np.max(w * (f_arr - z), axis=1) | |
| else: | |
| raise Exception('type not supported') | |