Towards Hierarchical Curiosity-Driven Exploration of Sensorimotor Models

Abstract for ICDL (March 23rd, 2015) Internship report

III. Results of preliminary experiments


In [99]:
import cPickle
import matplotlib.pyplot as plt
import os
import sys
from numpy import array, mean, std, sqrt
sys.path.append('../')
from explaupoppydiva.drawer import Drawer
logs = '../logs/'
log_dirs = [
#'2015-04-18_02-11-25-explaupoppydiva-riac-cube2',
'2015-04-18_02-19-01-explaupoppydiva-riac-cube3',
#'2015-04-18_02-17-58-explaupoppydiva-riac-cube5',
#'2015-04-14_11-09-45-explaupoppydiva-discretized_progress-cube2',
#'2015-04-14_11-09-52-explaupoppydiva-discretized_progress-cube3',
#'2015-04-14_11-09-45-explaupoppydiva-random-cube2',
'2015-04-11_12-08-52_cube3',
#'2015-04-09_16-27-45_cube5',
            ]

iterations = 10000
eval_at = range(1, iterations + 1, iterations / 50)

In [100]:
import sys
import explaupoppydiva.config as config
sys.modules['config'] = config
pickled_logs = {}

for log_dir in log_dirs:
    for xp_dir in os.listdir(os.path.join(logs,log_dir)) + ['']:
        if os.path.isdir(os.path.join(logs, log_dir, xp_dir)):
        
            print os.path.join(logs, log_dir, xp_dir)
            for log_file in os.listdir(os.path.join(logs, log_dir, xp_dir)):
                file_path = os.path.join(logs, log_dir, xp_dir, log_file)
                if file_path.endswith('.pickle'):
                    #print file_path
                    try:
                        with open(file_path, 'r') as f:
                            pickled_logs[file_path] = cPickle.load(f)
                            f.close()                                         
                    except ValueError:
                        print "ValueError", file_path


../logs/2015-04-18_02-19-01-explaupoppydiva-riac-cube3/SEQ-RIAC-seq_10000
../logs/2015-04-18_02-19-01-explaupoppydiva-riac-cube3/MS1-RIAC-seq_10000
../logs/2015-04-18_02-19-01-explaupoppydiva-riac-cube3/TOP-DOWN-CMA-RIAC-seq_500
../logs/2015-04-18_02-19-01-explaupoppydiva-riac-cube3/TOP-DOWN-RANDOM-RIAC-seq_500
../logs/2015-04-18_02-19-01-explaupoppydiva-riac-cube3/MS2-RIAC-seq_10000
../logs/2015-04-18_02-19-01-explaupoppydiva-riac-cube3/MOTOR_BABBLING-seq_10000
../logs/2015-04-18_02-19-01-explaupoppydiva-riac-cube3/S1S2-RIAC-seq_10000
../logs/2015-04-18_02-19-01-explaupoppydiva-riac-cube3/
../logs/2015-04-11_12-08-52_cube3/S1S2-GOAL-BABBLING-seq_10000
../logs/2015-04-11_12-08-52_cube3/MS2-GOAL-BABBLING-seq_10000
ValueError ../logs/2015-04-11_12-08-52_cube3/MS2-GOAL-BABBLING-seq_10000/log10.pickle
../logs/2015-04-11_12-08-52_cube3/TOP-DOWN-CMA-GOAL-BABBLING-seq_500
../logs/2015-04-11_12-08-52_cube3/TOP-DOWN-RANDOM-GOAL-BABBLING-seq_500
../logs/2015-04-11_12-08-52_cube3/MS1-GOAL-BABBLING-seq_10000
../logs/2015-04-11_12-08-52_cube3/SEQ-GOAL-BABBLING-seq_10000
../logs/2015-04-11_12-08-52_cube3/MOTOR_BABBLING-seq_10000
../logs/2015-04-11_12-08-52_cube3/

In [101]:
%pylab inline

explorations = {}

