本文整理汇总了Python中pyclustering.utils.read_sample函数的典型用法代码示例。如果您正苦于以下问题:Python read_sample函数的具体用法?Python read_sample怎么用?Python read_sample使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_sample函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
开发者ID:annoviko,项目名称:pyclustering,代码行数:8,代码来源:ut_general.py
示例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();
开发者ID:annoviko,项目名称:pyclustering,代码行数:9,代码来源:ut_general.py
示例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();
开发者ID:annoviko,项目名称:pyclustering,代码行数:9,代码来源:ut_general.py
示例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();
开发者ID:annoviko,项目名称:pyclustering,代码行数:10,代码来源:ut_general.py
示例5: testVisualizeByDataOnly
def testVisualizeByDataOnly(self):
visualizer = cluster_visualizer();
sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE1);
visualizer.append_clusters([ sample ]);
visualizer.show();
开发者ID:annoviko,项目名称:pyclustering,代码行数:7,代码来源:ut_general.py
示例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)
开发者ID:annoviko,项目名称:pyclustering,代码行数:29,代码来源:silhouette_templates.py
示例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);
开发者ID:terry07,项目名称:pyclustering,代码行数:29,代码来源:syncsom_examples.py
示例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);
开发者ID:annoviko,项目名称:pyclustering,代码行数:30,代码来源:bsas_templates.py
示例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)
开发者ID:annoviko,项目名称:pyclustering,代码行数:7,代码来源:ut_kmedoids.py
示例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)
开发者ID:annoviko,项目名称:pyclustering,代码行数:7,代码来源:ut_visualizer.py
示例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)
开发者ID:annoviko,项目名称:pyclustering,代码行数:29,代码来源:cure_templates.py
示例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);
开发者ID:annoviko,项目名称:pyclustering,代码行数:27,代码来源:ema_examples.py
示例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;
开发者ID:RuhiSharma,项目名称:pyclustering,代码行数:27,代码来源:syncnet_tests.py
示例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)
开发者ID:annoviko,项目名称:pyclustering,代码行数:35,代码来源:dbscan_templates.py
示例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();
开发者ID:Gudui,项目名称:pyclustering,代码行数:60,代码来源:agglomerative_examples.py
示例16: templateLengthProcessData
def templateLengthProcessData(data, start_medians, expected_cluster_length, ccore, **kwargs):
tolerance = kwargs.get('tolerance', 0.01)
metric = kwargs.get('metric', None)
itermax = kwargs.get('itermax', 200)
if isinstance(data, str):
sample = read_sample(data)
else:
sample = data
kmedians_instance = kmedians(sample, start_medians, tolerance, ccore, metric=metric, itermax=itermax)
kmedians_instance.process()
clusters = kmedians_instance.get_clusters()
medians = kmedians_instance.get_medians()
if itermax == 0:
assert clusters == []
assert start_medians == medians
return
obtained_cluster_sizes = [len(cluster) for cluster in clusters]
assert len(sample) == sum(obtained_cluster_sizes)
assert len(medians) == len(clusters)
if expected_cluster_length is not None:
obtained_cluster_sizes.sort()
expected_cluster_length.sort()
if obtained_cluster_sizes != expected_cluster_length:
print(obtained_cluster_sizes)
assert obtained_cluster_sizes == expected_cluster_length
开发者ID:annoviko,项目名称:pyclustering,代码行数:31,代码来源:kmedians_templates.py
示例17: elbow_analysis
def elbow_analysis(sample_file_path, kmin, kmax, **kwargs):
initializer = kwargs.get('initializer', kmeans_plusplus_initializer)
sample = read_sample(sample_file_path)
elbow_instance = elbow(sample, kmin, kmax, initializer=initializer)
elbow_instance.process()
amount_clusters = elbow_instance.get_amount()
wce = elbow_instance.get_wce()
centers = kmeans_plusplus_initializer(sample, amount_clusters).initialize()
kmeans_instance = kmeans(sample, centers)
kmeans_instance.process()
clusters = kmeans_instance.get_clusters()
centers = kmeans_instance.get_centers()
print("Sample '%s': Obtained amount of clusters: '%d'." % (sample_file_path, amount_clusters))
figure = plt.figure(1)
ax = figure.add_subplot(111)
ax.plot(range(kmin, kmax), wce, color='b', marker='.')
ax.plot(amount_clusters, wce[amount_clusters - kmin], color='r', marker='.', markersize=10)
ax.annotate("Elbow", (amount_clusters + 0.1, wce[amount_clusters - kmin] + 5))
ax.grid(True)
plt.ylabel("WCE")
plt.xlabel("K")
plt.show()
kmeans_visualizer.show_clusters(sample, clusters, centers)
开发者ID:annoviko,项目名称:pyclustering,代码行数:29,代码来源:elbow_examples.py
示例18: calculate_elbow
def calculate_elbow(path_to_data, path_to_answer, kmin, kmax, ccore, **kwargs):
repeat = 10 # Elbow method randomly chooses initial centers therefore we need to repeat test if it fails.
testing_result = False
initializer = kwargs.get('initializer', kmeans_plusplus_initializer)
sample = read_sample(path_to_data)
answer = answer_reader(path_to_answer)
additional_info = []
for _ in range(repeat):
elbow_instance = elbow(sample, kmin, kmax, ccore=ccore, initializer=initializer)
elbow_instance.process()
actual_elbow = elbow_instance.get_amount()
actual_wce = elbow_instance.get_wce()
assertion.gt(actual_elbow, kmin)
assertion.lt(actual_elbow, kmax)
assertion.eq(len(actual_wce), kmax - kmin)
assertion.lt(actual_wce[-1], actual_wce[0] + 0.0000001)
if actual_elbow != len(answer.get_clusters()):
additional_info.append(actual_elbow)
#time.sleep(0.05) # sleep to gain new seed for random generator
continue
testing_result = True
break
message = str(len(answer.get_clusters())) + ": " + str(additional_info)
assertion.true(testing_result, message=message)
开发者ID:annoviko,项目名称:pyclustering,代码行数:33,代码来源:elbow_template.py
示例19: templateDataClustering
def templateDataClustering(self, sample_path,
amount_clusters,
chromosome_count,
population_count,
count_mutation_gens,
coeff_mutation_count,
expected_clusters_sizes):
testing_result = False
for _ in range(3):
sample = read_sample(sample_path)
ga_instance = genetic_algorithm(sample, amount_clusters, chromosome_count, population_count,
count_mutations_gen=count_mutation_gens,
coeff_mutation_count=coeff_mutation_count)
ga_instance.process()
clusters = ga_instance.get_clusters()
obtained_cluster_sizes = [len(cluster) for cluster in clusters]
if len(sample) != sum(obtained_cluster_sizes):
continue
if expected_clusters_sizes is not None:
obtained_cluster_sizes.sort()
expected_clusters_sizes.sort()
if obtained_cluster_sizes != expected_clusters_sizes:
continue
testing_result = True
break
assert testing_result is True
开发者ID:annoviko,项目名称:pyclustering,代码行数:33,代码来源:ut_ga.py
示例20: templateLengthProcessData
def templateLengthProcessData(input_sample, start_centers, expected_cluster_length, type_splitting, kmax, ccore):
if isinstance(input_sample, str):
sample = read_sample(input_sample)
else:
sample = input_sample
#clusters = xmeans(sample, start_centers, 20, ccore);
xmeans_instance = xmeans(sample, start_centers, kmax, 0.025, type_splitting, ccore)
xmeans_instance.process()
clusters = xmeans_instance.get_clusters()
centers = xmeans_instance.get_centers()
obtained_cluster_sizes = [len(cluster) for cluster in clusters]
assert len(sample) == sum(obtained_cluster_sizes);
assert len(clusters) == len(centers);
assert len(centers) <= kmax;
if expected_cluster_length is not None:
assert len(centers) == len(expected_cluster_length);
obtained_cluster_sizes.sort()
expected_cluster_length.sort()
assert obtained_cluster_sizes == expected_cluster_length;
开发者ID:annoviko,项目名称:pyclustering,代码行数:26,代码来源:xmeans_templates.py
注:本文中的pyclustering.utils.read_sample函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论