Coresets On Bacalhau
Coreset is a data subsetting method. Since the uncompressed datasets can get very large when compressed, it becomes much harder to train them as training time increases with the dataset size. To reduce the training time to save costs we use the coreset method; the coreset method can also be applied to other datasets. In this case, we use the coreset method which can lead to a fast speed in solving the k-means problem among the big data with high accuracy in the meantime.
We construct a small coreset for arbitrary shapes of numerical data with a decent time cost. The implementation was mainly based on the coreset construction algorithm that was proposed by Braverman et al. (SODA 2021).
TD:LR
Running compressed dataset with Bacalhau
Running Locally
Clone the repo which contains the code
To download the dataset you should open Street Map, which is a public repository that aims to generate and distribute accessible geographic data for the whole world. Basically, it supplies detailed position information, including the longitude and latitude of the places around the world.
The dataset is a osm.pbf (compressed format for .osm file), the file can be downloaded from Geofabrik Download Server
The following command is installing Linux dependencies:
The following command is installing Python dependencies:
To run coreset locally, you need to convert from compressed pbf format to geojson format:
The following command is to run the Python script to generate the coreset:
Containerize Script using Docker
To build your own docker container, create a Dockerfile
, which contains instructions on how the image will be built, and what extra requirements will be included.
We will use the python:3.8
image, and we will choose the src directory in the container as our work directory, we run the same commands for installing dependencies that we used locally, but we also add files and directories which are present on our local machine, we also run a test command, in the end, to check whether the script works
:::info See more information on how to containerize your script/app here :::
Build the container
We will run docker build
command to build the container;
Before running the command replace;
hub-user with your docker hub username, If you don’t have a docker hub account follow these instructions to create docker account, and use the username of the account you created
repo-name with the name of the container, you can name it anything you want
tag this is not required but you can use the latest tag
In our case
Push the container
Next, upload the image to the registry. This can be done by using the Docker hub username, repo name or tag.
In our case
Running a Bacalhau Job
After the repo image has been pushed to Docker Hub, we can now use the container for running on Bacalhau. To submit a job, run the following Bacalhau command:
Backend: Docker backend here for running the job
input/liechtenstein-latest.osm.pbf
: Upload the .osm.pbf file-i ipfs://QmXuatKaWL24CwrBPC9PzmLW8NGjgvBVJfk6ZGCWUGZgCu:/input
: mount dataset to the folder inside the container so it can be used by the scriptjsace/coreset
: the name and the tag of the docker image we are using
The following command converts the osm.pbf dataset to geojson (the dataset is stored in the input volume folder):
Let's run the script, we use flag -f
to determine the path of the output geojson file from the step above.
We get the output in stdout
Additional parameters:
-k
: amount of initialized centers (default=5)-n
: size of coreset (default=50)-o
: the output folder
When a job is submitted, Bacalhau prints out the related job_id
. We store that in an environment variable so that we can reuse it later on.
Checking the State of your Jobs
Job status: You can check the status of the job using
bacalhau list
.
When it says Published
or Completed
, that means the job is done, and we can get the results.
Job information: You can find out more information about your job by using
bacalhau describe
.
Job download: You can download your job results directly by using
bacalhau get
. Alternatively, you can choose to create a directory to store your results. In the command below, we created a directory and downloaded our job output to be stored in that directory.
Viewing your Job Output
To view the file, run the following command:
To view the output as a CSV file, run:
Sources
[1] http://proceedings.mlr.press/v97/braverman19a/braverman19a.pdf
[2]https://aaltodoc.aalto.fi/bitstream/handle/123456789/108293/master_Wu_Xiaobo_2021.pdf?sequence=2