Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update star discrepancy examples #163

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
216 changes: 210 additions & 6 deletions example/example_star_discr.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"id": "2cb84e58-8b54-4d61-b5ff-08c845b13d4f",
"metadata": {},
"source": [
"This notebook illustrates how to access the Submodular problems using IOHexperimenter.\n",
"This notebook illustrates how to access the Star Discrepancy problems using IOHexperimenter.\n",
"To install IOHexperimenter, the following command can be used:"
]
},
Expand All @@ -32,6 +32,7 @@
"id": "d1d6d79b-8aa4-419e-80c7-15b7fd0c2492",
"metadata": {},
"source": [
"Please make sure that you use version >= 0.3.9 to follow the examples in this notebook.\n",
"Once installed, simply import the package"
]
},
Expand All @@ -58,13 +59,14 @@
"id": "d87a4346-c909-4c6e-8de8-6f80821fce69",
"metadata": {},
"source": [
"In ioh, everything revolves around the problem class, so we start by creating an individual submodular problem.\n",
"In ioh, everything revolves around the problem class, so we start by creating an individual problem. For the star discrepancy, the problems can be represented as either continuous or discrete. We start with the continuous version, but the underlying problems are identical, and the interfaces are equivalent. \n",
"\n",
"To see which problems are available, we can check:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"id": "f295e32c-aa60-45d9-88e3-fad61ca35dc5",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -103,13 +105,13 @@
" 59: 'HaltonStarDiscrepancy1000'}"
]
},
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ioh.ProblemClass.STAR_REAL_REAL.problems"
"ioh.ProblemClass.STAR_REAL.problems"
]
},
{
Expand Down Expand Up @@ -168,7 +170,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 14,
"id": "e4879f7e-1df2-4bf4-b5e8-7319b851c20d",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -374,6 +376,198 @@
"experiment()"
]
},
{
"cell_type": "markdown",
"id": "367dcea5-bc4f-4a17-95e4-5b3985a0cbc6",
"metadata": {},
"source": [
"## Discrete version of the problems"
]
},
{
"cell_type": "markdown",
"id": "4a452aca-234a-4ef3-86c6-b3c63feac18d",
"metadata": {},
"source": [
"In addition to the continuous problems, the star-discrepancy problem can also be considered as an integer optimization problem. Since we know that the optimial solution shares each of its coordinates with an exisiting grid-point, we can simply specify for each coordinate with the (sorted) grid points to use for the new solution. \n",
"\n",
"We can list the available problems in the same way as the continuous case"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "bfb36bd6-c259-4fd8-aef2-a0b51d36bd28",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{30: 'UniformStarDiscrepancy10',\n",
" 31: 'UniformStarDiscrepancy25',\n",
" 32: 'UniformStarDiscrepancy50',\n",
" 33: 'UniformStarDiscrepancy100',\n",
" 34: 'UniformStarDiscrepancy150',\n",
" 35: 'UniformStarDiscrepancy200',\n",
" 36: 'UniformStarDiscrepancy250',\n",
" 37: 'UniformStarDiscrepancy500',\n",
" 38: 'UniformStarDiscrepancy750',\n",
" 39: 'UniformStarDiscrepancy1000',\n",
" 40: 'SobolStarDiscrepancy10',\n",
" 41: 'SobolStarDiscrepancy25',\n",
" 42: 'SobolStarDiscrepancy50',\n",
" 43: 'SobolStarDiscrepancy100',\n",
" 44: 'SobolStarDiscrepancy150',\n",
" 45: 'SobolStarDiscrepancy200',\n",
" 46: 'SobolStarDiscrepancy250',\n",
" 47: 'SobolStarDiscrepancy500',\n",
" 48: 'SobolStarDiscrepancy750',\n",
" 49: 'SobolStarDiscrepancy1000',\n",
" 50: 'HaltonStarDiscrepancy10',\n",
" 51: 'HaltonStarDiscrepancy25',\n",
" 52: 'HaltonStarDiscrepancy50',\n",
" 53: 'HaltonStarDiscrepancy100',\n",
" 54: 'HaltonStarDiscrepancy150',\n",
" 55: 'HaltonStarDiscrepancy200',\n",
" 56: 'HaltonStarDiscrepancy250',\n",
" 57: 'HaltonStarDiscrepancy500',\n",
" 58: 'HaltonStarDiscrepancy750',\n",
" 59: 'HaltonStarDiscrepancy1000'}"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ioh.ProblemClass.STAR_INTEGER.problems"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "ccdd283d-8567-47ed-8fea-51037a21a5fa",
"metadata": {},
"outputs": [],
"source": [
"f = ioh.get_problem(30, instance=1, dimension=5, problem_class=ioh.ProblemClass.STAR_INTEGER)"
]
},
{
"cell_type": "markdown",
"id": "c15e6c63-391a-438d-be07-ccbcbe899e87",
"metadata": {},
"source": [
"The range of available integers scales with the number of grid-points, while the dimension remains the same as the continuous version. We can check this as follows (note that the bounds are inclusive):"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "7adb5523-8b05-4e48-8ff3-6253d8501fe1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<BoxConstraint lb: [[0, 0, 0, 0, 0]] ub: [[10, 10, 10, 10, 10]]>"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f.bounds"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "5160326c-84fc-4a21-9863-4f2b28ebdb3c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.14038693698597768"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f([10,0,10,10,10])"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "778a6697-dedd-4509-9a7e-13cd4cb4ce70",
"metadata": {},
"outputs": [],
"source": [
"class RandomSearch_int:\n",
" 'Simple random search algorithm'\n",
" def __init__(self, n: int, length: float = 0.0):\n",
" self.n: int = n\n",
" self.length: float = length\n",
" \n",
" def __call__(self, problem: ioh.problem.IntegerSingleObjective) -> None:\n",
" 'Evaluate the problem n times with a randomly generated solution'\n",
" \n",
" for _ in range(self.n):\n",
" # We can use the problems bounds accessor to get information about the problem bounds\n",
" x = np.random.randint(problem.bounds.lb, problem.bounds.ub+1) #+1 since our upper bound is inclusive\n",
" self.length = np.linalg.norm(x)\n",
" \n",
" problem(x) "
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "8948d79a-3042-4561-9a22-9963c27fdd4e",
"metadata": {},
"outputs": [],
"source": [
"r = RandomSearch_int(100)\n",
"r(f)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "059087e2-3b0b-4799-98c5-83bbccbe79d0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<State evaluations: 103 optimum_found: false current_best: <Solution x: [8, 10, 9, 6, 7] y: 0.31906960357524955>>"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f.state"
]
},
{
"cell_type": "markdown",
"id": "245df2bc-dffe-4ed4-b379-7fca48f6d342",
"metadata": {},
"source": [
"## More information"
]
},
{
"cell_type": "markdown",
"id": "33c20e04-a75a-4646-ad39-49702976f072",
Expand All @@ -384,6 +578,16 @@
"If you have any questions about the usage of the STAR_REAL discrepancy problems, or about IOHprofiler in general, please make an issue on https://github.com/IOHprofiler/IOHexperimenter"
]
},
{
"cell_type": "markdown",
"id": "d08d0d62-9e10-4529-ba36-4f3431721b3c",
"metadata": {
"tags": []
},
"source": [
"## Cleanup for CI"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down