Exemplo n.º 1
0
    def __init__(self, N, d, test_size):
        self.N = N
        self.d = d
        self.n_d = int(N * (N - 1) / 2)

        self.test_size = test_size
        self.etm = Algorithm(N, d)

        self.lossFun = CoordsToDMLoss(
            N=N, lossFun=nn.L1Loss(reduction='mean'))

        self.test_data = dataSource.generate_rand_DM(
            self.N, self.test_size, isInt=True, sample_space=(1000, 1))
        self.test_data = utils.minmax_norm(self.test_data, dmin=0)[0]
Exemplo n.º 2
0
    import numpy
    from torch import nn
    from mds.cmds import classicalMDS
    from lossFunction import CoordsToDMLoss
    torch.set_default_tensor_type('torch.DoubleTensor')

    dist_func = lambda p1, p2: torch.sum(torch.abs((p2 - p1)))

    cus = custom_distance(10,
                          3,
                          1000,
                          isInt=True,
                          sample_space=(1000, 1),
                          dist_func=dist_func)

    lossFun = CoordsToDMLoss(N=10, d=2, lossFun=nn.L1Loss(reduction='mean'))

    coords, dms = cus

    dms = utils.minmax_norm(dms, dmin=0)[0] + 1e-8
    dms = dms.detach().requires_grad_(True)

    cmds_rs = []

    for d in dms:

        d1 = numpy.array(d.data)
        cmds_rs.append(torch.tensor(classicalMDS(d1, 2)))

    cmds_rs = torch.stack(cmds_rs)
    print("cmds_loss: \t", lossFun(cmds_rs, dms))
Exemplo n.º 3
0
import model.RNN as rnn

from shutil import copyfile
import os

# %%
data = dataSource.load_data(shape=(ss, N, d))[0]
data = utils.minmax_norm(data, dmin=0)[0]

dlr = DataLoader(data, batch_size=batch, shuffle=True)

init_lr = 1e-3

train_id = '_'.join(['Coord', 'Linear', 'M', 'MSE'])

coordLoss = CoordsToDMLoss(N, lossFun=nn.MSELoss(reduction='mean'))
reconLoss = ReconLoss(lossFun=nn.MSELoss(reduction='mean'))
mseLoss = CustomLoss(lossFun=nn.MSELoss(reduction='mean'))

lossFun = MultiLoss(lossFunList=[coordLoss])

preprocess = PrepMatrix(N)

in_dim = preprocess.get_inShape()
out_dim = 2


def get_model(nNeuron, nLayer, in_dim, out_dim):

    nNeuron = nNeuron + in_dim
Exemplo n.º 4
0
import model.RNN as rnn

from shutil import copyfile
import os

# %%
data = dataSource.load_data(shape=(ss, N, d))[0]
data = utils.minmax_norm(data, dmin=0)[0]

dlr = DataLoader(data, batch_size=batch, shuffle=True)

init_lr = 1e-3

train_id = '_'.join(['Coord', 'Linear', 'M', 'SML'])

coordLoss = CoordsToDMLoss(N, lossFun=sammon_loss)
reconLoss = ReconLoss(lossFun=nn.MSELoss(reduction='mean'))
mseLoss = CustomLoss(lossFun=nn.MSELoss(reduction='mean'))

lossFun = MultiLoss(lossFunList=[coordLoss])

preprocess = PrepMatrix(N)

in_dim = preprocess.get_inShape()
out_dim = 2


def get_model(nNeuron, nLayer, in_dim, out_dim):

    nNeuron = nNeuron + in_dim
Exemplo n.º 5
0
import model.RNN as rnn

from shutil import copyfile
import os

# %%
data = dataSource.load_data(shape=(ss, N, d))[0]
data = utils.minmax_norm(data, dmin=0)[0]

dlr = DataLoader(data, batch_size=batch, shuffle=True)

init_lr = 1e-3

train_id = '_'.join(['Coord', 'Linear', 'M', 'RLL'])

coordLoss = CoordsToDMLoss(N, lossFun=lossF.relative_loss)
reconLoss = ReconLoss(lossFun=nn.MSELoss(reduction='mean'))
mseLoss = CustomLoss(lossFun=nn.MSELoss(reduction='mean'))

lossFun = MultiLoss(lossFunList=[coordLoss])

preprocess = PrepMatrix(N)

in_dim = preprocess.get_inShape()
out_dim = 2

def get_model(nNeuron, nLayer, in_dim, out_dim):

    nNeuron = nNeuron + in_dim
    
    mid1 = int((nNeuron + in_dim) / 2)