for log_dir in log_dirs:
    explorations[log_dir] = {}
    fig_explo, ax = plt.subplots()
    fig_explo.canvas.set_window_title('Exploration comparison for ' + log_dir)
    for xp_dir in sorted(os.listdir(os.path.join(logs,log_dir))) + ['']:
        if os.path.isdir(os.path.join(logs, log_dir, xp_dir)):
        
            explo = {}
            #print os.path.join(logs, log_dir, xp_dir)
            for log_file in os.listdir(os.path.join(logs, log_dir, xp_dir)):
                file_path = os.path.join(logs, log_dir, xp_dir, log_file)
                if file_path.endswith('.pickle'):
                    #print file_path
                    if pickled_logs.has_key(file_path):
                        log = pickled_logs[file_path]
                        if len(log.explo) == len(log.config.eval_at):
                            explo[log_file] = array(log.explo)
            if len(explo.values()) > 0:
                l = len(explo.values()[0])
                #print log.config.name
                #print explo.values()
                #print l
                x = eval_at[:l]
                y = mean(array(explo.values()), axis=0)
                error = std(array(explo.values()), axis=0)
                error = error / sqrt(len(explo)) # Standard error of the mean
                color_cycle = ax._get_lines.color_cycle
                next_color = next(color_cycle)
                ax.plot(x, y, label = log.config.name, color=next_color)
                ax.fill_between(x, y-error, y+error, alpha=0.2, label = log.config.name, color = next_color)
                #ax.errorbar(eval_at[:l],, yerr=, label = log.config.name)
                
                explorations[log_dir][xp_dir] = explo
                
    
    
    fig_explo.show()
    
    plt.xlabel('Iterations', fontsize=18)
    plt.ylabel('Explored cells', fontsize=18)
    ax.legend(loc='lower right')
    fig_explo.set_size_inches(16,10)
    plt.savefig(logs + log_dir + '/explo-' + log_dir[0:-1] + '.png')
    plt.show()


Populating the interactive namespace from numpy and matplotlib
WARNING: pylab import has clobbered these variables: ['f']
`%matplotlib` prevents importing * from pylab and numpy

In [102]:
end_explo = {}
for log_dir in explorations:
    end_explo[log_dir] = {}
    for xp in explorations[log_dir]:
        end_explo[log_dir][xp] = {}
        end_explo[log_dir][xp] = [explorations[log_dir][xp][key][-1] for key in explorations[log_dir][xp]]

In [103]:
for log_dir in end_explo:
    print log_dir
    for xp in end_explo[log_dir]:
        print "    ", xp
        print "        ", end_explo[log_dir][xp]


2015-04-11_12-08-52_cube3
     TOP-DOWN-CMA-GOAL-BABBLING-seq_500
         [245.0, 329.0, 364.0, 218.0, 237.0, 304.0, 226.0, 300.0]
     MOTOR_BABBLING-seq_10000
         [109.0, 101.0, 114.0, 107.0, 100.0, 101.0, 101.0, 99.0, 108.0]
     MS1-GOAL-BABBLING-seq_10000
         [140.0, 102.0, 101.0, 137.0, 118.0, 115.0, 135.0, 107.0, 124.0]
     S1S2-GOAL-BABBLING-seq_10000
         [134.0, 101.0, 141.0, 113.0, 97.0, 48.0, 66.0, 298.0, 70.0, 65.0]
     MS2-GOAL-BABBLING-seq_10000
         [298.0, 200.0, 237.0, 354.0, 184.0, 185.0, 423.0, 360.0, 228.0]
     TOP-DOWN-RANDOM-GOAL-BABBLING-seq_500
         [173.0, 162.0, 125.0, 225.0, 217.0, 207.0, 207.0, 268.0, 290.0]
     SEQ-GOAL-BABBLING-seq_10000
         [115.0, 144.0, 288.0, 188.0, 203.0, 249.0, 194.0, 233.0, 138.0]
2015-04-18_02-19-01-explaupoppydiva-riac-cube3
     MOTOR_BABBLING-seq_10000
         [110.0, 100.0, 102.0, 87.0, 95.0, 91.0, 106.0, 100.0, 103.0, 102.0]
     TOP-DOWN-RANDOM-RIAC-seq_500
         [256.0, 190.0, 221.0, 270.0, 214.0, 176.0, 229.0, 307.0, 449.0, 130.0]
     S1S2-RIAC-seq_10000
         [148.0, 100.0, 128.0, 104.0, 120.0, 167.0, 86.0, 77.0, 124.0, 84.0]
     MS1-RIAC-seq_10000
         [111.0, 86.0, 174.0, 100.0]
     TOP-DOWN-CMA-RIAC-seq_500
         [302.0, 340.0, 246.0, 212.0, 196.0, 159.0, 255.0, 231.0, 264.0, 252.0]
     SEQ-RIAC-seq_10000
         [226.0, 170.0, 196.0, 186.0, 242.0]
     MS2-RIAC-seq_10000
         [342.0, 352.0, 203.0, 202.0, 332.0, 176.0, 314.0, 262.0, 155.0, 202.0]

