예제 #1
0
파일: sgcn.py 프로젝트: youngwook06/SGCN
    def setup_layers(self):
        """
        Adding Base Layers, Deep Signed GraphSAGE layers.
        Assing Regression Parameters if the model is not a single layer model.
        """
        self.nodes = range(self.X.shape[0])
        self.neurons = self.args.layers
        self.layers = len(self.neurons)
        self.positive_base_aggregator = SignedSAGEConvolutionBase(self.X.shape[1]*2,
                                                                  self.neurons[0]).to(self.device)

        self.negative_base_aggregator = SignedSAGEConvolutionBase(self.X.shape[1]*2,
                                                                  self.neurons[0]).to(self.device)
        self.positive_aggregators = []
        self.negative_aggregators = []
        for i in range(1, self.layers):
            self.positive_aggregators.append(SignedSAGEConvolutionDeep(3*self.neurons[i-1],
                                                                       self.neurons[i]).to(self.device))

            self.negative_aggregators.append(SignedSAGEConvolutionDeep(3*self.neurons[i-1],
                                                                       self.neurons[i]).to(self.device))

        self.positive_aggregators = ListModule(*self.positive_aggregators)
        self.negative_aggregators = ListModule(*self.negative_aggregators)
        self.regression_weights = Parameter(torch.Tensor(4*self.neurons[-1], 3))
        init.xavier_normal_(self.regression_weights)
예제 #2
0
    def setup_layers(self):
        """
        Adding Base Layers, Deep Signed GraphSAGE layers.
        Assing Regression Parameters if the model is not a single layer model.
        """
        self.nodes = range(self.X.shape[0])
        self.neurons = self.args.layers

        self.layers = len(self.neurons)

        self.positive_base_aggregator = SignedSAGEConvolutionBase(
            (self.X.shape[1] * 2) * 1, self.neurons[0]).to(self.device)

        self.negative_base_aggregator = SignedSAGEConvolutionBase(
            (self.X.shape[1] * 2) * 1, self.neurons[0]).to(self.device)
        self.positive_aggregators = []
        self.negative_aggregators = []
        for i in range(
                1, self.layers
        ):  # different for deep and base - effects weight params
            self.positive_aggregators.append(
                SignedSAGEConvolutionDeep(
                    (
                        4 * self.neurons[i - 1]
                    ),  # 3 beacuse original, positive and negative and concatenated, decides the shape of weight matrix
                    self.neurons[i]).to(self.device))

            self.negative_aggregators.append(
                SignedSAGEConvolutionDeep((4 * self.neurons[i - 1]),
                                          self.neurons[i]).to(self.device))

        self.positive_aggregators = ListModule(*self.positive_aggregators)
        self.negative_aggregators = ListModule(*self.negative_aggregators)
        self.regression_weights = Parameter(
            torch.Tensor(4 * self.neurons[-1], self.neurons[-1]))
        self.fc_weights = Parameter(torch.Tensor(self.neurons[-1], 3))

        if (self.args.edge_features_incls):
            self.regression_weights = Parameter(
                torch.Tensor(
                    4 * (self.neurons[-1] + (edge_features_count - 2) * 4),
                    self.neurons[-1]))  # excluding users
            self.fc_weights = Parameter(torch.Tensor(self.neurons[-1], 3))

        init.xavier_normal_(self.regression_weights)
        init.xavier_normal_(self.fc_weights)
예제 #3
0
    def setup_layers(self):
        """
        Adding Base Layers, Deep Signed GraphSAGE layers and Regression Parameters if the model is not a single layer model.
        """
        self.nodes = range(self.X.shape[0])
        self.neurons = self.args.layers
        self.layers = len(self.neurons)
        self.positive_base_aggregator_out = SignedSAGEConvolutionBase(
            self.X.shape[1] * 2, self.neurons[0], ['out']).to(self.device)
        self.negative_base_aggregator_out = SignedSAGEConvolutionBase(
            self.X.shape[1] * 2, self.neurons[0], ['out']).to(self.device)
        self.positive_base_aggregator_in = SignedSAGEConvolutionBase(
            self.X.shape[1] * 2, self.neurons[0], ['in']).to(self.device)
        self.negative_base_aggregator_in = SignedSAGEConvolutionBase(
            self.X.shape[1] * 2, self.neurons[0], ['in']).to(self.device)

        self.outoutFriends_aggregator = SignedSAGEConvolutionDeep(
            4 * self.neurons[0], self.neurons[1],
            ['out', 'out']).to(self.device)
        self.outinFriends_aggregator = SignedSAGEConvolutionDeep(
            4 * self.neurons[0], self.neurons[1],
            ['out', 'in']).to(self.device)
        self.inoutFriends_aggregator = SignedSAGEConvolutionDeep(
            4 * self.neurons[0], self.neurons[1],
            ['in', 'out']).to(self.device)
        self.ininFriends_aggregator = SignedSAGEConvolutionDeep(
            4 * self.neurons[0], self.neurons[1], ['in', 'in']).to(self.device)
        self.outoutEnemies_aggregator = SignedSAGEConvolutionDeep(
            4 * self.neurons[0], self.neurons[1],
            ['out', 'out']).to(self.device)
        self.outinEnemies_aggregator = SignedSAGEConvolutionDeep(
            4 * self.neurons[0], self.neurons[1],
            ['out', 'in']).to(self.device)
        self.inoutEnemies_aggregator = SignedSAGEConvolutionDeep(
            4 * self.neurons[0], self.neurons[1],
            ['in', 'out']).to(self.device)
        self.ininEnemies_aggregator = SignedSAGEConvolutionDeep(
            4 * self.neurons[0], self.neurons[1], ['in', 'in']).to(self.device)

        self.regression_weights1 = Parameter(
            torch.Tensor(8 * self.neurons[-1], 64))
        self.regression_weights2 = Parameter(torch.Tensor(64, self.X.shape[1]))
        init.xavier_normal_(self.regression_weights1)
        init.xavier_normal_(self.regression_weights2)
