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

Python samples_generator.make_spd_matrix函数代码示例

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

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



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

示例1: setUp

 def setUp(self):
     self.prng = prng = np.random.RandomState(10)
     self.n_components = n_components = 3
     self.n_features = n_features = 3
     self.startprob = prng.rand(n_components)
     self.startprob = self.startprob / self.startprob.sum()
     self.transmat = prng.rand(n_components, n_components)
     self.transmat /= np.tile(self.transmat.sum(axis=1)[:, np.newaxis],
             (1, n_components))
     self.means = prng.randint(-20, 20, (n_components, n_features))
     self.covars = {
         'spherical': (1.0 + 2 * np.dot(prng.rand(n_components, 1),
                                        np.ones((1, n_features)))) ** 2,
         'tied': (make_spd_matrix(n_features, random_state=0)
                  + np.eye(n_features)),
         'diag': (1.0 + 2 * prng.rand(n_components, n_features)) ** 2,
         'full': np.array([make_spd_matrix(n_features, random_state=0)
                           + np.eye(n_features)
                           for x in range(n_components)]),
     }
     self.expanded_covars = {
         'spherical': [np.eye(n_features) * cov
                       for cov in self.covars['spherical']],
         'diag': [np.diag(cov) for cov in self.covars['diag']],
         'tied': [self.covars['tied']] * n_components,
         'full': self.covars['full'],
     }
开发者ID:WeatherGod,项目名称:scikit-learn,代码行数:27,代码来源:test_hmm.py


示例2: __init__

    def __init__(self, rng, n_samples=500, n_components=2, n_features=2,
                 scale=50):
        self.n_samples = n_samples
        self.n_components = n_components
        self.n_features = n_features

        self.weights = rng.rand(n_components)
        self.weights = self.weights / self.weights.sum()
        self.means = rng.rand(n_components, n_features) * scale
        self.covariances = {
            'spherical': .5 + rng.rand(n_components),
            'diag': (.5 + rng.rand(n_components, n_features)) ** 2,
            'tied': make_spd_matrix(n_features, random_state=rng),
            'full': np.array([
                make_spd_matrix(n_features, random_state=rng) * .5
                for _ in range(n_components)])}
        self.precisions = {
            'spherical': 1. / self.covariances['spherical'],
            'diag': 1. / self.covariances['diag'],
            'tied': linalg.inv(self.covariances['tied']),
            'full': np.array([linalg.inv(covariance)
                             for covariance in self.covariances['full']])}

        self.X = dict(zip(COVARIANCE_TYPE, [generate_data(
            n_samples, n_features, self.weights, self.means, self.covariances,
            covar_type) for covar_type in COVARIANCE_TYPE]))
        self.Y = np.hstack([np.full(int(np.round(w * n_samples)), k,
                                    dtype=np.int)
                            for k, w in enumerate(self.weights)])
开发者ID:jerry-dumblauskas,项目名称:scikit-learn,代码行数:29,代码来源:test_gaussian_mixture.py


示例3: make_covar_matrix

def make_covar_matrix(covariance_type, n_components, n_features):
    mincv = 0.1
    rand = np.random.random
    return {
        'spherical': (mincv + mincv * np.dot(rand((n_components, 1)),
                                             np.ones((1, n_features)))) ** 2,
        'tied': (make_spd_matrix(n_features)
                 + mincv * np.eye(n_features)),
        'diag': (mincv + mincv * rand((n_components, n_features))) ** 2,
        'full': np.array([(make_spd_matrix(n_features)
                           + mincv * np.eye(n_features))
                          for x in range(n_components)])
    }[covariance_type]
开发者ID:imanojkumar,项目名称:hmmlearn,代码行数:13,代码来源:__init__.py


示例4: make_covar_matrix

def make_covar_matrix(covariance_type, n_components, n_features):
    mincv = 0.1
    rand = np.random.random
    if covariance_type == 'spherical':
        return (mincv + mincv * rand((n_components,))) ** 2
    elif covariance_type == 'tied':
        return (make_spd_matrix(n_features)
                + mincv * np.eye(n_features))
    elif covariance_type == 'diag':
        return (mincv + mincv * rand((n_components, n_features))) ** 2
    elif covariance_type == 'full':
        return np.array([(make_spd_matrix(n_features)
                        + mincv * np.eye(n_features))
                        for x in range(n_components)])
开发者ID:tsnubbs2000,项目名称:hmmlearn,代码行数:14,代码来源:__init__.py


示例5: create_random_gmm

def create_random_gmm(n_mix, n_features, covariance_type, prng=0):
    prng = check_random_state(prng)
    g = mixture.GMM(n_mix, covariance_type=covariance_type)
    g.means_ = prng.randint(-20, 20, (n_mix, n_features))
    mincv = 0.1
    g.covars_ = {
        "spherical": (mincv + mincv * np.dot(prng.rand(n_mix, 1), np.ones((1, n_features)))) ** 2,
        "tied": (make_spd_matrix(n_features, random_state=prng) + mincv * np.eye(n_features)),
        "diag": (mincv + mincv * prng.rand(n_mix, n_features)) ** 2,
        "full": np.array(
            [make_spd_matrix(n_features, random_state=prng) + mincv * np.eye(n_features) for x in range(n_mix)]
        ),
    }[covariance_type]
    g.weights_ = hmm.normalize(prng.rand(n_mix))
    return g
开发者ID:vd4mmind,项目名称:scikit-learn,代码行数:15,代码来源:test_hmm.py


