本文整理汇总了Python中pyclustering.utils.read_sample函数的典型用法代码示例。如果您正苦于以下问题:Python read_sample函数的具体用法?Python read_sample怎么用?Python read_sample使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_sample函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testVisualize2DAnd3DClusters
def testVisualize2DAnd3DClusters(self):
sample_2d = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE1);
sample_3d = read_sample(FCPS_SAMPLES.SAMPLE_HEPTA);
visualizer = cluster_visualizer(2, 2);
visualizer.append_clusters([ sample_2d ], None, 0, markersize = 5);
visualizer.append_clusters([ sample_3d ], None, 1, markersize = 30);
visualizer.show();
示例2: testVisualize3DClustersTwoCanvases
def testVisualize3DClustersTwoCanvases(self):
sample_tetra = read_sample(FCPS_SAMPLES.SAMPLE_TETRA);
sample_hepta = read_sample(FCPS_SAMPLES.SAMPLE_HEPTA);
# Two canvas visualization
visualizer = cluster_visualizer(2);
visualizer.append_clusters([ sample_tetra ], None, 0, markersize = 30);
visualizer.append_clusters([ sample_hepta ], None, 1, markersize = 30);
visualizer.show();
示例3: testVisualize1DClustersTwoCanvases
def testVisualize1DClustersTwoCanvases(self):
sample_simple7 = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE7);
sample_simple8 = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE8);
# Two canvas visualization
visualizer = cluster_visualizer(2);
visualizer.append_clusters([ sample_simple7 ], None, 0, markersize = 30);
visualizer.append_clusters([ sample_simple8 ], None, 1, markersize = 30);
visualizer.show();
示例4: testVisualizeRectangeRepresentation2x2
def testVisualizeRectangeRepresentation2x2(self):
sample_simple1 = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE1);
sample_simple2 = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE2);
sample_simple3 = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3);
visualizer = cluster_visualizer(3, 2);
visualizer.append_clusters([ sample_simple1 ], None, 0, markersize = 5);
visualizer.append_clusters([ sample_simple2 ], None, 1, markersize = 5);
visualizer.append_clusters([ sample_simple3 ], None, 2, markersize = 5);
visualizer.show();
示例5: testVisualizeByDataOnly
def testVisualizeByDataOnly(self):
visualizer = cluster_visualizer();
sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE1);
visualizer.append_clusters([ sample ]);
visualizer.show();
示例6: correct_ksearch
def correct_ksearch(sample_path, answer_path, kmin, kmax, algorithm, ccore_flag):
attempts = 10
testing_result = False
sample = read_sample(sample_path)
clusters = answer_reader(answer_path).get_clusters()
for _ in range(attempts):
ksearch_instance = silhouette_ksearch(sample, kmin, kmax, algorithm=algorithm, ccore=ccore_flag).process()
amount = ksearch_instance.get_amount()
score = ksearch_instance.get_score()
scores = ksearch_instance.get_scores()
assertion.le(-1.0, score)
assertion.ge(1.0, score)
assertion.eq(kmax - kmin, len(scores))
upper_limit = len(clusters) + 1
lower_limit = len(clusters) - 1
if lower_limit < 1:
lower_limit = 1
if (amount > upper_limit) or (amount < lower_limit):
continue
testing_result = True
break
assertion.true(testing_result)
示例7: template_clustering
def template_clustering(file, map_size, trust_order, sync_order = 0.999, show_dyn = False, show_layer1 = False, show_layer2 = False, show_clusters = True):
# Read sample
sample = read_sample(file);
# Create network
network = syncsom(sample, map_size[0], map_size[1]);
# Run processing
(ticks, (dyn_time, dyn_phase)) = timedcall(network.process, trust_order, show_dyn, sync_order);
print("Sample: ", file, "\t\tExecution time: ", ticks, "\n");
# Show dynamic of the last layer.
if (show_dyn == True):
draw_dynamics(dyn_time, dyn_phase, x_title = "Time", y_title = "Phase", y_lim = [0, 2 * 3.14]);
if (show_clusters == True):
clusters = network.get_som_clusters();
draw_clusters(network.som_layer.weights, clusters);
# Show network stuff.
if (show_layer1 == True):
network.show_som_layer();
if (show_layer2 == True):
network.show_sync_layer();
if (show_clusters == True):
clusters = network.get_clusters();
draw_clusters(sample, clusters);
示例8: clustering
def clustering(path, amount, threshold, expected, ccore, **kwargs):
metric = kwargs.get('metric', distance_metric(type_metric.EUCLIDEAN));
sample = read_sample(path);
bsas_instance = bsas(sample, amount, threshold, ccore=ccore, metric=metric);
bsas_instance.process();
clusters = bsas_instance.get_clusters();
representatives = bsas_instance.get_representatives();
obtained_length = 0;
obtained_cluster_length = [];
for cluster in clusters:
obtained_length += len(cluster);
obtained_cluster_length.append(len(cluster));
assertion.eq(len(sample), obtained_length);
assertion.eq(len(expected), len(clusters));
assertion.eq(len(expected), len(representatives));
assertion.ge(amount, len(clusters));
dimension = len(sample[0]);
for rep in representatives:
assertion.eq(dimension, len(rep));
expected.sort();
obtained_cluster_length.sort();
assertion.eq(expected, obtained_cluster_length);
示例9: testAllocatedRequestedClustersSampleSimple03
def testAllocatedRequestedClustersSampleSimple03(self):
sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3)
KmedoidsTestTemplates.templateAllocateRequestedClusterAmount(sample, 2, None, False)
KmedoidsTestTemplates.templateAllocateRequestedClusterAmount(sample, 5, None, False)
KmedoidsTestTemplates.templateAllocateRequestedClusterAmount(sample, 8, None, False)
KmedoidsTestTemplates.templateAllocateRequestedClusterAmount(sample, 10, None, False)
KmedoidsTestTemplates.templateAllocateRequestedClusterAmount(sample, 15, None, False)
示例10: template_visualize
def template_visualize(self, path_sample, path_answer, filter=None, **kwargs):
data = read_sample(path_sample)
clusters = answer_reader(path_answer).get_clusters()
visualizer = cluster_visualizer_multidim()
visualizer.append_clusters(clusters, data)
visualizer.show(filter, **kwargs)
示例11: template_cluster_allocation
def template_cluster_allocation(input_data, cluster_sizes, number_cluster, number_represent_points = 5, compression = 0.5, ccore_flag = False, **kwargs):
if isinstance(input_data, str):
sample = read_sample(input_data)
else:
sample = input_data
numpy_usage = kwargs.get('numpy_usage', False)
if numpy_usage is True:
sample = numpy.array(sample)
cure_instance = cure(sample, number_cluster, number_represent_points, compression, ccore = ccore_flag)
cure_instance.process()
clusters = cure_instance.get_clusters()
representors = cure_instance.get_representors()
means = cure_instance.get_means()
assertion.eq(len(clusters), number_cluster)
assertion.eq(len(representors), number_cluster)
assertion.eq(len(means), number_cluster)
obtained_cluster_sizes = [len(cluster) for cluster in clusters]
total_length = sum(obtained_cluster_sizes)
assertion.eq(total_length, len(sample))
cluster_sizes.sort()
obtained_cluster_sizes.sort()
assertion.eq(cluster_sizes, obtained_cluster_sizes)
示例12: template_clustering
def template_clustering(sample_file_path, amount_clusters, initializer, show_animation = False):
sample = read_sample(sample_file_path);
observer = None;
if (show_animation is True):
observer = ema_observer();
initial_means, initial_covariance = ema_initializer(sample, amount_clusters).initialize(initializer);
ema_instance = ema(sample, amount_clusters, initial_means, initial_covariance, observer=observer);
ema_instance.process();
clusters = ema_instance.get_clusters();
covariances = ema_instance.get_covariances();
means = ema_instance.get_centers();
cluster_length = [ len(cluster) for cluster in clusters ];
print("Data '" + sample_file_path + "'");
print("Clusters: " + str(len(clusters)) + ", Length:" + str(cluster_length));
if (observer is True):
ema_visualizer.show_clusters(observer.get_evolution_clusters()[0], sample, observer.get_evolution_covariances()[0], observer.get_evolution_means()[0]);
ema_visualizer.show_clusters(clusters, sample, covariances, means);
if (show_animation is True):
ema_visualizer.animate_cluster_allocation(sample, observer);
示例13: templateClustering
def templateClustering(self, file, radius, order, solver, initial, storage_flag, conn_weigh_flag, tolerance, connection, expected_cluster_length, ccore_flag):
result_testing = False;
# If phases crosses each other because of random part of the network then we should try again.
for attempt in range(0, 4, 1):
sample = read_sample(file);
network = syncnet(sample, radius, connection, initial, conn_weigh_flag, ccore_flag);
analyser = network.process(order, solver, storage_flag);
clusters = analyser.allocate_clusters(tolerance);
obtained_cluster_sizes = [len(cluster) for cluster in clusters];
if (len(obtained_cluster_sizes) != len(expected_cluster_length)):
continue;
obtained_cluster_sizes.sort();
expected_cluster_length.sort();
if (obtained_cluster_sizes != expected_cluster_length):
continue;
# Unit-test is passed
result_testing = True;
break;
assert result_testing;
示例14: templateClusteringWithAnswers
def templateClusteringWithAnswers(sample_path, answer_path, radius, neighbors, ccore, **kwargs):
random_order = kwargs.get('random_order', False)
repeat = kwargs.get('repeat', 1)
for _ in range(repeat):
sample = read_sample(sample_path)
sample_index_map = [ i for i in range(len(sample)) ]
if random_order:
shuffle(sample_index_map)
sample_shuffled = [ sample[i] for i in sample_index_map ]
dbscan_instance = dbscan(sample_shuffled, radius, neighbors, ccore)
dbscan_instance.process()
clusters = dbscan_instance.get_clusters()
noise = dbscan_instance.get_noise()
for cluster in clusters:
for i in range(len(cluster)):
cluster[i] = sample_index_map[cluster[i]]
for i in range(len(noise)):
noise[i] = sample_index_map[noise[i]]
noise = sorted(noise)
reader = answer_reader(answer_path)
expected_noise = sorted(reader.get_noise())
expected_length_clusters = reader.get_cluster_lengths()
assertion.eq(len(sample), sum([len(cluster) for cluster in clusters]) + len(noise))
assertion.eq(sum(expected_length_clusters), sum([len(cluster) for cluster in clusters]))
assertion.eq(expected_length_clusters, sorted([len(cluster) for cluster in clusters]))
assertion.eq(expected_noise, noise)
示例15: template_clustering
def template_clustering(number_clusters, path, links):
sample = read_sample(path);
clusters_centroid_link = None;
clusters_single_link = None;
clusters_complete_link = None;
clusters_average_link = None;
visualizer = cluster_visualizer(len(links));
index_canvas = 0;
if (type_link.CENTROID_LINK in links):
agglomerative_centroid_link = agglomerative(sample, number_clusters, type_link.CENTROID_LINK);
(ticks, result) = timedcall(agglomerative_centroid_link.process);
clusters_centroid_link = agglomerative_centroid_link.get_clusters();
visualizer.append_clusters(clusters_centroid_link, sample, index_canvas);
visualizer.set_canvas_title('Link: Centroid', index_canvas);
index_canvas += 1;
print("Sample: ", path, "Link: Centroid", "\tExecution time: ", ticks, "\n");
if (type_link.SINGLE_LINK in links):
agglomerative_simple_link = agglomerative(sample, number_clusters, type_link.SINGLE_LINK);
(ticks, result) = timedcall(agglomerative_simple_link.process);
clusters_single_link = agglomerative_simple_link.get_clusters();
visualizer.append_clusters(clusters_single_link, sample, index_canvas);
visualizer.set_canvas_title('Link: Single', index_canvas);
index_canvas += 1;
print("Sample: ", path, "Link: Single", "\tExecution time: ", ticks, "\n");
if (type_link.COMPLETE_LINK in links):
agglomerative_complete_link = agglomerative(sample, number_clusters, type_link.COMPLETE_LINK);
(ticks, result) = timedcall(agglomerative_complete_link.process);
clusters_complete_link = agglomerative_complete_link.get_clusters();
visualizer.append_clusters(clusters_complete_link, sample, index_canvas);
visualizer.set_canvas_title('Link: Complete', index_canvas);
index_canvas += 1;
print("Sample: ", path, "Link: Complete", "\tExecution time: ", ticks, "\n");
if (type_link.AVERAGE_LINK in links):
agglomerative_average_link = agglomerative(sample, number_clusters, type_link.AVERAGE_LINK);
(ticks, result) = timedcall(agglomerative_average_link.process);
clusters_average_link = agglomerative_average_link.get_clusters();
visualizer.append_clusters(clusters_average_link, sample, index_canvas);
visualizer.set_canvas_title('Link: Average', index_canvas);
index_canvas += 1;
print("Sample: ", path, "Link: Average", "\tExecution time: ", ticks, "\n");
visualizer.show();