Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1078 the init status in initialize latent #1082

Merged
merged 18 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/test-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
- name: Install build dependencies
run: |
pip install setuptools

- name: Install lib
run: |
python setup.py develop
Expand All @@ -76,6 +76,7 @@ jobs:
- name: pytest
run: |
pytest GPy/testing

test-macos:
strategy:
matrix:
Expand Down Expand Up @@ -126,7 +127,6 @@ jobs:

- name: Build lib
run: |
pip install setuptools
pip install wheel
python setup.py develop
python setup.py bdist_wheel
Expand Down Expand Up @@ -159,7 +159,6 @@ jobs:

- name: Build lib
run: |
pip install setuptools
pip install wheel
python setup.py develop
python setup.py bdist_wheel
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`

Expand Down
46 changes: 37 additions & 9 deletions GPy/util/initialization.py
Original file line number Diff line number Diff line change
@@ -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)
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