• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.format_data函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中neupy.utils.format_data函数的典型用法代码示例。如果您正苦于以下问题:Python format_data函数的具体用法?Python format_data怎么用?Python format_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了format_data函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: train

    def train(self, input_train, target_train, input_test=None,
              target_test=None, epochs=100, epsilon=None,
              summary_type='table'):

        is_test_data_partialy_missed = (
            (input_test is None and target_test is not None) or
            (input_test is not None and target_test is None)
        )

        if is_test_data_partialy_missed:
            raise ValueError("Input and target test samples missed. "
                             "They must be defined both or none of them.")

        input_train = format_data(input_train)
        target_train = format_data(target_train)

        if input_test is not None:
            input_test = format_data(input_test)

        if target_test is not None:
            target_test = format_data(target_test)

        return super(SupervisedLearning, self).train(
            input_train=input_train, target_train=target_train,
            input_test=input_test, target_test=target_test,
            epochs=epochs, epsilon=epsilon,
            summary_type=summary_type
        )
开发者ID:mayblue9,项目名称:neupy,代码行数:28,代码来源:learning.py


示例2: train

    def train(self, input_train, target_train, copy=True):
        """
        Trains network. PNN doesn't actually train, it just stores
        input data and use it for prediction.

        Parameters
        ----------
        input_train : array-like (n_samples, n_features)

        target_train : array-like (n_samples,)
            Target variable should be vector or matrix
            with one feature column.

        copy : bool
            If value equal to ``True`` than input matrices will
            be copied. Defaults to ``True``.

        Raises
        ------
        ValueError
            In case if something is wrong with input data.
        """
        input_train = format_data(input_train, copy=copy)
        target_train = format_data(target_train, copy=copy)

        n_target_features = target_train.shape[1]
        if n_target_features != 1:
            raise ValueError("Target value must be one dimensional array")

        LazyLearningMixin.train(self, input_train, target_train)
开发者ID:itdxer,项目名称:neupy,代码行数:30,代码来源:grnn.py


示例3: wrapper

    def wrapper(actual, expected, *args, **kwargs):
        actual = format_data(actual)
        expected = format_data(expected)

        output = function(actual, expected, *args, **kwargs)
        # use .item(0) to get a first array element and automaticaly
        # convert vector that contains one element to scalar
        return output.eval().item(0)
开发者ID:EdwardBetts,项目名称:neupy,代码行数:8,代码来源:estimators.py


示例4: train

    def train(self, input_train, target_train, copy=True):
        input_train = format_data(input_train, copy=copy)
        target_train = format_data(target_train, copy=copy)

        if target_train.shape[1] != 1:
            raise ValueError("Target value must be one dimentional array")

        LazyLearning.train(self, input_train, target_train)
开发者ID:EdwardBetts,项目名称:neupy,代码行数:8,代码来源:grnn.py


示例5: _preformat_inputs

def _preformat_inputs(actual, predicted):
    actual = format_data(actual)
    predicted = format_data(predicted)

    if actual.shape != predicted.shape:
        raise ValueError("Actual and predicted values have different shapes. "
                         "Actual shape {}, predicted shape {}"
                         "".format(actual.shape, predicted.shape))

    return actual, predicted
开发者ID:Neocher,项目名称:neupy,代码行数:10,代码来源:errors.py


示例6: predict

    def predict(self, input_data):
        """
        Make a prediction from the input data.

        Parameters
        ----------
        input_data : array-like (n_samples, n_features)

        Raises
        ------
        ValueError
            In case if something is wrong with input data.

        Returns
        -------
        array-like (n_samples,)
        """
        if self.input_train is None:
            raise NotTrained("Cannot make a prediction. Network " "hasn't been trained yet")

        input_data = format_data(input_data)

        input_data_size = input_data.shape[1]
        train_data_size = self.input_train.shape[1]

        if input_data_size != train_data_size:
            raise ValueError(
                "Input data must contain {0} features, got " "{1}".format(train_data_size, input_data_size)
            )

        ratios = pdf_between_data(self.input_train, input_data, self.std)
        return (dot(self.target_train.T, ratios) / ratios.sum(axis=0)).T
开发者ID:itdxer,项目名称:neupy,代码行数:32,代码来源:grnn.py


示例7: visible_to_hidden

    def visible_to_hidden(self, visible_input):
        """
        Populates data throught the network and returns output
        from the hidden layer.

        Parameters
        ----------
        visible_input : array-like (n_samples, n_visible_features)

        Returns
        -------
        array-like
        """
        is_input_feature1d = (self.n_visible == 1)
        visible_input = format_data(visible_input, is_input_feature1d)

        outputs = self.apply_batches(
            function=self.methods.visible_to_hidden,
            input_data=visible_input,

            description='Hidden from visible batches',
            show_progressbar=True,
            show_error_output=False,
        )

        return np.concatenate(outputs, axis=0)
开发者ID:itdxer,项目名称:neupy,代码行数:26,代码来源:rbm.py


示例8: predict

    def predict(self, input_data):
        row1d = is_row1d(self.input_layer)
        result = format_data(input_data, row1d=row1d)

        for layer in self.layers:
            result = layer.output(result)
        return result
