def experiment_10(a): concatenate={} concatenate[111]=DATA_111_URL concatenate[290]=DATA_290_URL concatenate[896]=DATA_896_URL data_table = load_data_table(concatenate[a]) ##for the hierarchical singleton_list = [] for line in data_table: singleton_list.append(alg_cluster.Cluster(set([line[0]]), line[1], line[2], line[3], line[4])) for ele in x: singleton_list=HW3.hierarchical_clustering(singleton_list,ele) distortion=0 for cluster in singleton_list: distortion+=cluster.cluster_error(data_table) if a==111: y_111_H.append(distortion) elif a==290: y_290_H.append(distortion) else: y_896_H.append(distortion) ##K-means singleton_list = [] for line in data_table: singleton_list.append(alg_cluster.Cluster(set([line[0]]), line[1], line[2], line[3], line[4])) for ele in x: singleton_list=HW3.kmeans_clustering(singleton_list,ele,5) distortion=0 for cluster in singleton_list: distortion+=cluster.cluster_error(data_table) if a==111: y_111_K.append(distortion) elif a==290: y_290_K.append(distortion) else: y_896_K.append(distortion) if a==111: plt.plot(x,y_111_H) plt.plot(x,y_111_K) elif a==290: plt.plot(x,y_290_H) plt.plot(x,y_290_K) else: plt.plot(x,y_896_H) plt.plot(x,y_896_K) plt.xlabel('Number of the clusters ') plt.ylabel('Total Distortion') plt.legend(['Hierarchical Clustering','K-mean clustering']) plt.title('Distortion comparison of two clustering method-'+str(a)+'counties') plt.grid(True) plt.savefig("HW3_"+str(a)+".png") plt.show()
def run_example(): """ Load a data table, compute a list of clusters and plot a list of clusters Set DESKTOP = True/False to use either matplotlib or simplegui """ data_table = load_data_table(DATA_3108_URL) singleton_list = [] for line in data_table: singleton_list.append(alg_cluster.Cluster(set([line[0]]), line[1], line[2], line[3], line[4])) #cluster_list = sequential_clustering(singleton_list, 15) #print "Displaying", len(cluster_list), "sequential clusters" cluster_list = HW3.hierarchical_clustering(singleton_list, 15) print "Displaying", len(cluster_list), "hierarchical clusters" # cluster_list = HW3.kmeans_clustering(singleton_list,9, 5) # print "Displaying", len(cluster_list), "k-means clusters" #draw the clusters using matplotlib or simplegui if DESKTOP: alg_clusters_matplotlib.plot_clusters(data_table, cluster_list, False)
def test_mergeSort(self): self.assertEqual(HW3.mergeSort(random_array), sorted_array)
def test_bubblesort(self): self.assertEqual(HW3.bubblesort(random_array), sorted_array)
import sys import os import pathlib p = pathlib.Path(os.getcwd()) p /= "../../../starter/lesson 7/Alex Shvab" p = p.resolve() sys.path.insert(0, str(p)) import HW3 x = int(input("Enter range of simple number: ")) HW3.simpl_numb(x + 1) print((HW3.list))
import HW3 import pprint documents = [{ "type": "passport", "number": "2207", "name": "Василий Гупкин" }, { "type": "invoice", "number": "11-2", "name": "Геннадий Покемонов" }, { "type": "insurance", "number": "10006", "name": "Аристарх Павлов" }, { "type": "insurance", "number": "2" }] print(documents) # print(HW3.get_owner(documents, '2')) print(documents[0].keys()) if 'name' in documents[0].keys(): print('++') print(HW3.get_owner(documents, '2'))
batch_size = 20 seq_length = 30 dropout = 0.3 learning_rate = 0.005 seed = 621 date = datetime.datetime.now().strftime("%d-%m-%y %H-%M-%S") device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') corpus = Corpus() ids = corpus.get_data('data/train.txt', batch_size) # divide to batch size valid_d = corpus.get_data('data/valid.txt', batch_size) test_d = corpus.get_data('data/test.txt', batch_size) vocab_size = len(corpus.dictionary) num_batches = ids.size(1) // seq_length model = HW3.RNNLM(vocab_size, embed_size, hidden_size, num_layers, dropout) model.load_state_dict(torch.load(model_name,map_location=device)) model.eval() torch.manual_seed(seed) if torch.cuda.is_available(): torch.cuda.manual_seed(seed) model.cuda() else: model.cpu() # Set the random seed manually for reproducibility. generate() print(' ****** END of generative process ******')
import HW3 print(HW3.create_snp(3, 'ACGCTCGCTGAC'))
from matplotlib import pyplot # Loop that gets a list of times for each type of sort N = 10 trials = 4 merge_times = [0] * trials bubble_times = [0] * trials quick_times = [0] * trials for i in range(0, trials): random_array = range(1, N) random.shuffle(random_array) start_time = time.clock() HW3.mergeSort(random_array) merge_times[i] = time.clock() - start_time random_array = range(1, N) random.shuffle(random_array) start_time = time.clock() HW3.bubblesort(random_array) bubble_times[i] = time.clock() - start_time random_array = range(1, N) random.shuffle(random_array) start_time = time.clock() random_array.sort() quick_times[i] = time.clock() - start_time