示例#1
0
    def FadingModel(self, Time=1, Graphs=False, Results=False):
        """
		"""
        from scipy.stats import rice
        from scipy import integrate

        #CALCULATING THE RICE CONTINUOUS DISTIBUTION
        shape = 0.775
        #MeanPowerGain = (1/Time) * integrate(pow(rice.logcdf(t, shape), 2), (t, 0, Time))
        h = lambda x: pow(rice.logpdf(x, shape), 2)
        MeanPowerGain, err = integrate.quad(h, 0, Time)

        #PLOTING THE PROBABILITY DENSITY FUNCTION
        if Graphs is True:
            fig, ax = plt.subplots(1, 1)
            x = linspace(rice.ppf(0.01, shape), rice.ppf(0.99, shape), 100)
            ax.plot(x,
                    rice.pdf(x, shape),
                    'r-',
                    lw=5,
                    alpha=0.6,
                    label='Rice PDF')

            rv = rice(shape)
            ax.plot(x, rv.pdf(x), 'k-', lw=2, label='Frozen PDF')

            r = rice.rvs(shape, size=1000)
            ax.hist(r, normed=True, histtype='stepfilled', alpha=0.2)
            ax.legend(loc='best', frameon=False)

        #PRINTING RESULTS
        if Results is True:
            print("Fading - Mean Power Gain: {}".format(
                (1 / Time) * MeanPowerGain))
        return (1 / Time) * MeanPowerGain
    def _model_fit(self, x, b, off, sigma, scale):
        """Function defining the Gaussian model.

        Parameters
        ----------
        x : ndarray, shape (n_samples, )
            Array for which we have to compute the PDF.

        b : float
            Distance between the reference point and the center of the
            bivariate distribution.

        off : float
            Offset of the Rician model.

        sigma : float
            Standard deviation of the model.

        scale : float
            Scaling factor of the model.

        Returns
        -------
        pdf : ndarray, shape (n_samples)
            The associated PDF to x parametrize through b, off, sigma,
            and scale.

        """
        # The pdf with the Rice distribution should be in the interval 0-1

        return rice.pdf(x, b, off, sigma) * scale
示例#3
0
    def _update_canvas(self):
        """
        Update the figure when the user changes an input value.
        :return:
        """
        # Get the parameters from the form
        loc = float(self.loc.text())
        scale = float(self.scale.text())
        shape_factor = float(self.shape_factor.text())

        # Get the selected distribution from the form
        distribution_type = self.distribution_type.currentText()

        if distribution_type == 'Gaussian':
            x = linspace(norm.ppf(0.001, loc, scale),
                         norm.ppf(0.999, loc, scale), 200)
            y = norm.pdf(x, loc, scale)
        elif distribution_type == 'Weibull':
            x = linspace(weibull_min.ppf(0.001, shape_factor),
                         weibull_min.ppf(0.999, shape_factor), 200)
            y = weibull_min.pdf(x, shape_factor, loc, scale)
        elif distribution_type == 'Rayleigh':
            x = linspace(rayleigh.ppf(0.001, loc, scale),
                         rayleigh.ppf(0.999, loc, scale), 200)
            y = rayleigh.pdf(x, loc, scale)
        elif distribution_type == 'Rice':
            x = linspace(rice.ppf(0.001, shape_factor),
                         rice.ppf(0.999, shape_factor), 200)
            y = rice.pdf(x, shape_factor, loc, scale)
        elif distribution_type == 'Chi Squared':
            x = linspace(chi2.ppf(0.001, shape_factor),
                         chi2.ppf(0.999, shape_factor), 200)
            y = chi2.pdf(x, shape_factor, loc, scale)

        # Clear the axes for the updated plot
        self.axes1.clear()

        # Display the results
        self.axes1.plot(x, y, '')

        # Set the plot title and labels
        self.axes1.set_title('Probability Density Function', size=14)
        self.axes1.set_xlabel('x', size=12)
        self.axes1.set_ylabel('Probability p(x)', size=12)

        # Set the tick label size
        self.axes1.tick_params(labelsize=12)

        # Turn on the grid
        self.axes1.grid(linestyle=':', linewidth=0.5)

        # Update the canvas
        self.my_canvas.draw()
示例#4
0
 def single_likelihood(self, source_locations, l, z):
     d = compute_distance(source_locations.reshape(-1, 2), l.reshape(-1, 2))
     rss = self.rss_noiseless(d)
     fading = rss - z
     if np.all(fading < 0):
         # ALL source locations have neg. fading, ignore this measurement
         p = np.ones(fading.shape)
     else:
         p = rice.pdf(fading,
                      self.rice_b,
                      loc=self.rice_loc,
                      scale=self.sigma)
     return p
示例#5
0
def skewed_data(direction='left', amount='medium'):
    '''Generate data with a left or right skew.
  The amount can be:
  
  'low'    - A low amount of skew
  'medium' - A medium amount of skew
  'high'   - A high amount of skew
  '''
    x = np.linspace(0, 1, 1000)
    if amount == 'medium':
        y = rice.pdf((x + 0.05) * 5, 1.5) + 0.025
    else:
        raise ArugmentError("illegal amount: {}".format(amount))

    # Flip
    if direction == 'right':
        y = y[::-1]

    return x, y
示例#6
0
    def __parametrization__(self, x, norm_factor, v, loc, sigma):
        """Function to parametrise the Rician PDF
        
        Parameters
        ----------
        x : 1d-array
            Array containing the x values in order to compute the PDF
        norm_factor: double
            Amplitude of the Rician representation
        v: double
            Distance to center of the Rician representation
        loc: double
            Location of the Rician representation
        sigma: double
            Scale of the Rician representation
        Returns
        -------
        pdf: 1d-array 
            Return the Gaussian PDF according the parameters
    
        """

        return rice.pdf(x, v, loc, sigma) / norm_factor
