コード例 #1
0
def train_and_calc_inf_network(
        i, j, k, layerSize, num_of_ephocs, learning_rate_local, batch_size,
        indexes, save_grads, data_sets_org, model_type, percent_of_train,
        interval_accuracy_display, calc_information, calc_information_last,
        num_of_bins, interval_information_display, save_ws, rand_int, cov_net):
    """Train the network and calculate it's information"""
    network_name = '{0}_{1}_{2}_{3}'.format(i, j, k, rand_int)
    print('Training network  - {0}'.format(network_name))
    network = train_network(layerSize, num_of_ephocs, learning_rate_local,
                            batch_size, indexes, save_grads, data_sets_org,
                            model_type, percent_of_train,
                            interval_accuracy_display, network_name, cov_net)
    network['information'] = []
    if calc_information:
        print('Calculating the information')
        infomration = np.array([
            inn.get_information(network['ws'], data_sets_org.data,
                                data_sets_org.labels, num_of_bins,
                                interval_information_display, network['model'],
                                layerSize)
        ])
        network['information'] = infomration
    elif calc_information_last:
        print('Calculating the infomration for the last epoch')
        infomration = np.array([
            inn.get_information([network['ws'][-1]], data_sets_org.data,
                                data_sets_org.labels, num_of_bins,
                                interval_information_display, network['model'],
                                layerSize)
        ])
        network['information'] = infomration
    # If we dont want to save layer's output
    if not save_ws:
        network['weights'] = 0
    return network
コード例 #2
0
ファイル: network.py プロジェクト: HounD/IDNNs
def train_and_calc_inf_network(i, j, k, layerSize, num_of_ephocs, learning_rate_local, batch_size, indexes, save_grads,
                               data_sets_org,
                               model_type, percent_of_train, interval_accuracy_display, calc_information,
                               calc_information_last, num_of_bins,
                               interval_information_display, save_ws, rand_int, cov_net):
	"""Train the network and calculate it's information"""
	network_name = '{0}_{1}_{2}_{3}'.format(i, j, k, rand_int)
	print ('Training network  - {0}'.format(network_name))
	network = train_network(layerSize, num_of_ephocs, learning_rate_local, batch_size, indexes, save_grads,
	                        data_sets_org, model_type, percent_of_train, interval_accuracy_display, network_name,
	                        cov_net)
	network['information'] = []
	if calc_information:
		print ('Calculating the infomration')
		infomration = np.array([inn.get_information(network['ws'], data_sets_org.data, data_sets_org.labels,
		                                            num_of_bins, interval_information_display, network['model'],
		                                            layerSize)])
		network['information'] = infomration
	elif calc_information_last:
		print ('Calculating the infomration for the last epoch')
		infomration = np.array([inn.get_information([network['ws'][-1]], data_sets_org.data, data_sets_org.labels,
		                                            num_of_bins, interval_information_display,
		                                            network['model'], layerSize)])
		network['information'] = infomration
	# If we dont want to save layer's output
	if not save_ws:
		network['weights'] = 0
	return network
コード例 #3
0
 def calc_information_last(self):
     """Calculate the information of the last epoch"""
     if self.traind_network and self.save_ws:
         return np.array([inn.get_information([self.ws[k][j][i][-1]], self.data_sets.data, self.data_sets.labels,
                                              self.args.num_of_bins, self.args.interval_information_display, self.epochs_indexes)
                                  for i in range(len(self.train_samples)) for j in
                                  range(len(self.layers_sizes)) for k in range(self.args.num_of_repeats)])
コード例 #4
0
 def calc_information(self):
     """Calculate the infomration of the network for all the epochs - only valid if we save the activation values and trained the network"""
     if self.traind_network and self.save_ws:
         self.information =  np.array([inn.get_information(self.ws[k][j][i], self.data_sets.data, self.data_sets.labels,
                                                           self.args.num_of_bins, self.args.interval_information_display, self.epochs_indexes)
                                      for i in range(len(self.train_samples)) for j in
                                      range(len(self.layers_sizes)) for k in range(self.args.num_of_repeats)])
     else:
         print ('Cant calculate the infomration of the networks!!!')
コード例 #5
0
def train_and_calc_inf_network(
        i, j, k, layerSize, num_of_ephocs, learning_rate_local, batch_size,
        indexes, save_grads, data_sets_org, model_type, percent_of_train,
        interval_accuracy_display, calc_information, calc_information_last,
        num_of_bins, interval_information_display, save_ws, rand_int, cov_net):
    """Train the network and calculate it's information"""

    # where is the "network" getting trained? Don't see it getting passed in...
    network_name = '{0}_{1}_{2}_{3}'.format(i, j, k, rand_int)
    print('Training network  - {0}'.format(network_name))
    # so technically everything is saved in network dict here!!
    # but NOT information, only 'ws' and other things
    network = train_network(layerSize, num_of_ephocs, learning_rate_local,
                            batch_size, indexes, save_grads, data_sets_org,
                            model_type, percent_of_train,
                            interval_accuracy_display, network_name, cov_net)
    network['information'] = []
    if calc_information:  # default branch
        # trained model with the history of training is passed into this function
        print('Calculating the infomration')
        infomration = np.array([
            inn.get_information(network['ws'], data_sets_org.data,
                                data_sets_org.labels, num_of_bins,
                                interval_information_display, network['model'],
                                layerSize)
        ])
        network['information'] = infomration
    elif calc_information_last:
        print('Calculating the infomration only for the last epoch')
        infomration = np.array([
            inn.get_information([network['ws'][-1]], data_sets_org.data,
                                data_sets_org.labels, num_of_bins,
                                interval_information_display, network['model'],
                                layerSize)
        ])
        network['information'] = infomration
    # ws is NOT even saved here...it's saved outside
    if not save_ws:
        network['weights'] = 0  # we changed save_ws to default true
    return network
コード例 #6
0
ファイル: network.py プロジェクト: zchenry/IDNNs
def train_and_calc_inf_network(i, j, k, layers, num_of_ephocs, lr_local,
                               batchsize, indexes, data_sets, model_type,
                               percent_of_train, nbins, cov):
    """Train the network and calculate its information"""
    network_name = '{0}_{1}_{2}'.format(i, j, k)
    print('Training network  - {0}'.format(network_name))
    network = train_network(layers, num_of_ephocs, lr_local, batchsize,
                            indexes, data_sets, model_type, percent_of_train,
                            network_name, cov)
    network['information'] = []

    print('Calculating the infomration')
    infomration = np.array([
        inn.get_information(network['ws'], data_sets[:, :-1],
                            data_sets[:, -1:], nbins, network['model'], layers)
    ])
    network['information'] = infomration
    print('Successfully calculated the infomration !!!')
    return network