Esempio n. 1
0
def plot_lyapunov(f, filename):
    params = rnn_print_log.read_parameter(f)
    target_num = int(params['target_num'])
    ls_size = int(params['lyapunov_spectrum_size'])
    p = re.compile(r'(^#)|(^$)')
    tmp = tempfile.NamedTemporaryFile('w+')
    for line in f:
        if p.match(line) == None:
            input = list(map(float, line[:-1].split()))
            lyapunov = [input[0]]
            for i in range(ls_size):
                lyapunov.append(sum(input[i + 1::ls_size]) / target_num)
            tmp.write('%s\n' % '\t'.join([str(x) for x in lyapunov]))
    tmp.flush()
    p = subprocess.Popen(['gnuplot -persist'],
                         stdin=subprocess.PIPE,
                         shell=True)
    gnuplot = lambda s: p.stdin.write(s.encode())
    gnuplot('set nokey;')
    gnuplot("set title 'Type=Lyapunov  File=%s';" % filename)
    gnuplot("set xlabel 'Learning epoch';")
    gnuplot("set ylabel 'Lyapunov';")
    command = ['plot 0 w l lt 0']
    for i in range(ls_size):
        command.append("'%s' u 1:%d w l lt %d" % (tmp.name, i + 2, i + 1))
    gnuplot(','.join(command))
    gnuplot('\n')
    gnuplot('exit\n')
    p.wait()
Esempio n. 2
0
def data_extract_for_state(fp, filename, epoch, layer_type):
    params = rnn_print_log.read_parameter(fp)
    r = re.compile(r'^# target')
    target_num = int(re.search('\d+', filename).group(0))
    target_length = int(params['target'][target_num])
    out_state_size = int(params['out_state_size'])

    if epoch == None:
        # get final epoch data
        lines = rnn_print_log.tail_n(fp, target_length + 1, 1)
        values = []
        flag = False

        for line in lines:
            if flag:
                values.append([])
                value_elems = line.split('\t')[1:]
                if layer_type == 'OUTPUT_TYPE':
                    for elems in value_elems[1:out_state_size * 3:3]:
                        values[-1].append(float(elems))
                elif layer_type == 'CONTEXT_TYPE':
                    for elems in value_elems[out_state_size * 3:]:
                        values[-1].append(float(elems))
                else:
                    raise NotImplementedError
            if r.match(line):
                flag = True

    return values
Esempio n. 3
0
def plot_entropy(f, filename, multiplot=False):
    params = rnn_print_log.read_parameter(f)
    target_num = int(params['target_num'])
    ptype = ['KL-divergence', 'generation-rate', 'entropy(target)',
            'entropy(out)']
    if multiplot:
        p = subprocess.Popen(['gnuplot -persist'], stdin=subprocess.PIPE,
                shell=True)
        gnuplot = lambda s: p.stdin.write(s.encode())
        gnuplot('set nokey;')
        gnuplot('set multiplot layout 3,1 title ' +
                "'Type=Entropy File=%s';" % filename)
        for i in [0, 1, 3]:
            gnuplot("set xlabel 'Learning epoch';")
            gnuplot("set ylabel '%s';" % ptype[i])
            command = ['plot ']
            for j in range(target_num):
                command.append("'%s' u 1:%d w l," % (filename, i+j*4+2))
            gnuplot(''.join(command)[:-1])
            gnuplot('\n')
        gnuplot('unset multiplot\n')
    else:
        for i in [0, 1, 3]:
            p = subprocess.Popen(['gnuplot -persist'], stdin=subprocess.PIPE,
                    shell=True)
            gnuplot = lambda s: p.stdin.write(s.encode())
            gnuplot('set nokey;')
            gnuplot("set title 'Type=%s  File=%s';" % (ptype[i], filename))
            gnuplot("set xlabel 'Learning epoch';")
            gnuplot("set ylabel '%s';" % ptype[i])
            command = ['plot ']
            for j in range(target_num):
                command.append("'%s' u 1:%d w l," % (filename, i+j*4+2))
            gnuplot(''.join(command)[:-1])
            gnuplot('\n')
