# Testbed

Testing Tie-Zones

``` 1 def iafittz(feats, labels, fdist):
2     from scipy.spatial import distance
3     from iaOPF import iaprim, iamstseeds, iadijkstratz
4     from numpy import array
5
6     A = distance.squareform(distance.pdist(feats, fdist))
7     B = iaprim(A)
8     P = iamstseeds(B, labels)
9     P = array(P)
10     print 'Protótipos:',P
11     labels = array(labels)
12     seeds_labels = labels[P]
13     OPF = iadijkstratz(A, P, seeds_labels)
14     return OPF
15
16 from scikits.learn import datasets
17
20     labels = iris.target
21     feats = iris['data']
22     return feats, labels
23
24 def euclidian(X, Y):
25     E = X - Y
26     return log(sqrt(dot(E, E)))
27
29
30 OPF = iafittz(feats, labels, euclidian)
31
32 print 'costs to root: ', OPF[0]
33 print 'parents: ', OPF[1]
34 print 'labels: ', OPF[2]
35
36 print 'tie-zone? ', (array(OPF[2]) == -1).any()
```
```Protótipos: [ 23  70  72  77  83  84  98 101 106 119 133 138 147]
costs to root:  [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.]
parents:  [  23.   23.   23.   23.   23.   23.   23.   23.   23.   23.   23.   23.
23.    0.    0.    5.   23.   23.   23.   23.   23.   23.   23.   23.
23.   23.   23.   23.   23.   23.   23.   23.   23.    0.   23.   23.
23.   23.   23.   23.   23.    1.   23.   23.   23.   23.   23.   23.
23.   23.   51.   70.   51.   55.   70.   70.   70.   53.   70.   55.
53.   70.   55.   70.   55.   70.   70.   54.   54.   55.   70.   51.
72.   70.   70.   70.   51.   77.   70.   53.   55.   55.   55.   83.
84.   70.   70.   51.   70.   55.   55.   70.   54.   53.   70.   70.
70.   70.   98.   70.  103.  101.  103.   70.   77.  102.  106.  102.
77.  100.   70.   70.   52.   70.   70.   70.   70.  105.  105.  119.
77.   70.  105.   70.   77.  102.   70.   70.   72.   52.  102.  105.
77.  133.   63.  102.  103.   70.  138.   52.   77.   50.   70.  103.
103.   52.   70.  147.   70.   70.]
labels:  [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  1.  1.  1.
1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.
1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.
1.  1.  1.  1.  1.  1.  1.  1.  1.  1. -1. -1. -1. -1. -1. -1. -1. -1.
-1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1.
-1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1.
-1. -1. -1. -1. -1. -1.]
tie-zone?  True
```

Testing Discretization

``` 1 def iafittzdisc(feats, labels, fdist):
2     from scipy.spatial import distance
3     from iaOPF import iaprim, iamstseeds, iadijkstratz
4     from numpy import array
5
6     A = distance.squareform(distance.pdist(feats, fdist))
7     A = A.round(1)
8     B = iaprim(A)
9     P = iamstseeds(B, labels)
10     P = array(P)
11     print 'Protótipos=', P
12     labels = array(labels)
13     seeds_labels = labels[P]
14     OPF = iadijkstratz(A, P, seeds_labels)
15     return OPF
16
17 OPF2 = iafittzdisc(feats, labels, euclidian)
18
19 print 'costs to root: ', OPF2[0]
20 print 'parents: ', OPF2[1]
21 print 'labels: ', OPF2[2]
22
23 print 'tie-zone? ', (array(OPF2[2]) == -1).any()
24
25 print OPF[2] == OPF2[2]
```
```Protótipos= [ 23  70  72  83  84  98 106 119 123 133 134 138 149]
costs to root:  [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.]
parents:  [  23.   23.   23.   23.   23.   23.   23.   23.   23.   23.   23.   23.
23.    0.    0.    5.   23.   23.   23.   23.   23.   23.   23.   23.
23.   23.   23.   23.   23.   23.   23.   23.   23.    0.   23.   23.
23.   23.   23.   23.   23.    1.   23.   23.   23.   23.   23.   23.
23.   23.   51.   70.   51.   55.   70.   70.   70.   53.   70.   55.
53.   70.   55.   70.   55.   70.   70.   51.   51.   55.   70.   70.
72.   70.   70.   70.   51.   70.   70.   53.   55.   55.   51.   83.
84.   70.   70.   51.   70.   55.   70.   70.   51.   53.   70.   70.
70.   70.   98.   70.  103.   70.  103.   70.   77.  102.  106.  102.
72.  100.   70.   70.   52.   70.   70.   70.   70.  105.  105.  119.
77.   70.  102.  123.   52.  103.   70.   70.   72.   52.  102.  105.
72.  133.  134.  102.  103.   70.  138.   50.   77.   50.   70.  103.
103.   70.   70.   70.   70.  149.]
labels:  [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  1.  1.  1.
1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.
1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.
1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1. -1.  1.
1.  1.  1.  1.  1. -1. -1. -1. -1.  1.  1. -1. -1. -1.  1. -1. -1. -1.
-1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1.
-1. -1. -1. -1. -1. -1.]
tie-zone?  True
[ True  True  True  True  True  True  True  True  True  True  True  True
True  True  True  True  True  True  True  True  True  True  True  True
True  True  True  True  True  True  True  True  True  True  True  True
True  True  True  True  True  True  True  True  True  True  True  True
True  True  True  True  True  True  True  True  True  True  True  True
True  True  True  True  True  True  True  True  True  True  True  True
True  True  True  True  True  True  True  True  True  True  True  True
True  True  True  True  True  True  True  True  True  True  True  True
True  True  True  True False False False False False False  True False
False False False False False  True  True  True  True False False  True
True  True False  True  True  True  True  True  True  True  True  True
True  True  True  True  True  True  True  True  True  True  True  True
True  True  True  True  True  True]
```

```Testing a bug on MST calculation

.. code:: python

from numpy import *
from iaOPF import *
from scipy.spatial import distance

from scikits.learn import datasets

labels = iris.target
feats = iris['data']
return feats, labels

def euclidian(X, Y):
E = X - Y
return sqrt(dot(E, E))