In [107]:
from scipy.stats import mannwhitneyu
x = end_explo['2015-04-18_02-19-01-explaupoppydiva-riac-cube3']['MS1-RIAC-seq_10000']
y = end_explo['2015-04-18_02-19-01-explaupoppydiva-riac-cube3']['SEQ-RIAC-seq_10000']
print mannwhitneyu(x, y)


(1.0, 0.018668207960331439)

In [33]:
from scipy.stats import mannwhitneyu
x = end_explo['2015-04-11_12-08-52_cube3']['MOTOR_BABBLING-seq_10000']
y = end_explo['2015-04-11_12-08-52_cube3']['MS1-GOAL-BABBLING-seq_10000']
print mannwhitneyu(x, y)


(13.0, 0.0082467781068696969)

Competent Explo


In [45]:
import cPickle
import matplotlib.pyplot as plt
import os
import sys
from numpy import array, mean, std, sqrt
sys.path.append('../')
from explaupoppydiva.drawer import Drawer
logs = '../logs/'
log_dirs = [
'2015-04-30_12-54-30-explaupoppydiva-tree-cube3'
            ]

iterations = 10000
eval_at = range(iterations / 10, iterations + 1, iterations / 10)

In [48]:
plot_explo = True
plot_explo_comp = True
explorations = {}
exploration_comp = {}

conditions_to_plot = [
                      'MOTOR_BABBLING-seq_10000',
                      'MS2-tree-seq_10000',
                      'SEQ-tree-seq_10000',
                      'TOP-DOWN-CMA-tree-seq_500',
                      'MS2-GOAL-BABBLING-seq_10000',
                      'SEQ-GOAL-BABBLING-seq_10000',
                      'TOP-DOWN-CMA-GOAL-BABBLING-seq_500',                      
                      ]

for log_dir in log_dirs:
    explorations[log_dir] = {}
    exploration_comp[log_dir] = {}
    if plot_explo:
        fig_explo, ax_explo = plt.subplots()
        fig_explo.canvas.set_window_title('Exploration comparison for ' + log_dir)
    
    if plot_explo_comp:
        fig_explo_comp, ax_explo_comp = plt.subplots()
        fig_explo_comp.canvas.set_window_title('ExploComp comparison for ' + log_dir)   
         
    for xp_dir in sorted(os.listdir(os.path.join(logs,log_dir))) + ['']:
        print xp_dir
        if xp_dir in conditions_to_plot and os.path.isdir(os.path.join(logs, log_dir, xp_dir)):
        
            comp = {}
            explo = {}
            explo_comp = {}
            print os.path.join(logs, log_dir, xp_dir)
            for log_file in os.listdir(os.path.join(logs, log_dir, xp_dir)):
                file_path = os.path.join(logs, log_dir, xp_dir, log_file)
                if file_path.endswith('.pickle'):
                    print file_path
                    try:
                        with open(file_path, 'r') as f:
                            log = cPickle.load(f)
                            f.close()
                            #print "explo", log.explo, "explocomp", log.explo_comp, "comp", log.eval_errors
                            
                            if plot_explo:
                                if len(log.explo) == len(eval_at):
                                    explo[log_file] = array(log.explo)
                                    
                            if plot_explo_comp:
                                if len(log.explo_comp) == len(eval_at):
                                    explo_comp[log_file] = array(log.explo_comp)
                                    
                    except ValueError:
                        print "ValueError"
            if plot_explo:
                if len(explo.values()) > 0:
                    print "Explo", mean(array(explo.values()), axis=0)
                    l = len(explo.values()[0])
                    print log.config.name
                    #print explo.values()
                    #print l
                    x = eval_at[:l]
                    y = mean(array(explo.values()), axis=0)
                    error = std(array(explo.values()), axis=0)
                    error = error / sqrt(len(explo)) # Standard error of the mean
                    color_cycle = ax_explo._get_lines.color_cycle
                    next_color = next(color_cycle)
                    ax_explo.plot(x, y, label = log.config.name, color=next_color)
                    if len(explo.values()) > 1:
                        ax_explo.fill_between(x, y-error, y+error, alpha=0.2, label = log.config.name, color = next_color)
                    #ax.errorbar(eval_at[:l],, yerr=, label = log.config.name)
                    
                    explorations[log_dir][xp_dir] = explo
                    
            if plot_explo_comp:
                if len(explo_comp.values()) > 0:
                    print "ExploComp", explo_comp.values()
                    l = len(explo_comp.values()[0])
                    print log.config.name
                    #print explo_comp.values()
                    #print l
                    x = eval_at[:l]
                    y = mean(array(explo_comp.values()), axis=0)
                    error = std(array(explo_comp.values()), axis=0)
                    error = error / sqrt(len(explo_comp)) # Standard error of the mean
                    color_cycle = ax_explo_comp._get_lines.color_cycle
                    next_color = next(color_cycle)
                    ax_explo_comp.plot(x, y, label = log.config.name, color=next_color)
                    if len(explo_comp.values()) > 1:
                        ax_explo_comp.fill_between(x, y-error, y+error, alpha=0.2, label = log.config.name, color = next_color)
                    #ax_comp.errorbar(eval_at[:l],, yerr=, label = log.config.name)
                
                    exploration_comp[log_dir][xp_dir] = explo_comp
                
    
    if plot_explo:
        fig_explo.show()
        ax_explo.legend(loc='upper left')
        #fig_explo.set_size_inches(19.2,12)
        plt.xlabel('Iterations', fontsize=18)
        plt.ylabel('Explored cells', fontsize=18)
        #plt.show(block=False)
        plt.savefig(logs + log_dir + '/explo-' + log_dir[0:-1] + '.png')
    
    
    if plot_explo_comp:
        fig_explo_comp.show()
        ax_explo_comp.legend(loc='upper left')
        #fig_explo_comp.set_size_inches(19.2,12)
        
        plt.xlabel('Iterations', fontsize=18)
        plt.ylabel('Reached cells', fontsize=18)
        #plt.show(block=False)
        plt.savefig(logs + log_dir + '/explo_comp-' + log_dir[0:-1] + '.png')
    plt.show()