Esempio n. 4
0
def plot_lyapunov(f, filename):
    params = rnn_print_log.read_parameter(f)
    target_num = int(params['target_num'])
    ls_size = int(params['lyapunov_spectrum_size'])
    p = re.compile(r'(^#)|(^$)')
    tmp = tempfile.NamedTemporaryFile('w+')
    for line in f:
        if p.match(line) == None:
            input = list(map(float, line[:-1].split()))
            lyapunov = [input[0]]
            for i in range(ls_size):
                lyapunov.append(sum(input[i+1::ls_size]) / target_num)
            tmp.write('%s\n' % '\t'.join([str(x) for x in lyapunov]))
    tmp.flush()
    p = subprocess.Popen(['gnuplot -persist'], stdin=subprocess.PIPE,
            shell=True)
    gnuplot = lambda s: p.stdin.write(s.encode())
    gnuplot('set nokey;')
    gnuplot("set title 'Type=Lyapunov  File=%s';" % filename)
    gnuplot("set xlabel 'Learning epoch';")
    gnuplot("set ylabel 'Lyapunov';")
    command = ['plot 0 w l lt 0']
    for i in range(ls_size):
        command.append("'%s' u 1:%d w l lt %d" % (tmp.name, i+2, i+1))
    gnuplot(','.join(command))
    gnuplot('\n')
    gnuplot('exit\n')
    p.wait()
Esempio n. 5
0
def plot_init(f, filename, epoch):
    params = rnn_print_log.read_parameter(f)
    c_state_size = int(params['c_state_size'])
    tmp = tempfile.NamedTemporaryFile('w+')
    sys.stdout = tmp
    rnn_print_log.print_init(f, epoch)
    sys.stdout.flush()
    p = subprocess.Popen(['gnuplot -persist'], stdin=subprocess.PIPE,
            shell=True)
    gnuplot = lambda s: p.stdin.write(s.encode())
    gnuplot('set nokey;')
    gnuplot("set title 'Type=Init  File=%s';" % filename)
    gnuplot("set xlabel 'x';")
    gnuplot("set ylabel 'y';")
    gnuplot('set pointsize 3;')
    command = ['plot ']
    index = [(2*x,(2*x+1)%c_state_size) for x in range(c_state_size) if 2*x <
            c_state_size]
    for x in index:
        command.append("'%s' u %d:%d w p," % (tmp.name, x[0]+2, x[1]+2))
    gnuplot(''.join(command)[:-1])
    gnuplot('\n')
    gnuplot('exit\n')
    p.wait()
    sys.stdout = sys.__stdout__
Esempio n. 6
0
def plot_init(f, filename, epoch):
    params = rnn_print_log.read_parameter(f)
    c_state_size = int(params['c_state_size'])
    tmp = tempfile.NamedTemporaryFile('w+')
    sys.stdout = tmp
    rnn_print_log.print_init(f, epoch)
    sys.stdout.flush()
    p = subprocess.Popen(['gnuplot -persist'],
                         stdin=subprocess.PIPE,
                         shell=True)
    gnuplot = lambda s: p.stdin.write(s.encode())
    gnuplot('set nokey;')
    gnuplot("set title 'Type=Init  File=%s';" % filename)
    gnuplot("set xlabel 'x';")
    gnuplot("set ylabel 'y';")
    gnuplot('set pointsize 3;')
    command = ['plot ']
    index = [(2 * x, (2 * x + 1) % c_state_size) for x in range(c_state_size)
             if 2 * x < c_state_size]
    for x in index:
        command.append("'%s' u %d:%d w p," % (tmp.name, x[0] + 2, x[1] + 2))
    gnuplot(''.join(command)[:-1])
    gnuplot('\n')
    gnuplot('exit\n')
    p.wait()
    sys.stdout = sys.__stdout__
