Esempio n. 1
0
File: dagan.py Progetto: sjjdd/fxgan
    def plot_feature_distr(self, bg, size=50):
        x, y = bg.dataset_x, bg.dataset_y
        real = bg.ramdom_kshot_images_dagan(self.k_shot,
                                            np.full(size, bg.classes[0]),
                                            False)

        fakes = self.generate(real, self.generate_latent([0] * size))

        fake_labels = [np.full((size, ), 'fake of 0')]

        for classid in bg.classes[1:5]:
            real = bg.ramdom_kshot_images_dagan(self.k_shot,
                                                np.full(size, classid))
            fake = self.generate(real, self.generate_latent([classid] * size),
                                 False)
            fakes = np.concatenate([fakes, fake])
            fake_labels.append(np.full((size, ), 'fake of {}'.format(classid)))

        # latent_encoder
        imgs = np.concatenate([x, fakes])
        labels = np.concatenate([
            np.full((x.shape[0], ), 'real'),
            np.full((fakes.shape[0], ), 'fake'),
        ])

        labels = np.concatenate([y, np.concatenate(fake_labels)])
        utils.scatter_plot(imgs, labels, self.latent_encoder, 'latent encoder')
Esempio n. 2
0
def main():
    """
    A sample main program to test our algorithms.

    @return: None
    """
    t0 = time.time()
    # initialize the random generator seed to always use the same set of points
    seed(0)
    # creates some points
    pts = create_points(30)

    show = True  # to display a frame
    save = False  # to save into .png files in "figs" directory
    scatter_plot(pts, [[]],
                 title="convex hull : initial set",
                 show=show,
                 save=save)
    print("Points:", pts)
    # compute the hull
    hull = Graham(pts, show=show, save=save)
    print("Hull:", hull)
    scatter_plot(pts, [hull],
                 title="convex hull : final result",
                 show=True,
                 save=save)
    t1 = time.time()
    print("temps en secondes :")
    print(t1 - t0)
Esempio n. 3
0
def main():
    """
    A sample main program to test our algorithms.

    @return: None
    """
    # initialize the random generator seed to always use the same set of points
    seed(0)
    # creates some points
    pts = create_points(6)
    show = True  # to display a frame
    save = False  # to save into .png files in "figs" directory
    scatter_plot(pts, [[]],
                 title="convex hull : initial set",
                 show=show,
                 save=save)
    print("Points:", pts)
    # compute the hull
    #hull = exhaustive(pts, show=show, save=save)
    hull = graham(pts, show=show, save=save)
    #hull = jarvis(pts, show=show, save=save)
    #hull = eddy_floyd(pts)
    print("Hull:", hull)
    scatter_plot(pts, [hull],
                 title="convex hull : final result",
                 show=True,
                 save=save)
Esempio n. 4
0
    def train_del_outliers(self,
                           column1_set,
                           column2,
                           x_lim_set,
                           y_lim,
                           plot=False):
        for column1 in column1_set:
            for x_lim in x_lim_set:
                self.train.drop(
                    self.train[(self.train[column1] > x_lim)
                               & (self.train[column2] < y_lim)].index,
                    inplace=True)

        if plot:
            scatter_plot(train, [column1], [column2])

        return self.train
Esempio n. 5
0
def exhaustive(points, show=True, save=False, detailed=False):
    """
    Returns the vertices comprising the boundaries of convex hull containing all points in the input set.
    The input 'points' is a list of [x,y] coordinates.
    Uses a very naive method: iterates over the whole set of convex polygons from size 3 to n

    :param points: the points from which to find the convex hull
    :param show: if True, the progress in constructing the hull will be plotted on each iteration in a window
    :param save: if True, the progress in constructing the hull will be saved on each iteration in a .png file
    :param detailed: if True, even non convex explored polygons are plotted
    :return: the convex hull
    """
    i = 3
    while i <= len(points):
        # iterates over the whole set of subset of points
        for subset in permutations(points, i):
            if (show or save) and detailed:
                scatter_plot(points, [subset],
                             title="exhaustive search",
                             show=show,
                             save=save)
            # only consider convex subsets
            if is_convex(subset):
                if (show or save) and not detailed:
                    scatter_plot(points, [subset],
                                 title="exhaustive search",
                                 show=show,
                                 save=save)
                one_out = False
                j = 0
                # iterates until a point is found outside the polygon
                while not one_out and j < len(points):
                    point = points[j]
                    if point not in list(subset) and not point_in_polygon(
                            point, list(subset)):
                        one_out = True
                    j = j + 1
                if not one_out:
                    return subset
        i = i + 1
    return points