MOTOR_BABBLING-seq_10000
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/MOTOR_BABBLING-seq_10000
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/MOTOR_BABBLING-seq_10000/log1.pickle
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/MOTOR_BABBLING-seq_10000/log3.pickle
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/MOTOR_BABBLING-seq_10000/log2.pickle
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/MOTOR_BABBLING-seq_10000/log4.pickle
Explo [  3.66666667  20.66666667  26.          30.66666667  34.66666667  36.
  38.33333333  38.66666667  39.          42.        ]
MOTOR_BABBLING
ExploComp [array([1, 2, 2, 3, 3, 1, 0, 2, 0, 3]), array([0, 2, 2, 4, 2, 4, 5, 3, 4, 4]), array([2, 4, 3, 3, 3, 3, 2, 2, 4, 2])]
MOTOR_BABBLING
MS1-tree-seq_10000
MS2-tree-seq_10000
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/MS2-tree-seq_10000
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/MS2-tree-seq_10000/log1.pickle
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/MS2-tree-seq_10000/log3.pickle
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/MS2-tree-seq_10000/log2.pickle
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/MS2-tree-seq_10000/log5.pickle
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/MS2-tree-seq_10000/log4.pickle
Explo [  4.75  42.75  52.75  58.25  66.    70.5   74.    77.5   78.25  80.25]
MS2-tree
ExploComp [array([2, 4, 4, 3, 5, 6, 5, 4, 3, 4]), array([1, 4, 3, 0, 3, 5, 7, 4, 3, 3]), array([1, 8, 3, 1, 4, 3, 6, 5, 1, 3]), array([2, 4, 2, 3, 3, 4, 3, 1, 1, 3])]
MS2-tree
S1S2-tree-seq_10000
SEQ-tree-seq_10000
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/SEQ-tree-seq_10000
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/SEQ-tree-seq_10000/log1.pickle
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/SEQ-tree-seq_10000/log3.pickle
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/SEQ-tree-seq_10000/log2.pickle
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/SEQ-tree-seq_10000/log4.pickle
Explo [  5.          20.33333333  25.66666667  30.66666667  34.33333333
  36.66666667  48.66666667  55.33333333  58.66666667  60.        ]
SEQ-tree
ExploComp [array([3, 6, 7, 5, 7, 4, 8, 7, 7, 7]), array([2, 4, 6, 8, 7, 5, 7, 6, 4, 6]), array([ 3,  8,  6,  8,  6, 11,  6, 10, 10,  7])]
SEQ-tree
TOP-DOWN-CMA-tree-seq_500
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/TOP-DOWN-CMA-tree-seq_500
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/TOP-DOWN-CMA-tree-seq_500/log1.pickle
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/TOP-DOWN-CMA-tree-seq_500/log3.pickle
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/TOP-DOWN-CMA-tree-seq_500/log2.pickle
../logs/2015-04-30_12-54-30-explaupoppydiva-tree-cube3/TOP-DOWN-CMA-tree-seq_500/log4.pickle
Explo [  4.66666667  30.          43.33333333  51.66666667  58.66666667
  62.33333333  65.66666667  67.33333333  68.66666667  71.        ]