开发者ID:sonia2599,项目名称:neupy,代码行数:7,代码来源:base.py


示例9: predict_raw

 def predict_raw(self, input_data):
     input_data = format_data(input_data)
     output = np.zeros((input_data.shape[0], self.n_outputs))
     for i, input_row in enumerate(input_data):
         output[i, :] = self.transform(input_row.reshape(1, -1),
                                       self.weight)
     return output
开发者ID:mayblue9,项目名称:neupy,代码行数:7,代码来源:sofm.py


示例10: train

    def train(self, input_data):
        self.discrete_validation(input_data)

        input_data = bin2sign(input_data)
        input_data = format_data(input_data, is_feature1d=False)

        n_rows, n_features = input_data.shape
        n_rows_after_update = self.n_memorized_samples + n_rows

        if self.check_limit:
            memory_limit = math.ceil(n_features / (2 * math.log(n_features)))

            if n_rows_after_update > memory_limit:
                raise ValueError("You can't memorize more than {0} "
                                 "samples".format(memory_limit))

        weight_shape = (n_features, n_features)

        if self.weight is None:
            self.weight = np.zeros(weight_shape, dtype=int)

        if self.weight.shape != weight_shape:
            n_features_expected = self.weight.shape[1]
            raise ValueError("Input data has invalid number of features. "
                             "Got {} features instead of {}."
                             "".format(n_features, n_features_expected))

        self.weight = input_data.T.dot(input_data)
        np.fill_diagonal(self.weight, np.zeros(len(self.weight)))
        self.n_memorized_samples = n_rows_after_update
开发者ID:itdxer,项目名称:neupy,代码行数:30,代码来源:discrete_hopfield_network.py


示例11: train

    def train(self, input_data, target_data, epochs=100):
        target_data = format_data(target_data, is_feature1d=True)

        output_size = target_data.shape[1]
        if output_size != 1:
            raise ValueError("Target data must contains only 1 column, got "
                             "{0}".format(output_size))

        input_size = input_data.shape[1]

        gating_network = self.gating_network
        gating_network_input_size = gating_network.input_layer.size

        if gating_network_input_size != input_size:
            raise ValueError(
                "Gating Network expected get {0} input features, got "
                "{1}".format(gating_network_input_size, input_size)
            )

        networks = self.networks

        for epoch in range(epochs):
            predictions = []
            for i, network in enumerate(networks):
                predictions.append(network.predict(input_data))
                network.train_epoch(input_data, target_data)

            predictions = np.concatenate(predictions, axis=1)
            gating_network.train_epoch(input_data, predictions)
开发者ID:itdxer,项目名称:neupy,代码行数:29,代码来源:mixture_of_experts.py


示例12: gibbs_sampling

    def gibbs_sampling(self, visible_input, n_iter=1):
        """
        Makes Gibbs sampling n times using visible input.

        Parameters
        ----------
        visible_input : 1d or 2d array
        n_iter : int
            Number of Gibbs sampling iterations. Defaults to ``1``.

        Returns
        -------
        array-like
            Output from the visible units after perfoming n
            Gibbs samples. Array will contain only binary
            units (0 and 1).
        """
        is_input_feature1d = (self.n_visible == 1)
        visible_input = format_data(visible_input, is_input_feature1d)

        gibbs_sampling = self.methods.gibbs_sampling

        input_ = visible_input
        for iteration in range(n_iter):
            input_ = gibbs_sampling(input_)

        return input_
开发者ID:itdxer,项目名称:neupy,代码行数:27,代码来源:rbm.py


示例13: prediction_error

    def prediction_error(self, input_data, target_data=None):
        """
        Compute the pseudo-likelihood of input samples.

        Parameters
        ----------
        input_data : array-like
            Values of the visible layer

        Returns
        -------
        float
            Value of the pseudo-likelihood.
        """
        is_input_feature1d = (self.n_visible == 1)
        input_data = format_data(input_data, is_input_feature1d)

        errors = self.apply_batches(
            function=self.methods.prediction_error,
            input_data=input_data,

            description='Validation batches',
            show_error_output=True,
        )
        return average_batch_errors(
            errors,
            n_samples=len(input_data),
            batch_size=self.batch_size,
        )
开发者ID:itdxer,项目名称:neupy,代码行数:29,代码来源:rbm.py


示例14: hidden_to_visible

    def hidden_to_visible(self, hidden_input):
        """
        Propagates output from the hidden layer backward
        to the visible.

        Parameters
        ----------
        hidden_input : array-like (n_samples, n_hidden_features)

        Returns
        -------
        array-like
        """
        is_input_feature1d = (self.n_hidden == 1)
        hidden_input = format_data(hidden_input, is_input_feature1d)

        outputs = self.apply_batches(
            function=self.methods.hidden_to_visible,
            input_data=hidden_input,

            description='Visible from hidden batches',
            show_progressbar=True,
            show_error_output=False,
        )

        return np.concatenate(outputs, axis=0)
开发者ID:itdxer,项目名称:neupy,代码行数:26,代码来源:rbm.py


