
# Principal Component Analysis Code : 

from numpy import mean,cov,double,cumsum,dot,linalg,array,rank,size,flipud
from pylab import *
import numpy as np
import matplotlib.pyplot as pp
#from enthought.mayavi import mlab

import scipy.ndimage as ni

import roslib; roslib.load_manifest('sandbox_tapo_darpa_m3')
import rospy
#import hrl_lib.mayavi2_util as mu
import hrl_lib.viz as hv
import hrl_lib.util as ut
import hrl_lib.matplotlib_util as mpu
import pickle

from mvpa.clfs.knn import kNN
from mvpa.datasets import Dataset
from mvpa.clfs.transerror import TransferError
from mvpa.misc.data_generators import normalFeatureDataset
from mvpa.algorithms.cvtranserror import CrossValidatedTransferError
from mvpa.datasets.splitters import NFoldSplitter

if __name__ == '__main__':

    matplotlib.rcParams['font.size'] = 12

# Categories

# Considering 1 cm
# 4 Categories
# Resolution
    cat_acc_resolution = np.array([60, 65.71, 64.29, 75, 79.29])
    cat_taxel_resolution = np.array([1, 2, 7, 25, 100])
    i = 0
    cat_acc_resolution_percent = np.zeros(5)
    while i < len(cat_acc_resolution)-1:
        cat_acc_resolution_percent[i+1] = 100*(cat_acc_resolution[i+1] - cat_acc_resolution[0])/cat_acc_resolution[0]
        i = i+1

# Objects

# Resolution
    ob_acc_resolution = np.array([62.14, 58.57, 64.29, 65.71, 72.86])
    ob_taxel_resolution = np.array([1, 2, 7, 25, 100])
    i = 0
    ob_acc_resolution_percent = np.zeros(5)
    while i < len(ob_acc_resolution)-1:
        ob_acc_resolution_percent[i+1] = 100*(ob_acc_resolution[i+1] - ob_acc_resolution[0])/ob_acc_resolution[0]
        i = i+1

# Considering 0.9 cm
# 4 Categories
# Resolution
    cat_acc_resolution_2 = np.array([60, 65.71, 64.29, 75, 79.29])
    cat_taxel_resolution_2 = np.array([1, 2, 7, 28, 112])
    i = 0
    cat_acc_resolution_2_percent = np.zeros(5)
    while i < len(cat_acc_resolution_2)-1:
        cat_acc_resolution_2_percent[i+1] = 100*(cat_acc_resolution_2[i+1] - cat_acc_resolution_2[0])/cat_acc_resolution_2[0]
        i = i+1

# Objects

# Resolution
    ob_acc_resolution_2 = np.array([62.14, 58.57, 64.29, 65.71, 72.86])
    ob_taxel_resolution_2 = np.array([1, 2, 7, 28, 112])
    i = 0
    ob_acc_resolution_2_percent = np.zeros(5)
    while i < len(ob_acc_resolution_2)-1:
        ob_acc_resolution_2_percent[i+1] = 100*(ob_acc_resolution_2[i+1] - ob_acc_resolution_2[0])/ob_acc_resolution_2[0]
        i = i+1


# Plots
# Resolution
    figure(1)
    plot(cat_taxel_resolution,cat_acc_resolution_percent,'-s')
    grid('True')
    hold('True')
    plot(ob_taxel_resolution,ob_acc_resolution_percent,'-s')
    title('Effect of Taxel Resolution Without Contact Motion Feature')
    legend(('Classification(Rigid-Fixed,Rigid-Movable,Soft-Fixed,Soft-Movable)', 'Object Recognition'),loc='4')
    ylabel('Percentage Improvement in Cross-Validation Accuracy from 1-Taxel')
    xlabel('Taxels/m (Each Taxel = 1cm X 1cm)')
    #axis([0,100,0,90])

# Resolution
    figure(2)
    plot(cat_taxel_resolution_2,cat_acc_resolution_2_percent,'-s', linewidth=3)
    grid('True')
    hold('True')
    plot(ob_taxel_resolution_2,ob_acc_resolution_2_percent,'-s', linewidth=3)
    title('Effect of Taxel Resolution Without Contact Motion Feature', fontsize='14')
    legend(('Classification\n(Rigid-Fixed,Rigid-Movable)\n(Soft-Fixed,Soft-Movable)', 'Object Recognition'),loc='4')
    ylabel('Cross-Validation Accuracy \n(Percent change from 1-Taxel)', fontsize='14')
    xlabel('Taxels/m (Each Taxel = 9mm X 9mm)', fontsize='14')
    show()



