diPLSlib.utils subpackage
diPLSlib.utils.misc module
Some helper functions for diPLSlib
- diPLSlib.utils.misc.calibrateAnalyticGaussianMechanism(epsilon, delta, GS, tol=1e-12)[source]
Calibrate a Gaussian perturbation for differential privacy using the analytic Gaussian mechanism of [Balle and Wang, ICML’18]
- Parameters:
- epsilonfloat
Privacy parameter epsilon
- deltafloat
Desired privacy failure probability
- GSfloat
Upper bound on the L2-sensitivity of the function to which the mechanism is applied
- tolfloat
Error tolerance for binary search
- Returns:
- sigmafloat
Standard deviation of Gaussian noise needed to achieve (epsilon,delta)-DP under global sensitivity GS
References
Balle, B., & Wang, Y. X. (2018, July). Improving the gaussian mechanism for differential privacy: Analytical calibration and optimal denoising. In International Conference on Machine Learning (pp. 394-403). PMLR.
Examples
>>> from diPLSlib.utils.misc import calibrateAnalyticGaussianMechanism >>> calibrateAnalyticGaussianMechanism(1.0, 1e-5, 1.0) 3.730631634944469
- diPLSlib.utils.misc.gengaus(length, mu, sigma, mag, noise=0)[source]
Generate a Gaussian spectrum-like signal with optional random noise.
- Parameters:
- lengthint
Length of the generated signal.
- mufloat
Mean of the Gaussian function.
- sigmafloat
Standard deviation of the Gaussian function.
- magfloat
Magnitude of the Gaussian signal.
- noisefloat, optional (default=0)
Standard deviation of the Gaussian noise to be added to the signal.
- Returns:
- signalndarray of shape (length,)
The generated Gaussian signal with noise.
Examples
>>> from diPLSlib.utils.misc import gengaus >>> import numpy as np >>> import scipy.stats >>> signal = gengaus(100, 50, 10, 5, noise=0.1)
- diPLSlib.utils.misc.hellipse(X, alpha=0.05)[source]
Compute the 95% confidence interval ellipse for a 2D scatter plot.
- Parameters:
- Xndarray of shape (n_samples, 2)
Matrix of data points.
- alphafloat, optional (default=0.05)
Significance level for the confidence interval.
- Returns:
- elndarray of shape (2, 100)
Coordinates of the ellipse’s points. To plot, use plt.plot(el[0, :], el[1, :]).
Examples
>>> import matplotlib.pyplot as plt >>> import numpy as np >>> from diPLSlib.utils.misc import hellipse >>> X = np.random.random((100, 2)) >>> el = hellipse(X) >>> plt.scatter(X[:,0], X[:,1], label='Data points') <matplotlib.collections.PathCollection object at ...> >>> plt.plot(el[0,:], el[1,:], label='95% Confidence Ellipse') [<matplotlib.lines.Line2D object at ...>] >>> plt.legend() <matplotlib.legend.Legend object at ...>
- diPLSlib.utils.misc.rmse(y, yhat)[source]
Compute the Root Mean Squared Error (RMSE) between two arrays.
- Parameters:
- yndarray of shape (n_samples,)
True values.
- yhatndarray of shape (n_samples,)
Predicted values.
- Returns:
- errorndarray of shape (n_samples,)
The RMSE between y and yhat.
Examples
>>> import numpy as np >>> from diPLSlib.utils.misc import rmse >>> x = np.array([1, 2, 3]) >>> y = np.array([2, 3, 4]) >>> error = rmse(x, y) >>> print(error) 1.0