示例#7
0
    def __Parametrization__(self, x, norm_factor, v, loc, sigma):
        """Function to parametrise the Rician PDF
        
        Parameters
        ----------
        x : 1d-array
            Array containing the x values in order to compute the PDF
        norm_factor: double
            Amplitude of the Rician representation
        v: double
            Distance to center of the Rician representation
        loc: double
            Location of the Rician representation
        sigma: double
            Scale of the Rician representation

        Returns
        -------
        pdf: 1d-array 
            Return the Gaussian PDF according the parameters
    
        """

        return rice.pdf(x, v, loc, sigma) / norm_factor
示例#8
0
                                                 ret, self.n_step)
        GLOBAL_LOGGER.get_tb_logger().add_scalar('N_CH_TX_OK_' + str(self.id),
                                                 n_successful_tx, self.n_step)
        self.change_position()

        return float(n_successful_tx)


if __name__ == '__main__':
    # err = tx_error_rate_for_n_bytes(32, 6, 1.0221785259170593, 0.000125, 180000.0)
    # print(err)

    for x in range(50):
        err = tx_error_rate_for_n_bytes(50., x + 1, db_to_dec(0), 1e-4, 180e3)
        print(err, x)

    from scipy.stats import expon
    import matplotlib.pyplot as plt

    scale = 0.559
    shape = 0.612 / scale
    print(rice.rvs(shape, scale=scale))
    fig, ax = plt.subplots(1, 1)
    x = np.linspace(rice.ppf(0.0001, shape, scale=scale),
                    rice.ppf(0.9999, shape, scale=scale), 10000)
    ax.plot(x, rice.pdf(x, shape, scale=scale), 'r-', label='rice pdf')
    x = np.linspace(expon.ppf(0.01), expon.ppf(0.99), 100)
    ax.plot(x, expon.pdf(x), 'r-', lw=5, alpha=0.6, label='expon pdf')
    print(rice.rvs(shape, scale=scale))
    plt.show()
示例#9
0
def _PDF(A, B):
    """
    The Rice probability distribution function for p(A|B).
    """
    return rice.pdf(A, B)
示例#10
0
 def density(self, x):
     return rice.pdf(x, self.b, loc=self.mu, scale=self.sigma)
示例#11
0
 def Rice(sigma=0.2, num_samples=101):
     sampGrid = np.linspace(0.0, 1.0, num_samples)
     mm = rice.pdf(sampGrid, 0.0, 0.0, sigma)
     mm /= mm.max()
     return interp1d(sampGrid, mm)
示例#12
0
from scipy.stats import rice
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)

# Calculate a few first moments:

b = 0.775
mean, var, skew, kurt = rice.stats(b, moments='mvsk')

# Display the probability density function (``pdf``):

x = np.linspace(rice.ppf(0.01, b), rice.ppf(0.99, b), 100)
ax.plot(x, rice.pdf(x, b), 'r-', lw=5, alpha=0.6, label='rice pdf')

# Alternatively, the distribution object can be called (as a function)
# to fix the shape, location and scale parameters. This returns a "frozen"
# RV object holding the given parameters fixed.

# Freeze the distribution and display the frozen ``pdf``:

rv = rice(b)
ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')

# Check accuracy of ``cdf`` and ``ppf``:

vals = rice.ppf([0.001, 0.5, 0.999], b)
np.allclose([0.001, 0.5, 0.999], rice.cdf(vals, b))
# True

# Generate random numbers:
示例#13
0
            })
        plt.legend(bbox_to_anchor=(0., 1.02, 1., .102),
                   loc=3,
                   ncol=4,
                   mode="expand",
                   borderaxespad=0.)

    # define wave
    N = 400
    N_modes = 20
    b = 0.775
    phi = np.random.uniform(0, 2 * np.pi, N_modes)
    t = np.linspace(100, 2100, N)
    k = np.linspace(0.01, 0.2, N_modes)
    x = np.linspace(-1, 5, N_modes)
    amp = rice.pdf(x, b)
    eta = np.dot(amp, np.sin(np.outer(k, t) + np.outer(phi, np.ones(len(t)))))

    # define random masks
    N_gaps = 15
    mean_gap_length = 8
    illu = construct_mask(N, N_gaps, mean_gap_length)

    # use deconvolution directly
    w = grid2spectral(t)
    w1 = 0.02
    w2 = 0.16
    gap_filling_core = GapFillingCore(w, w1, w2)
    eta_dec = gap_filling_core.deconvolve(eta * illu,
                                          illu,
                                          replace_all=True,
示例#14
0
from scipy.stats import rice
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
from cycler import cycler

matplotlib.rc('text', usetex=True)
fig, ax = plt.subplots(1, 1)
b = 10
mean, var, skew, kurt = rice.stats(b, moments='mvsk')
ax.set_prop_cycle(
    cycler('color', ['c', 'm', 'y', 'k']) + cycler('lw', [1, 2, 3, 4]))

for i in np.arange(0, 3, 0.75):
    x = np.linspace(rice.ppf(0.01, i), rice.ppf(0.99, i), 100)
    ax.plot(x, rice.pdf(x, i), lw=2, alpha=0.6, label=r"$\nu =$ " + str(i))

plt.legend()
plt.xlabel(r"$\nu$")
plt.ylabel(r"$p(x | \nu)$")

plt.show()