示例#1
0
def agronomicplotwithdistributions(length, width, sowing_density, plant_density, inter_row, mu=0.0, kappa=3.0, noise = 0,convunit=100):
    """
    Returns the
        - number of plants
        - the positions
        - azimuthal orientation of each plant
        - the domain
        - the simulated density
        of a micro-plot specified with agronomical variables
       
    Inputs:
        - length (m) is plot dimension along row direction
        - width (m) is plot dimension perpendicular to row direction
        - sowing density is the density of seeds sawn
        - plant_density is the density of plants that are present (after loss due to bad emergence, early death...)
        - inter_row (m) is for the  distance between rows
        - mu, kappa are the von Mises parameters of the azimuthal distribution
        - noise (%), indicates the precision of the sowing for the inter plant spacing
        - unit (m or cm) is for the unit of the position and domain
    """
    inter_plant = 1. / inter_row / sowing_density
    nrow = max(1, int(float(width) / inter_row))
    plant_per_row = max(1,int(float(length) / inter_plant))
    nplants = nrow * plant_per_row
    positions, domain = regular(nplants, nrow, inter_plant * convunit, inter_row * convunit)
    n_emerged = int(nplants * plant_density / sowing_density)
    positions = sample(positions, n_emerged)
    density = int(n_emerged / ( abs(domain[1][0] - domain[0][0]) / convunit * abs(domain[1][1] - domain[0][1]) / convunit))
    azimuths = vonmises(mu, kappa, nplants)
    return n_emerged, positions, azimuths, domain, density
示例#2
0
文件: stand.py 项目: imane-aanna/adel
def agronomicplotwithdistributions(length, width, sowing_density, plant_density, inter_row, mu=0.0, kappa=3.0, noise = 0,convunit=100):
    """
    Returns the
        - number of plants
        - the positions
        - azimuthal orientation of each plant
        - the domain
        - the simulated density
        of a micro-plot specified with agronomical variables
       
    Inputs:
        - length (m) is plot dimension along row direction
        - width (m) is plot dimension perpendicular to row direction
        - sowing density is the density of seeds sawn
        - plant_density is the density of plants that are present (after loss due to bad emergence, early death...)
        - inter_row (m) is for the  distance between rows
        - mu, kappa are the von Mises parameters of the azimuthal distribution
        - noise (%), indicates the precision of the sowing for the inter plant spacing
        - unit (m or cm) is for the unit of the position and domain
    """
    inter_plant = 1. / inter_row / sowing_density
    nrow = max(1, int(float(width) / inter_row))
    plant_per_row = max(1,int(float(length) / inter_plant))
    nplants = nrow * plant_per_row
    positions, domain = regular(nplants, nrow, inter_plant * convunit, inter_row * convunit)
    n_emerged = int(nplants * plant_density / sowing_density)
    positions = sample(positions, n_emerged)
    density = int(n_emerged / ( abs(domain[1][0] - domain[0][0]) / convunit * abs(domain[1][1] - domain[0][1]) / convunit))
    azimuths = vonmises(mu, kappa, nplants)
    return n_emerged, positions, azimuths, domain, density
示例#3
0
    def get_landmark_measurements(self, X_WB_xy):
        """
        :param X_WB_xy: robot pose ([x, y]]) in world frame.
        :return:
        (1) idx_visible_l: indices into self.l_xy whose distance to t_xy is
            smaller than self.r_sensor.
        (2) noisy measurements of distances to self.l_xy[idx_visible_l]
        """
        X_WB = meshcat.transformations.rotation_matrix(0, np.array([0, 0, 1.]))
        X_WB[:2, 3] = X_WB_xy
        l_xyz_W = np.zeros((self.nl, 3))
        l_xyz_W[:, :2] = self.l_xy

        X_BW = np.linalg.inv(X_WB)
        l_xyz_B = (X_BW[:3, :3].dot(l_xyz_W.T)).T + X_BW[:3, 3]
        d_l = np.linalg.norm(l_xyz_B, axis=1)
        theta_l_B = np.arctan2(l_xyz_B[:, 1], l_xyz_B[:, 0])

        is_visible = np.all(
            [d_l > self.r_range_min, d_l < self.r_range_max], axis=0)
        idx_visible_l = np.where(is_visible)[0]
        d_l_noisy = d_l[idx_visible_l] + random.normal(
            scale=self.sigma_range, size=idx_visible_l.size)
        bearings_noisy = random.vonmises(
            theta_l_B[idx_visible_l], self.kappa_bearing)

        return idx_visible_l, d_l_noisy, bearings_noisy
示例#4
0
 def _sample_nu(self):
     ang_bar = self._calc_ang()
     nu0 = np.array([np.cos(self.nu0), np.sin(self.nu0)])
     for r in self.nu:
         tmp = self.kappa[r] * ang_bar[r] + nu0 * self.kappa0
         kappa = linalg.norm(tmp)
         nu = tmp / kappa
         nu = np.arctan2(nu[1], nu[0])
         self.nu[r] = rd.vonmises(nu, kappa)
def von_mises(num_bins: int,
              num_points: int,
              kappa: float = 0.5,
              mean_loc: float = 0.,
              visualize: bool = False) -> np.ndarray:
    '''
    Generates von mises distributed data on the unit circle. 
    '''
    samples = npr.vonmises(mean_loc, kappa=kappa, size=num_points)
    result = np.histogram(samples, bins=num_bins, range=(-pi, pi))[0]

    # induce a random circular shift
    result = np.roll(result, npr.randint(0, num_bins))

    if visualize is True:
        plot_distribution(result, 'Von Mises')

    return result
 def test_VonMises_range(self):
     # Make sure generated random variables are in [-pi, pi].
     # Regression test for ticket #986.
     for mu in np.linspace(-7., 7., 5):
         r = random.vonmises(mu, 1, 50)
         assert_(np.all(r > -np.pi) and np.all(r <= np.pi))
示例#7
0
 def creat_rel_samp(para):
     [mu_theta, ka_theta, mn, std] = para
     theta = rd.vonmises(mu_theta, ka_theta)
     r = abs(rd.normal(mn, std))
     X = [np.cos(theta), np.sin(theta), r, 1]
     return np.array(X).T
示例#8
0
 def wander(self):
     phi = vonmises(self.last_heading, self.wander_faith)
     rho = self.wander_effort * self.max_speed
     return Decisions.WANDER, (rho, phi)
示例#9
0
 def wander(self):
     phi = util.wrap_angle(self.last_heading +
                           vonmises(0, self.wander_faith))
     rho = self.wander_effort * self.max_speed
     self._move(rho, phi)
示例#10
0
文件: utils.py 项目: kunlegiwa/MANGO
def vonmises(size, params):
    try:
        return random.vonmises(params['mu'], params['kappa'], size)
    except ValueError as e:
        exit(e)
示例#11
0
if __name__ == "__main__":
    from numpy.random import vonmises
    from dials.array_family import flex
    from math import cos, sin, pi

    m = 0
    k = 0.1
    k1 = 1.0 / k
    r = 1.0

    num = 1000
    z = flex.double(flex.grid(100, 100))

    for i in range(1000):
        u = vonmises(m, k1)

        for j in range(num):
            t = 2 * pi * j / num
            xx = (r - r * cos(u)) + r * cos(t)
            yy = (r * sin(u)) + r * sin(t)
            ii = 40 + int(xx * 40)
            jj = 40 + int(yy * 40)
            if ii >= 0 and ii < 100 and jj >= 0 and jj < 100:
                z[jj, ii] += 1

    from matplotlib import pylab

    pylab.imshow(z.as_numpy_array())
    pylab.show()