We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Documentation is out of date for 0.2.0
Trying to run examples like:

https://github.com/facebookresearch/nevergrad/blob/master/docs/machinelearning.md

gives errors.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `nevergrad/instrumentation/variables.py`
Content:
```
1 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2 # This source code is licensed under the MIT license found in the
3 # LICENSE file in the root directory of this source tree.
4 
5 from typing import List, Optional, TypeVar, Union, Sequence, Any
6 import numpy as np
7 from . import discretization
8 from ..common.typetools import ArrayLike
9 from . import transforms
10 from . import utils
11 
12 
13 X = TypeVar("X")
14 
15 
16 class SoftmaxCategorical(utils.Variable[X]):
17     """Discrete set of n values transformed to a n-dim continuous variable.
18     Each of the dimension encodes a weight for a value, and the softmax of weights
19     provide probabilities for each possible value. A random value is sampled from
20     this distribution.
21 
22     Parameter
23     ---------
24     possibilities: list
25         a list of possible values for the variable
26 
27     Note
28     ----
29     Since the chosen value is drawn randomly, the use of this variable makes deterministic
30     functions become stochastic, hence "adding noise"
31     """
32 
33     def __init__(self, possibilities: List[X], deterministic: bool = False) -> None:
34         self.deterministic = deterministic
35         self.possibilities = list(possibilities)
36 
37     @property
38     def dimension(self) -> int:
39         return len(self.possibilities)
40 
41     def data_to_argument(self, data: ArrayLike, deterministic: bool = False) -> X:
42         assert len(data) == len(self.possibilities)
43         deterministic = deterministic | self.deterministic
44         index = int(discretization.softmax_discretization(data, len(self.possibilities), deterministic=deterministic)[0])
45         return self.possibilities[index]
46 
47     def argument_to_data(self, arg: X) -> ArrayLike:
48         assert arg in self.possibilities, f'{arg} not in allowed values: {self.possibilities}'
49         return discretization.inverse_softmax_discretization(self.possibilities.index(arg), len(self.possibilities))
50 
51     def get_summary(self, data: ArrayLike) -> str:
52         output = self.data_to_argument(data, deterministic=True)
53         probas = discretization.softmax_probas(np.array(data, copy=False))
54         proba_str = ", ".join([f'"{s}": {round(100 * p)}%' for s, p in zip(self.possibilities, probas)])
55         return f"Value {output}, from data: {data} yielding probas: {proba_str}"
56 
57     def _short_repr(self) -> str:
58         return "SC({}|{})".format(",".join([str(x) for x in self.possibilities]), int(self.deterministic))
59 
60 
61 class OrderedDiscrete(SoftmaxCategorical[X]):
62     """Discrete list of n values transformed to a 1-dim discontinuous variable.
63     A gaussian input yields a uniform distribution on the list of variables.
64 
65     Parameter
66     ---------
67     possibilities: list
68         a list of possible values for the variable
69 
70     Note
71     ----
72     The variables are assumed to be ordered.
73     """
74 
75     @property
76     def dimension(self) -> int:
77         return 1
78 
79     def data_to_argument(self, data: ArrayLike, deterministic: bool = False) -> X:  # pylint: disable=arguments-differ, unused-argument
80         assert len(data) == 1
81         index = discretization.threshold_discretization(data, arity=len(self.possibilities))[0]
82         return self.possibilities[index]
83 
84     def argument_to_data(self, arg: X) -> ArrayLike:
85         assert arg in self.possibilities, f'{arg} not in allowed values: {self.possibilities}'
86         index = self.possibilities.index(arg)
87         return discretization.inverse_threshold_discretization([index], len(self.possibilities))
88 
89     def _short_repr(self) -> str:
90         return "OD({})".format(",".join([str(x) for x in self.possibilities]))
91 
92 
93 Y = Union[float, np.ndarray]
94 
95 
96 class Gaussian(utils.Variable[Y]):
97     """Gaussian variable with a mean and a standard deviation, and
98     possibly a shape (when using directly in Python)
99     The output will simply be mean + std * data
100     """
101 
102     def __init__(self, mean: float, std: float, shape: Optional[Sequence[int]] = None) -> None:
103         self.mean = mean
104         self.std = std
105         self.shape = shape
106 
107     @property
108     def dimension(self) -> int:
109         return 1 if self.shape is None else int(np.prod(self.shape))
110 
111     def data_to_argument(self, data: ArrayLike, deterministic: bool = True) -> Y:
112         assert len(data) == self.dimension
113         x = data[0] if self.shape is None else np.reshape(data, self.shape)
114         return self.std * x + self.mean
115 
116     def argument_to_data(self, arg: Y) -> ArrayLike:
117         return [(arg - self.mean) / self.std]
118 
119     def _short_repr(self) -> str:
120         return f"G({self.mean},{self.std})"
121 
122 
123 class _Constant(utils.Variable[X]):
124     """Fake variable so that constant variables can fit into the
125     pipeline.
126     """
127 
128     def __init__(self, value: X) -> None:
129         self.value = value
130 
131     @classmethod
132     def convert_non_instrument(cls, x: Union[X, utils.Variable[X]]) -> utils.Variable[X]:
133         return x if isinstance(x, utils.Variable) else cls(x)
134 
135     @property
136     def dimension(self) -> int:
137         return 0
138 
139     def data_to_argument(self, data: ArrayLike, deterministic: bool = False) -> X:  # pylint: disable=unused-argument
140         return self.value
141 
142     def argument_to_data(self, arg: X) -> ArrayLike:
143         assert arg == self.value, f'{arg} != {self.value}'
144         return []
145 
146     def get_summary(self, data: ArrayLike) -> str:
147         raise RuntimeError("Constant summary should not be called")
148 
149     def _short_repr(self) -> str:
150         return f"{self.value}"
151 
152 
153 class Array(utils.Variable[Y]):
154     """Array variable of a given shape, on which several transforms can be applied.
155 
156     Parameters
157     ----------
158     *dims: int
159         dimensions of the array (elements of shape)
160 
161     Note
162     ----
163     Interesting methods (which can be chained):
164     - asfloat(): converts the array into a float (only for arrays with 1 element)
165     - with_transform(transform): apply a transform to the array
166     - affined(a, b): applies a*x+b
167     - bounded(min_val, max_val, transform="tanh"): applies a transform ("tanh" or "arctan")
168       so that output values are in range [min_val, max_val]
169     - exponentiated(base, coeff): applies base**(coeff * x)
170     """
171 
172     def __init__(self, *dims: int) -> None:
173         self.transforms: List[Any] = []
174         self.shape = tuple(dims)
175         self._asfloat = False
176 
177     @property
178     def dimension(self) -> int:
179         return int(np.prod(self.shape))
180 
181     def data_to_argument(self, data: ArrayLike, deterministic: bool = False) -> Y:  # pylint: disable=unused-argument
182         assert len(data) == self.dimension
183         array = np.array(data, copy=False)
184         for transf in self.transforms:
185             array = transf.forward(array)
186         if self._asfloat:
187             return float(array[0])
188         return array.reshape(self.shape)
189 
190     def argument_to_data(self, arg: Y) -> np.ndarray:
191         if self._asfloat:
192             output = np.array([arg])
193         else:
194             output = np.array(arg, copy=False).ravel()
195         for transf in reversed(self.transforms):
196             output = transf.backward(output)
197         return output
198 
199     def _short_repr(self) -> str:
200         dims = ",".join(str(d) for d in self.shape)
201         transf = "" if not self.transforms else (",[" + ",".join(f"{t:short}" for t in self.transforms) + "]")
202         fl = "" if not self._asfloat else "f"
203         return f"A({dims}{transf}){fl}"
204 
205     def asfloat(self) -> 'Array':
206         if self.dimension != 1:
207             raise RuntimeError("Only Arrays with 1 element can be cast to float")
208         self._asfloat = True
209         return self
210 
211     def with_transform(self, transform: transforms.Transform) -> 'Array':
212         self.transforms.append(transform)
213         return self
214 
215     def exponentiated(self, base: float, coeff: float) -> 'Array':
216         """Exponentiation transform base ** (coeff * x)
217         This can for instance be used for to get a logarithmicly distruted values 10**(-[1, 2, 3]).
218 
219         Parameters
220         ----------
221         base: float
222         coeff: float
223         """
224         return self.with_transform(transforms.Exponentiate(base=base, coeff=coeff))
225 
226     def affined(self, a: float, b: float = 0.) -> 'Array':
227         """Affine transform a * x + b
228 
229         Parameters
230         ----------
231         a: float
232         b: float
233         """
234         return self.with_transform(transforms.Affine(a=a, b=b))
235 
236     def bounded(self, min_val: float, max_val: float, transform: str = "tanh") -> 'Array':
237         """Bounds all real values into [min_val, max_val] using a tanh transform.
238         Beware, tanh goes very fast to its limits.
239 
240         Parameters
241         ----------
242         min_val: float
243         max_val: float
244         transform: str
245             either "tanh" or "arctan" (note that "tanh" reaches the boundaries really quickly,
246             while "arctan" is much softer)
247         """
248         if transform not in ["tanh", "arctan"]:
249             raise ValueError("Only 'tanh' and 'arctan' are allowed as transform")
250         Transf = transforms.ArctanBound if transform == "arctan" else transforms.TanhBound
251         return self.with_transform(Transf(min_val=min_val, max_val=max_val))
252
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/nevergrad/instrumentation/variables.py b/nevergrad/instrumentation/variables.py
--- a/nevergrad/instrumentation/variables.py
+++ b/nevergrad/instrumentation/variables.py
@@ -58,7 +58,7 @@
         return "SC({}|{})".format(",".join([str(x) for x in self.possibilities]), int(self.deterministic))
 
 
-class OrderedDiscrete(SoftmaxCategorical[X]):
+class OrderedDiscrete(utils.Variable[X]):
     """Discrete list of n values transformed to a 1-dim discontinuous variable.
     A gaussian input yields a uniform distribution on the list of variables.
 
@@ -72,6 +72,9 @@
     The variables are assumed to be ordered.
     """
 
+    def __init__(self, possibilities: List[X]) -> None:
+        self.possibilities = list(possibilities)
+
     @property
     def dimension(self) -> int:
         return 1
@@ -108,7 +111,7 @@
     def dimension(self) -> int:
         return 1 if self.shape is None else int(np.prod(self.shape))
 
-    def data_to_argument(self, data: ArrayLike, deterministic: bool = True) -> Y:
+    def data_to_argument(self, data: ArrayLike, deterministic: bool = True) -> Y:  # pylint: disable=unused-argument
         assert len(data) == self.dimension
         x = data[0] if self.shape is None else np.reshape(data, self.shape)
         return self.std * x + self.mean

{"golden_diff": "diff --git a/nevergrad/instrumentation/variables.py b/nevergrad/instrumentation/variables.py\n--- a/nevergrad/instrumentation/variables.py\n+++ b/nevergrad/instrumentation/variables.py\n@@ -58,7 +58,7 @@\n         return \"SC({}|{})\".format(\",\".join([str(x) for x in self.possibilities]), int(self.deterministic))\n \n \n-class OrderedDiscrete(SoftmaxCategorical[X]):\n+class OrderedDiscrete(utils.Variable[X]):\n     \"\"\"Discrete list of n values transformed to a 1-dim discontinuous variable.\n     A gaussian input yields a uniform distribution on the list of variables.\n \n@@ -72,6 +72,9 @@\n     The variables are assumed to be ordered.\n     \"\"\"\n \n+    def __init__(self, possibilities: List[X]) -> None:\n+        self.possibilities = list(possibilities)\n+\n     @property\n     def dimension(self) -> int:\n         return 1\n@@ -108,7 +111,7 @@\n     def dimension(self) -> int:\n         return 1 if self.shape is None else int(np.prod(self.shape))\n \n-    def data_to_argument(self, data: ArrayLike, deterministic: bool = True) -> Y:\n+    def data_to_argument(self, data: ArrayLike, deterministic: bool = True) -> Y:  # pylint: disable=unused-argument\n         assert len(data) == self.dimension\n         x = data[0] if self.shape is None else np.reshape(data, self.shape)\n         return self.std * x + self.mean\n", "issue": "Documentation is out of date for 0.2.0\nTrying to run examples like:\r\n\r\nhttps://github.com/facebookresearch/nevergrad/blob/master/docs/machinelearning.md\r\n\r\ngives errors.\n", "before_files": [{"content": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nfrom typing import List, Optional, TypeVar, Union, Sequence, Any\nimport numpy as np\nfrom . import discretization\nfrom ..common.typetools import ArrayLike\nfrom . import transforms\nfrom . import utils\n\n\nX = TypeVar(\"X\")\n\n\nclass SoftmaxCategorical(utils.Variable[X]):\n    \"\"\"Discrete set of n values transformed to a n-dim continuous variable.\n    Each of the dimension encodes a weight for a value, and the softmax of weights\n    provide probabilities for each possible value. A random value is sampled from\n    this distribution.\n\n    Parameter\n    ---------\n    possibilities: list\n        a list of possible values for the variable\n\n    Note\n    ----\n    Since the chosen value is drawn randomly, the use of this variable makes deterministic\n    functions become stochastic, hence \"adding noise\"\n    \"\"\"\n\n    def __init__(self, possibilities: List[X], deterministic: bool = False) -> None:\n        self.deterministic = deterministic\n        self.possibilities = list(possibilities)\n\n    @property\n    def dimension(self) -> int:\n        return len(self.possibilities)\n\n    def data_to_argument(self, data: ArrayLike, deterministic: bool = False) -> X:\n        assert len(data) == len(self.possibilities)\n        deterministic = deterministic | self.deterministic\n        index = int(discretization.softmax_discretization(data, len(self.possibilities), deterministic=deterministic)[0])\n        return self.possibilities[index]\n\n    def argument_to_data(self, arg: X) -> ArrayLike:\n        assert arg in self.possibilities, f'{arg} not in allowed values: {self.possibilities}'\n        return discretization.inverse_softmax_discretization(self.possibilities.index(arg), len(self.possibilities))\n\n    def get_summary(self, data: ArrayLike) -> str:\n        output = self.data_to_argument(data, deterministic=True)\n        probas = discretization.softmax_probas(np.array(data, copy=False))\n        proba_str = \", \".join([f'\"{s}\": {round(100 * p)}%' for s, p in zip(self.possibilities, probas)])\n        return f\"Value {output}, from data: {data} yielding probas: {proba_str}\"\n\n    def _short_repr(self) -> str:\n        return \"SC({}|{})\".format(\",\".join([str(x) for x in self.possibilities]), int(self.deterministic))\n\n\nclass OrderedDiscrete(SoftmaxCategorical[X]):\n    \"\"\"Discrete list of n values transformed to a 1-dim discontinuous variable.\n    A gaussian input yields a uniform distribution on the list of variables.\n\n    Parameter\n    ---------\n    possibilities: list\n        a list of possible values for the variable\n\n    Note\n    ----\n    The variables are assumed to be ordered.\n    \"\"\"\n\n    @property\n    def dimension(self) -> int:\n        return 1\n\n    def data_to_argument(self, data: ArrayLike, deterministic: bool = False) -> X:  # pylint: disable=arguments-differ, unused-argument\n        assert len(data) == 1\n        index = discretization.threshold_discretization(data, arity=len(self.possibilities))[0]\n        return self.possibilities[index]\n\n    def argument_to_data(self, arg: X) -> ArrayLike:\n        assert arg in self.possibilities, f'{arg} not in allowed values: {self.possibilities}'\n        index = self.possibilities.index(arg)\n        return discretization.inverse_threshold_discretization([index], len(self.possibilities))\n\n    def _short_repr(self) -> str:\n        return \"OD({})\".format(\",\".join([str(x) for x in self.possibilities]))\n\n\nY = Union[float, np.ndarray]\n\n\nclass Gaussian(utils.Variable[Y]):\n    \"\"\"Gaussian variable with a mean and a standard deviation, and\n    possibly a shape (when using directly in Python)\n    The output will simply be mean + std * data\n    \"\"\"\n\n    def __init__(self, mean: float, std: float, shape: Optional[Sequence[int]] = None) -> None:\n        self.mean = mean\n        self.std = std\n        self.shape = shape\n\n    @property\n    def dimension(self) -> int:\n        return 1 if self.shape is None else int(np.prod(self.shape))\n\n    def data_to_argument(self, data: ArrayLike, deterministic: bool = True) -> Y:\n        assert len(data) == self.dimension\n        x = data[0] if self.shape is None else np.reshape(data, self.shape)\n        return self.std * x + self.mean\n\n    def argument_to_data(self, arg: Y) -> ArrayLike:\n        return [(arg - self.mean) / self.std]\n\n    def _short_repr(self) -> str:\n        return f\"G({self.mean},{self.std})\"\n\n\nclass _Constant(utils.Variable[X]):\n    \"\"\"Fake variable so that constant variables can fit into the\n    pipeline.\n    \"\"\"\n\n    def __init__(self, value: X) -> None:\n        self.value = value\n\n    @classmethod\n    def convert_non_instrument(cls, x: Union[X, utils.Variable[X]]) -> utils.Variable[X]:\n        return x if isinstance(x, utils.Variable) else cls(x)\n\n    @property\n    def dimension(self) -> int:\n        return 0\n\n    def data_to_argument(self, data: ArrayLike, deterministic: bool = False) -> X:  # pylint: disable=unused-argument\n        return self.value\n\n    def argument_to_data(self, arg: X) -> ArrayLike:\n        assert arg == self.value, f'{arg} != {self.value}'\n        return []\n\n    def get_summary(self, data: ArrayLike) -> str:\n        raise RuntimeError(\"Constant summary should not be called\")\n\n    def _short_repr(self) -> str:\n        return f\"{self.value}\"\n\n\nclass Array(utils.Variable[Y]):\n    \"\"\"Array variable of a given shape, on which several transforms can be applied.\n\n    Parameters\n    ----------\n    *dims: int\n        dimensions of the array (elements of shape)\n\n    Note\n    ----\n    Interesting methods (which can be chained):\n    - asfloat(): converts the array into a float (only for arrays with 1 element)\n    - with_transform(transform): apply a transform to the array\n    - affined(a, b): applies a*x+b\n    - bounded(min_val, max_val, transform=\"tanh\"): applies a transform (\"tanh\" or \"arctan\")\n      so that output values are in range [min_val, max_val]\n    - exponentiated(base, coeff): applies base**(coeff * x)\n    \"\"\"\n\n    def __init__(self, *dims: int) -> None:\n        self.transforms: List[Any] = []\n        self.shape = tuple(dims)\n        self._asfloat = False\n\n    @property\n    def dimension(self) -> int:\n        return int(np.prod(self.shape))\n\n    def data_to_argument(self, data: ArrayLike, deterministic: bool = False) -> Y:  # pylint: disable=unused-argument\n        assert len(data) == self.dimension\n        array = np.array(data, copy=False)\n        for transf in self.transforms:\n            array = transf.forward(array)\n        if self._asfloat:\n            return float(array[0])\n        return array.reshape(self.shape)\n\n    def argument_to_data(self, arg: Y) -> np.ndarray:\n        if self._asfloat:\n            output = np.array([arg])\n        else:\n            output = np.array(arg, copy=False).ravel()\n        for transf in reversed(self.transforms):\n            output = transf.backward(output)\n        return output\n\n    def _short_repr(self) -> str:\n        dims = \",\".join(str(d) for d in self.shape)\n        transf = \"\" if not self.transforms else (\",[\" + \",\".join(f\"{t:short}\" for t in self.transforms) + \"]\")\n        fl = \"\" if not self._asfloat else \"f\"\n        return f\"A({dims}{transf}){fl}\"\n\n    def asfloat(self) -> 'Array':\n        if self.dimension != 1:\n            raise RuntimeError(\"Only Arrays with 1 element can be cast to float\")\n        self._asfloat = True\n        return self\n\n    def with_transform(self, transform: transforms.Transform) -> 'Array':\n        self.transforms.append(transform)\n        return self\n\n    def exponentiated(self, base: float, coeff: float) -> 'Array':\n        \"\"\"Exponentiation transform base ** (coeff * x)\n        This can for instance be used for to get a logarithmicly distruted values 10**(-[1, 2, 3]).\n\n        Parameters\n        ----------\n        base: float\n        coeff: float\n        \"\"\"\n        return self.with_transform(transforms.Exponentiate(base=base, coeff=coeff))\n\n    def affined(self, a: float, b: float = 0.) -> 'Array':\n        \"\"\"Affine transform a * x + b\n\n        Parameters\n        ----------\n        a: float\n        b: float\n        \"\"\"\n        return self.with_transform(transforms.Affine(a=a, b=b))\n\n    def bounded(self, min_val: float, max_val: float, transform: str = \"tanh\") -> 'Array':\n        \"\"\"Bounds all real values into [min_val, max_val] using a tanh transform.\n        Beware, tanh goes very fast to its limits.\n\n        Parameters\n        ----------\n        min_val: float\n        max_val: float\n        transform: str\n            either \"tanh\" or \"arctan\" (note that \"tanh\" reaches the boundaries really quickly,\n            while \"arctan\" is much softer)\n        \"\"\"\n        if transform not in [\"tanh\", \"arctan\"]:\n            raise ValueError(\"Only 'tanh' and 'arctan' are allowed as transform\")\n        Transf = transforms.ArctanBound if transform == \"arctan\" else transforms.TanhBound\n        return self.with_transform(Transf(min_val=min_val, max_val=max_val))\n", "path": "nevergrad/instrumentation/variables.py"}], "after_files": [{"content": "# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nfrom typing import List, Optional, TypeVar, Union, Sequence, Any\nimport numpy as np\nfrom . import discretization\nfrom ..common.typetools import ArrayLike\nfrom . import transforms\nfrom . import utils\n\n\nX = TypeVar(\"X\")\n\n\nclass SoftmaxCategorical(utils.Variable[X]):\n    \"\"\"Discrete set of n values transformed to a n-dim continuous variable.\n    Each of the dimension encodes a weight for a value, and the softmax of weights\n    provide probabilities for each possible value. A random value is sampled from\n    this distribution.\n\n    Parameter\n    ---------\n    possibilities: list\n        a list of possible values for the variable\n\n    Note\n    ----\n    Since the chosen value is drawn randomly, the use of this variable makes deterministic\n    functions become stochastic, hence \"adding noise\"\n    \"\"\"\n\n    def __init__(self, possibilities: List[X], deterministic: bool = False) -> None:\n        self.deterministic = deterministic\n        self.possibilities = list(possibilities)\n\n    @property\n    def dimension(self) -> int:\n        return len(self.possibilities)\n\n    def data_to_argument(self, data: ArrayLike, deterministic: bool = False) -> X:\n        assert len(data) == len(self.possibilities)\n        deterministic = deterministic | self.deterministic\n        index = int(discretization.softmax_discretization(data, len(self.possibilities), deterministic=deterministic)[0])\n        return self.possibilities[index]\n\n    def argument_to_data(self, arg: X) -> ArrayLike:\n        assert arg in self.possibilities, f'{arg} not in allowed values: {self.possibilities}'\n        return discretization.inverse_softmax_discretization(self.possibilities.index(arg), len(self.possibilities))\n\n    def get_summary(self, data: ArrayLike) -> str:\n        output = self.data_to_argument(data, deterministic=True)\n        probas = discretization.softmax_probas(np.array(data, copy=False))\n        proba_str = \", \".join([f'\"{s}\": {round(100 * p)}%' for s, p in zip(self.possibilities, probas)])\n        return f\"Value {output}, from data: {data} yielding probas: {proba_str}\"\n\n    def _short_repr(self) -> str:\n        return \"SC({}|{})\".format(\",\".join([str(x) for x in self.possibilities]), int(self.deterministic))\n\n\nclass OrderedDiscrete(utils.Variable[X]):\n    \"\"\"Discrete list of n values transformed to a 1-dim discontinuous variable.\n    A gaussian input yields a uniform distribution on the list of variables.\n\n    Parameter\n    ---------\n    possibilities: list\n        a list of possible values for the variable\n\n    Note\n    ----\n    The variables are assumed to be ordered.\n    \"\"\"\n\n    def __init__(self, possibilities: List[X]) -> None:\n        self.possibilities = list(possibilities)\n\n    @property\n    def dimension(self) -> int:\n        return 1\n\n    def data_to_argument(self, data: ArrayLike, deterministic: bool = False) -> X:  # pylint: disable=arguments-differ, unused-argument\n        assert len(data) == 1\n        index = discretization.threshold_discretization(data, arity=len(self.possibilities))[0]\n        return self.possibilities[index]\n\n    def argument_to_data(self, arg: X) -> ArrayLike:\n        assert arg in self.possibilities, f'{arg} not in allowed values: {self.possibilities}'\n        index = self.possibilities.index(arg)\n        return discretization.inverse_threshold_discretization([index], len(self.possibilities))\n\n    def _short_repr(self) -> str:\n        return \"OD({})\".format(\",\".join([str(x) for x in self.possibilities]))\n\n\nY = Union[float, np.ndarray]\n\n\nclass Gaussian(utils.Variable[Y]):\n    \"\"\"Gaussian variable with a mean and a standard deviation, and\n    possibly a shape (when using directly in Python)\n    The output will simply be mean + std * data\n    \"\"\"\n\n    def __init__(self, mean: float, std: float, shape: Optional[Sequence[int]] = None) -> None:\n        self.mean = mean\n        self.std = std\n        self.shape = shape\n\n    @property\n    def dimension(self) -> int:\n        return 1 if self.shape is None else int(np.prod(self.shape))\n\n    def data_to_argument(self, data: ArrayLike, deterministic: bool = True) -> Y:  # pylint: disable=unused-argument\n        assert len(data) == self.dimension\n        x = data[0] if self.shape is None else np.reshape(data, self.shape)\n        return self.std * x + self.mean\n\n    def argument_to_data(self, arg: Y) -> ArrayLike:\n        return [(arg - self.mean) / self.std]\n\n    def _short_repr(self) -> str:\n        return f\"G({self.mean},{self.std})\"\n\n\nclass _Constant(utils.Variable[X]):\n    \"\"\"Fake variable so that constant variables can fit into the\n    pipeline.\n    \"\"\"\n\n    def __init__(self, value: X) -> None:\n        self.value = value\n\n    @classmethod\n    def convert_non_instrument(cls, x: Union[X, utils.Variable[X]]) -> utils.Variable[X]:\n        return x if isinstance(x, utils.Variable) else cls(x)\n\n    @property\n    def dimension(self) -> int:\n        return 0\n\n    def data_to_argument(self, data: ArrayLike, deterministic: bool = False) -> X:  # pylint: disable=unused-argument\n        return self.value\n\n    def argument_to_data(self, arg: X) -> ArrayLike:\n        assert arg == self.value, f'{arg} != {self.value}'\n        return []\n\n    def get_summary(self, data: ArrayLike) -> str:\n        raise RuntimeError(\"Constant summary should not be called\")\n\n    def _short_repr(self) -> str:\n        return f\"{self.value}\"\n\n\nclass Array(utils.Variable[Y]):\n    \"\"\"Array variable of a given shape, on which several transforms can be applied.\n\n    Parameters\n    ----------\n    *dims: int\n        dimensions of the array (elements of shape)\n\n    Note\n    ----\n    Interesting methods (which can be chained):\n    - asfloat(): converts the array into a float (only for arrays with 1 element)\n    - with_transform(transform): apply a transform to the array\n    - affined(a, b): applies a*x+b\n    - bounded(min_val, max_val, transform=\"tanh\"): applies a transform (\"tanh\" or \"arctan\")\n      so that output values are in range [min_val, max_val]\n    - exponentiated(base, coeff): applies base**(coeff * x)\n    \"\"\"\n\n    def __init__(self, *dims: int) -> None:\n        self.transforms: List[Any] = []\n        self.shape = tuple(dims)\n        self._asfloat = False\n\n    @property\n    def dimension(self) -> int:\n        return int(np.prod(self.shape))\n\n    def data_to_argument(self, data: ArrayLike, deterministic: bool = False) -> Y:  # pylint: disable=unused-argument\n        assert len(data) == self.dimension\n        array = np.array(data, copy=False)\n        for transf in self.transforms:\n            array = transf.forward(array)\n        if self._asfloat:\n            return float(array[0])\n        return array.reshape(self.shape)\n\n    def argument_to_data(self, arg: Y) -> np.ndarray:\n        if self._asfloat:\n            output = np.array([arg])\n        else:\n            output = np.array(arg, copy=False).ravel()\n        for transf in reversed(self.transforms):\n            output = transf.backward(output)\n        return output\n\n    def _short_repr(self) -> str:\n        dims = \",\".join(str(d) for d in self.shape)\n        transf = \"\" if not self.transforms else (\",[\" + \",\".join(f\"{t:short}\" for t in self.transforms) + \"]\")\n        fl = \"\" if not self._asfloat else \"f\"\n        return f\"A({dims}{transf}){fl}\"\n\n    def asfloat(self) -> 'Array':\n        if self.dimension != 1:\n            raise RuntimeError(\"Only Arrays with 1 element can be cast to float\")\n        self._asfloat = True\n        return self\n\n    def with_transform(self, transform: transforms.Transform) -> 'Array':\n        self.transforms.append(transform)\n        return self\n\n    def exponentiated(self, base: float, coeff: float) -> 'Array':\n        \"\"\"Exponentiation transform base ** (coeff * x)\n        This can for instance be used for to get a logarithmicly distruted values 10**(-[1, 2, 3]).\n\n        Parameters\n        ----------\n        base: float\n        coeff: float\n        \"\"\"\n        return self.with_transform(transforms.Exponentiate(base=base, coeff=coeff))\n\n    def affined(self, a: float, b: float = 0.) -> 'Array':\n        \"\"\"Affine transform a * x + b\n\n        Parameters\n        ----------\n        a: float\n        b: float\n        \"\"\"\n        return self.with_transform(transforms.Affine(a=a, b=b))\n\n    def bounded(self, min_val: float, max_val: float, transform: str = \"tanh\") -> 'Array':\n        \"\"\"Bounds all real values into [min_val, max_val] using a tanh transform.\n        Beware, tanh goes very fast to its limits.\n\n        Parameters\n        ----------\n        min_val: float\n        max_val: float\n        transform: str\n            either \"tanh\" or \"arctan\" (note that \"tanh\" reaches the boundaries really quickly,\n            while \"arctan\" is much softer)\n        \"\"\"\n        if transform not in [\"tanh\", \"arctan\"]:\n            raise ValueError(\"Only 'tanh' and 'arctan' are allowed as transform\")\n        Transf = transforms.ArctanBound if transform == \"arctan\" else transforms.TanhBound\n        return self.with_transform(Transf(min_val=min_val, max_val=max_val))\n", "path": "nevergrad/instrumentation/variables.py"}]}