Skip to content

maksymshylo/statistical_methods

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Statistical Methods of Pattern Recognition

Laboratory work from the university course.

Setup

To run these applications you need to have Python3.10.

  1. Clone repo:
git clone https://github.com/maksymshylo/statistical-methods.git
  1. Create virtual environment.
python3.10 -m venv .venv
  1. Activate it
source .venv/bin/activate
  1. Install requirements:
pip install -r requirements.txt

Lab 1 - Recognition of a noised image.

Description

The program converts a string to noised image and then decodes it.

Usage

 $ python3 lab1/decode_string.py --help
usage: decode_string.py [-h] --input_string INPUT_STRING --noise_level NOISE_LEVEL [--seed SEED]

options:
  -h, --help            show this help message and exit
  --input_string INPUT_STRING
                        input string
  --noise_level NOISE_LEVEL
                        noise level of bernoulli distribution
  --seed SEED           seed to debug

Examples

python3 lab1/generate_string.py --input_string "billy herrington" --noise_level 0.35 --seed 45

Decoded string: "billy herrington"

Original image Noised image Decoded image
python3 lab1/generate_string.py --input_string "van darkholme" --noise_level 0.45 --seed 45

Decoded string: "nde deauff sc"

Original image Noised image Decoded image

Lab 2 - Recognition of black vertical and horizontal lines

Description

The program creates an image with black vertical and horizontal lines, apply bernoulli noise, and denoise it.

Gibbs Sampling

Usage

$ python3 lab2/gibbs_sampler.py --help
usage: gibbs_sampler.py [-h] [--h H] [--w W] [--n_lines N_LINES]
                        [--noise_level NOISE_LEVEL]
                        [--column_prob COLUMN_PROB] [--n_iter N_ITER]

options:
  -h, --help            show this help message and exit
  --h H                 Height of image.
  --w W                 Width of image.
  --n_lines N_LINES     Number of horizontal and vertical lines.
  --noise_level NOISE_LEVEL
                        Noise level of bernoulli distribution.
  --column_prob COLUMN_PROB
                        Probability of column to be black.
  --n_iter N_ITER       Number of iterations for Gibbs Sampler.

Examples

 $ python3 lab2/gibbs_sampler.py --h 250 --w 250 --n_lines 40 --noise_level 0.42 --column_prob 0.5 --n_iter 100

column accuracy 99.6

row accuracy 99.6

Original image Noised image Decoded image
Precise solution

Usage

 $ python3 lab2/precise_solution.py --help
usage: precise_solution.py [-h] --h H --w W --n_lines N_LINES --noise_level NOISE_LEVEL --column_prob COLUMN_PROB

options:
  -h, --help            show this help message and exit
  --h H                 Height of image.
  --w W                 Width of image.
  --n_lines N_LINES     Number of horizontal and vertical lines.
  --noise_level NOISE_LEVEL
                        Noise level of bernoulli distribution.
  --column_prob COLUMN_PROB
                        Probability of column to be black.

Examples

 $ python3 lab2/precise_solution.py --h 250 --w 250 --n_lines 40 --noise_level 0.42 --column_prob 0.5

column accuracy 96.8

row accuracy 99.2

Original image Noised image Decoded image

Lab 3 - Gibbs Sampler for recognizing a noised string over another one

Note: Lengths of string should be the same.

Usage

 $ python3 lab3/row_over_row.py --help
usage: row_over_row.py [-h] --string_1 STRING_1 --string_2 STRING_2 --noise_level NOISE_LEVEL --n_iter N_ITER [--seed SEED]

options:
  -h, --help            show this help message and exit
  --string_1 STRING_1   The first string to decode.
  --string_2 STRING_2   The second string to decode.
  --noise_level NOISE_LEVEL
                        Noise level of bernoulli distribution.
  --n_iter N_ITER       Number of Gibbs Sampler iterations.
  --seed SEED           Seed to debug

Examples