TOP-DOWN-CMA-tree
ExploComp [array([ 2,  5,  9,  4, 10, 10,  9,  8,  7,  8]), array([ 3,  9,  6,  8,  9, 10,  6,  8,  9,  8]), array([ 3, 10,  9,  6,  8,  5,  7,  4,  2,  6])]
TOP-DOWN-CMA-tree
TOP-DOWN-RANDOM-tree-seq_500
comp.png
explo-2015-04-30_12-54-30-explaupoppydiva-tree-cube.png
explo.png
explo_comp-2015-04-30_12-54-30-explaupoppydiva-tree-cube.png
explo_comp.png


In [54]:
end_explo = {}
for log_dir in explorations:
    end_explo[log_dir] = {}
    for xp in explorations[log_dir]:
        end_explo[log_dir][xp] = {}
        end_explo[log_dir][xp] = [explorations[log_dir][xp][key][-1] for key in explorations[log_dir][xp]]
print end_explo
end_explo_comp = {}
for log_dir in exploration_comp:
    end_explo_comp[log_dir] = {}
    for xp in exploration_comp[log_dir]:
        end_explo_comp[log_dir][xp] = {}
        end_explo_comp[log_dir][xp] = [exploration_comp[log_dir][xp][key][-1] for key in exploration_comp[log_dir][xp]]
print end_explo_comp


{'2015-04-30_12-54-30-explaupoppydiva-tree-cube3': {'SEQ-tree-seq_10000': [39.0, 63.0, 78.0], 'MS2-tree-seq_10000': [69.0, 106.0, 75.0, 71.0], 'TOP-DOWN-CMA-tree-seq_500': [62.0, 96.0, 55.0], 'MOTOR_BABBLING-seq_10000': [44.0, 40.0, 42.0]}}
{'2015-04-30_12-54-30-explaupoppydiva-tree-cube3': {'SEQ-tree-seq_10000': [7, 6, 7], 'MS2-tree-seq_10000': [4, 3, 3, 3], 'TOP-DOWN-CMA-tree-seq_500': [8, 8, 6], 'MOTOR_BABBLING-seq_10000': [3, 4, 2]}}

In [63]:
for log_dir in end_explo:
    print log_dir
    for xp in end_explo_comp[log_dir]:
        print "    ", xp
        print "        ", end_explo_comp[log_dir][xp]


2015-04-30_12-54-30-explaupoppydiva-tree-cube3
     SEQ-tree-seq_10000
         [7, 6, 7]
     MS2-tree-seq_10000
         [4, 3, 3, 3]
     TOP-DOWN-CMA-tree-seq_500
         [8, 8, 6]
     MOTOR_BABBLING-seq_10000
         [3, 4, 2]

In [61]:
from scipy.stats import mannwhitneyu
x = end_explo_comp['2015-04-30_12-54-30-explaupoppydiva-tree-cube3']['MOTOR_BABBLING-seq_10000']
y = end_explo_comp['2015-04-30_12-54-30-explaupoppydiva-tree-cube3']['TOP-DOWN-CMA-tree-seq_500']
print mannwhitneyu(x, y)


(0.0, 0.038261250237529611)

ARM SEQ


In [72]:
import cPickle
import matplotlib.pyplot as plt
from numpy import array, mean, std, sqrt
import os
import sys

from explaupoppydiva.drawer import Drawer

logs = '../logs/'
log_dirs = [
            '2015-05-30_16-11-48-Test-Arm-Seq',
            #'2015-05-30_15-30-09-Test-Arm-Seq',
            #'2015-05-30_14-44-11-Test-Arm-Seq',
            #'2015-05-27_17-21-18-Test-Arm-Seq',
#  '2015-05-27_15-07-24-Test-Arm-Seq',
#  '2015-05-26_19-58-11-Test-Arm-Seq'
            ]

