athena.feature_map.FeatureMap.tune_pr_matrix

FeatureMap.tune_pr_matrix(func, bounds, method=None, maxiter=50, save_file=False, fn_args=None)[source]

Tune the parameters of the spectral distribution. Three methods are available: log-grid-search (brute), annealing (dual_annealing) and Bayesian stochastic optimization (bso) from GpyOpt. The default object function to optimize is athena.utils.average_rrmse, which uses a cross-validation procedure from athena.utils, see Example and tutorial 06_kernel-based_AS.

Example

>>> from athena.kas import KernelActiveSubspaces
>>> from athena.feature_map import FeatureMap
>>> from athena.projection_factory import ProjectionFactory
>>> from athena.utils import CrossValidation, average_rrmse
>>> input_dim, output_dim, n_samples = 2, 1, 30
>>> n_features, n_params = 10, 1
>>> xx = np.ones((n_samples, input_dim))
>>> f = np.ones((n_samples, output_dim))
>>> df = np.ones((n_samples, output_dim, input_dim))
>>> fm = FeatureMap(distr='laplace',
                    bias=np.random.uniform(0, 2 * np.pi, n_features),
                    input_dim=input_dim,
                    n_features=n_features,
                    params=np.zeros(n_params),
                    sigma_f=f.var())
>>> kss = KernelActiveSubspaces(feature_map=fm, dim=1, n_features=n_features)
>>> csv = CrossValidation(inputs=xx,
                        outputs=f.reshape(-1, 1),
                        gradients=df.reshape(n_samples, output_dim, input_dim),
                        folds=3,
                        subspace=kss)
>>> best = fm.tune_pr_matrix(func=average_rrmse,
                            bounds=[slice(-2, 1, 0.2) for i in range(n_params)],
                            args=(csv, ),
                            method='bso',
                            maxiter=20,
                            save_file=False)
Parameters
  • func (callable) – the objective function to be minimized. Must be in the form f(x, *args), where x is the argument in the form of a 1-D array and args is a tuple of any additional fixed parameters needed to completely specify the function.

  • bounds (tuple) – each component of the bounds tuple must be a slice tuple of the form (low, high, step). It defines bounds for the objective function parameter in a logarithmic scale. Step will be ignored for ‘dual_annealing’ method.

  • args (tuple) – any additional fixed parameters needed to completely specify the objective function.

  • method (str) – method used to optimize the objective function. Possible values are ‘brute’, or ‘dual_annealing’. Default value is None, and the choice is made automatically wrt the dimension of self.params. If the dimension is less than 4 brute force is used, otherwise a traditional Generalized Simulated Annealing will be performed with no local search strategy applied.

  • maxiter (int) – the maximum number of global search iterations. Default value is 50.

  • save_file (bool) – True to save the optimal projection matrix

  • fn_args (dict) – dictionary of arguments passed to func.

Raises

ValueError

Returns

list that records the best score and the best projection matrix. The initial values are 0.8 and a n_features-by-input_dim numpy.ndarray of zeros.

Return type

list