def loadDataSet(self,save_path): ''' input_data output_data ''' import os if os.path.exists(save_path): file=open(save_path,'r') output=[] num=0 for line in file: inputString=line[line.find("["):line.find("\n")] output.append(inputString) num+=1 #print line #print output input_data=[] output_data=[] for i in range(num/2): input_data.append(convertStringListToList(output[2*i])) output_data.append(convertStringListToList(output[2*i+1])) input_num=len(input_data[0]) output_num=len(output_data[0]) data=DataSet(input_num,output_num) for i in range(len(input_data)): data.addItem(input_data[i], output_data[i]) return data else: print(save_path+"does not exist")
def loadNeuronBuilder(self,save_path): ''' input_layer=self.net.input_layer hidden_layers=self.net.hidden_layers output_layer=self.net.output_layer has_bias=self.net.has_bias layer_to_layer_weight=self.net.layer_to_layer_weight bias_to_layer=self.net.bias_to_neuron neuron_function=self.net.neuron_function neuron_dict=self.net.neuron_dict name_dict=self.net.name_dict input_data=self.net.input_data output_data=self.net.output_data ''' import os if save_path.find('.')==-1: save_path+='.nnet' if os.path.exists(save_path): file=open(save_path,'r') output=[] for lines in file: output.append(lines) #print output dic={} for line in output: # print line dic[line[0:line.find(':')]]=line[line.find(':')+1:line.find('\\')] #print dic file.close() input_layer=convertStringListToList(dic['input_layer']) for i in range(len(input_layer)): input_layer[i]=int(input_layer[i]) hidden_layers=convertStringListToList(dic['hidden_layers']) for i in range(len(hidden_layers)): hidden_layers[i]=int(hidden_layers[i]) output_layer=convertStringListToList(dic['output_layer']) for i in range(len(output_layer)): output_layer[i]=int(output_layer[i]) has_bias=dic['has_bias'] if has_bias=='True': has_bias=True elif has_bias=='False': has_bias=False else: print("Mistake occurred when load has_bias:"+has_bias) layer_to_layer_weight=convertStringDictToDict(dic['layer_to_layer_weight']) print dic['layer_to_layer_weight'] print layer_to_layer_weight for key in layer_to_layer_weight.keys(): layer_to_layer_weight[key]=convertStringListToList(layer_to_layer_weight[key]) bias_to_layer=convertStringDictToDict(dic['bias_to_layer']) print dic['bias_to_layer'] print bias_to_layer for key in bias_to_layer: bias_to_layer[key]=convertStringListToList(bias_to_layer[key]) neuron_function=convertStringDictToDict(dic['neuron_function']) neuron_dict=convertStringDictToDict(dic['neuron_dict']) name_dict=convertStringDictToDict(dic['name_dict']) input_data=convertStringListToList(dic['input_data']) output_data=convertStringListToList(dic['output_data']) net=NeuronBuilder(input_layer,hidden_layers,output_layer,has_bias) net.layer_to_layer_weight=layer_to_layer_weight net.updateNeuronToNeuronWeightByLayerToLayerWeight() net.bias_to_layer=bias_to_layer net.updateBiasToNeuronByBiasToLayer() net.neuron_function=neuron_function net.neuron_dict=neuron_dict net.name_dict=name_dict data=DataSet(len(input_data[0]),len(output_data[0])) for i in range(len(input_data)): data.addItem(input_data[i], output_data[i]) net.setDataSet(data) #print neural_network_type #print input_num #print output_num #print weight #print bias #print function_name return net else: print(save_path+"does not exist") return None