conditions_to_plot = [
                      'Arm-Seq-MB-F-seq_5000',
                      'Arm-Seq-MB-H-seq_5000',
                    'Arm-Seq-GB-F-seq_5000',
                    'Arm-Seq-GB-H-seq_5000',
                    'Arm-Seq-GB-H-TD-seq_1240',   
                    'Arm-Seq-Tr-H-TD-seq_1240', 
                     'Arm-Seq-Tr-H-seq_5000', 
                     'Arm-Seq-Tr-F-seq_5000',            
                      ]


plot_explo = True

iterations = 5000

explorations = {}

for log_dir in log_dirs:
    explorations[log_dir] = {}
    
    if plot_explo:
        fig_explo, ax_explo = plt.subplots()
        fig_explo.canvas.set_window_title('Exploration comparison for ' + log_dir)
    
    
    for xp_dir in sorted(os.listdir(os.path.join(logs,log_dir)) + ['']):
        print xp_dir
        if xp_dir in conditions_to_plot and os.path.isdir(os.path.join(logs, log_dir, xp_dir)):
#             if xp_dir[-3:] == '840':                
#                 eval_at = range(1, iterations, 840/50)
#             else:
#                 eval_at = range(1, iterations, iterations/50)
            explo = {}
            explo_comp = {}
            comp = {}
            #print os.path.join(logs, log_dir, xp_dir)
            for log_file in os.listdir(os.path.join(logs, log_dir, xp_dir)):
                file_path = os.path.join(logs, log_dir, xp_dir, log_file)
                if file_path.endswith('.pickle'):
                    #print file_path
                    try:
                        with open(file_path, 'r') as f:
                            log = cPickle.load(f)
                            f.close()
                            
                            #print "explo", log.explo#, "explocomp", log.explo_comp, "comp", mean(array(log.eval_errors[0]))
                            
                            if plot_explo:
                                eval_at = range(1, iterations, iterations/len(log.explo))
                                explo[log_file] = array(log.explo)
#                                 if len(log.explo) == len(eval_at):
#                                     explo[log_file] = array(log.explo)
#                                 elif len(log.explo) == 2*len(log.config.eval_at):
#                                     explo[log_file] = array(log.explo)[range(0,len(log.explo),2)]
#                                 else:
#                                     print "Warning:", len(log.explo), len(eval_at)
                                    
                    except ValueError:
                        print "ValueError"
            if plot_explo:
                if len(explo.values()) > 0:
                    l = len(explo.values()[0])
                    #print log.config.name
                    #print explo.values()
                    #print l
                    if log.config.iter == 5000:
                        x = eval_at[:l]
                    else:
                        e2 = range(1,1240,1240/50)
                        v = array(e2)
                        v[v > 300] = (v[v>300]-300)*5 + 300
                        x = list(v)
                        #print len(x), x, mean(array(explo.values()), axis=0)
                    y = mean(array(explo.values()), axis=0)
                    error = std(array(explo.values()), axis=0)
                    error = error / sqrt(len(explo)) # Standard error of the mean
                    color_cycle = ax_explo._get_lines.color_cycle
                    next_color = next(color_cycle)
                    ax_explo.plot(x, y, label = log.config.name, color=next_color)
                    ax_explo.fill_between(x, y-error, y+error, alpha=0.2, label = log.config.name, color = next_color)
                    #ax.errorbar(eval_at[:l],, yerr=, label = log.config.name)
                    
                    explorations[log_dir][xp_dir] = explo
                
                
    
    if plot_explo:
        fig_explo.show()
        ax_explo.legend(loc='upper left')
        fig_explo.set_size_inches(19.2,12)
        plt.xlabel('Iterations', fontsize=18)
        plt.ylabel('Explored cells', fontsize=18)
        plt.ylim([0,900])
        plt.savefig(logs + log_dir + '/explo-' + log_dir[0:] + '.png')
    
    
plt.show()


Arm-Seq-GB-F-seq_5000
Arm-Seq-GB-H-TD-seq_1240
Arm-Seq-GB-H-seq_5000
Arm-Seq-MB-F-seq_5000
Arm-Seq-MB-H-seq_5000
Arm-Seq-Tr-F-seq_5000
Arm-Seq-Tr-H-TD-seq_1240
Arm-Seq-Tr-H-seq_5000
explo-2015-05-30_16-11-48-Test-Arm-Seq-GB.png
explo-2015-05-30_16-11-48-Test-Arm-Seq-Tr.png
explo-2015-05-30_16-11-48-Test-Arm-Seq.png

