當前位置: 首頁>>代碼示例>>Python>>正文


Python Dataset.get_instances方法代碼示例

本文整理匯總了Python中Dataset.Dataset.get_instances方法的典型用法代碼示例。如果您正苦於以下問題:Python Dataset.get_instances方法的具體用法?Python Dataset.get_instances怎麽用?Python Dataset.get_instances使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Dataset.Dataset的用法示例。


在下文中一共展示了Dataset.get_instances方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from Dataset import Dataset [as 別名]
# 或者: from Dataset.Dataset import get_instances [as 別名]
    def __init__(self, nn_conf):
        print "[+] Building neural network... [NeuralNetwork]"

        self.__conf_params = nn_conf.get_NN_parameters()

        self.__iterations = self.__conf_params[Conf_Params.ITERATIONS]
        self.__nodes_per_layer = self.__conf_params[Conf_Params.NODES_PER_LAYER]
        self.__input_number = self.__conf_params[Conf_Params.INPUTS_NUMBER]
        self.__path_training = self.__conf_params[Conf_Params.TRAIN_FILE_PATH]
        self.__output_number = self.__nodes_per_layer[len(self.__nodes_per_layer) - 1]
        self.__path_weights = self.__conf_params[Conf_Params.WEIGHTS_FILE]
        self.__algorithm = self.__conf_params[Conf_Params.ALGORITHM]
        # The self.__conf_params[6] is the conf_file. Here it is not needed.
        self.__learning_rate = self.__conf_params[Conf_Params.LEARNING_RATE]
        self.__learning_type = self.__conf_params[Conf_Params.LEARNING_TYPE]
        self.__phase = self.__conf_params[Conf_Params.PHASE]
        self.__enabled_graphics = self.__conf_params[Conf_Params.ENABLED_GRAPHICS]
        if self.__enabled_graphics == "on":
            # Each point is the average error of all instances in that iteration
            self.__mean_grapher = Grapher("Error evolution", "Iteration", "Error")
            # Average output error of all instances for all iterations
            self.__grapher = Grapher("Average output error of all instances for all iterations", "Instance", "Error")
            # If something goes wrong initializating the graphers
            if not (self.__mean_grapher and self.__grapher): 
                self.__enabled_graphics = "off"
        self.__sigmoid = self.__conf_params[Conf_Params.SIGMOID]
        self.__momentum = self.__conf_params[Conf_Params.MOMENTUM]


        # First of all, we add the input nodes as a layer. We will work with input nodes as nodes in a normal layer
        # Layer 0 will be the one with the inputs.
        '''
        We don't have anymore the input nodes list. That data belongs to the topology parameter
        count = 0
        nodes_list = []
        for i in range(self.__input_number):
            node = Node(i)
            nodes_list.append(node)
        layer = Layer(count, nodes_list)
        self.__layers.append(layer)
        '''
        count = 0
        for n_nodes in self.__nodes_per_layer:
            nodes_list = []
            count += 1
            for i in range(n_nodes):
                node = Node(i)    # pos_in_layer, error, weight list, value. If not specified, getting default values in node constructor.
                nodes_list.append(node)
            layer = Layer(count, nodes_list)
            self.__layers.append(layer)

        if not self.__layers:
            print "[-] There are no layers. Something went wrong. [NeuralNetwork]"
            print "[*] See you, neural cowboy."
            exit()

        if len(self.__layers) == 1:
            print "[-] The is only one layer (in theory, input layer). You need at least inputs and one more layer. [NeuralNetwork]"
            print "[*] See you, neural cowboy."
            exit()

        # Here we have built all the layers with the nodes of the neural network.
        # We have to obtain all the dataset instances. The instances will be stored in a list
        # of lists of n+1 positions where n is the number of inputs and x is the number of outputs
        ds = Dataset(self.__conf_params)
        self.__dataset = ds.get_instances()
        # Once here, we have to return and the activate method must be invoked.
        print "[+] Neural network built. [NeuralNetwork]"
開發者ID:newlog,項目名稱:college,代碼行數:70,代碼來源:NeuralNetwork.py

示例2: Dataset

# 需要導入模塊: from Dataset import Dataset [as 別名]
# 或者: from Dataset.Dataset import get_instances [as 別名]
curpath = os.path.abspath(os.curdir)
packet_file = "%s/%s.txt" % ("dataset", "dataset")
print "Current path is: %s" % (curpath)
print "Trying to open: %s" % (os.path.join(curpath, packet_file))

#########################################
# END OF CODE TO KNOW CURRENT DIRECTORY #
#########################################

print "##############################"
print "##     TESTING DATASET      ##"
print "##############################"


ds = Dataset("./src/dataset/prove.txt", 5, 1)
data = ds.get_instances()
print "Data.txt - Printing instances: " , data

ds = Dataset("./src/dataset/data2.txt", 5, 1)
data = ds.get_instances()
print "Data2.txt - Printing instances: " , data

ds = Dataset("./src/dataset/data3.txt", 1, 1)
data = ds.get_instances()
print "Data3.txt - Printing instances: " , data

ds = Dataset("./src/dataset/data4.txt", 1, 1)
data = ds.get_instances()
print "Data4.txt - Printing instances: " , data

ds = Dataset("./src/dataset/data5.txt", 1, 1)
開發者ID:newlog,項目名稱:college,代碼行數:33,代碼來源:test_dataset.py


注:本文中的Dataset.Dataset.get_instances方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。