PySecurityCameras is an application which finds optimal arrangement of cameras located in collection od rooms. Cameras and rooms are difined as shapes on 2D plane - camera being a circle and room being a rectangle. Search of the best coordinates is performed using Simulated Annealing algorithm.
Process of optimization can be configured through the ./config.json file which has following structure:
{ "boxes": [ { "vertex": { "x": 0.0, "y": 0.0 }, "width": 0.3, "height": 1.0 }, { "vertex": { "x": 0.3, "y": 0.3 }, "width": 0.7, "height": 0.6 } ], "cooling": { "type": "lin", "base": 0.001, "tau": 20.0 }, "camera_range": 0.15, "max_cameras": 10, "max_iterations": 20000, "distance": 0.02, "sigma": 0.1, "alpha": 1.0, "beta": 150.0, "h_exp": 1.0, "n_exp": 1.0, "verbose": true }
where:
-
"boxes" - list of rooms' representations.
- "vertex" - box's bottom left vertex.
- "x" - vertex's x coordinate.
- "y" - vertex's y coordinate.
- "width" - box's width.
- "height" - box's height.
- "vertex" - box's bottom left vertex.
-
"cooling" - configuration of cooling.
- "type" - cooling type (three possibilites: "log", "lin" & "exp").
- "base" - initial baseline (see "Cooling" section).
- "tau" - tau (see "Cooling" section).
-
"camera_range" - camera's range of vision.
-
"max_cameras" - maximum number of cameras.
-
"max_iterations" - maximum number of iterations.
-
"distance" - distance between checkpoints.
-
"sigma" - standard deviation of new coordiantes (exploration).
-
"alpha" - linear factor which scales loss component related to unobserved checkpoints (see "Loss function" section).
-
"beta" - linear factor which scales loss component related to cameras number (see "Loss function" section).
-
"h_exp" - exponent which scales loss component related to unobserved checkpoints (see "Loss function" section),
-
"n_exp" - linear factor which scales loss component related to cameras number (see "Loss function" section).
-
"verbose" - when true provides additional details about initialization and optimization.
where:
h - number of unobserved checkpoints,
n - number of cameras.
Type of cooling is configured through property "type" of object "cooling" in ./config.json file. There are three types of cooling (where i is a number of iteration):
- Logarithmic - set "type" to "log"
- Linear - set "type" to "lin",
- Exponential - set "type" to "exp"
- ./config.json
cd PySecurityCameras python main.py
After optimization following files are generated:
- ./init.png - image with initial camera's arrengment.
- ./out.png - image with final cameras' arrengment.
- ./cost.png - image with value of cost function during optimization.
On the left are final arrengments of cameras and on the right are values of loss functions during optimization.
Hyperparameters can be found using experiments which can be performed by running the ./experiments/main.py file. In configuaraion file ./experiments/experiment_config.json user can select examined parameter as well as intervals from which values are sampled. Experiment configuration file has a following structure:
{ "problem": { /* object from _./config.json_ file */ }, "interval": { "beg": 0.5, "end": 1 }, "num_values": 10, "num_tries": 10, "param": "beta", "tested": "cost" }
where:
-
"problem" - object from ./config.json file.
-
"interval" - numerical interval from which values of examined parameter are sampled.
- "beg" - beginnig of the interval.
- "end" - end of the interval.
-
"num_values" - number of samples.
-
"num_tries" - number of tries on one sample.
-
"param" - name of parameter which is a independent variable.
-
"tested" - name of parameter which is a dependent variable with 5 possible values:
- "cost" - value of cost function.
- "num_cameras" - value of cameras' number.
- "unobserved_fraction" - fraction of unobserved checkpoints to observed ones.
- "exec_time" - execution time.
- ./experiments/experiment_config.json
cd PySecurityCameras/experiments python main.py
In a result a ./experiments/{param}_test_on_{tested}.png is generated.