Esempio n. 7
0
def plot_state(f, filename, epoch, multiplot=False):
    params = rnn_print_log.read_parameter(f)
    c_state_size = int(params['c_state_size'])
    out_state_size = int(params['out_state_size'])
    output_type = params['output_type']
    if re.search('STANDARD_TYPE', output_type):
        prange = '[][-1:1]'
        pass
    elif re.search('SOFTMAX_TYPE', output_type):
        prange = '[][0:1]'
    else:
        prange = ''
    tmp = tempfile.NamedTemporaryFile('w+')
    sys.stdout = tmp
    rnn_print_log.print_state(f, epoch)
    sys.stdout.flush()
    ptype = []
    ptype.append(('Target', out_state_size, lambda x: 2 * x + 2, prange))
    ptype.append(('Output', out_state_size, lambda x: 2 * x + 3, prange))
    ptype.append(
        ('Context', c_state_size, lambda x: x + 2 * out_state_size + 2, ''))
    if multiplot:
        p = subprocess.Popen(['gnuplot -persist'],
                             stdin=subprocess.PIPE,
                             shell=True)
        gnuplot = lambda s: p.stdin.write(s.encode())
        gnuplot('set nokey;')
        gnuplot("set multiplot layout 3,1 title 'Type=State  File=%s';" %
                filename)
        for v in ptype:
            gnuplot("set xlabel 'Time step';")
            gnuplot("set ylabel '%s';" % v[0])
            command = ['plot %s ' % v[3]]
            for i in range(v[1]):
                command.append("'%s' u 1:%d w l," % (tmp.name, v[2](i)))
            gnuplot(''.join(command)[:-1])
            gnuplot('\n')
        gnuplot('unset multiplot\n')
        gnuplot('exit\n')
        p.wait()
    else:
        for v in ptype:
            p = subprocess.Popen(['gnuplot -persist'],
                                 stdin=subprocess.PIPE,
                                 shell=True)
            gnuplot = lambda s: p.stdin.write(s.encode())
            gnuplot('set nokey;')
            gnuplot("set title 'Type=%s  File=%s';" % (v[0], filename))
            gnuplot("set xlabel 'Time step';")
            gnuplot("set ylabel '%s';" % v[0])
            command = ['plot %s ' % v[3]]
            for i in range(v[1]):
                command.append("'%s' u 1:%d w l," % (tmp.name, v[2](i)))
            gnuplot(''.join(command)[:-1])
            gnuplot('\n')
            gnuplot('exit\n')
            p.wait()
    sys.stdout = sys.__stdout__
Esempio n. 8
0
def plot_state(f, filename, epoch, multiplot=False):
    params = rnn_print_log.read_parameter(f)
    c_state_size = int(params['c_state_size'])
    out_state_size = int(params['out_state_size'])
    output_type = params['output_type']
    if re.search('STANDARD_TYPE', output_type):
        prange = '[][-1:1]'
        pass
    elif re.search('SOFTMAX_TYPE', output_type):
        prange = '[][0:1]'
    else:
        prange = ''
    tmp = tempfile.NamedTemporaryFile('w+')
    sys.stdout = tmp
    rnn_print_log.print_state(f, epoch)
    sys.stdout.flush()
    ptype = []
    ptype.append(('Target', out_state_size, lambda x: 2 * x + 2, prange))
    ptype.append(('Output', out_state_size, lambda x: 2 * x + 3, prange))
    ptype.append(('Context', c_state_size, lambda x: x + 2 * out_state_size +
        2, ''))
    if multiplot:
        p = subprocess.Popen(['gnuplot -persist'], stdin=subprocess.PIPE,
                shell=True)
        gnuplot = lambda s: p.stdin.write(s.encode())
        gnuplot('set nokey;')
        gnuplot("set multiplot layout 3,1 title 'Type=State  File=%s';" %
                filename)
        for v in ptype:
            gnuplot("set xlabel 'Time step';")
            gnuplot("set ylabel '%s';" % v[0])
            command = ['plot %s ' % v[3]]
            for i in range(v[1]):
                command.append("'%s' u 1:%d w l," % (tmp.name, v[2](i)))
            gnuplot(''.join(command)[:-1])
            gnuplot('\n')
        gnuplot('unset multiplot\n')
        gnuplot('exit\n')
        p.wait()
    else:
        for v in ptype:
            p = subprocess.Popen(['gnuplot -persist'], stdin=subprocess.PIPE,
                    shell=True)
            gnuplot = lambda s: p.stdin.write(s.encode())
            gnuplot('set nokey;')
            gnuplot("set title 'Type=%s  File=%s';" % (v[0], filename))
            gnuplot("set xlabel 'Time step';")
            gnuplot("set ylabel '%s';" % v[0])
            command = ['plot %s ' % v[3]]
            for i in range(v[1]):
                command.append("'%s' u 1:%d w l," % (tmp.name, v[2](i)))
            gnuplot(''.join(command)[:-1])
            gnuplot('\n')
            gnuplot('exit\n')
            p.wait()
    sys.stdout = sys.__stdout__
