mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-04-24 20:36:23 +02:00
Merge pull request #1082 from SheffieldML/1078-the-init-status-in-initialize_latent
1078 the init status in initialize latent
This commit is contained in:
commit
dd04700c0e
3 changed files with 43 additions and 13 deletions
5
.github/workflows/test-and-deploy.yml
vendored
5
.github/workflows/test-and-deploy.yml
vendored
|
|
@ -63,7 +63,7 @@ jobs:
|
|||
- name: Install build dependencies
|
||||
run: |
|
||||
pip install setuptools
|
||||
|
||||
|
||||
- name: Install lib
|
||||
run: |
|
||||
python setup.py develop
|
||||
|
|
@ -76,6 +76,7 @@ jobs:
|
|||
- name: pytest
|
||||
run: |
|
||||
pytest GPy/testing
|
||||
|
||||
test-macos:
|
||||
strategy:
|
||||
matrix:
|
||||
|
|
@ -126,7 +127,6 @@ jobs:
|
|||
|
||||
- name: Build lib
|
||||
run: |
|
||||
pip install setuptools
|
||||
pip install wheel
|
||||
python setup.py develop
|
||||
python setup.py bdist_wheel
|
||||
|
|
@ -159,7 +159,6 @@ jobs:
|
|||
|
||||
- name: Build lib
|
||||
run: |
|
||||
pip install setuptools
|
||||
pip install wheel
|
||||
python setup.py develop
|
||||
python setup.py bdist_wheel
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
# Changelog
|
||||
|
||||
## Unreleased
|
||||
* update string checks in initialization method for latent variable and put `empirical_samples` init-method on a deprecation path
|
||||
|
||||
* update dependencies to `numpy>=1.7.0,<2.0.0`
|
||||
|
||||
* update dependencies to `numpy>=1.7.0,<2.0.0`
|
||||
|
||||
|
|
|
|||
|
|
@ -1,31 +1,59 @@
|
|||
'''
|
||||
"""
|
||||
Created on 24 Feb 2014
|
||||
|
||||
@author: maxz
|
||||
'''
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import warnings
|
||||
from ..util.pca import PCA
|
||||
|
||||
|
||||
def initialize_latent(init, input_dim, Y):
|
||||
"""
|
||||
:param init: initialization method for the latent space, 'PCA' or 'random'
|
||||
"""
|
||||
Xr = np.asfortranarray(np.random.normal(0, 1, (Y.shape[0], input_dim)))
|
||||
if 'PCA' in init:
|
||||
if "PCA" == init:
|
||||
p = PCA(Y)
|
||||
PC = p.project(Y, min(input_dim, Y.shape[1]))
|
||||
Xr[:PC.shape[0], :PC.shape[1]] = PC
|
||||
var = .1*p.fracs[:input_dim]
|
||||
elif init in 'empirical_samples':
|
||||
Xr[: PC.shape[0], : PC.shape[1]] = PC
|
||||
var = 0.1 * p.fracs[:input_dim]
|
||||
elif init == "empirical_samples":
|
||||
# dealing with depcrecated initialization method
|
||||
# should be remove along the next major release
|
||||
warnings.warn(
|
||||
"Deprecated initialization method 'empirical_samples'. "
|
||||
"Use 'random' instead.",
|
||||
DeprecationWarning,
|
||||
)
|
||||
|
||||
from ..util.linalg import tdot
|
||||
from ..util import diag
|
||||
|
||||
YYT = tdot(Y)
|
||||
diag.add(YYT, 1e-6)
|
||||
EMP = np.asfortranarray(np.random.multivariate_normal(np.zeros(Y.shape[0]), YYT, min(input_dim, Y.shape[1])).T)
|
||||
Xr[:EMP.shape[0], :EMP.shape[1]] = EMP
|
||||
EMP = np.asfortranarray(
|
||||
np.random.multivariate_normal(
|
||||
np.zeros(Y.shape[0]), YYT, min(input_dim, Y.shape[1])
|
||||
).T
|
||||
)
|
||||
Xr[: EMP.shape[0], : EMP.shape[1]] = EMP
|
||||
var = np.random.uniform(0.5, 1.5, input_dim)
|
||||
else:
|
||||
elif init == "random":
|
||||
var = Xr.var(0)
|
||||
else:
|
||||
# dealing with depcrecated initialization method
|
||||
# should be remove along the next major release
|
||||
warnings.warn(
|
||||
f"{init} is not a valid initialization method."
|
||||
"Supoprt for anything else than 'PCA' or 'random' will be removed in the next major release.",
|
||||
DeprecationWarning,
|
||||
)
|
||||
var = Xr.var(0)
|
||||
|
||||
|
||||
Xr -= Xr.mean(0)
|
||||
Xr /= Xr.std(0)
|
||||
|
||||
return Xr, var/var.max()
|
||||
return Xr, var / var.max()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue