sample.optimize module¶
Automatic optimization of SAMPLE hyperparameters
- class sample.optimize.SAMPLEOptimizer(model: ~sample.sample.SAMPLE = None, loss_fn: ~typing.Callable[[~numpy.ndarray, ~numpy.ndarray], float] = <function multiscale_spectral_loss>, loss_kw: ~typing.Optional[~typing.Dict[str, ~typing.Any]] = None, remap: ~typing.Optional[~typing.Callable[[...], ~typing.Dict[str, ~typing.Any]]] = <function sample_kwargs_remapper>, clip: bool = True, **kwargs)¶
Bases:
objectHyperparameter optimizer for a SAMPLE model, based on Gaussian Process minimization
- Parameters:
sample_fn (callable) – Constructor for a SAMPLE model
sample_kw (dict) – Keyword arguments for
sample_fn. These parameters will not be optimized. These parameters will potentially be remapped byremaploss_fn (callable) – Loss function. It should take, as two positional arguments, the arrays of original and resynthesised audio samples
loss_kw (dict) – Keyword arguments for the loss function
remap (callable) – Function that accepts keyword arguments and returns a new dictionary of keyword arguments for
sample_fn. Default issample_kwargs_remapper()clip (bool) – If
True(default), then clip resynthesised audio to the same peak of the original audio**kwargs – Parameters to optimize. See
skopt.gp_minimize()dimensions for definition options
- gp_minimize(x: ndarray, fs: float = 44100, state: Optional[OptimizeResult] = None, ignore_warnings: bool = True, fit_kws: Optional[Dict[str, Any]] = None, **kwargs) Tuple[SAMPLE, OptimizeResult]¶
Use
skopt.gp_minimize()to tune the hyperparameters- Parameters:
x (array) – Audio samples
fs (float) – Sample rate
ignore_warnings (bool) – If
True(default), then ignore warnings while optimizingfit_kws (dict) – Arguments for the
self.model.fit()method**kwargs – Keyword arguments for
skopt.gp_minimize()
- Returns:
Best model, and optimization summary
- Return type:
SAMPLE, OptimizeResult
- loss(x: ndarray, fs: float) Callable[[...], float]¶
Define a loss function for the target audio based on computing
loss_fnon the target and resynthesised audio- Parameters:
x (array) – Audio samples
fs (float) – Sample rate
- Returns:
Loss function
- Return type:
callable
- property model¶
Default fget function
- class sample.optimize.TqdmCallback(sample_opt: ~sample.optimize.SAMPLEOptimizer, n_calls: int, n_initial_points: int = 0, tqdm_fn: ~typing.Callable[[...], ~tqdm.std.tqdm] = <class 'tqdm.std.tqdm'>, minimum: bool = True)¶
Bases:
objectCallback for using tqdm with
SAMPLEOptimizer- Parameters:
sample_opt (SAMPLEOptimizer) – Optimizer instance
n_calls (int) – Number of total calls
n_initial_points (int) – Number of initial (random) points
tqdm_fn (callable) – Constructor for a tqdm object
minimum (bool) – If
True(default), show current minimum in postfix
- reset() TqdmCallback¶
Reset the state of the callback, e.g. for using it again
- start() TqdmCallback¶
Start the callback. Calls to this method initialize internal objects
- property started: bool¶
If
True, the callback has already been started
- sample.optimize.sample_kwargs_remapper(sinusoidal__log_n: Optional[int] = None, sinusoidal__wtype: str = 'hamming', sinusoidal__wsize: float = 1.0, sinusoidal__overlap: float = 0.5, **kwargs) Dict[str, Any]¶
Default argument remapper for
SAMPLEOptimizer. It remaps stft window paramaters and lets every other parameter pass through- Parameters:
sinusoidal__log_n (int) – Logarithm of fft size. Will be remapped to
sinusoidal__nif not inkwargssinusoidal__wtype (str) – Name of the window to use. Default is
"hamming". It is used to compute the windowsinusoidal__wif not inkwargssinusoidal__wsize (float) – Window size as a fraction of fft size. Default is
1.0. It is used to compute the windowsinusoidal__wif not inkwargssinusoidal__overlap (float) – Window overlap as a fraction of the window size. Default is
0.5. It is used to compute the hop sizesinusoidal__tracker__hif not inkwargs**kwargs – Pass-through keyword arguments
- Returns:
Remapped keyword arguments
- Return type:
dict