|
8 | 8 |
|
9 | 9 | import numpy as np |
10 | 10 | import scipy as sp |
| 11 | +from scipy.stats import ortho_group, multivariate_normal |
11 | 12 | from .utils import check_random_state, deprecated |
12 | 13 |
|
13 | 14 |
|
@@ -180,3 +181,97 @@ def make_data_classif(dataset, n, nz=0.5, theta=0, p=0.5, random_state=None, **k |
180 | 181 | def get_data_classif(dataset, n, nz=0.5, theta=0, random_state=None, **kwargs): |
181 | 182 | """Deprecated see make_data_classif""" |
182 | 183 | return make_data_classif(dataset, n, nz=0.5, theta=0, random_state=None, **kwargs) |
| 184 | + |
| 185 | + |
| 186 | +def make_gauss_hd( |
| 187 | + ns, nt, p=100, dim=5, m_diff=3.0, a=(10.0, 15.0), b=(3.0, 3.0), sub_the_same=False |
| 188 | +): |
| 189 | + """Generation of source and target domains from Gaussian HD distributions |
| 190 | +
|
| 191 | + Parameters |
| 192 | + ---------- |
| 193 | + ns : int |
| 194 | + number of samples (source) |
| 195 | + nt : int |
| 196 | + number of samples (target) |
| 197 | + p : int |
| 198 | + dimension of the ambient space the data live in |
| 199 | + dim : (int,int) or int |
| 200 | + the intrinsic dimensions of the source and target Gaussian HD distriutions. If a single int the intrinsic dimension is assumed to be the same |
| 201 | + m_diff : float |
| 202 | + the shift in the first coordinate of the means of the Gaussian HD distributions, i.e. ms_0 and mt_0, respectively (see code) |
| 203 | + a : (float, float) |
| 204 | + positive floating numbers corresponding to the isotropic variances in the principal subspace, for the source and target distributions, respectively. The same as \delta in :ref:`[1] <references-make_gauss-hd>`, Proposition 2.2 |
| 205 | + b : (float, float) |
| 206 | + positive floating numbers corresponding to the isotropic variance outside the principal subspace for the source and target distributions, respectively. |
| 207 | + sub_the_same : bool |
| 208 | + should the source/target Gaussian HD distributions live in the same principal subspace? |
| 209 | +
|
| 210 | + Returns |
| 211 | + ------- |
| 212 | + Xs : ndarray, shape (ns, p) |
| 213 | + `ns` observations of size `p` (source) |
| 214 | + Xt : ndarray, shape (nt, p) |
| 215 | + `nt` observations of size `p` (destination) |
| 216 | + pmts : list |
| 217 | + a list containing the parameters of the Gaussian HD distributions |
| 218 | +
|
| 219 | + .. _references-make_gauss_hd: |
| 220 | + References |
| 221 | + ---------- |
| 222 | +
|
| 223 | + .. [1] Bouveyron, C. & Corneli, M. ("Scaling Optimal Transport to High-Dimensional Gaussian Distributions") |
| 224 | +
|
| 225 | + """ |
| 226 | + d = (dim, dim) if isinstance(dim, int) else dim |
| 227 | + mu = np.zeros((2, p)) |
| 228 | + S = [] |
| 229 | + mu[1, 0] = m_diff |
| 230 | + Q = [ortho_group.rvs(p) for _ in range(2)] |
| 231 | + |
| 232 | + if sub_the_same: |
| 233 | + Q[1] = Q[0] |
| 234 | + |
| 235 | + S.append( |
| 236 | + Q[0] |
| 237 | + @ np.diag(np.hstack((np.full(d[0], a[0]), np.full(p - d[0], b[0])))) |
| 238 | + @ Q[0].T |
| 239 | + ) |
| 240 | + S.append( |
| 241 | + Q[1] |
| 242 | + @ np.diag(np.hstack((np.full(d[1], a[1]), np.full(p - d[1], b[1])))) |
| 243 | + @ Q[1].T |
| 244 | + ) |
| 245 | + |
| 246 | + Xs = multivariate_normal.rvs(mean=mu[0], cov=S[0], size=ns) |
| 247 | + Xt = multivariate_normal.rvs(mean=mu[1], cov=S[1], size=ns) |
| 248 | + |
| 249 | + ms = mu[0] |
| 250 | + mt = mu[1] |
| 251 | + ds = d[0] |
| 252 | + dt = d[1] |
| 253 | + sigma2_s = np.array(b[0]) |
| 254 | + sigma2_t = np.array(b[1]) |
| 255 | + ls = np.repeat(a[0], ds) - sigma2_s |
| 256 | + lt = np.repeat(a[1], dt) - sigma2_t |
| 257 | + Us = Q[0][:, :ds] |
| 258 | + Ut = Q[1][:, :dt] |
| 259 | + ds = np.array([ds]) |
| 260 | + dt = np.array([dt]) |
| 261 | + |
| 262 | + prmts = { |
| 263 | + "ms": ms, |
| 264 | + "mt": mt, |
| 265 | + "sigma2_s": sigma2_s, |
| 266 | + "sigma2_t": sigma2_t, |
| 267 | + "ls": ls, |
| 268 | + "lt": lt, |
| 269 | + "Us": Us, |
| 270 | + "Ut": Ut, |
| 271 | + "ds": ds, |
| 272 | + "dt": dt, |
| 273 | + "Cs": S[0], |
| 274 | + "Ct": S[1], |
| 275 | + } |
| 276 | + |
| 277 | + return Xs, Xt, prmts |
0 commit comments