python3 lab3/row_over_row.py --string_1 'deliver' --string_2 'reviled' --noise_level 0.3 --n_iter 10 --seed 67
Decoding strings...
Iteration 0. String 1: deliver; String 2: reviled.
Iteration 1. String 1: deliver; String 2: reviled.
Iteration 2. String 1: deliver; String 2: reviled.
Iteration 3. String 1: deliver; String 2: reviled.
Iteration 4. String 1: deliver; String 2: reviled.
Iteration 5. String 1: deliver; String 2: reviled.
Iteration 6. String 1: deliver; String 2: reviled.
Iteration 7. String 1: deliver; String 2: reviled.
Iteration 8. String 1: deliver; String 2: reviled.
Iteration 9. String 1: deliver; String 2: reviled.
Input string 1:  deliver
Input string 2:  reviled
The first decoded string:  deliver
The second decoded string:  reviled
Input string over string image Noised string over string image Decoded string 1 Decoded string 2
 $ python3 lab3/row_over_row.py --string_1 'hello' --string_2 'world' --noise_level 0.35 --n_iter 25 --seed 67
Iteration 0. String 1: h|e|||||||||rdo||||; String 2: wo||||||||h||ld.
Iteration 1. String 1: h|e|||||||||r||||||||||||o||||; String 2: wo||||||||h||ld.
Iteration 2. String 1: h|e|||||||||r||||||||||||o||||; String 2: wo||||||||h||ld.
Iteration 3. String 1: h|e|||||||||r||||||||||||o||||; String 2: wo||||||||||||||||||||||ld.
Iteration 4. String 1: h|||z|||||r||||||||||||o||||; String 2: wo||||||||h||ld.
Iteration 5. String 1: he||||||||||r||||||||||||o||||; String 2: wo||||||||h||ld.
Iteration 6. String 1: he||||||||||r||||||||||||o||||; String 2: wo||||||||h||ld.
Iteration 7. String 1: h|e|||||||||r||||||||||||o||||; String 2: wo||||||||h||ld.
Iteration 8. String 1: he||||||||||r||||||||||||o||||; String 2: wo||||||||h||ld.
Iteration 9. String 1: h|e|||||||||r||||||||||||o||||; String 2: wo||||||||h||ld.
Iteration 10. String 1: he||||||||||r||||||||||||o||||; String 2: wo||||||||h||ld.
Iteration 11. String 1: h|e|||||||||r||||||||||||o||||; String 2: wo||||||||h||ld.
Iteration 12. String 1: h|e|||||||||r||||||||||||o||||; String 2: wo||||||||h||ld.
Iteration 13. String 1: he||||||||||r||||||||||||o||||; String 2: wo||||||||h||ld.
Iteration 14. String 1: h|e|||||||||r||||||||||||o||||; String 2: wo||||||||h||ld.
Iteration 15. String 1: h|e|||||||||r||||||||||||o||||; String 2: wo||||||||||||||||||||||ld.
Iteration 16. String 1: h||e||||||||r||||||||||||o||||; String 2: world.
Iteration 17. String 1: hello||||; String 2: world.
Iteration 18. String 1: hello||||; String 2: world.
Iteration 19. String 1: hello||||; String 2: world.
Iteration 20. String 1: hello||||; String 2: world.
Iteration 21. String 1: hello||||; String 2: world.
Iteration 22. String 1: hello||||; String 2: world.
Iteration 23. String 1: hello||||; String 2: world.
Iteration 24. String 1: hello||||; String 2: world.
Input string 1:  hello
Input string 2:  world
The first decoded string:  hello||||
The second decoded string:  world
Input string over string image Noised string over string image Decoded string 1 Decoded string 2

Some other examples of possible input strings with the same widths:

deliver <=> reviled
animal <=> lamina
depots <=> stoped
diaper <=> repaid
drawer <=> reward
looter <=> retool
murder <=> redrum
redips <=> spider
debut <=> tubed
deeps <=> speed
peels <=> sleep
serif <=> fires
steel <=> leets

Releases

No releases published

Packages

No packages published

Languages