Exemple #1
0
    #
    np.random.seed(0)

    # generate the data
    (Xp, Xu, yu) = gendata(100, 100, 0.2)

    # generate some lists
    theta_list = np.linspace(0, 1, 30)
    sigma_list = np.array([0.1, 0.5, 0.8, 1.0])
    lambda_list = np.array([0.001, 0.1, 1, 10])
    cr = 1
    kfolds = 4

    # calculate the class prior with cl1fast
    fl1_theta, fl1_info = cl1fast(Xp, Xu)


    # calculate the class prior
    theta, l1_c2info = l1_cpe_cv(Xp, Xu, cr=2)

    # plot the result
    pyplt.plot(fl1_info['theta_list'], fl1_info['score'], label='fastL1')
    pyplt.plot(l1_c2info['theta_list'], l1_c2info['score'], label='l1cr2')
    pyplt.xlabel(r'$\theta$')
    pyplt.ylabel(r'cl_1')
    pyplt.legend(loc='upper center')
    pyplt.axis([0, 1, 0, 2])
    pyplt.show()

    # plot the results
Exemple #2
0
    dataset = sys.argv[3]
    nunlab = int(sys.argv[4])
    npos = int(sys.argv[5])
    theta = float(sys.argv[6])

    # create the file name and check if simulation was already run (file exists)
    datafname = '../results/{dataset}/{dataset}-{method}-theta-{theta}-nu-{nu}-np-{np}-{seed}.mat'.format(dataset=dataset, \
                        method=method, theta=theta,np=npos, nu=nunlab, seed=seed )
    datafname = os.path.abspath(os.path.join(os.getcwd(), datafname))
    if os.path.isfile(datafname):
        print('Simulation already run for this seed: {0}'.format(datafname))
        exit()

    # set the simulation function
    if method=='cl1':
        simfun = lambda Xp, Xu: cl1fast(Xp, Xu)
    elif method=='l1c1':
        simfun = lambda Xp, Xu: l1_cpe_cv(Xp, Xu, cr=1)

    # load the dataset
    np.random.seed(seed)
    (Xp, Xu, yu) = simdata.loaddataset(datapath, dataset, npos, nunlab, theta)

    # time the execution
    start_time = time.time()

    # run simulation
    if method=='cl1':
        theta_est, info = cl1fast(Xp, Xu)
    elif method=='l1c1':
        theta_est, info = l1_cpe_cv(Xp, Xu,cr=1)