Ejemplo n.º 1
0
    def predict_neuron_output(self, input_data_x, layer_idx, neuron_idx):

        if layer_idx >= len(self.layers) or layer_idx < 0:
            raise ValueError('layer index is out of range')
        if neuron_idx >= len(self.layers[layer_idx]) or neuron_idx < 0:
            raise ValueError('neuron index is out of range')

        # check dimensions
        # check validity of the model
        input_data_x, data_len = predict_preprocessing(input_data_x,
                                                       self.n_features)

        if self.param.normalize:
            input_data_x = np.array(self.scaler.transform(input_data_x),
                                    copy=True)
        layer_data_x = None

        prev_layer = None
        # calculate outputs of all layers with indexes up to layer_idx
        for n in range(0, max(1, layer_idx - 1)):
            layer_data_x = self._set_internal_data(prev_layer, input_data_x,
                                                   layer_data_x)
            prev_layer = self.layers[n]

        # calculate output for the last layer
        # we choose the first (best) model of the last layer as output of multilayered gmdh
        output_y = np.zeros([data_len], dtype=np.double)
        model = self.layers[layer_idx][neuron_idx]
        for i in range(0, input_data_x.shape[0]):
            u1 = layer_data_x[i, model.u1_index]
            u2 = layer_data_x[i, model.u2_index]
            output_y[i] = model.transfer(u1, u2, model.w)

        return output_y
Ejemplo n.º 2
0
    def predict(self, input_data_x):
        """
        Predict using multilayered group method of data handling algorithm (model)

        Parameters
        ----------

        input_data_x : numpy array of shape [predicted_n_samples, n_features]
                       samples

        Returns
        -------
        numpy array of shape [predicted_n_samples]
        Returns predicted values.

        Example of using:
        from gmdh import MultilayerGMDH, CriterionType
        gmdh = MultilayerGMDH()
        gmdh.fit(data_x, data_y)
        predict_y = gmdh.predict(exam_x)

        where

        data_x - training data, numpy array of shape [n_samples, n_features]
        data_y - target values, numpy array of shape [n_samples]
        predict_x - samples to be predicted, numpy array of shape [predicted_n_samples, n_features]
        """

        # check dimensions
        # check validity of the model
        input_data_x, data_len = predict_preprocessing(input_data_x,
                                                       self.n_features)

        if self.param.normalize:
            input_data_x = np.array(self.scaler.transform(input_data_x),
                                    copy=True)
        layer_data_x = None

        prev_layer = None
        # calculate outputs of all layers except the last one
        for n in range(0, len(self.layers)):
            layer_data_x = self._set_internal_data(prev_layer, input_data_x,
                                                   layer_data_x)
            prev_layer = self.layers[n]

        # calculate output for the last layer
        # we choose the first (best) model of the last layer as output of multilayered gmdh
        output_y = np.zeros([data_len], dtype=np.double)
        model = self.layers[-1][0]
        for i in range(0, input_data_x.shape[0]):
            u1 = layer_data_x[i, model.u1_index]
            u2 = layer_data_x[i, model.u2_index]
            output_y[i] = model.transfer(u1, u2, model.w)

        return output_y
Ejemplo n.º 3
0
    def _predict(self, input_data_x):
        """Predict using self-organizing deep learning polynomial neural network

        :param input_data_x : numpy array of shape [predicted_n_samples, n_features]
                       samples

        :return numpy array of shape [predicted_n_samples]
        Returns predicted values.

        Example of using:
        from gmdh import Regressor, CriterionType
        model = Regressor()
        model.fit(data_x, data_y)
        predict_y = model.predict(test_x)

        where

        data_x - training data, numpy array of shape [n_samples, n_features]
        data_y - target values, numpy array of shape [n_samples]
        predict_x - samples to be predicted, numpy array of shape [predicted_n_samples, n_features]
        """

        if not self.valid:
            raise ValueError('Model is not fit')

        # check dimensions
        # check validity of the neuron
        input_data_x, data_len = predict_preprocessing(input_data_x,
                                                       self.n_features)

        if self.param.normalize:
            input_data_x = np.array(self.scaler.transform(input_data_x),
                                    copy=True)
        layer_data_x = None

        prev_layer = None
        # calculate outputs of all layers except the last one
        for n in range(0, len(self.layers)):
            layer_data_x = self._set_internal_data(prev_layer, input_data_x,
                                                   layer_data_x)
            prev_layer = self.layers[n]

        # calculate output for the last layer
        # we choose the first (best) neuron of the last layer as output of network
        neuron = self.layers[-1][0]
        u1 = layer_data_x[:, neuron.u1_index]
        u2 = layer_data_x[:, neuron.u2_index]
        output_y = neuron.transfer(u1, u2, neuron.w)

        return output_y
