Пример #1
0
                      nn.Sigmoid())
# out is five.
criterion = torch.nn.MSELoss()
optimizer = torch.optim.SGD(model.parameters(), lr=0.01)  # learning rate
# you always got something to say.
# can we reload it?
# can we use cuda?
# print(model,type(model))
# # you can check it, just for sure.
# always got doc.
# cast it to list then.
# does not support complex datatype.
# we will check it later.
# better print it here.
model = model.to(device)
x = x.to(device)
y = y.to(device)
t = time.time()
# get the params out!
for epoch in range(5000):
    y_pred = model(x)
    # print(y)
    # s=y_pred.tolist()
    # # print(s)
    # y_pred=ComplexTensor(s)
    # print("prediction", y_pred.size())
    # print("target",y.size())
    yz = y.tolist()
    # print("prediction",ComplexTensor(y_pred.tolist()))
    # print("target", y)
    loss = criterion(y_pred, torch.tensor(yz))  # here is the problem.
Пример #2
0
# # the model, is it changeable?
# # not working though.
# model = nn.Sequential(nn.Linear(n_in, n_h), nn.ReLU(),
#                       nn.Linear(n_h, n_out), nn.Sigmoid())
# criterion = torch.nn.MSELoss()
# optimizer = torch.optim.SGD(model.parameters(), lr=0.01)  # learning rate
# # you always got something to say.
# # can we reload it?
# # can we use cuda?
# # print(model,type(model))
# # # you can check it, just for sure.
# # always got doc.
# # does not support complex datatype.
# # we will check it later.
# model = model.to(device)
x = x.to(device)
y = y.to(device)
print(x)
print("#######################################################")
print(y)
# does not change.
# t = time.time()
# for epoch in range(50000):
#     y_pred = model(x)
#     print("prediction", y_pred)
#     loss = criterion(y_pred, y)
#     print("epoch", epoch, "loss", loss, type(loss))
#     optimizer.zero_grad()
#     loss.backward()
#     optimizer.step()
# print("total time", time.time()-t)