コード例 #1
0
ファイル: play.py プロジェクト: h-mayorquin/pynexa
distance_matrix = 1 - np.abs(np.corrcoef(data_matrix))
print('Zeros on the distance matrix', np.sum(distance_matrix == 0))
# This could be another possible way
# distance_matrix = np.dot(data_matrix, data_matrix.T)

nexa_data = NexaData(data_matrix, distance_matrix)

# Now we need to put this in the Nexa class. Which does all the data processing.
# But first we require some parameters

Nsensor_clusters = 5
Ndata_clusters =  5
Nembedding = 3

# Create the Nexa object
nexa_object = Nexa(nexa_data, Nsensor_clusters, Ndata_clusters, Nembedding)

# Doing the calculations
nexa_object.calculate_distance_matrix()  # So the nexa_objecct knows the distance
# Do the embedding
nexa_object.calculate_embedding()

# Now we calculate sensor clustering
nexa_object.calculate_sensor_clustering()
# And after this we can extract a map from sensor to cluster
sensor_to_cluster_mappping = nexa_object.sensor_to_cluster_mapping
# Which we can visualize
# visualization_clustering = np.vstack(sensor_to_cluster_mappping, sensor_to_cluster_mappping, sensor_to_cluster_mappping)
# And this you can use imshow to plot.

# Now we can the cluster to sensors
コード例 #2
0
ファイル: mnist_demo.py プロジェクト: h-mayorquin/pynexa
X += np.random.rand(Ndata, Nside * Nside)

# Need to calculate the distance and the data in X
data = X.T  # We put the data the sensors in the 0 axis and the data in the 1 axis.
distance = 1 - np.abs(np.corrcoef(data))  # Calculate the correlation coefficients

# Wrap the data in the NexaData format.
nexa_data = NexaData(data, distance)

# Nexa parameters
Nsensor_clusters = 5
Ndata_clusters = 3
Nembedding = 3

# Build Nexa object and calculate all the quantities
nexa_object = Nexa(nexa_data, Nsensor_clusters, Ndata_clusters, Nembedding)

# First we calculate the distance matrix
nexa_object.calculate_distance_matrix()

# Now we calculate the embedding
nexa_object.calculate_embedding()

# Now we calculat how the sensors clustering, this also makes
# available a mapping from each sensor to the cluster that it belongs
nexa_object.calculate_sensor_clustering()

# Get's a map from each to cluster to all the sensors wichh belong to it.
nexa_object.calculate_cluster_to_sensors()

# Calculates teh data clustering and also makes available a map from each