Esempio n. 6
0
def main():
    """
    A sample main program to test our algorithms.

    @return: None
    """
    to=time.time()
    # initialize the random generator seed to always use the same set of points
    seed(0)
    # creates some points
    pts = create_points(1800)
    show = True  # to display a frame
    save = False  # to save into .png files in "figs" directory
    scatter_plot(pts, [[]], title="convex hull : initial set", show=show, save=save)
    print("Points:", pts)
    # compute the hull
    #hull = exhaustive(pts, show=show, save=save)
    print("graham",graham(pts))
    hull=graham(pts)
    print("Hull:", hull)
    scatter_plot(pts, [hull], title="convex hull : final result", show=True, save=save)
    print("Temps d'éxecution: %s secondes" %(time.time()-to))
Esempio n. 7
0
        atm = None

    if VERBOSE:
        plt.imshow(wsi_mask)
        plt.savefig(WSI_MASK_PATH, dpi=180)

    ################################
    # Visualise and Quantify Spots #
    ################################

    cluster_preds = pd.read_csv(CLUSTER_PREDICTIONS_PATH, header=0, sep=',')
    cluster_preds = cluster_preds.rename(columns={'label': 'pred_colour'})
    #Scale Affine Transform Matrix to account for DOWNSCALE FACTOR
    scatter_plot(cluster_preds.spot_x,
                 cluster_preds.spot_y,
                 colors=cluster_preds.pred_colour,
                 alignment=atm,
                 image=WSI_SMALL_CONTOUR_PATH,
                 output=WSI_SMALL_CONTOUR_SPOT_PATH)
    # transform spot coords to pixel coords
    spot_x_scale = atm[0, 0] * DOWNSCALE_FACTOR
    spot_x_offset = atm[0, 2] * DOWNSCALE_FACTOR
    spot_y_scale = atm[1, 1] * DOWNSCALE_FACTOR
    spot_y_offset = atm[1, 2] * DOWNSCALE_FACTOR
    verboseprint(
        'x_scale: {0} | x_offset: {1} | y_scale: {2} | y_offset: {3}'.format(
            spot_x_scale, spot_x_offset, spot_y_scale, spot_y_offset))
    cluster_preds_scaled = cluster_preds.apply(
        transform_spot,
        args=(spot_x_offset, spot_y_offset, spot_x_scale, spot_y_scale),
        axis=1)
Esempio n. 8
0
                               axis=0,
                               copy=True)
        preprocessing += "scale_"

    if len(preprocessing) == 0:
        preprocessing == "no_preprocessing"
    else:
        preprocessing = preprocessing[0:-1]
    # combined model
    cluster = run_combine_model(cm_val, tfv_val, loss=LOSS)
    out_path = os.path.join(
        CLUSTER_PATH_MODEL, '{}-{}-{}-{}'.format("combined_model", "both_data",
                                                 LOSS, preprocessing))
    scatter_plot(x_points,
                 y_points,
                 colors=cluster,
                 alignment=atm,
                 image=IMG_PATH,
                 output=out_path)
    save_label(x_points, y_points, cluster, out_path)
    # single model for gene counts
    cluster, br_gene = run_single_model(cm_val, loss=LOSS)
    out_path = os.path.join(
        CLUSTER_PATH_MODEL, '{}-{}-{}-{}'.format("single_model", "gene_count",
                                                 LOSS, preprocessing))
    scatter_plot(x_points,
                 y_points,
                 colors=cluster,
                 alignment=atm,
                 image=IMG_PATH,
                 output=out_path)
    save_label(x_points, y_points, cluster, out_path)