In [73]:
end_explo = {}
for log_dir in explorations:
    end_explo[log_dir] = {}
    for xp in explorations[log_dir]:
        end_explo[log_dir][xp] = {}
        end_explo[log_dir][xp] = [explorations[log_dir][xp][key][-1] for key in explorations[log_dir][xp]]
        
for log_dir in end_explo:
    print log_dir
    for xp in end_explo[log_dir]:
        print "    ", xp
        print "        ", end_explo[log_dir][xp]


2015-05-30_16-11-48-Test-Arm-Seq
     Arm-Seq-Tr-F-seq_5000
         [418.0, 380.0, 354.0, 383.0, 362.0, 402.0, 416.0, 378.0, 241.0, 344.0]
     Arm-Seq-Tr-H-TD-seq_1240
         [650.0, 643.0, 615.0, 639.0, 590.0, 611.0, 545.0, 647.0, 633.0, 676.0]
     Arm-Seq-GB-F-seq_5000
         [351.0, 410.0, 400.0, 290.0, 439.0, 413.0, 360.0, 339.0, 387.0, 217.0]
     Arm-Seq-MB-F-seq_5000
         [16.0, 13.0, 9.0, 10.0, 15.0, 22.0, 17.0, 10.0, 13.0, 10.0]
     Arm-Seq-GB-H-TD-seq_1240
         [670.0, 681.0, 669.0, 649.0, 675.0, 652.0, 655.0, 675.0, 663.0, 678.0]
     Arm-Seq-GB-H-seq_5000
         [803.0, 811.0, 827.0, 793.0, 816.0, 809.0, 811.0, 820.0, 817.0, 807.0]
     Arm-Seq-Tr-H-seq_5000
         [793.0, 786.0, 809.0, 812.0, 799.0, 811.0, 807.0, 819.0, 795.0, 788.0]
     Arm-Seq-MB-H-seq_5000
         [432.0, 410.0, 446.0, 429.0, 420.0, 480.0, 388.0, 451.0, 442.0, 463.0]

In [85]:
from scipy.stats import mannwhitneyu
x = end_explo['2015-05-30_16-11-48-Test-Arm-Seq']['Arm-Seq-GB-H-seq_5000']
y = end_explo['2015-05-30_16-11-48-Test-Arm-Seq']['Arm-Seq-Tr-H-seq_5000']
u, p = mannwhitneyu(x, y)
print "U:", u, "p:", 2*p


U: 27.5 p: 0.095427449698

ARM-DIVA


In [87]:
import cPickle
import matplotlib.pyplot as plt
from numpy import array, mean, std, sqrt
import os
import sys

from explaupoppydiva.drawer import Drawer

logs = os.getenv('HOME') + '/scm/Flowers/explaupoppydiva/logs/'
log_dirs = [
'2015-05-27_11-51-43-ARM-DIVA',
#'2015-05-26_20-59-31-ARM-DIVA',
            ]

conditions_to_plot = [
                      'Arm-Diva-Tr-H-seq_3000',    
                      'Arm-Diva-GB-H-seq_3000',   
                      'Arm-Diva-GB-F-seq_3000',   
                      'Arm-Diva-MB-H-seq_3000',   
                      'Arm-Diva-Tr-F-seq_3000',   
                      'Arm-Diva-MB-F-seq_3000',               
                      ]


plot_explo = True

iterations = 3000
eval_at = range(1, iterations +1, iterations/10)

explorations = {}

for log_dir in log_dirs:
    explorations[log_dir] = {}
    
    if plot_explo:
        fig_explo, ax_explo = plt.subplots()
        fig_explo.canvas.set_window_title('Exploration comparison for ' + log_dir)
    
    if plot_explo_comp:
        fig_explo_comp, ax_explo_comp = plt.subplots()
        fig_explo_comp.canvas.set_window_title('ExploComp comparison for ' + log_dir)   
         
    if plot_comp:
        fig_comp, ax_comp = plt.subplots()
        fig_comp.canvas.set_window_title('Comp comparison for ' + log_dir)   
    
    for xp_dir in os.listdir(os.path.join(logs,log_dir)) + ['']:
        print xp_dir
        if xp_dir in conditions_to_plot and os.path.isdir(os.path.join(logs, log_dir, xp_dir)):
        
            explo = {}
            explo_comp = {}
            comp = {}
            #print os.path.join(logs, log_dir, xp_dir)
            for log_file in os.listdir(os.path.join(logs, log_dir, xp_dir)):
                file_path = os.path.join(logs, log_dir, xp_dir, log_file)
                if file_path.endswith('.pickle'):
                    #print file_path
                    try:
                        with open(file_path, 'r') as f:
                            log = cPickle.load(f)
                            f.close()
                            
                            #print "explo", log.explo, "explocomp"#, log.explo_comp, "comp", mean(array(log.eval_errors[0]))
                            
                            if plot_explo:
                                eval_at = range(1, iterations, iterations/len(log.explo))
                                explo[log_file] = array(log.explo)
