def l21RDAE(X, layers, lamda, folder, learning_rate = 0.15, inner = 100, outer = 10, batch_size = 133,inputsize = (28,28)):
    if not os.path.isdir(folder):
        os.makedirs(folder)
    os.chdir(folder)
    with tf.Graph().as_default():
        with tf.Session() as sess:
            rael21 = l21RDA.RobustL21Autoencoder(sess = sess, lambda_= lamda*X.shape[0], layers_sizes=layers)
            l21L, l21S = rael21.fit(X = X, sess = sess, inner_iteration = inner, iteration = outer, batch_size = batch_size, learning_rate = learning_rate,  verbose = True)
            l21R = rael21.getRecon(X = X, sess = sess)
            l21H = rael21.transform(X, sess)
            Image.fromarray(I.tile_raster_images(X=l21S,img_shape=inputsize, tile_shape=(10, 10),tile_spacing=(1, 1))).save(r"l21S.png")
            Image.fromarray(I.tile_raster_images(X=l21R,img_shape=inputsize, tile_shape=(10, 10),tile_spacing=(1, 1))).save(r"l21R.png")
            Image.fromarray(I.tile_raster_images(X=l21L,img_shape=inputsize, tile_shape=(10, 10),tile_spacing=(1, 1))).save(r"l21L.png")
            l21S.dump("l21S.npk")
    os.chdir("../")
def experiment_frame():
    X = np.load(r"./data/data.npk")

    inner = 50
    outer = 20

    lamda_list = np.arange(0.00035, 0.0015, 0.0001)

    layers = [784, 400, 200]  ## S trans
    folder = r"OutlierDetectionResult"
    if not os.path.isdir(folder):
        os.makedirs(folder)
    os.chdir(folder)

    image_X = Image.fromarray(
        I.tile_raster_images(X=X,
                             img_shape=(28, 28),
                             tile_shape=(10, 10),
                             tile_spacing=(1, 1)))
    image_X.save(r"X.png")
    for lam in lamda_list:
        folder = "lam" + str(lam)
        l21RDAE(X=X,
                layers=layers,
                lamda=lam,
                folder=folder,
                learning_rate=0.001,
                inner=inner,
                outer=outer,
                batch_size=133,
                re_init=True,
                inputsize=(28, 28))
    os.chdir("../")