示例6: _setUp

 def _setUp(self):
     self.n_components = 10
     self.n_features = 4
     self.weights = rng.rand(self.n_components)
     self.weights = self.weights / self.weights.sum()
     self.means = rng.randint(-20, 20, (self.n_components, self.n_features))
     self.threshold = -0.5
     self.I = np.eye(self.n_features)
     self.covars = {
         "spherical": (0.1 + 2 * rng.rand(self.n_components, self.n_features)) ** 2,
         "tied": (make_spd_matrix(self.n_features, random_state=0) + 5 * self.I),
         "diag": (0.1 + 2 * rng.rand(self.n_components, self.n_features)) ** 2,
         "full": np.array(
             [make_spd_matrix(self.n_features, random_state=0) + 5 * self.I for x in range(self.n_components)]
         ),
     }
开发者ID:agamemnonc,项目名称:scikit-learn,代码行数:16,代码来源:test_gmm.py


示例7: create_random_gmm

def create_random_gmm(n_mix, n_features, cvtype, prng=prng):
    from sklearn import mixture

    g = mixture.GMM(n_mix, cvtype=cvtype)
    g.means = prng.randint(-20, 20, (n_mix, n_features))
    mincv = 0.1
    g.covars = {
        'spherical': (mincv + mincv * prng.rand(n_mix)) ** 2,
        'tied': (make_spd_matrix(n_features, random_state=prng)
                 + mincv * np.eye(n_features)),
        'diag': (mincv + mincv * prng.rand(n_mix, n_features)) ** 2,
        'full': np.array(
            [make_spd_matrix(n_features, random_state=prng)
             + mincv * np.eye(n_features) for x in xrange(n_mix)])
    }[cvtype]
    g.weights = hmm.normalize(prng.rand(n_mix))
    return g
开发者ID:Scott-Alex,项目名称:scikit-learn,代码行数:17,代码来源:test_hmm.py


示例8: _setUp

 def _setUp(self):
     self.n_components = 10
     self.n_features = 4
     self.weights = rng.rand(self.n_components)
     self.weights = self.weights / self.weights.sum()
     self.means = rng.randint(-20, 20, (self.n_components, self.n_features))
     self.threshold = -0.5
     self.I = np.eye(self.n_features)
     self.covars = {'spherical': (0.1 + 2 * \
                     rng.rand(self.n_components, self.n_features)) ** 2,
               'tied': make_spd_matrix(self.n_features, random_state=0) +\
                     5 * self.I,
               'diag': (0.1 + 2 * rng.rand(self.n_components,\
                     self.n_features)) ** 2,
               'full': np.array([make_spd_matrix(self.n_features,\
                     random_state=0)
                   + 5 * self.I for x in range(self.n_components)])}
开发者ID:Honglang,项目名称:scikit-learn,代码行数:17,代码来源:test_gmm.py


示例9: make_covar_matrix

def make_covar_matrix(covariance_type, n_components, n_features,
                      random_state=None):
    mincv = 0.1
    prng = check_random_state(random_state)
    if covariance_type == 'spherical':
        return (mincv + mincv * prng.random_sample((n_components,))) ** 2
    elif covariance_type == 'tied':
        return (make_spd_matrix(n_features)
                + mincv * np.eye(n_features))
    elif covariance_type == 'diag':
        return (mincv + mincv *
                prng.random_sample((n_components, n_features))) ** 2
    elif covariance_type == 'full':
        return np.array([
            (make_spd_matrix(n_features, random_state=prng)
             + mincv * np.eye(n_features))
            for x in range(n_components)
        ])
开发者ID:anntzer,项目名称:hmmlearn,代码行数:18,代码来源:__init__.py


示例10: calculate_covariance

def calculate_covariance(states, feature_list, n_features):
    # due to shortage of data we can't calculate the covariance matrix, that's why we return random

    np.set_printoptions(threshold='nan')
    random = np.array([make_spd_matrix(n_features, random_state=0) + np.eye(n_features) for x in range(len(states))])
    # covariance = list()
    # for i in range(0, len(states), 1):
    #     state = states[i]
    #     f_list_da = feature_list[state]
    #     # feat_transpose = np.transpose(f_list_da)
    #     arr = np.cov(np.array(f_list_da), rowvar=0)
    #     # adjusted_cov = arr + 0.2*np.identity(arr.shape[0])
    #     if np.isnan(arr).all():
    #         arr = random[i]
    #     # arr_tr = np.transpose(arr)
    #     # new_arr = np.multiply(arr, arr_tr)
    #
    #     # arr[arr == 0.] = 0.00001
    #     # covariance.append(new_arr)

    #     # diagonal = arr.diagonal()
    #     # print (arr.transpose() == arr).all()
    #     a = 0
    #     while not is_pos_def(arr):
    #         arr += 0.2
    #         a += 1
    #         if a == 10:
    #             arr = random[i]
    #     if not (arr.transpose() == arr).all():
    #         arr = make_summetric(arr)

    #     # np.linalg.cholesky(arr)
    #     covariance.append(arr)
    #     # t = np.linalg.cholesky(adjusted_cov)
    # covariance = np.array(covariance)

    #
    # np.linalg.cholesky(covariance)
    # # covariance_tr = np.transpose(covariance)
    # # cov = np.multiply(covariance, covariance_tr)
    # return covariance

    return random
开发者ID:anukat2015,项目名称:Twitter_DA_Recognition,代码行数:43,代码来源:hmm_gaussian.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python decomposition.sklearnPCA函数代码示例发布时间:2022-05-27
下一篇:
Python samples_generator.make_regression函数代码示例发布时间: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