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_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__