예제 #4
0
    def setup_layers(self):
        """
        Adding Base Layers, Deep Signed GraphSAGE layers and Regression Parameters if the model is not a single layer model.
        """
        self.nodes = range(self.X.shape[0])
        self.neurons = self.args.layers
        self.layers = len(self.neurons)
        self.positive_base_aggregator_out = SignedSAGEConvolutionBase(
            self.X.shape[1] * 2, self.neurons[0], ['out']).to(self.device)
        self.negative_base_aggregator_out = SignedSAGEConvolutionBase(
            self.X.shape[1] * 2, self.neurons[0], ['out']).to(self.device)
        self.positive_base_aggregator_in = SignedSAGEConvolutionBase(
            self.X.shape[1] * 2, self.neurons[0], ['in']).to(self.device)
        self.negative_base_aggregator_in = SignedSAGEConvolutionBase(
            self.X.shape[1] * 2, self.neurons[0], ['in']).to(self.device)

        self.outoutFriends_aggregator = SignedSAGEConvolutionDeep(
            4 * self.neurons[0], self.neurons[1],
            ['out', 'out']).to(self.device)
        self.outinFriends_aggregator = SignedSAGEConvolutionDeep(
            4 * self.neurons[0], self.neurons[1],
            ['out', 'in']).to(self.device)
        self.inoutFriends_aggregator = SignedSAGEConvolutionDeep(
            4 * self.neurons[0], self.neurons[1],
            ['in', 'out']).to(self.device)
        self.ininFriends_aggregator = SignedSAGEConvolutionDeep(
            4 * self.neurons[0], self.neurons[1], ['in', 'in']).to(self.device)
        self.outoutEnemies_aggregator = SignedSAGEConvolutionDeep(
            4 * self.neurons[0], self.neurons[1],
            ['out', 'out']).to(self.device)
        self.outinEnemies_aggregator = SignedSAGEConvolutionDeep(
            4 * self.neurons[0], self.neurons[1],
            ['out', 'in']).to(self.device)
        self.inoutEnemies_aggregator = SignedSAGEConvolutionDeep(
            4 * self.neurons[0], self.neurons[1],
            ['in', 'out']).to(self.device)
        self.ininEnemies_aggregator = SignedSAGEConvolutionDeep(
            4 * self.neurons[0], self.neurons[1], ['in', 'in']).to(self.device)

        #        self.positive_aggregators_out = []
        #         self.negative_aggregators_out = []
        #         self.positive_aggregators_in = []
        #         self.negative_aggregators_in = []

        #         for i in range(1,self.layers):
        #             self.positive_aggregators_out.append(SignedSAGEConvolutionDeep(6*self.neurons[i-1], self.neurons[i], 'out').to(self.device))
        #             self.negative_aggregators_out.append(SignedSAGEConvolutionDeep(6*self.neurons[i-1], self.neurons[i], 'out').to(self.device))
        #             self.positive_aggregators_in.append(SignedSAGEConvolutionDeep(6*self.neurons[i-1], self.neurons[i], 'in').to(self.device))
        #             self.negative_aggregators_in.append(SignedSAGEConvolutionDeep(6*self.neurons[i-1], self.neurons[i], 'in').to(self.device))
        #         positive_out = SignedSAGEConvolutionDeep(6*self.neurons[0], self.neurons[0], 'out').to(self.device)
        #         negative_out = SignedSAGEConvolutionDeep(6*self.neurons[0], self.neurons[0], 'out').to(self.device)
        #         positive_in = SignedSAGEConvolutionDeep(6*self.neurons[0], self.neurons[0], 'in').to(self.device)
        #         negative_in= SignedSAGEConvolutionDeep(6*self.neurons[0], self.neurons[0], 'in').to(self.device)
        #         for i in range(1,self.layers):
        #             self.positive_aggregators_out.append(positive_out)
        #             self.negative_aggregators_out.append(negative_out)
        #             self.positive_aggregators_in.append(positive_in)
        #             self.negative_aggregators_in.append(negative_in)

        #         self.positive_aggregators_out = ListModule(*self.positive_aggregators_out)
        #         self.negative_aggregators_out = ListModule(*self.negative_aggregators_out)
        #         self.positive_aggregators_in = ListModule(*self.positive_aggregators_in)
        #         self.negative_aggregators_in = ListModule(*self.negative_aggregators_in)

        # self.regression_weights = Parameter(torch.Tensor(4*self.neurons[-1], 3))
        # self.regression_weights = Parameter(torch.Tensor(8*self.neurons[-1], 2))
        self.regression_weights = Parameter(
            torch.Tensor(8 * self.neurons[-1], 1))
        init.xavier_normal_(self.regression_weights)