Ejemplo n.º 4
0
    def _predict(self, input_data_x):
        """Predict using self-organizing deep learning polynomial neural network

        :param input_data_x : numpy array of shape [predicted_n_samples, n_features]
                       samples

        :return numpy array of shape [predicted_n_samples]
        Returns predicted values.

        Example of using:
        from gmdh import Regressor, CriterionType
        model = Regressor()
        model.fit(data_x, data_y)
        predict_y = model.predict(test_x)

        where

        data_x - training data, numpy array of shape [n_samples, n_features]
        data_y - target values, numpy array of shape [n_samples]
        predict_x - samples to be predicted, numpy array of shape [predicted_n_samples, n_features]
        """

        if not self.valid:
            raise ValueError('Model is not fit')

        # check dimensions
        # check validity of the neuron
        input_data_x, data_len = predict_preprocessing(input_data_x, self.n_features)

        if self.param.normalize:
            input_data_x = np.array(self.scaler.transform(input_data_x), copy=True)
        layer_data_x = None

        prev_layer = None
        # calculate outputs of all layers except the last one
        for n in range(0, len(self.layers)):
            layer_data_x = self._set_internal_data(prev_layer, input_data_x, layer_data_x)
            prev_layer = self.layers[n]

        # calculate output for the last layer
        # we choose the first (best) neuron of the last layer as output of network
        neuron = self.layers[-1][0]
        u1 = layer_data_x[:, neuron.u1_index]
        u2 = layer_data_x[:, neuron.u2_index]
        output_y = neuron.transfer(u1, u2, neuron.w)

        return output_y
Ejemplo n.º 5
0
    def predict_neuron_output(self, input_data_x, layer_idx, neuron_idx):
        """Return output od specified neuron
        :param input_data_x:
        :param layer_idx: layer index
        :type layer_idx: int
        :param neuron_idx: neuron index within the layer
        :type neuron_idx: int
        :rtype: double
        """

        if layer_idx >= len(self.layers) or layer_idx < 0:
            raise ValueError('layer index is out of range')
        if neuron_idx >= len(self.layers[layer_idx]) or neuron_idx < 0:
            raise ValueError('neuron index is out of range')

        # check dimensions
        # check validity of the neuron
        input_data_x, data_len = predict_preprocessing(input_data_x,
                                                       self.n_features)

        if self.param.normalize:
            input_data_x = np.array(self.scaler.transform(input_data_x),
                                    copy=True)
        layer_data_x = None

        prev_layer = None
        # calculate outputs of all layers with indexes up to layer_idx
        for n in range(0, max(1, layer_idx - 1)):
            layer_data_x = self._set_internal_data(prev_layer, input_data_x,
                                                   layer_data_x)
            prev_layer = self.layers[n]

        # calculate output for the last layer
        # we choose the first (best) neuron of the last layer as output of network
        neuron = self.layers[layer_idx][neuron_idx]
        u1 = layer_data_x[:, neuron.u1_index]
        u2 = layer_data_x[:, neuron.u2_index]
        output_y = neuron.transfer(u1, u2, neuron.w)

        return output_y
Ejemplo n.º 6
0
    def predict_neuron_output(self, input_data_x, layer_idx, neuron_idx):
        """Return output od specified neuron
        :param input_data_x:
        :param layer_idx: layer index
        :type layer_idx: int
        :param neuron_idx: neuron index within the layer
        :type neuron_idx: int
        :rtype: double
        """

        if layer_idx >= len(self.layers) or layer_idx < 0:
            raise ValueError('layer index is out of range')
        if neuron_idx >= len(self.layers[layer_idx]) or neuron_idx < 0:
            raise ValueError('neuron index is out of range')

        # check dimensions
        # check validity of the neuron
        input_data_x, data_len = predict_preprocessing(input_data_x, self.n_features)

        if self.param.normalize:
            input_data_x = np.array(self.scaler.transform(input_data_x), copy=True)
        layer_data_x = None

        prev_layer = None
        # calculate outputs of all layers with indexes up to layer_idx
        for n in range(0, max(1, layer_idx - 1)):
            layer_data_x = self._set_internal_data(prev_layer, input_data_x, layer_data_x)
            prev_layer = self.layers[n]

        # calculate output for the last layer
        # we choose the first (best) neuron of the last layer as output of network
        neuron = self.layers[layer_idx][neuron_idx]
        u1 = layer_data_x[:, neuron.u1_index]
        u2 = layer_data_x[:, neuron.u2_index]
        output_y = neuron.transfer(u1, u2, neuron.w)

        return output_y