Exemple #1
0
    def testClustersAssignments(self):
        # Ignore noise
        ignore_noise = True
        num_categories = self.num_categories - 1
        (cluster_assignments,
         sdr_slices) = find_cluster_assignments(self.sdrs, self.clusters,
                                                ignore_noise)
        self.assertEqual(len(cluster_assignments), num_categories * self.reps)
        self.assertEqual(len(sdr_slices), num_categories * self.reps)

        # Don't ignore the noise
        ignore_noise = False
        num_categories = self.num_categories
        (cluster_assignments,
         sdr_slices) = find_cluster_assignments(self.sdrs, self.clusters,
                                                ignore_noise)
        self.assertEqual(len(cluster_assignments), num_categories * self.reps)
        self.assertEqual(len(sdr_slices), num_categories * self.reps)
Exemple #2
0
def plot_inter_sequence_distances(output_dir, plot_id, distance_func, sdrs,
                                  cluster_ids, ignore_noise):
    cluster_assignments, sdr_slices = find_cluster_assignments(
        sdrs, cluster_ids, ignore_noise)

    distance_mat = cluster_distance_matrix(sdr_slices, distance_func)

    title = 'distance_matrix_%s' % plot_id
    outputFile = '%s/%s' % (output_dir, '%s.png' % title)
    plot_distance_mat(distance_mat, title, outputFile)
Exemple #3
0
  def testClustersAssignments(self):
    # Ignore noise
    ignore_noise = True
    num_categories = self.num_categories - 1
    (cluster_assignments,
     sdr_slices) = find_cluster_assignments(self.sdrs,
                                            self.clusters,
                                            ignore_noise)
    self.assertEqual(len(cluster_assignments), num_categories * self.reps)
    self.assertEqual(len(sdr_slices), num_categories * self.reps)

    # Don't ignore the noise
    ignore_noise = False
    num_categories = self.num_categories
    (cluster_assignments,
     sdr_slices) = find_cluster_assignments(self.sdrs,
                                            self.clusters,
                                            ignore_noise)
    self.assertEqual(len(cluster_assignments), num_categories * self.reps)
    self.assertEqual(len(sdr_slices), num_categories * self.reps)
def plot_inter_sequence_distances(output_dir,
                                  plot_id,
                                  distance_func,
                                  sdrs,
                                  cluster_ids,
                                  ignore_noise):
  cluster_assignments, sdr_slices = find_cluster_assignments(sdrs, cluster_ids,
                                                             ignore_noise)

  distance_mat = cluster_distance_matrix(sdr_slices, distance_func)

  title = 'distance_matrix_%s' % plot_id
  outputFile = '%s/%s' % (output_dir, '%s.png' % title)
  plot_distance_mat(distance_mat, title, outputFile)
def main():
    # OPTICS demo with SDRs
    radius = 10.0
    neighbors = 2
    epsilon_cutoff = 0.3
    file_path = os.path.join(
        os.getcwd(), 'htm_traces', 'binary_ampl=10.0_mean=0.0_noise=0.0_'
        'sp=True_tm=True_tp=False_SDRClassifier.csv')
    sdrs, cluster_ids = load_sdrs(file_path)
    (cluster_assignments,
     sdr_slices) = find_cluster_assignments(sdrs,
                                            cluster_ids,
                                            ignore_noise=True)
    sdr_cluster_centroids = get_sdr_cluster_centroids(sdr_slices)

    # Project SDRs in 2D for visualization purposes
    distance_mat = distance_matrix(sdr_cluster_centroids, euclidian_distance)
    sdr_projections = project_clusters_2D(distance_mat, method='mds')

    # OPTICS SDR results
    sample_sdr = sdr_projections  # or: sdr_cluster_centroids
    ordering_sdr, clusters_sdr, noise_sdr = analyze(sample_sdr, radius,
                                                    neighbors)

    # Plot OPTICS results
    sample_sdr = sdr_projections
    plot_results(sample_sdr, ordering_sdr, clusters_sdr, noise_sdr, 'SDR',
                 epsilon_cutoff)

    # Plot SDR 2D projections
    title = '2d_projections'
    output_file = '%s' % ('%s.png' % title)
    plt = plot_2D_projections(title, output_file, cluster_assignments,
                              sdr_projections)
    plt.show()

    # OPTICS demo with 2D vectors
    radius = 2.0
    neighbors = 2
    epsilon_cutoff = 0.5
    sample_2d = read_sample(
        FCPS_SAMPLES.SAMPLE_LSUN)  # or: gaussian_clusters(3)
    ordering_2d, clusters_2d, noise_2d = analyze(sample_2d, radius, neighbors)
    plot_results(sample_2d, ordering_2d, clusters_2d, noise_2d, '2D',
                 epsilon_cutoff)

    # Plot input data and clustering structure
    ordering_visualizer.show_ordering_diagram(ordering_sdr)
    ordering_visualizer.show_ordering_diagram(ordering_2d)
