Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions examples/general_sampling/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sampler
*walk.txt
54 changes: 54 additions & 0 deletions examples/general_sampling/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

cmake_minimum_required(VERSION 3.11)
project(VolEstiGeneralSampling)

option(DISABLE_NLP_ORACLES "Disable non-linear oracles" ON)
option(BUILTIN_EIGEN "Use eigen from ../../external" OFF)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_compile_options(-O3 -march=native -DTIME_KEEPING -DBOOST_NO_AUTO_PTR -DEIGEN_NO_DEBUG)

if(DISABLE_NLP_ORACLES)
add_definitions(-DDISABLE_NLP_ORACLES)
endif()

include("../../external/cmake-files/Eigen.cmake")
GetEigen()

include("../../external/cmake-files/Boost.cmake")
GetBoost()

include("../../external/cmake-files/HiGHS.cmake")
GetHighs()

include("../../external/cmake-files/QD.cmake")
GetQD()

set(HIGHS highs::highs)

if(NOT TARGET highs::highs)
message(FATAL_ERROR "HiGHS target was not found!")
else()
message(STATUS "Library HiGHS found: ${HIGHS}")
endif()

include_directories(BEFORE ../../include)
include_directories(BEFORE ../../include/convex_bodies)
include_directories(BEFORE ../../include/generators)
include_directories(BEFORE ../../external)
include_directories(BEFORE ../../external/minimum_ellipsoid)

find_package(Threads REQUIRED)

add_executable(general_sampling_time_limit
general_sampling_time_limit.cpp
)

target_link_libraries(general_sampling_time_limit
PRIVATE
${HIGHS}
qd
Threads::Threads
)
157 changes: 157 additions & 0 deletions examples/general_sampling/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
## Compilation

Create a build directory.
Build the example by running the following commands in the build directory you created.

```bash
cmake
make
```
If you are here before the HIGHS update, you might have to specify the path to liblpsolve55.so/dll/dylib. Try these:

```bash
cmake . -DLP_SOLVE=_PATH_TO_LIB_FILE
make
```
To find where this path is Try this command

find /usr -name "liblpsolve55.so" 2>/dev/null
For example: -DLP_SOLVE=/usr/lib/lpsolve/liblpsolve55.so

If you dont find it try downloading it. Most common way is:

sudo apt update
sudo apt install lpsolve55 lpsolve55-dev

## Usage:
```bash
./general_sampling_time_limit
```

***How to use general_sampling_time_limit.cpp***

# Introduction

The main focus of the example is to apply the uniform sampling methods of Volesti.
The polytope is generated by Volesti generators or is a custom Ax<=b polytope with A and b in csv form.
Then, most of the uniform methods are used to sample from it. The sampling lasts until an ESS limit
is reached or after you generate as many samples as you want.
In the end, the code returns (among others):
- Total samples
- ESS
- Time

There are many custom parameters you can modify. Unfortunatelly, you currently need to modify the source code:

# Choosing your desired sampling method

You can choose to use one or all of the uniform sampling methods provided.
To do that check lines 608-614. Set true to the methods you want to run and false to the ones you don't.

# Batch size:

In line 143 you can find a function called compute_batch_size. There you can define how many samples each batch will return.
In order to reach a specific ess we sample in small batches and calculate the ESS. There are a few things to notice here:
- The smaller the batch size, the more time is spent on calculating the ESS.
- The higher the batch size the more difficult it is to reach the target exactly.

Thus a compromise is needed. We provide numbers for some of the most common polytopes after many trial and error experiments. You can follow them or use your own.

# Dynamic Batch size:

A dynamic batch size calculation is also implemented like this: we begin with 10*target_ESS samples and check their ESS.
Calculating the efficiency of these samples, we request as many samplse as needed to reach the target ESS. After 3 batches at most target is reached.
You can turn on/off the dynamic batch size following these steps:

How to turn ON dynamic batch size:
- Comment lines 278-279 and uncomment lines 280-281.
- Uncomment lines 347-360.
How to turn OFF dynamic batch size:
- Uncomment lines 278-279 and comment lines 280-281.
- Comment lines 347-360.

Recommendation: Don't start your sampling with the dynamic batch size. There is a chance that the sampler will get stuck or that
it will take TOO long to sample 10 times your target. It is better (especially for an unknown polytope) to begin with a small
custom batch size, check the behaviour and then use the dynamic batch size is all is ok.

# Walk lenght:

In line 247 you cn find a set_walk_len function. Walk length works like a thinning factor. The values already set are standard.
You should not change then unless you want to experiment with different values if needed. Just change the return value to what you want.

# Volume Shell Analysis:

Uncomment lines 420-433 to see the full Shell Analysis of the KS test. These lines are commented by default to avoid clutter.

# Print samples to file

Uncomment lines 438-439 (same for lines 576-577 if you use CRHMC) to print output samples to a txt file for later use.
Carefull as only one file is kept, the last written, so if you aim for a specific method samples run only that method.

# Choose native Polytope

Volesti already provides generators for some classic polytopes. In lines 658-662 you can select one of them to sample from.
Just uncomment the one you want and comment the rest. You can select from Cube,Simplex,Cross,Birkhoff,Skinny Cube.

# Custom Polytope

If you want to sample from a custom polytope, we offer an option. The polytope must be in H-representation (A*x <= b).
A and b matrices must be in csv form.

How to use custom mode:
- In line 627 you must set this boolean to true (false for native polytopes)
- In line 634 you must provide the names of the csv files holding A and b matrices.

# Choose dimensions, target ESS and time limit

- In line 595 there is a vector holding the dimensions. Add the dimensions you want the sampling to take place. We later loop this vector
so you can add multiple dimensions. (example {3,5,6,7,8,9,10})
- In line 597 you can choose the target ESS.
- In order to sample only for as many samples as you choose, set target ESS to 1 and batch size to how many samples you want.
- In line 604 is the time limit in seconds. After some sampling methods exceed this limit, the method is aborted and the current results saved.

# Rotate polytope

We offer the chance to rotate any polytope around each plane. This is usefull to reduce bias from the fact that generating polytopes
sits aligned with the axis and thus helping some of the sampling methods.

How to rotate a polytope
- In lines 670-671 choose an angle or define your own angle.

# Print the polytope

Sometimes, for debugging purposes it is useful to see the polytope that you sample from.

How to print the polytope
- Uncomment or comment line 674

# Expected output (example)

```text
Starting Benchmark.
Target ESS: 500
Time Limit: 3600s per method.

========================================
*** Running for dimension 10 ***

[AcceleratedBilliardWalk] Current batch_size: 2162
[AcceleratedBilliardWalk] Current walk_len: 1
[AcceleratedBilliardWalk] Samples: 10810 | ESS: 638 | Time: 0.248768s
[AcceleratedBilliardWalk] DONE. Final ESS: 638
```

Results are also saved in a file after each sampling...
The file is called `benchmark_results.txt` and should look like this:

```csv
Dim, Method, Time(s), Points, ESS
81, AcceleratedBilliardWalk, 0.248768, 10810, 638
81, CDHRWalk, 0.188994, 6744, 662
81, BilliardWalk, 1.12567, 40400, 570
81, RDHRWalk, 26.7692, 59700, 552
81, SparseBilliardWalk, 3.03094, 4324, 780
```



Loading