Пример #1
0
def synthesize_tensor(dims, datatype, using_ratio, noise):
    real_dim = 100
    means = [
        np.ones((real_dim, )) * 5,
        np.ones((real_dim, )) * 10,
        np.ones((real_dim, )) * 2
    ]
    covariances = [
        np.eye(real_dim) * 2,
        np.eye(real_dim) * 3,
        np.eye(real_dim) * 2
    ]

    if datatype == "binary":
        tensor = binary_tensor()
    elif datatype == "real":
        tensor = RV_tensor()
    elif datatype == "count":
        tensor = count_tensor()
    """
    """
    tensor.synthesize_data(dims, means, covariances, real_dim, \
                           train=0.8, sparsity=1, noise=noise, noise_ratio=using_ratio)
    # tensor.reduce_train_size(0.1)
    return tensor
Пример #2
0
def synthesize_matrix(dims, datatype, noise_ratio, noise_amount):
    real_dim = 100
    means = [np.ones((real_dim,)) * 5, np.ones((real_dim,)) * 2]
    covariances = [np.eye(real_dim) * 2, np.eye(real_dim) * 3]

    if datatype == "binary":
        tensor = binary_tensor()
    elif datatype == "real":
        tensor = RV_tensor()
    else:
        tensor = count_tensor()

    tensor.synthesize_data(dims, means, covariances, real_dim, \
                           train=0.8, sparsity=1, noise=noise_amount, noise_ratio=noise_ratio)
    return tensor
Пример #3
0
def test_learning_curve(datatype, model):
    assert (datatype in ["real", "binary", "count"])
    assert (model in ["deterministic", "simple", "robust"])
    mean_update = "S"
    cov_update = "N"
    tensor = None
    D = 20
    if datatype == "real":
        tensor = RV_tensor()
        mean0 = np.ones((D, )) * 5
        cov0 = np.eye(D)

    elif datatype == "binary":
        tensor = binary_tensor()
        mean0 = np.zeros((D, ))
        cov0 = np.eye(D)

    elif datatype == "count":
        tensor = count_tensor()

    factorizer = None
    fact_D = 20

    if model == "deterministic":
        factorizer = SSVI_TF_d(real_tensor, rank=fact_D, \
                               mean_update=mean_update, cov_update=cov_update, \
                               k1=64, k2=64, \
                               mean0=mean0, cov0=cov0)
    elif model == "simple":
        factorizer = SSVI_TF_simple(data, rank=D, \
                                    mean_update=mean_update, cov_update=cov_update, \
                                    k1=64, k2=64, \
                                    mean0=mean0, cov0=cov0)

    elif model == "robust":
        factorizer = SSVI_TF_robust(data, rank=D, \
                                    mean_update=mean_update, cov_update=cov_update, \
                                    mean0=mean0, cov0=cov0, k1=128, k2=64, \
                                    eta=1, cov_eta=0.1)

    do_learning_curve(factorizer, tensor)
Пример #4
0
diag = args.diag
num_iters = args.num_iters
report = args.report
m_eta = args.mean_eta
c_eta = args.cov_eta
k1 = args.k1
k2 = args.k2
D = args.rank
output_folder = args.output

tensor = None

if datatype == "real":
    tensor = RV_tensor()
elif datatype == "binary":
    tensor = binary_tensor()
else:
    tensor = count_tensor()

# Read from file to initialize tensor
tensor.read_from_file(filename, 0.8, 0, 0.2)

# Initialize the parameters for the algorithm
default_params = {"mean_update": "S", "cov_update": "N", "rank": D}
factorizer_param = {"eta": 1, "cov_eta": 0.001}

params = {**default_params, **factorizer_param, "tensor": tensor}
params["cov_eta"] = args.cov_eta
params["eta"] = args.mean_eta
params["k1"] = args.k1
params["k2"] = args.k2