<filename>src/criterion.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author： 11360
# datetime： 2021/5/25 17:50 

import torch.nn as nn
import torch


class MyLossFunction(nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, x, y):
        return torch.mean(-y * torch.log(x) + - (1 - y) * torch.log(1 - x))


class Criterion:
    def __init__(self, model):
        self.model = model

    def loss_func(self, data):
        # N x 1
        # print(len(data))
        output = self.model(data[:-1])
        error = torch.mean((output - data[-1]) ** 2)
        return error
<filename>src/criterion.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author： 11360
# datetime： 2021/5/25 17:50 

import torch.nn as nn
import torch


class MyLossFunction(nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, x, y):
        return torch.mean(-y * torch.log(x) + - (1 - y) * torch.log(1 - x))


class Criterion:
    def __init__(self, model):
        self.model = model

    def loss_func(self, data):
        # N x 1
        # print(len(data))
        output = self.model(data[:-1])
        error = torch.mean((output - data[-1]) ** 2)
        return error
#!/usr/bin/env python # -*- coding: utf-8 -*- # author： 11360 # datetime： 2021/5/25 17:50 # N x 1 # print(len(data))