当前位置: 首页>>代码示例>>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;未经允许,请勿转载。