какова цель "я" - PullRequest
       6

какова цель "я"

0 голосов
/ 28 июня 2018

Я изучал ручные нейронные сети, используя python3. Я видел использование self после оператора присваивания, такого как _default_graph = self в методе класса. Я знаю назначение себя в python, что оно относится к конкретному объекту, созданному для класса, но я не могу ясно понять его назначение, что оно такое же, как self._default_graph или имеет другое назначение. Также я не могу ясно понять возвращение себя цель в методе класса.

class Graph():

def __init__(self):

    self.operations = []
    self.placeholders = []
    self.variables = []

def set_as_default(self):
    """
    Sets this Graph instance as the Global Default Graph
    """
    global _default_graph
    _default_graph = self 

класс для заполнителя:

class Placeholder():
"""
A placeholder is a node that needs to be provided a value for computing the output in the Graph.
"""

def __init__(self):

    self.output_nodes = []

    _default_graph.placeholders.append(self)

класс для переменных:

class Variable():
"""
This variable is a changeable parameter of the Graph.
"""

def __init__(self, initial_value = None):

    self.value = initial_value
    self.output_nodes = []

    _default_graph.variables.append(self)

класс для работы:

class Operation():
"""
An Operation is a node in a "Graph". TensorFlow will also use this concept of a Graph.

This Operation class will be inherited by other classes that actually compute the specific operation, such as adding or matrix multiplication.
"""

def __init__(self, input_nodes = []):
    """
    Intialize an Operation
    """
    self.input_nodes = input_nodes # The list of input nodes
    self.output_nodes = [] # List of nodes consuming this node's output

    for node in input_nodes:
        node.output_nodes.append(self)

    _default_graph.operations.append(self)

def compute(self):
    """ 
    This is a placeholder function. It will be overwritten by the actual specific operation that inherits from this class.

    """
    pass

и базовый график выглядит как z = ax + b с a = 10 и b = 1 z = 10x + 1 выглядит следующим образом ..

Может ли кто-нибудь мне через это .... Спасибо заранее

...