Esempio n. 9
0
def plot_weight(f, filename, multiplot=False):
    params = rnn_print_log.read_parameter(f)
    in_state_size = int(params['in_state_size'])
    c_state_size = int(params['c_state_size'])
    out_state_size = int(params['out_state_size'])
    index_i2c, index_c2c, index_c2o = [], [], []
    s = [
        x + 2 for x in range(c_state_size *
                             (in_state_size + c_state_size + out_state_size))
    ]
    for i in range(c_state_size):
        index_i2c.extend(s[:in_state_size])
        s = s[in_state_size:]
        index_c2c.extend(s[:c_state_size])
        s = s[c_state_size:]
    for i in range(out_state_size):
        index_c2o.extend(s[:c_state_size])
        s = s[c_state_size:]
    ptype = []
    ptype.append(('Weight (input to context)', index_i2c))
    ptype.append(('Weight (context to context)', index_c2c))
    ptype.append(('Weight (context to output)', index_c2o))
    if multiplot:
        p = subprocess.Popen(['gnuplot -persist'],
                             stdin=subprocess.PIPE,
                             shell=True)
        gnuplot = lambda s: p.stdin.write(s.encode())
        gnuplot('set nokey;')
        gnuplot("set multiplot layout 3,1 title 'Type=Weight File=%s';" %
                filename)
        for v in ptype:
            gnuplot("set xlabel 'Learning epoch';")
            gnuplot("set ylabel '%s';" % v[0])
            command = ['plot ']
            for i in v[1]:
                command.append("'%s' u 1:%d w l," % (filename, i))
            gnuplot(''.join(command)[:-1])
            gnuplot('\n')
        gnuplot('unset multiplot\n')
    else:
        for v in ptype:
            p = subprocess.Popen(['gnuplot -persist'],
                                 stdin=subprocess.PIPE,
                                 shell=True)
            gnuplot = lambda s: p.stdin.write(s.encode())
            gnuplot('set nokey;')
            gnuplot("set title 'Type=Weight  File=%s';" % filename)
            gnuplot("set xlabel 'Learning epoch';")
            gnuplot("set ylabel '%s';" % v[0])
            command = ['plot ']
            for i in v[1]:
                command.append("'%s' u 1:%d w l," % (filename, i))
            gnuplot(''.join(command)[:-1])
            gnuplot('\n')
