Beispiel #1
0
    def plots(self, global_step):
        """ Log plots """
        # Get first batch of source(s) and target data
        data_a = self.method.get_next_batch_multiple(
            [next(iter(x)) for x in self.method.source_test_eval_datasets],
            is_target=False)

        if not self.target_domain:
            data_b = None
        else:
            data_b = self.method.get_next_batch_single(next(
                iter(self.method.target_test_eval_dataset)),
                                                       is_target=True)

        # We'll only plot the real plots once since they don't change
        step = int(global_step)
        first_time = step == 1

        # Generate plots
        #
        # TODO probably broken with heterogeneous DA models since they have more
        # than one feature extractor, so this will error
        t = time.time()
        if type(self.method.model) is list:
            plots = generate_plots(data_a, data_b,
                                   self.method.model[0].feature_extractor,
                                   first_time)
        else:
            plots = generate_plots(data_a, data_b,
                                   self.method.model.feature_extractor,
                                   first_time)
        t = time.time() - t

        # Write all the values to the file
        with self.writer.as_default():
            for name, plot in plots:
                tf.summary.image(name, plot, step=step)

            tf.summary.scalar("step_time/plots", t, step=step)

        # Make sure we sync to disk
        self.writer.flush()
Beispiel #2
0
def simualte_over_coverage(start,
                           end,
                           step,
                           epochs,
                           fastq_files,
                           output_dir=OUTPUT_DIR):
    stats_per_cov = {}
    for cov in np.arange(start, end, step):
        print("testing for cov = {} ".format(cov))
        # create a directory for cov
        cov_dir = os.path.join(output_dir, "Cov_" + str(cov))
        os.mkdir(cov_dir)
        stats_list = []
        for i in range(epochs):
            print("EPHOCH: {} with cov {}".format(i + 1, cov))
            # make dir for experiment
            experiment_dir = os.path.join(cov_dir, "Exp_" + str(i + 1))
            os.mkdir(experiment_dir)

            stats = single_ineration_per_corr(fastq_files,
                                              cov,
                                              output_dir=experiment_dir)
            print("###################STATS##########################")
            print(stats)
            stats_list.append(stats)

        stats_per_cov[cov] = stats_list

    #save stats and plots
    plots.save_stats(stats_per_cov, output_dir)
    print("stats saved at {}".format(output_dir))
    plots.generate_plots(stats_per_cov, directory=output_dir)
    print("plots saved at {}".format(output_dir))

    print("FINISHED :)")
    return
Beispiel #3
0
def index():
    figures = generate_plots()
    ids = ['figure-{}'.format(i) for i, _ in enumerate(figures)]
    figuresJSON = json.dumps(figures, cls=plotly.utils.PlotlyJSONEncoder)
    return render_template('index.html', ids=ids, figuresJSON=figuresJSON)
def BTWsandpile(M = 3, N = 3, show_step = False,
                    time=10000, threshold=4, method='random', plot = False):
    """ Runs the simulation and returns the sandpile

        Args:
            M          (int): Pile width
            N          (int): Pile height
            show_step  (bool): If True, prints sandpile at each time step
            time       (int): How many time steps to run the simulation
            threshold  (int): Critical moment threshold
            method     (string): type of simulation 'center' or 'random'
            plot       (bool): If True, it will print all plots

        Returns:
            avalanche_mass     (list[int]): the mass at all time steps
            avalanche_size     (list[int]): list of avalanche sizes
            avalanche_lifetime (list[int]): list of avalanche lifetimes
            avalanche_area     (list[int]): list of avalanche areas
            avalanche_radius   (list[int]): list of avalanche radius
            sandpile           (M*N np.array): the last sandpile
    """

    avalanche_mass = []  # sand particles on the table at a point in time
    avalanche_size = []  # sand particles moved by the avalanche
    avalanche_lifetime = []  # timesteps it takes for an avalanche to relax the
                             #system to a critical state. '
    avalanche_radius = []
    avalanche_area = []

    # (1) -  initializes an M by N grid
    sandpile = np.zeros((M, N), dtype=int)
    

    # Initial call to print 0% progress
    printProgressBar(0, time-1, prefix = 'Progress:',
                        suffix = 'Complete', length = 50)

    # (2) -  loop through time steps
    for t in range(time-1):
        if method == 'random':
            # Choose random spot
            M_index = randrange(0, M)
            N_index = randrange(0, N)
        elif method == 'center':
            M_index = M//2
            N_index = N//2

        # Add sand grain
        sandpile[M_index, N_index] += 1

        # (3) - toppling
        radius   = np.zeros((M, N), dtype=int)
        radius[M_index, N_index] = 10
        size     = np.zeros((M, N), dtype=int)
        lifetime = np.zeros((M, N), dtype=int)
        area     = np.zeros((M, N), dtype=int)

        size, lifetime, area, radius = check_threshold(sandpile, M_index,
                                        N_index, threshold, s=size, l=lifetime,
                                        a=area, r=radius)

        # plotting each step
        if show_step:
            plot(sandpile)

        # calculating mass at time step
        avalanche_mass.append(sandpile.sum())
        avalanche_size.append(size)
        avalanche_lifetime.append(lifetime)
        avalanche_area.append(area)
        avalanche_radius.append(radius)

        # Update Progress Bar
        sleep(0.1)
        printProgressBar(t + 1, time-1, prefix = 'Progress:',
                         suffix = 'Complete', length = 50)

    print('Sandpile simulation done. ', time, ' time steps elapsed, ', M,
           '*', N, ' pile size.          ')

    # get a plot for the final sandpile, and plot the avalanche's features
    # plot3D(sandpile, max(M,N))
    if plot:
        generate_plots(sandpile, time, avalanche_mass, avalanche_size,
                        avalanche_lifetime, avalanche_area, avalanche_radius,
                        cutoff = 1000)

    return (avalanche_mass, avalanche_size, avalanche_lifetime, avalanche_area,
            avalanche_radius, sandpile)