File: checkerboard.h

package info (click to toggle)
mldemos 0.5.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 32,224 kB
  • ctags: 46,525
  • sloc: cpp: 306,887; ansic: 167,718; ml: 126; sh: 109; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,343 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef DLIB_CHECKERBOARD_TeST_H_
#define DLIB_CHECKERBOARD_TeST_H_

#include <dlib/matrix.h>
#include <vector>
#include <dlib/rand.h>

namespace dlib
{

    template <typename scalar_type>
    void get_checkerboard_problem (
        std::vector<matrix<scalar_type,2,1> >& x,
        std::vector<scalar_type>& y,
        const long num_samples,
        const long board_dimension = 8
    )
    /*!
        requires
            - num_samples > 0
            - board_dimension > 0
        ensures
            - #x.size() == y.size() == num_samples
            - is_binary_classification_problem(#x,#y) == true
            - #x will contain points and #y labels that were
              sampled randomly from a checkers board that has 
              board_dimension squares on each side. 
    !*/
    {
        static dlib::rand rnd;

        x.clear();
        y.clear();

        matrix<scalar_type,2,1> sample;
        for (long i = 0; i < num_samples; ++i)
        {
            sample(0) = rnd.get_random_double();
            sample(1) = rnd.get_random_double();
            sample *= board_dimension;

            x.push_back(sample);
            if (((int)sum(floor(sample)) %2) == 0)
                y.push_back(+1);
            else
                y.push_back(-1);
            
        }
    }


}

#endif // DLIB_CHECKERBOARD_TeST_H_