示例15: train

    def train(self, input_data):
        self.discrete_validation(input_data)

        input_data = bin2sign(input_data)
        input_data = format_data(input_data, is_feature1d=False)

        nrows, n_features = input_data.shape
        nrows_after_update = self.n_remembered_data + nrows

        if self.check_limit:
            memory_limit = ceil(n_features / (2 * log(n_features)))

            if nrows_after_update > memory_limit:
                raise ValueError("You can't memorize more than {0} "
                                 "samples".format(memory_limit))

        weight_shape = (n_features, n_features)

        if self.weight is None:
            self.weight = zeros(weight_shape, dtype=int)

        if self.weight.shape != weight_shape:
            raise ValueError("Invalid input shapes. Number of input "
                             "features must be equal to {} and {} output "
                             "features".format(*weight_shape))

        self.weight = input_data.T.dot(input_data)
        fill_diagonal(self.weight, zeros(len(self.weight)))
        self.n_remembered_data = nrows_after_update
开发者ID:InSertCod3,项目名称:neupy,代码行数:29,代码来源:discrete_hopfield_network.py


示例16: train

 def train(self, input_train, epochs=100):
     input_train = format_data(input_train, is_feature1d=True)
     return super(BaseAssociative, self).train(
         input_train=input_train, target_train=None,
         input_test=None, target_test=None,
         epochs=epochs, epsilon=None,
         summary='table'
     )
开发者ID:itdxer,项目名称:neupy,代码行数:8,代码来源:base.py


示例17: energy

    def energy(self, input_data, output_data):
        self.discrete_validation(input_data)
        self.discrete_validation(output_data)

        input_data, output_data = bin2sign(input_data), bin2sign(output_data)
        input_data = format_data(input_data, row1d=True)
        output_data = format_data(output_data, row1d=True)
        nrows, n_features = input_data.shape

        if nrows == 1:
            return hopfield_energy(self.weight, input_data, output_data)

        output = zeros(nrows)
        for i, rows in enumerate(zip(input_data, output_data)):
            output[i] = hopfield_energy(self.weight, *rows)

        return output
开发者ID:Neocher,项目名称:neupy,代码行数:17,代码来源:bam.py


示例18: train

    def train(self, input_train, target_train, copy=True):
        """
        Trains network. PNN doesn't actually train, it just stores
        input data and use it for prediction.

        Parameters
        ----------
        input_train : array-like (n_samples, n_features)

        target_train : array-like (n_samples,)
            Target variable should be vector or matrix
            with one feature column.

        copy : bool
            If value equal to ``True`` than input matrices will
            be copied. Defaults to ``True``.

        Raises
        ------
        ValueError
            In case if something is wrong with input data.
        """
        input_train = format_data(input_train, copy=copy)
        target_train = format_data(target_train, copy=copy)

        LazyLearningMixin.train(self, input_train, target_train)

        n_target_features = target_train.shape[1]
        if n_target_features != 1:
            raise ValueError("Target value should be a vector or a "
                             "matrix with one column")

        classes = self.classes = np.unique(target_train)
        n_classes = classes.size
        n_samples = input_train.shape[0]

        row_comb_matrix = self.row_comb_matrix = np.zeros(
            (n_classes, n_samples)
        )
        class_ratios = self.class_ratios = np.zeros(n_classes)

        for i, class_name in enumerate(classes):
            class_val_positions = (target_train == i)
            row_comb_matrix[i, class_val_positions.ravel()] = 1
            class_ratios[i] = np.sum(class_val_positions)
开发者ID:itdxer,项目名称:neupy,代码行数:45,代码来源:pnn.py


示例19: test_format_data

    def test_format_data(self):
        # None input
        self.assertEqual(format_data(None), None)

        # Sparse data
        sparse_matrix = csr_matrix((3, 4), dtype=np.int8)
        formated_sparce_matrix = format_data(sparse_matrix)
        np.testing.assert_array_equal(formated_sparce_matrix, sparse_matrix)
        self.assertEqual(formated_sparce_matrix.dtype, sparse_matrix.dtype)

        # Vector input
        x = np.random.random(10)
        formated_x = format_data(x, is_feature1d=True)
        self.assertEqual(formated_x.shape, (10, 1))

        x = np.random.random(10)
        formated_x = format_data(x, is_feature1d=False)
        self.assertEqual(formated_x.shape, (1, 10))
开发者ID:itdxer,项目名称:neupy,代码行数:18,代码来源:test_utils.py


示例20: train

    def train(self, input_train, epsilon=1e-5):
        n_clusters = self.n_clusters
        input_train = format_data(input_train)

        if input_train.shape[0] <= n_clusters:
            raise ValueError("Count of clusters must be less than count of "
                             "input data.")

        self.centers = input_train[:n_clusters, :].copy()
        super(RBFKMeans, self).train(input_train, epsilon=epsilon)
开发者ID:sonia2599,项目名称:neupy,代码行数:10,代码来源:rbf_kmeans.py



注:本文中的neupy.utils.format_data函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python neuralnet.NeuralNet类代码示例发布时间:2022-05-27
下一篇:
Python utils.asfloat函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap