def get_form(): """ @return: a list of form objects """ # sample some points to use as the defaults M = np.array(list(SpiralSampler.gen_points(200, 0.01))) # define the form objects form_objects = [Form.Matrix("points", "points", M), Form.ImageFormat()] return form_objects
def get_form(): """ @return: a list of form objects """ # sample some points to use as the defaults M = np.array(list(SpiralSampler.gen_points(200, .01))) # define the form objects form_objects = [Form.Matrix('points', 'points', M), Form.ImageFormat()] return form_objects
def get_response_content(fs): # unpack some options npoints = fs.npoints stddev = fs.stddev # define the data rows and the headers if fs.add_labels: headers = ('x', 'y', 'label') data_rows = list(SpiralSampler.gen_labeled_points(npoints, stddev)) else: headers = ('x', 'y') data_rows = list(SpiralSampler.gen_points(npoints, stddev)) # begin the response if fs.raw: lines = [] for data_row in data_rows: line = '\t'.join(str(x) for x in data_row) lines.append(line) response_text = '\n'.join(lines) elif fs.table: response_text = RUtil.get_table_string(data_rows, headers) # return the response return response_text
def main(): """ Make images from the command line. """ # set the sampling options npoints_per_group = 200 sample_stddev = 0.05 # video options nframes = 51 # clustering options kernel_stddev_initial = 1.0 kernel_stddev_final = 0.1 kernel_stddev_gap = kernel_stddev_final - kernel_stddev_initial kernel_stddev_step = kernel_stddev_gap / (nframes - 1) # sample some points points = np.array(list(SpiralSampler.gen_points(npoints_per_group, sample_stddev))) # make the distance matrix D = points_to_distance_matrix(points) # get two eigenvectors for each frame frame_eigenvectors = [] for i in range(nframes): print "calculating eigendecomposition for frame", i # set the kernel standard deviation for this frame kernel_stddev = kernel_stddev_initial + i * kernel_stddev_step # make the laplacian matrix laplacian_matrix = make_laplacian(D, kernel_stddev) # get the eigenvectors eigenvectors = get_eigenvectors(laplacian_matrix) # possibly flip the signs of the eigenvectors if i: vx, vy = eigenvectors last_vx, last_vy = frame_eigenvectors[i - 1] # possibly flip the x vector match_count = sum(1 for a, b in zip(vx, last_vx) if a * b >= 0) if match_count < len(points) / 2: print "flipping x" vx = [-value for value in vx] # possibly flip the y vector match_count = sum(1 for a, b in zip(vy, last_vy) if a * b >= 0) if match_count < len(points) / 2: print "flipping y" vy = [-value for value in vy] eigenvectors = (vx, vy) frame_eigenvectors.append(eigenvectors) # get all the eigenvector elements in each direction x_eigenvector_elements = [] y_eigenvector_elements = [] for x_eigenvector, y_eigenvector in frame_eigenvectors: x_eigenvector_elements.extend(x_eigenvector) y_eigenvector_elements.extend(y_eigenvector) # get the max and min of the eigenvectors in each direction xmin, xmax = min(x_eigenvector_elements), max(x_eigenvector_elements) ymin, ymax = min(y_eigenvector_elements), max(y_eigenvector_elements) # write the files for i, (vx, vy) in enumerate(frame_eigenvectors): print "writing frame", i # get the image image_format = "png" image_size = (800, 600) draw_axes = True image_string = get_image_helper(xmin, ymin, xmax, ymax, vx, vy, image_size, image_format) # get the filename filename = "frame-%04d.png" % i # write the image with open(filename, "wb") as fout: fout.write(image_string)
def main(): """ Make images from the command line. """ # set the sampling options npoints_per_group = 200 sample_stddev = .05 # video options nframes = 51 # clustering options kernel_stddev_initial = 1.0 kernel_stddev_final = 0.1 kernel_stddev_gap = kernel_stddev_final - kernel_stddev_initial kernel_stddev_step = kernel_stddev_gap / (nframes - 1) # sample some points points = np.array( list(SpiralSampler.gen_points(npoints_per_group, sample_stddev))) # make the distance matrix D = points_to_distance_matrix(points) # get two eigenvectors for each frame frame_eigenvectors = [] for i in range(nframes): print 'calculating eigendecomposition for frame', i # set the kernel standard deviation for this frame kernel_stddev = kernel_stddev_initial + i * kernel_stddev_step # make the laplacian matrix laplacian_matrix = make_laplacian(D, kernel_stddev) # get the eigenvectors eigenvectors = get_eigenvectors(laplacian_matrix) # possibly flip the signs of the eigenvectors if i: vx, vy = eigenvectors last_vx, last_vy = frame_eigenvectors[i - 1] # possibly flip the x vector match_count = sum(1 for a, b in zip(vx, last_vx) if a * b >= 0) if match_count < len(points) / 2: print 'flipping x' vx = [-value for value in vx] # possibly flip the y vector match_count = sum(1 for a, b in zip(vy, last_vy) if a * b >= 0) if match_count < len(points) / 2: print 'flipping y' vy = [-value for value in vy] eigenvectors = (vx, vy) frame_eigenvectors.append(eigenvectors) # get all the eigenvector elements in each direction x_eigenvector_elements = [] y_eigenvector_elements = [] for x_eigenvector, y_eigenvector in frame_eigenvectors: x_eigenvector_elements.extend(x_eigenvector) y_eigenvector_elements.extend(y_eigenvector) # get the max and min of the eigenvectors in each direction xmin, xmax = min(x_eigenvector_elements), max(x_eigenvector_elements) ymin, ymax = min(y_eigenvector_elements), max(y_eigenvector_elements) # write the files for i, (vx, vy) in enumerate(frame_eigenvectors): print 'writing frame', i # get the image image_format = 'png' image_size = (800, 600) draw_axes = True image_string = get_image_helper(xmin, ymin, xmax, ymax, vx, vy, image_size, image_format) # get the filename filename = 'frame-%04d.png' % i # write the image with open(filename, 'wb') as fout: fout.write(image_string)