本文整理汇总了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'],
}
示例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)])
示例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]
示例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)])
示例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
示例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)]
),
}
示例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
示例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)])}
示例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)
])
示例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