Esempio n. 10
0
def plot_weight(f, filename, multiplot=False):
    params = rnn_print_log.read_parameter(f)
    in_state_size = int(params['in_state_size'])
    c_state_size = int(params['c_state_size'])
    out_state_size = int(params['out_state_size'])
    index_i2c, index_c2c, index_c2o = [], [], []
    s = [x+2 for x in range(c_state_size *
        (in_state_size + c_state_size + out_state_size))]
    for i in range(c_state_size):
        index_i2c.extend(s[:in_state_size])
        s = s[in_state_size:]
        index_c2c.extend(s[:c_state_size])
        s = s[c_state_size:]
    for i in range(out_state_size):
        index_c2o.extend(s[:c_state_size])
        s = s[c_state_size:]
    ptype = []
    ptype.append(('Weight (input to context)', index_i2c))
    ptype.append(('Weight (context to context)', index_c2c))
    ptype.append(('Weight (context to output)', index_c2o))
    if multiplot:
        p = subprocess.Popen(['gnuplot -persist'], stdin=subprocess.PIPE,
                shell=True)
        gnuplot = lambda s: p.stdin.write(s.encode())
        gnuplot('set nokey;')
        gnuplot("set multiplot layout 3,1 title 'Type=Weight File=%s';" %
                filename)
        for v in ptype:
            gnuplot("set xlabel 'Learning epoch';")
            gnuplot("set ylabel '%s';" % v[0])
            command = ['plot ']
            for i in v[1]:
                command.append("'%s' u 1:%d w l," % (filename, i))
            gnuplot(''.join(command)[:-1])
            gnuplot('\n')
        gnuplot('unset multiplot\n')
    else:
        for v in ptype:
            p = subprocess.Popen(['gnuplot -persist'], stdin=subprocess.PIPE,
                    shell=True)
            gnuplot = lambda s: p.stdin.write(s.encode())
            gnuplot('set nokey;')
            gnuplot("set title 'Type=Weight  File=%s';" % filename)
            gnuplot("set xlabel 'Learning epoch';")
            gnuplot("set ylabel '%s';" % v[0])
            command = ['plot ']
            for i in v[1]:
                command.append("'%s' u 1:%d w l," % (filename, i))
            gnuplot(''.join(command)[:-1])
            gnuplot('\n')
Esempio n. 11
0
def plot_tau(f, filename):
    params = rnn_print_log.read_parameter(f)
    c_state_size = int(params['c_state_size'])
    p = subprocess.Popen(['gnuplot -rv -persist'],
                         stdin=subprocess.PIPE,
                         shell=True)
    p.stdin.write('set nokey;')
    p.stdin.write("set title 'Type=Time-constant  File=%s';" % filename)
    p.stdin.write("set xlabel 'Learning epoch';")
    p.stdin.write("set ylabel 'Time constant';")
    command = ['plot ']
    for i in xrange(c_state_size):
        command.append("'%s' u 1:%d w l," % (filename, i + 2))
    p.stdin.write(''.join(command)[:-1])
    p.stdin.write('\n')
Esempio n. 12
0
def plot_tau(f, filename):
    params = rnn_print_log.read_parameter(f)
    c_state_size = int(params['c_state_size'])
    p = subprocess.Popen(['gnuplot -persist'], stdin=subprocess.PIPE,
            shell=True)
    gnuplot = lambda s: p.stdin.write(s.encode())
    gnuplot('set nokey;')
    gnuplot("set title 'Type=Time-constant  File=%s';" % filename)
    gnuplot("set xlabel 'Learning epoch';")
    gnuplot("set ylabel 'Time constant';")
    command = ['plot ']
    for i in range(c_state_size):
        command.append("'%s' u 1:%d w l," % (filename, i+2))
    gnuplot(''.join(command)[:-1])
    gnuplot('\n')
Esempio n. 13
0
def plot_period(f, filename):
    params = rnn_print_log.read_parameter(f)
    target_num = int(params['target_num'])
    p = subprocess.Popen(['gnuplot -rv -persist'],
                         stdin=subprocess.PIPE,
                         shell=True)
    p.stdin.write('set nokey;')
    p.stdin.write('set logscale y;')
    p.stdin.write("set title 'Type=Period  File=%s';" % filename)
    p.stdin.write("set xlabel 'Learning epoch';")
    p.stdin.write("set ylabel 'Period';")
    command = ['plot ']
    for i in xrange(target_num):
        command.append("'%s' u 1:%d w l," % (filename, i + 2))
    p.stdin.write(''.join(command)[:-1])
    p.stdin.write('\n')
Esempio n. 14
0
def plot_period(f, filename):
    params = rnn_print_log.read_parameter(f)
    target_num = int(params['target_num'])
    p = subprocess.Popen(['gnuplot -persist'], stdin=subprocess.PIPE,
            shell=True)
    gnuplot = lambda s: p.stdin.write(s.encode())
    gnuplot('set nokey;')
    gnuplot('set logscale y;')
    gnuplot("set title 'Type=Period  File=%s';" % filename)
    gnuplot("set xlabel 'Learning epoch';")
    gnuplot("set ylabel 'Period';")
    command = ['plot ']
    for i in range(target_num):
        command.append("'%s' u 1:%d w l," % (filename, i+2))
    gnuplot(''.join(command)[:-1])
    gnuplot('\n')
