def gpoints(SceneArea, npoints, amax=1., seed=None): """Generates point targets Parameters ---------- SceneArea : tulpe or list The area of scene. npoints : int The number of points. amax : float, optional The maximum amplitude. seed : int or None, optional The seed for random generator. Returns ------- tensor A tensor contains coordinate and amplitude information. """ if seed is not None: setseed(seed) xmin, xmax, ymin, ymax = SceneArea xs = th.rand(npoints, 1) * (xmax - xmin) + xmin ys = th.rand(npoints, 1) * (ymax - ymin) + ymin amps = th.rand(npoints, 1) * amax targets = th.zeros(npoints, 7) targets[:, [0]] = xs targets[:, [1]] = ys targets[:, [-1]] = amps return targets
def mkpec(self, n, seed=None): """Make phase error Args: n (int): The number of phase errors. seed (None or int, optional): The random seed. Returns: TYPE: Description """ if seed is not None: ts.setseed(seed) if self.ma is not None: ca = th.zeros(n, self.ma - 1) for i, lowhigh in enumerate(zip(self.carange[0], self.carange[1])): low, high = lowhigh ca[:, i] = th.rand(n) * (high - low) + low if self.mr is not None: cr = th.zeros(n, self.mr - 1) for i, lowhigh in enumerate(zip(self.crrange[0], self.crrange[1])): low, high = lowhigh cr[:, i] = th.rand(n) * (high - low) + low if self.ma is not None and self.mr is None: return ca if self.mr is not None and self.ma is None: return cr if self.ma is not None and self.mr is not None: return ca, cr
def mksarp(self, n=1, seed=None): """Makes SAR Parameters Parameters ---------- n : int, optional The number of experiments. seed : None, optional The seed for random generator. Returns ------- dict The SAR Parameter dict. """ if seed is not None: ts.setseed(seed) pdict = {} for k, v in self.prdict.items(): if v is not None: low, high = v if n == 1: pdict[k] = th.rand(n).item() * (high - low) + low else: pdict[k] = th.rand(n) * (high - low) + low return pdict
def __init__(self, carange=None, crrange=None, seed=None): """Polynominal phase error generator. Args: carange (None or tuple or list, optional): List of coefficients range of phase error in azimuth direction. crrange (None or tuple or list, optional): List of coefficients range of phase error in range direction. seed (None or int, optional): The random seed. """ self.carange = carange self.crrange = crrange self.seed = seed self.ma = len( carange[0]) + 1 if carange is not None else None # order 2-ma self.mr = len( crrange[0]) + 1 if crrange is not None else None # order 2-mr if seed is not None: ts.setseed(seed)
if self.std is None: if self.axis is None: std = th.std(x, self.unbiased) else: std = th.std(x, self.axis, self.unbiased, keepdim=True) if self.extra is True: return (x - mean) / (std + EPS), mean, std else: return (x - mean) / (std + EPS) if __name__ == '__main__': import torchsar as ts ts.setseed(seed=2020, target='torch') x = th.randn(5, 2, 4, 3) * 10000 f = Standardization(axis=(2, 3), unbiased=False, extra=True) y, meanv, stdv = f(x) print(y[0], y.shape, meanv.shape, stdv.shape) g = th.nn.InstanceNorm2d(2) z = g(x) print(z[0], z.shape) f = Standardization(axis=(0, 2, 3), unbiased=False, extra=True) y, meanv, stdv = f(x) print(y[0], y.shape, meanv.shape, stdv.shape)
def __init__(self, prdict, seed=None): self.prdict = prdict self.seed = seed if seed is not None: ts.setseed(seed)