import numpy as np
import pylab as pl

import os


def plot_full_weak():
    # full + weak plotter for syntetic data
    # on different full-labeled training set sizes
    weak_results = np.genfromtxt('weak_labeled.csv', delimiter=',')
    full_results = np.genfromtxt('full_labeled.csv', delimiter=',')

    weak_results[0, 2] = 0.5
    full_results[0, 1] = 0.5

    y = np.mean(weak_results[:17, :6], axis=0)
    y_min = np.min(weak_results[:17, :6], axis=0)
    y_max = np.max(weak_results[:17, :6], axis=0)
    x = np.array([0, 2, 4, 10, 25, 100])

    full_y = np.mean(full_results[:17, :5], axis=0)
    full_y_min = np.min(full_results[:17, :5], axis=0)
    full_y_max = np.max(full_results[:17, :5], axis=0)

    pl.errorbar([0, 1, 2, 3, 4, 5], 1 - y, yerr=[y_max - y, y - y_min],
                label='+weak')
    pl.errorbar([1, 2, 3, 4, 5], 1 - full_y,
                yerr=[full_y_max - full_y, full_y - full_y_min], label='full')
    pl.xticks(np.arange(0, 6), x)
    pl.title('C=0.01')
    pl.xlabel('number of fully-labeled examples')
    pl.ylabel('hamming loss')
    pl.ylim([0, 1])
    pl.xlim([-0.1, 5.1])
    pl.legend(loc='lower right')


def plot_heterogenous_weak():
    results = np.genfromtxt('heterogenous')
    results = np.reshape(results, (-1, 6))

    y = np.mean(results, axis=0)
    y_min = np.min(results, axis=0)
    y_max = np.max(results, axis=0)
    x = np.array([0, 2, 4, 10, 25, 100])

    pl.errorbar([0, 1, 2, 3, 4, 5], 1 - y,
                yerr=[y_max - y, y - y_min], label='+weak')
    pl.xticks(np.arange(0, 6), x)
    pl.title('C=0.1')
    pl.xlabel('number of fully-labeled examples')
    pl.ylabel('hamming loss')
    pl.ylim([0, 1])
    pl.xlim([-0.1, 5.1])


def plot_msrc_full():
    y = np.genfromtxt('msrc_full.txt')
    x = np.array([0, 20, 40, 80, 160, 276])

    pl.plot([1, 2, 3, 4, 5], y)
    pl.scatter([1, 2, 3, 4, 5], y, marker='o')
    pl.xticks(np.arange(0, 6), x)
    pl.title('C=0.01')
    pl.xlabel('number of fully-labeled examples')
    pl.ylabel('hamming loss')
    pl.ylim([0, 1])
    pl.xlim([-0.1, 5.1])

if __name__ == '__main__':
    os.chdir("results/msrc")

    plot_msrc_full()
#    plot_full_weak()
#    plot_heterogenous_weak()

    pl.show()

@@ -49,24 +49,33 @@
 %0A%0A%0Adef plot_
+syntetic_
 full_weak():
@@ -71,24 +71,24 @@
 ull_weak():%0A
-
     # full +
@@ -170,16 +170,49 @@
 t sizes%0A
+    os.chdir(%22results/syntetic%22)%0A
     weak
@@ -1200,24 +1200,33 @@
 %0A%0A%0Adef plot_
+syntetic_
 heterogenous
@@ -1225,24 +1225,124 @@
 rogenous
-_weak():
+():%0A    # plot results from heterogenous lssvm trained on weak labeled data%0A    os.chdir(%22results/syntetic%22)
 %0A    res
@@ -1873,24 +1873,114 @@
 src_full():%0A
+    # plot results of ssvm trained on full labeled msrc data%0A    os.chdir(%22results/msrc%22)%0A
     y = np.g
@@ -2348,104 +2348,22 @@
     
-os.chdir(%22results/msrc%22)%0A%0A    plot_msrc_full()%0A#    plot_full_weak()%0A#    plot_heterogenous_weak
+plot_msrc_full
 ()%0A%0A

add some comments; rename functions