Esempio n. 15
0
def plot_pca_init(f, filename, epoch):
    params = rnn_print_log.read_parameter(f)
    target_num = int(params['target_num'])

    r = re.compile(r'^# epoch')
    if epoch == None:
        lines = rnn_print_log.tail_n(f, target_num + 1)
        init_value = []
        init_value_end_index = 0
        flag = 0
        for line in lines:
            if flag:
                init_value.append([])
                init_value_elems = line.split('\t')
                for elem in init_value_elems:
                    init_value[init_value_end_index].append(float(elem))
                init_value[init_value_end_index].remove(init_value_end_index)
                init_value_end_index += 1
            if r.match(line):
                flag = 1
    print init_value
    pca_data = pca(init_value)
    print pca_data

    tmp = tempfile.NamedTemporaryFile()
    sys.stdout = tmp
    for data in pca_data:
        print '%f\t%f\n\n' % (data[0], data[1])
    sys.stdout.flush()
    p = subprocess.Popen(['gnuplot -persist'],
                         stdin=subprocess.PIPE,
                         shell=True)
    p.stdin.write('set nokey;')
    p.stdin.write('set key right top;')
    p.stdin.write("set title 'Type PCA_Init File=%s';" % filename)
    p.stdin.write("set xlabel 'x';")
    p.stdin.write("set ylabel 'y';")
    p.stdin.write('set pointsize 3;')
    p.stdin.write('set grid;')
    command = ['plot ']
    for x in xrange(0, target_num):
        command.append("'%s' i %d u 1:2 w p t '%d'," % (tmp.name, x, x))
    p.stdin.write(''.join(command)[:-1])
    p.stdin.write('\n')
    p.stdin.write('exit\n')
    p.wait()
    sys.stdout = sys.__stdout__
Esempio n. 16
0
def plot_error(f, filename):
    params = rnn_print_log.read_parameter(f)
    target_num = int(params['target_num'])
    p = subprocess.Popen(['gnuplot -persist'],
                         stdin=subprocess.PIPE,
                         shell=True)
    gnuplot = lambda s: p.stdin.write(s.encode())
    gnuplot('set nokey;')
    gnuplot('set logscale y;')
    gnuplot("set title 'Type=Error  File=%s';" % filename)
    gnuplot("set xlabel 'Learning epoch';")
    gnuplot("set ylabel 'Error / (Length times Dimension)';")
    command = ['plot ']
    for i in range(target_num):
        command.append("'%s' u 1:%d w l," % (filename, i + 2))
    gnuplot(''.join(command)[:-1])
    gnuplot('\n')
Esempio n. 17
0
def plot_threshold(f, filename, multiplot=False):
    params = rnn_print_log.read_parameter(f)
    c_state_size = int(params['c_state_size'])
    out_state_size = int(params['out_state_size'])
    ptype = []
    ptype.append(('Threshold (context)', c_state_size, lambda x: x + 2))
    ptype.append(
        ('Threshold (output)', out_state_size, lambda x: x + c_state_size + 2))
    if multiplot:
        p = subprocess.Popen(['gnuplot -persist'],
                             stdin=subprocess.PIPE,
                             shell=True)
        gnuplot = lambda s: p.stdin.write(s.encode())
        gnuplot('set nokey;')
        gnuplot('set multiplot layout 2,1 title ' +
                "'Type=Threshold File=%s';" % filename)
        for v in ptype:
            gnuplot("set xlabel 'Learning epoch';")
            gnuplot("set ylabel '%s';" % v[0])
            command = ['plot ']
            for i in range(v[1]):
                command.append("'%s' u 1:%d w l," % (filename, v[2](i)))
            gnuplot(''.join(command)[:-1])
            gnuplot('\n')
        gnuplot('unset multiplot\n')
    else:
        for v in ptype:
            p = subprocess.Popen(['gnuplot -persist'],
                                 stdin=subprocess.PIPE,
                                 shell=True)
            gnuplot = lambda s: p.stdin.write(s.encode())
            gnuplot('set nokey;')
            gnuplot("set title 'Type=Threshold  File=%s';" % filename)
            gnuplot("set xlabel 'Learning epoch';")
            gnuplot("set ylabel '%s';" % v[0])
            command = ['plot ']
            for i in range(v[1]):
                command.append("'%s' u 1:%d w l," % (filename, v[2](i)))
            gnuplot(''.join(command)[:-1])
            gnuplot('\n')
