TensorFlow/ADDA > 선형 방정식의 초기 값에 대한 데이터 학습 > 학습 코드 : v0.4 (Exr, Exi, Eyr, Eyi, Ezr, Ezi의 모든 학습)

18434 단어 borgWarpADDA#migrated
운영 환경
GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 14.04 LTS desktop amd64
TensorFlow v0.11
cuDNN v5.1 for Linux
CUDA v8.0
Python 2.7.6
IPython 5.1.0 -- An enhanced Interactive Python.
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
GNU bash, version 4.3.8(1)-release (x86_64-pc-linux-gnu)

v0.1 : ぃ tp // m / 7 / f9 / ms / 09262 a 2 a b01d037d169b

개요



This article is related to ADDA (light scattering simulator based on the discrete dipole approximation) .

ADDA의 계산에서 중요하게 되는 것이 X, Y, Z 방향의 전계 값. 무작위 초기 값을 사용하면 계산이 느리고 최종 해에 가까운 초기 값을 사용하면 계산이 빨라지는 것은 경험이 끝났습니다.

supercomputer로 계산한 최종해를 바탕으로 Deep learning으로 학습을 실시해, 그 결과를 통상의 PC로 이용한다. 그렇게 함으로써, 통상의 PC상에서의 계산을 고속화해, Community로서의 계산 자원의 효율 이용을 생각하고 있다.

X, Y, Z 방향의 전계 값을 TensorFlow에서 학습시키려고 한다.

학습 코드 : v0.4



v0.3: h tp : 작은 m / 7 오 f9 / MS / 80 아 7d62 아 4240f70b1C4 그림
에 있어서, Exr와 Exi의 동시 학습을 할 수 있었다.

음색을 타고 Exr, Exi, Eyr, Eyi, Ezr, Ezi의 전 학습을 해 보았다.

learnExr_170422.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import sys
import tensorflow as tf
import tensorflow.contrib.slim as slim
import numpy as np

'''
v0.4 Mar. 03, 2017
  - learn [Exr, Exi, Eyr, Eyi, Ezr, Ezi]
v0.3 Mar. 03, 2017
  - learn [Exr] and [Exi]
  - add [Eyr, Eri, Ezr, Ezi] for decode_csv()
v0.2 Apr. 29, 2017
  - save to [model_variables_170429.npy]
  - learn [Exr] only, instead of [Exr, Exi]
v0.1 Apr. 23, 2017
  - change [NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN] from [100] to [9328]
  - change input layer's node from [2] to [3]
  - [input.csv] has 9 columns
=== branched from [learn_xxyyfunc_170321.py] to [learnExr_170422.py] ===
v0.5 Apr. 01, 2017
  - change network from [7,7,7] to [100, 100, 100]
v0.4 Mar. 31, 2017
  - calculate [capacity] from [min_queue_examples] and [batch_size]
v0.3 Mar. 24, 2017
  - change [capacity] from 100 to 40
v0.2 Mar. 24, 2017
  - change [capacity] from 40 to 100
  - output [model_variables] after training
v0.1 Mar. 22, 2017
  - learn mapping of R^2 input to R^2 output
     + using data prepared by [prep_data_170321.py]
  - branched from sine curve learning at
    http://qiita.com/7of9/items/ce58e66b040a0795b2ae
'''

# codingrule:PEP8


filename_queue = tf.train.string_input_producer(["input.csv"])

# prase CSV
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
def_rec = [[0.], [0.], [0.], [0.], [0.], [0.], [0.], [0.], [0.]]
wrk = tf.decode_csv(value, record_defaults=def_rec)
xpos, ypos, zpos, Exr, Exi, Eyr, Eyi, Ezr, Ezi = wrk
inputs = tf.pack([xpos, ypos, zpos])
output = tf.pack([Exr, Exi, Eyr, Eyi, Ezr, Ezi])

batch_size = 4  # [4]
# Ref: cifar10_input.py
min_fraction_of_examples_in_queue = 0.2  # 0.4
NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN = 9328
min_queue_examples = int(NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN *
                         min_fraction_of_examples_in_queue)
#
inputs_batch, output_batch = tf.train.shuffle_batch(
    [inputs, output], batch_size, capacity=min_queue_examples + 3 * batch_size,
    min_after_dequeue=batch_size)

input_ph = tf.placeholder("float", [None, 3])
output_ph = tf.placeholder("float", [None, 6])

## network
hiddens = slim.stack(input_ph, slim.fully_connected, [100, 100, 100],
                     activation_fn=tf.nn.sigmoid, scope="hidden")
prediction = slim.fully_connected(
    hiddens, 6, activation_fn=None, scope="output")
loss = tf.contrib.losses.mean_squared_error(prediction, output_ph)

train_op = slim.learning.create_train_op(loss, tf.train.AdamOptimizer(0.001))

init_op = tf.initialize_all_variables()

with tf.Session() as sess:
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(sess=sess, coord=coord)

    try:
        sess.run(init_op)
        for i in range(90000):  # 30000
            inpbt, outbt = sess.run([inputs_batch, output_batch])
            _, t_loss = sess.run([train_op, loss],
                                 feed_dict={input_ph: inpbt, output_ph: outbt})

            if (i+1) % 100 == 0:
                print("%d,%f" % (i+1, t_loss))
                sys.stdout.flush()

    finally:
        coord.request_stop()

    # output the model
    model_variables = slim.get_model_variables()
    res = sess.run(model_variables)
    np.save('model_variables_170429.npy', res)

    coord.join(threads)

loss 경과





감소 정도는 나빠졌지만, 일단 감소하고 있다.

결과



실부



Exr (학습 대상 및 학습 결과)




Eyr (학습 대상 및 학습 결과)




Ezr (학습 대상 및 학습 결과)




허부



Exi (학습 대상 및 학습 결과)





Eyi (학습 대상 및 학습 결과)





Ezi (학습 대상 및 학습 결과)





고찰



Z에 대해서는 컬러 바의 범위가 다를 수도 있지만, 재현성은 조금 나쁘다.
X, Y에 대해서는 거의 재현할 수 있었던 것 같다.

TODO



선형 방정식을 다시 풀기
  • ぃ tp // m / 7, f9 / ms / 굳이 3617 네 c95c12b6184

  • 좋은 웹페이지 즐겨찾기