Function iafeaturespace

Generate an 2D image feature space from prototypes and samples

Synopsis

function img = iafeatspace(prot_A,samp_A,prot_B,samp_B, imgshape, maxv)

Input:

  • prot_A: list of 2D coordinates of prototypes of class A
  • samp_A: ordered list of 2D coordinates of samples of class A, ordered by the cost to the nearest prototype
  • prot_B: list of 2D coordinates of prototypes of class B
  • samp_B: ordered list of 2D coordinates of samples of class B, ordered by the cost to the nearest prototype
  • imgshape: tuple, output image size, in pixels (cols, rows)
  • maxv: tuple, maximum values of coordinates (width, height), (0,0) is at the center of the image

Output:

  • img: image ready to be displayed using adshow()

Description

iafeatspace generates a graphical representation of the 2D features space of the OPF classifier for the case of two classes. The input are lists of class A and class B prototypes and samples. The image display in gray scale the distance from the nearest prototype overlayed by a red line dividing the feature space; prototypes as circles in green (class A) and blue (class B) and samples as squares in green (class A) and blue (class B). The choice of prototypes and samples has to be consistent with OPF classifier, i.e., they need to be defined from OPF methodology of finding prototypes from MST.

Warning: the list of samples (samp_A and samp_B) must be ordered.

Code

Examples

One prototype for each class and one sample for class A. We can visualize the interfere that the sample of class A make on the feature space.

1 from iaOPF import iafeatspace
2 prot_A = [(-1,0)]   # prototypes of class A
3 samp_A = [(-1,-2)]  # samples of class A
4 prot_B = [(+1,0)]   # prototypes of class B
5 samp_B = []  # samples of class B
6 img = iafeatspace(prot_A,samp_A,prot_B,samp_B, (400,200), (6,3))
7 adshow(img)

A more elaborate case, with two prototypes and two samples for each class.

1 from iaOPF import iafeatspace
2 prot_A = [(-1,0),(-1.5,0)]   # prototypes of class A
3 samp_A = [(-1,-2),(-1,-3)]  # samples of class A
4 prot_B = [(+1,0),(+1.5,0.5)]   # prototypes of class B
5 samp_B = [(+1,+3),(+1,+3.5)]  # samples of class B
6 img = iafeatspace(prot_A,samp_A,prot_B,samp_B, (400,200), (6,3))
7 adshow(img)

Comparing the previous example with the nearest neighbor classifier, where all samples are prototypes.

1 from iaOPF import iafeatspace
2 prot_A = [(-1,0),(-1.5,0),(-1,-2),(-1,-3)]   # prototypes of class A
3 samp_A = []  # samples of class A
4 prot_B = [(+1,0),(+1.5,0.5),(+1,+3),(+1,+3.5)]   # prototypes of class B
5 samp_B = []  # samples of class B
6 img = iafeatspace(prot_A,samp_A,prot_B,samp_B, (400,200), (6,3))
7 adshow(img)