Esempio n. 18
0
def data_extract_for_init(fp, epoch):
    params = rnn_print_log.read_parameter(fp)
    target_num = int(params['target_num'])

    rep_init_size = int(params['rep_init_size'])

    r = re.compile(r'^# epoch')
    if epoch == None:
        lines = rnn_print_log.tail_n(fp, target_num + 1)
        init_value = []
        flag = False

        for line in lines:
            if flag:
                init_value.append([])
                init_value_elems = line.split('\t')[1 + rep_init_size:]
                for elem in init_value_elems:
                    init_value[-1].append(float(elem))
            if r.match(line):
                flag = True
    #print init_value
    return init_value
Esempio n. 19
0
def plot_threshold(f, filename, multiplot=False):
    params = rnn_print_log.read_parameter(f)
    c_state_size = int(params['c_state_size'])
    out_state_size = int(params['out_state_size'])
    ptype = []
    ptype.append(('Threshold (context)', c_state_size, lambda x: x + 2))
    ptype.append(('Threshold (output)', out_state_size, lambda x: x +
        c_state_size + 2))
    if multiplot:
        p = subprocess.Popen(['gnuplot -persist'], stdin=subprocess.PIPE,
                shell=True)
        gnuplot = lambda s: p.stdin.write(s.encode())
        gnuplot('set nokey;')
        gnuplot('set multiplot layout 2,1 title ' +
                "'Type=Threshold File=%s';" % filename)
        for v in ptype:
            gnuplot("set xlabel 'Learning epoch';")
            gnuplot("set ylabel '%s';" % v[0])
            command = ['plot ']
            for i in range(v[1]):
                command.append("'%s' u 1:%d w l," % (filename, v[2](i)))
            gnuplot(''.join(command)[:-1])
            gnuplot('\n')
        gnuplot('unset multiplot\n')
    else:
        for v in ptype:
            p = subprocess.Popen(['gnuplot -persist'], stdin=subprocess.PIPE,
                    shell=True)
            gnuplot = lambda s: p.stdin.write(s.encode())
            gnuplot('set nokey;')
            gnuplot("set title 'Type=Threshold  File=%s';" % filename)
            gnuplot("set xlabel 'Learning epoch';")
            gnuplot("set ylabel '%s';" % v[0])
            command = ['plot ']
            for i in range(v[1]):
                command.append("'%s' u 1:%d w l," % (filename, v[2](i)))
            gnuplot(''.join(command)[:-1])
            gnuplot('\n')
Esempio n. 20
0
def plot_entropy(f, filename, multiplot=False):
    params = rnn_print_log.read_parameter(f)
    target_num = int(params['target_num'])
    ptype = [
        'KL-divergence', 'generation-rate', 'entropy(target)', 'entropy(out)'
    ]
    if multiplot:
        p = subprocess.Popen(['gnuplot -persist'],
                             stdin=subprocess.PIPE,
                             shell=True)
        gnuplot = lambda s: p.stdin.write(s.encode())
        gnuplot('set nokey;')
        gnuplot('set multiplot layout 3,1 title ' +
                "'Type=Entropy File=%s';" % filename)
        for i in [0, 1, 3]:
            gnuplot("set xlabel 'Learning epoch';")
            gnuplot("set ylabel '%s';" % ptype[i])
            command = ['plot ']
            for j in range(target_num):
                command.append("'%s' u 1:%d w l," % (filename, i + j * 4 + 2))
            gnuplot(''.join(command)[:-1])
            gnuplot('\n')
        gnuplot('unset multiplot\n')
    else:
        for i in [0, 1, 3]:
            p = subprocess.Popen(['gnuplot -persist'],
                                 stdin=subprocess.PIPE,
                                 shell=True)
            gnuplot = lambda s: p.stdin.write(s.encode())
            gnuplot('set nokey;')
            gnuplot("set title 'Type=%s  File=%s';" % (ptype[i], filename))
            gnuplot("set xlabel 'Learning epoch';")
            gnuplot("set ylabel '%s';" % ptype[i])
            command = ['plot ']
            for j in range(target_num):
                command.append("'%s' u 1:%d w l," % (filename, i + j * 4 + 2))
            gnuplot(''.join(command)[:-1])
            gnuplot('\n')