Exemple #6
0
def plot_inter_sequence_distances(output_dir, plot_id, distance_func, sdrs,
                                  cluster_ids, ignore_noise):
    cluster_assignments, sdr_slices = find_cluster_assignments(
        sdrs, cluster_ids, ignore_noise)

    distance_mat = cluster_distance_matrix(sdr_slices, distance_func)

    title = 'distance_matrix_%s' % plot_id
    output_file = '%s/%s' % (output_dir, '%s.png' % title)
    plot_distance_mat(distance_mat, title, output_file)

    projections = project_clusters_2D(distance_mat, method='mds')
    title = '2d_projections_%s' % plot_id
    output_file = '%s/%s' % (output_dir, '%s.png' % title)
    plot_2D_projections(title, output_file, cluster_assignments, projections)
Exemple #7
0
def main():
  # OPTICS demo with SDRs
  radius = 10.0
  neighbors = 2
  epsilon_cutoff = 0.3
  file_path = os.path.join(os.getcwd(), 'htm_traces',
                           'binary_ampl=10.0_mean=0.0_noise=0.0_'
                           'sp=True_tm=True_tp=False_SDRClassifier.csv')
  sdrs, cluster_ids = load_sdrs(file_path)
  (cluster_assignments,
   sdr_slices) = find_cluster_assignments(sdrs, cluster_ids, ignore_noise=True)
  sdr_cluster_centroids = get_sdr_cluster_centroids(sdr_slices)

  # Project SDRs in 2D for visualization purposes 
  distance_mat = distance_matrix(sdr_cluster_centroids, euclidian_distance)
  sdr_projections = project_clusters_2D(distance_mat, method='mds')

  # OPTICS SDR results  
  sample_sdr = sdr_projections  # or: sdr_cluster_centroids
  ordering_sdr, clusters_sdr, noise_sdr = analyze(sample_sdr,
                                                  radius,
                                                  neighbors)

  # Plot OPTICS results
  sample_sdr = sdr_projections
  plot_results(sample_sdr, ordering_sdr, clusters_sdr, noise_sdr,
               'SDR', epsilon_cutoff)

  # Plot SDR 2D projections
  title = '2d_projections'
  output_file = '%s' % ('%s.png' % title)
  plt = plot_2D_projections(title, output_file, cluster_assignments,
                            sdr_projections)
  plt.show()

  # OPTICS demo with 2D vectors
  radius = 2.0
  neighbors = 2
  epsilon_cutoff = 0.5
  sample_2d = read_sample(FCPS_SAMPLES.SAMPLE_LSUN)  # or: gaussian_clusters(3)
  ordering_2d, clusters_2d, noise_2d = analyze(sample_2d, radius, neighbors)
  plot_results(sample_2d, ordering_2d, clusters_2d, noise_2d, '2D',
               epsilon_cutoff)

  # Plot input data and clustering structure
  ordering_visualizer.show_ordering_diagram(ordering_sdr)
  ordering_visualizer.show_ordering_diagram(ordering_2d)
Exemple #8
0
def plot_inter_sequence_distances(output_dir,
                                  plot_id,
                                  distance_func,
                                  sdrs,
                                  cluster_ids,
                                  ignore_noise):
  cluster_assignments, sdr_slices = find_cluster_assignments(sdrs, cluster_ids,
                                                             ignore_noise)

  distance_mat = cluster_distance_matrix(sdr_slices, distance_func)

  title = 'distance_matrix_%s' % plot_id
  output_file = '%s/%s' % (output_dir, '%s.png' % title)
  plot_distance_mat(distance_mat, title, output_file)

  projections = project_clusters_2D(distance_mat, method='mds')
  title = '2d_projections_%s' % plot_id
  output_file = '%s/%s' % (output_dir, '%s.png' % title)
  plot_2D_projections(title, output_file, cluster_assignments, projections)