Skip to content

PySecurityCameras is an application which finds optimal arrangement of cameras located in collection od rooms. Search is performed using Simulated Annealing algorithm.

Notifications You must be signed in to change notification settings

gizmoy/PySecurityCameras

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PySecurityCameras

Introduction

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.

Configuration

Configuration file

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.
  • "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.

Loss function

loss function

where:
      h - number of unobserved checkpoints,
      n - number of cameras.

Cooling

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):

  1. Logarithmic - set "type" to "log"

            

  1. Linear - set "type" to "lin",

            

  1. Exponential - set "type" to "exp"

            

Execution

Input

  • ./config.json

Run

cd PySecurityCameras
python main.py

Output

After optimization following files are generated:

  1. ./init.png - image with initial camera's arrengment.
  2. ./out.png - image with final cameras' arrengment.
  3. ./cost.png - image with value of cost function during optimization.

Examples of results

On the left are final arrengments of cameras and on the right are values of loss functions during optimization.

results

Hyperparameters fine-tuning

Configuration

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.

Execution

Input

  • ./experiments/experiment_config.json

Run

cd PySecurityCameras/experiments
python main.py

Output

In a result a ./experiments/{param}_test_on_{tested}.png is generated.

Examples of experiments results

example of experiment

About

PySecurityCameras is an application which finds optimal arrangement of cameras located in collection od rooms. Search is performed using Simulated Annealing algorithm.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages