本文整理汇总了Python中menpo.model.PCAModel.mean方法的典型用法代码示例。如果您正苦于以下问题:Python PCAModel.mean方法的具体用法?Python PCAModel.mean怎么用?Python PCAModel.mean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类menpo.model.PCAModel
的用法示例。
在下文中一共展示了PCAModel.mean方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pca_increment_centred
# 需要导入模块: from menpo.model import PCAModel [as 别名]
# 或者: from menpo.model.PCAModel import mean [as 别名]
def test_pca_increment_centred():
pca_samples = [PointCloud(np.random.randn(10, 2)) for _ in range(10)]
ipca_model = PCAModel(pca_samples[:3])
ipca_model.increment(pca_samples[3:6])
ipca_model.increment(pca_samples[6:])
bpca_model = PCAModel(pca_samples)
assert_almost_equal(np.abs(ipca_model.components),
np.abs(bpca_model.components))
assert_almost_equal(ipca_model.eigenvalues, bpca_model.eigenvalues)
assert_almost_equal(ipca_model.mean().as_vector(),
bpca_model.mean().as_vector())
示例2: test_pca_init_from_covariance
# 需要导入模块: from menpo.model import PCAModel [as 别名]
# 或者: from menpo.model.PCAModel import mean [as 别名]
def test_pca_init_from_covariance():
n_samples = 30
n_features = 10
n_dims = 2
centre_values = [True, False]
for centre in centre_values:
# generate samples list and convert it to nd.array
samples = [PointCloud(np.random.randn(n_features, n_dims))
for _ in range(n_samples)]
data, template = as_matrix(samples, return_template=True)
# compute covariance matrix and mean
if centre:
mean_vector = np.mean(data, axis=0)
mean = template.from_vector(mean_vector)
X = data - mean_vector
C = np.dot(X.T, X) / (n_samples - 1)
else:
mean = samples[0]
C = np.dot(data.T, data) / (n_samples - 1)
# create the 2 pca models
pca1 = PCAModel.init_from_covariance_matrix(C, mean,
centred=centre,
n_samples=n_samples)
pca2 = PCAModel(samples, centre=centre)
# compare them
assert_array_almost_equal(pca1.component_vector(0, with_mean=False),
pca2.component_vector(0, with_mean=False))
assert_array_almost_equal(pca1.component(7).as_vector(),
pca2.component(7).as_vector())
assert_array_almost_equal(pca1.components, pca2.components)
assert_array_almost_equal(pca1.eigenvalues, pca2.eigenvalues)
assert_array_almost_equal(pca1.eigenvalues_cumulative_ratio(),
pca2.eigenvalues_cumulative_ratio())
assert_array_almost_equal(pca1.eigenvalues_ratio(),
pca2.eigenvalues_ratio())
weights = np.random.randn(pca1.n_active_components)
assert_array_almost_equal(pca1.instance(weights).as_vector(),
pca2.instance(weights).as_vector())
weights2 = np.random.randn(pca1.n_active_components - 4)
assert_array_almost_equal(pca1.instance_vector(weights2),
pca2.instance_vector(weights2))
assert_array_almost_equal(pca1.mean().as_vector(),
pca2.mean().as_vector())
assert_array_almost_equal(pca1.mean_vector,
pca2.mean_vector)
assert(pca1.n_active_components == pca2.n_active_components)
assert(pca1.n_components == pca2.n_components)
assert(pca1.n_features == pca2.n_features)
assert(pca1.n_samples == pca2.n_samples)
assert(pca1.noise_variance() == pca2.noise_variance())
assert(pca1.noise_variance_ratio() == pca2.noise_variance_ratio())
assert_almost_equal(pca1.variance(), pca2.variance())
assert_almost_equal(pca1.variance_ratio(), pca2.variance_ratio())
assert_array_almost_equal(pca1.whitened_components(),
pca2.whitened_components())
示例3: _build_appearance_model_full
# 需要导入模块: from menpo.model import PCAModel [as 别名]
# 或者: from menpo.model.PCAModel import mean [as 别名]
def _build_appearance_model_full(all_patches, n_appearance_parameters,
level_str, verbose):
# build appearance model
if verbose:
print_dynamic('{}Training appearance distribution'.format(level_str))
# apply pca
appearance_model = PCAModel(all_patches)
# trim components
if n_appearance_parameters is not None:
appearance_model.trim_components(n_appearance_parameters)
# get mean appearance vector
app_mean = appearance_model.mean().as_vector()
# compute covariance matrix
app_cov = appearance_model.components.T.dot(np.diag(1/appearance_model.eigenvalues)).dot(appearance_model.components)
return app_mean, app_cov