Esempio n. 21
0
def plot_state(f, filename, epoch, multiplot=False):
    params = rnn_print_log.read_parameter(f)
    c_state_size = int(params['c_state_size'])
    out_state_size = int(params['out_state_size'])
    output_type = params['output_type']
    if re.search('STANDARD_TYPE', output_type):
        range = '[][-1:1]'
        pass
    elif re.search('SOFTMAX_TYPE', output_type):
        range = '[][0:1]'
    else:
        range = ''
    tmp = tempfile.NamedTemporaryFile()
    sys.stdout = tmp
    rnn_print_log.print_state(f, epoch)
    sys.stdout.flush()
    type = []
    if (re.compile(r'STANDARD_TYPE').search(output_type)):
        type.append(('Target', out_state_size, lambda x: 3 * x + 2, range))
        type.append(('Output', out_state_size, lambda x: 3 * x + 3, range))
        type.append(('Variance', out_state_size, lambda x: 3 * x + 4, ''))
        type.append(('Context', c_state_size,
                     lambda x: x + 3 * out_state_size + 2, ''))
    else:
        type.append(('Target', out_state_size, lambda x: 2 * x + 2, range))
        type.append(('Output', out_state_size, lambda x: 2 * x + 3, range))
        type.append(('Context', c_state_size,
                     lambda x: x + 2 * out_state_size + 2, ''))
    if multiplot:
        p = subprocess.Popen(['gnuplot -rv -persist'],
                             stdin=subprocess.PIPE,
                             shell=True)
        p.stdin.write('set bmargin 0;')
        p.stdin.write('set tmargin 0;')
        p.stdin.write('set lmargin 6;')
        p.stdin.write('set rmargin 4;')
        p.stdin.write('set nokey;')
        p.stdin.write("set format x'';")
        p.stdin.write("set format y'';")
        p.stdin.write(
            "set multiplot layout %d,1 title 'Type=State  File=%s';" %
            (len(type) + 1, filename))
        for v in type:
            if v[0] == 'Context':
                p.stdin.write("set xlabel 'Time step' font 'Helvetica, 10';")
                p.stdin.write("set format x'%g';")
            p.stdin.write("set ylabel '%s' font 'Helvetica, 10';" % v[0])  #
            p.stdin.write("set ylabel '%s';" % v[0])
            command = ['plot %s ' % v[3]]
            for i in xrange(v[1]):
                command.append("'%s' u 1:%d w l," % (tmp.name, v[2](i)))
            p.stdin.write(''.join(command)[:-1])
            p.stdin.write('\n')
        p.stdin.write('unset multiplot\n')
        p.stdin.write('exit\n')
        p.wait()
    else:
        for v in type:
            p = subprocess.Popen(['gnuplot -rv -persist'],
                                 stdin=subprocess.PIPE,
                                 shell=True)
            p.stdin.write('set nokey;')
            p.stdin.write("set title 'Type=%s  File=%s';" % (v[0], filename))
            p.stdin.write("set xlabel 'Time step';")
            p.stdin.write("set ylabel '%s';" % v[0])
            command = ['plot %s ' % v[3]]
            for i in xrange(v[1]):
                command.append("'%s' u 1:%d w l," % (tmp.name, v[2](i)))
            p.stdin.write(''.join(command)[:-1])
            p.stdin.write('\n')
            p.stdin.write('exit\n')
            p.wait()
    sys.stdout = sys.__stdout__