GeneticNetwork.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:TF-Genetic 作者: thepropterhoc 项目源码 文件源码
def __init__(self, layerDimensions=[], netDimensions=[], validActivationFunctions=[]):

        self.layerDimensions = layerDimensions

        self.x = tf.placeholder(tf.float32, [None, netDimensions[0]])
        previousActivation = self.x

        for idx in range(len(layerDimensions)):
            currentLayer = layerDimensions[idx]
            thisActivation = None
            for functionIndex in range(len(currentLayer)):
                inDim, outDim = currentLayer[functionIndex]
                thisW = tf.Variable(tf.random_normal([inDim, outDim]))
                thisB = tf.Variable(tf.random_normal([outDim]))
                thisFunction = validActivationFunctions[functionIndex]
                newTensor = thisFunction(tf.matmul(previousActivation, thisW) + thisB)
                thisActivation = newTensor if thisActivation is None else tf.concat(1, [thisActivation, newTensor])

            previousActivation = thisActivation

        self.predictedOutput = previousActivation
        self.y_ = tf.placeholder(tf.float32, [None, netDimensions[-1]])
        cross_entropy = tf.reduce_mean(tf.square(self.predictedOutput - self.y_))
        self.train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)

        init = tf.initialize_all_variables()
        self.sess = tf.Session(config=tf.ConfigProto(
            inter_op_parallelism_threads=4,
                        intra_op_parallelism_threads=4
        ))
        self.sess.run(init)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号