#                                 if len(log.explo) == len(eval_at):
#                                     explo[log_file] = array(log.explo)
#                                 if len(log.explo) == 2*len(log.config.eval_at):
#                                     explo[log_file] = array(log.explo)[range(0,len(log.explo),2)]
#                                     
                    except ValueError:
                        print "ValueError"
            if plot_explo:
                if len(explo.values()) > 0:
                    l = len(explo.values()[0])
                    #print log.config.name
                    #print explo.values()
                    #print l
                    x = eval_at[:l]
                    y = mean(array(explo.values()), axis=0)
                    error = std(array(explo.values()), axis=0)
                    error = error / sqrt(len(explo)) # Standard error of the mean
                    color_cycle = ax_explo._get_lines.color_cycle
                    next_color = next(color_cycle)
                    ax_explo.plot(x, y, label = log.config.name, color=next_color)
                    ax_explo.fill_between(x, y-error, y+error, alpha=0.2, label = log.config.name, color = next_color)
                    #ax.errorbar(eval_at[:l],, yerr=, label = log.config.name)
                    
                    explorations[log_dir][xp_dir] = explo
                
    
    if plot_explo:
        fig_explo.show()
        ax_explo.legend(loc='upper left')
        fig_explo.set_size_inches(19.2,12)
        plt.xlabel('Iterations', fontsize=18)
        plt.ylabel('Explored cells', fontsize=18)
        plt.xlim([0,2700])
        plt.savefig(logs + log_dir + '/explo-' + log_dir[0:] + '.png')
    
    
plt.show()


explo.png
Arm-Diva-Tr-H-seq_3000
Arm-Diva-GB-H-seq_3000
Arm-Diva-GB-F-seq_3000
Arm-Diva-MB-H-seq_3000
Arm-Diva-DP-H-seq_3000
Arm-Diva-Tr-F-seq_3000
Arm-Diva-MB-F-seq_3000
explo-2015-05-27_11-51-43-ARM-DIVA.png
Arm-Diva-DP-F-seq_3000


In [90]:
end_explo = {}
for log_dir in explorations:
    end_explo[log_dir] = {}
    for xp in explorations[log_dir]:
        end_explo[log_dir][xp] = {}
        end_explo[log_dir][xp] = [explorations[log_dir][xp][key][-1] for key in explorations[log_dir][xp]]
        
for log_dir in end_explo:
    print log_dir
    for xp in end_explo[log_dir]:
        print "    ", xp
        print "        ", end_explo[log_dir][xp]


2015-05-27_11-51-43-ARM-DIVA
     Arm-Diva-GB-H-seq_3000
         [84.0, 69.0, 66.0, 86.0, 95.0, 69.0, 64.0, 70.0, 72.0, 90.0]
     Arm-Diva-Tr-F-seq_3000
         [61.0, 67.0, 62.0, 60.0, 60.0, 64.0, 66.0, 62.0, 65.0, 59.0]
     Arm-Diva-MB-H-seq_3000
         [51.0, 56.0, 53.0, 52.0, 57.0, 57.0, 55.0, 66.0, 60.0, 54.0]
     Arm-Diva-MB-F-seq_3000
         [30.0, 32.0, 27.0, 23.0, 30.0, 24.0, 22.0, 28.0, 25.0, 30.0]
     Arm-Diva-Tr-H-seq_3000
         [68.0, 66.0, 77.0, 83.0, 65.0, 65.0, 89.0, 93.0, 61.0, 64.0]
     Arm-Diva-GB-F-seq_3000
         [62.0, 65.0, 66.0, 63.0, 56.0, 63.0, 58.0, 68.0, 60.0, 63.0]

In [97]:
from scipy.stats import mannwhitneyu
x = end_explo['2015-05-27_11-51-43-ARM-DIVA']['Arm-Diva-GB-H-seq_3000']
y = end_explo['2015-05-27_11-51-43-ARM-DIVA']['Arm-Diva-Tr-H-seq_3000']
u, p = mannwhitneyu(x, y)
print "U:", u, "p:", 2*p


U: 35.0 p: 0.27231412206

In [ ]: