Ejemplo n.º 1
0
def plot_state(f, filename, epoch):
    params = mregn_print_log.read_parameter(f)
    out_state_size = int(params['out_state_size'])
    tmp = tempfile.NamedTemporaryFile('w+')
    sys.stdout = tmp
    mregn_print_log.print_state(f, epoch)
    sys.stdout.flush()
    ptype = {}
    ptype['Target'] = (out_state_size, lambda x: 2 * x + 2)
    ptype['Output'] = (out_state_size, lambda x: 2 * x + 3)
    for k,v in ptype.items():
        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';" % (k, filename))
        gnuplot("set xlabel 'Time step';")
        gnuplot("set ylabel '%s';" % k)
        command = ['plot ']
        for i in range(v[0]):
            command.append("'%s' u 1:%d w l," % (tmp.name, v[1](i)))
        gnuplot(''.join(command)[:-1])
        gnuplot('\n')
        gnuplot('exit\n')
        p.wait()
    sys.stdout = sys.__stdout__
Ejemplo n.º 2
0
def plot_threshold(f, filename):
    params = mregn_print_log.read_parameter(f)
    expert_num = int(params['expert_num'])
    c_state_size = int(params['c_state_size'])
    out_state_size = int(params['out_state_size'])
    s = [x+2 for x in range(expert_num * (c_state_size + out_state_size))]
    for i in range(expert_num):
        index_c = s[:c_state_size]
        s = s[c_state_size:]
        index_o = s[:out_state_size]
        s = s[out_state_size:]
        ptype = {'Threshold (context)':index_c, 'Threshold (output)':index_o}
        for k,v in ptype.items():
            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(Expert %d)  File=%s';" %
                    (i, filename))
            gnuplot("set xlabel 'Learning epoch';")
            gnuplot("set ylabel '%s';" % k)
            command = ['plot ']
            for j in v:
                command.append("'%s' u 1:%d w l," % (filename, j))
            gnuplot(''.join(command)[:-1])
            gnuplot('\n')
Ejemplo n.º 3
0
def plot_error(f, filename):
    params = mregn_print_log.read_parameter(f)
    target_num = int(params['target_num'])
    ptype = {}
    ptype['Error'] = ('Error / (Length times Dimension)', lambda x: 3 * x + 2,
            'set logscale y;')
    ptype['Joint likelihood'] = ('Joint-likelihood / Length',
            lambda x: 3 * x + 3, '')
    ptype['Total likelihood'] = ('Total-likelihood / Length',
            lambda x: 3 * x + 4, '')
    for k,v in ptype.items():
        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';" % (k, filename))
        gnuplot("set xlabel 'Learning epoch';")
        gnuplot("set ylabel '%s';" % v[0])
        gnuplot(v[2])
        command = ['plot ']
        for i in range(target_num):
            command.append("'%s' u 1:%d w l," % (filename, v[1](i)))
        gnuplot(''.join(command)[:-1])
        gnuplot('\n')
        gnuplot('exit\n')
        p.wait()
Ejemplo n.º 4
0
def plot_init(f, filename, epoch):
    params = mregn_print_log.read_parameter(f)
    expert_num = int(params['expert_num'])
    c_state_size = int(params['c_state_size'])
    tmp = tempfile.NamedTemporaryFile('w+')
    sys.stdout = tmp
    mregn_print_log.print_init(f, epoch)
    sys.stdout.flush()
    index = [(2*x,(2*x+1)%c_state_size) for x in range(c_state_size) if 2*x <
            c_state_size]
    for i in range(expert_num):
        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(Expert %d)  File=%s';" % (i, filename))
        gnuplot("set xlabel 'x';")
        gnuplot("set ylabel 'y';")
        gnuplot('set pointsize 3;')
        command = ['plot ']
        k = expert_num * i + 2
        for x in index:
            command.append("'%s' u %d:%d w p," % (tmp.name, x[0] + k,
                x[1] + k))
        gnuplot(''.join(command)[:-1])
        gnuplot('\n')
        gnuplot('exit\n')
        p.wait()
    sys.stdout = sys.__stdout__
Ejemplo n.º 5
0
def plot_sigma(f, filename):
    params = mregn_print_log.read_parameter(f)
    expert_num = int(params['expert_num'])
    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=Variance  File=%s';" % filename)
    gnuplot("set xlabel 'Learning epoch';")
    gnuplot("set ylabel 'Variance';")
    command = ['plot ']
    for i in range(expert_num):
        command.append("'%s' u 1:%d w l," % (filename, 2*i+3))
    gnuplot(''.join(command)[:-1])
    gnuplot('\n')
Ejemplo n.º 6
0
def plot_tau(f, filename):
    params = mregn_print_log.read_parameter(f)
    expert_num = int(params['expert_num'])
    c_state_size = int(params['c_state_size'])
    for i in range(expert_num):
        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(Expert %d)  File=%s';" %
                (i, filename))
        gnuplot("set xlabel 'Learning epoch';")
        gnuplot("set ylabel 'Time constant';")
        command = ['plot ']
        for j in range(c_state_size):
            command.append("'%s' u 1:%d w l," % (filename, i*expert_num+j+2))
        gnuplot(''.join(command)[:-1])
        gnuplot('\n')
Ejemplo n.º 7
0
def plot_gate(f, filename, epoch):
    params = mregn_print_log.read_parameter(f)
    expert_num = int(params['expert_num'])
    tmp = tempfile.NamedTemporaryFile('w+')
    sys.stdout = tmp
    mregn_print_log.print_state(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=Gate  File=%s';" % filename)
    gnuplot("set xlabel 'Time step';")
    gnuplot("set ylabel 'Gate opening value';")
    command = ['plot ']
    for i in range(expert_num):
        command.append("'%s' u 1:%d w l," % (tmp.name, i+2))
    gnuplot(''.join(command)[:-1])
    gnuplot('\n')
    gnuplot('exit\n')
    p.wait()
    sys.stdout = sys.__stdout__