marta-marta commited on
Commit
e8a1ac5
1 Parent(s): 3e918de

Added TSNE Plot

Browse files
Files changed (1) hide show
  1. app.py +16 -0
app.py CHANGED
@@ -7,6 +7,7 @@ import streamlit as st
7
 
8
  from Data_Generation.Dataset_Generation_Functions import make_boxes
9
  from Data_Generation.Piecewise_Box_Functions import basic_box_array, forward_slash_array, combine_arrays, add_thickness
 
10
  ########################################################################################################################
11
  # User Inputs
12
  image_size = st.slider('Select a value for the image size', min_value=9, max_value=16)
@@ -73,6 +74,21 @@ if st.button('Generate Dataset'): # Generate the dataset
73
  box_arrays, box_density, basic_box_thickness, forward_slash_box_thickness, back_slash_box_thickness,hot_dog_box_thickness, hamburger_box_thickness\
74
  = list(zip(*boxes))[0], list(zip(*boxes))[1], list(zip(*boxes))[2], list(zip(*boxes))[3], list(zip(*boxes))[4], list(zip(*boxes))[5], list(zip(*boxes))[6]
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  class NumpyArrayEncoder(JSONEncoder):
77
  def default(self, obj):
78
  if isinstance(obj, np.ndarray):
 
7
 
8
  from Data_Generation.Dataset_Generation_Functions import make_boxes
9
  from Data_Generation.Piecewise_Box_Functions import basic_box_array, forward_slash_array, combine_arrays, add_thickness
10
+ from Data_Plotting.Plot_TSNE import TSNE_reduction
11
  ########################################################################################################################
12
  # User Inputs
13
  image_size = st.slider('Select a value for the image size', min_value=9, max_value=16)
 
74
  box_arrays, box_density, basic_box_thickness, forward_slash_box_thickness, back_slash_box_thickness,hot_dog_box_thickness, hamburger_box_thickness\
75
  = list(zip(*boxes))[0], list(zip(*boxes))[1], list(zip(*boxes))[2], list(zip(*boxes))[3], list(zip(*boxes))[4], list(zip(*boxes))[5], list(zip(*boxes))[6]
76
 
77
+ # Plot TSNE of the data
78
+ # define a function to flatten a 2D array
79
+ def flatten_array(array):
80
+ return array.flatten()
81
+
82
+ # apply the flatten_array function to each array in the list and create a list of flattened arrays
83
+ flattened_arrays = [flatten_array(a) for a in box_arrays]
84
+
85
+ # Perform the TSNE Reduction
86
+ x, y, title, embedding = TSNE_reduction(flattened_arrays)
87
+
88
+ plt.scatter(x, y)
89
+ plt.title(title)
90
+ plt.show()
91
+
92
  class NumpyArrayEncoder(JSONEncoder):
93
  def default(self, obj):
94
  if isinstance(obj, np.ndarray):