Beispiel #1
0
 def __init__(self, x, y, name, maxhealth, speed, damage, image, attacktimer, mass, attack_range):
     self.x = x
     self.y = y
     self.name = name
     self.maxhealth = maxhealth
     self.speed = speed
     self.damage = damage
     self.image = image
     self.attacktimer = attacktimer
     self.mass = mass
     self.uuid = core.Var.uuid_gen
     core.Var.uuid_gen += 1
     self.health = self.maxhealth
     self.frame = self.image.get_rect()
     self.size = (self.image.get_width() / 2) ** 2
     self.vect = core.p.math.Vector2(core.Gameobj.hero.x - self.x, core.Gameobj.hero.y - self.y)
     self.vect_long = core.p.math.Vector2(core.Gameobj.hero.x - self.x, core.Gameobj.hero.y - self.y)
     self.time_attacked = 0
     self.attack_bool = False
     self.kickback = 0
     self.collision_with_other = [False, 1, 1]
     self.kick_direction = [0, 0]
     self.attack_range = (core.dpp(attack_range) + core.sqrt(self.size) + core.sqrt(core.Gameobj.hero.size)) ** 2
Beispiel #2
0
def corrcoef(x, y=None, rowvar=True, bias=False, allow_masked=True):
    """
    The correlation coefficients formed from the array x, where the
    rows are the observations, and the columns are variables.

    corrcoef(x,y) where x and y are 1d arrays is the same as
    corrcoef(transpose([x,y]))

    Parameters
    ----------
    x : ndarray
        Input data. If x is a 1D array, returns the variance.
        If x is a 2D array, returns the covariance matrix.
    y : {None, ndarray} optional
        Optional set of variables.
    rowvar : {False, True} optional
        If True, then each row is a variable with observations in columns.
        If False, each column is a variable and the observations are in the rows.
    bias : {False, True} optional
        Whether to use a biased (True) or unbiased (False) estimate of the
        covariance.
        If True, then the normalization is by N, the number of non-missing
        observations.
        Otherwise, the normalization is by (N-1).
    allow_masked : {True, False} optional
        If True, masked values are propagated pair-wise: if a value is masked
        in x, the corresponding value is masked in y.
        If False, raises an exception.

    See Also
    --------
    cov

    """
    # Get the data
    (x, xnotmask, rowvar) = _covhelper(x, y, rowvar, allow_masked)
    # Compute the covariance matrix
    if not rowvar:
        fact = np.dot(xnotmask.T, xnotmask) * 1.0 - (1 - bool(bias))
        c = (dot(x.T, x.conj(), strict=False) / fact).squeeze()
    else:
        fact = np.dot(xnotmask, xnotmask.T) * 1.0 - (1 - bool(bias))
        c = (dot(x, x.T.conj(), strict=False) / fact).squeeze()
    # Check whether we have a scalar
    try:
        diag = ma.diagonal(c)
    except ValueError:
        return 1
    #
    if xnotmask.all():
        _denom = ma.sqrt(ma.multiply.outer(diag, diag))
    else:
        _denom = diagflat(diag)
        n = x.shape[1 - rowvar]
        if rowvar:
            for i in range(n - 1):
                for j in range(i + 1, n):
                    _x = mask_cols(vstack((x[i], x[j]))).var(axis=1, ddof=1 - bias)
                    _denom[i, j] = _denom[j, i] = ma.sqrt(ma.multiply.reduce(_x))
        else:
            for i in range(n - 1):
                for j in range(i + 1, n):
                    _x = mask_cols(vstack((x[:, i], x[:, j]))).var(axis=1, ddof=1 - bias)
                    _denom[i, j] = _denom[j, i] = ma.sqrt(ma.multiply.reduce(_x))
    return c / _denom
Beispiel #3
0
def corrcoef(x, y=None, rowvar=True, bias=False, allow_masked=True):
    """The correlation coefficients formed from the array x, where the
    rows are the observations, and the columns are variables.

    corrcoef(x,y) where x and y are 1d arrays is the same as
    corrcoef(transpose([x,y]))

    Parameters
    ----------
    x : ndarray
        Input data. If x is a 1D array, returns the variance.
        If x is a 2D array, returns the covariance matrix.
    y : {None, ndarray} optional
        Optional set of variables.
    rowvar : {False, True} optional
        If True, then each row is a variable with observations in columns.
        If False, each column is a variable and the observations are in the rows.
    bias : {False, True} optional
        Whether to use a biased (True) or unbiased (False) estimate of the
        covariance.
        If True, then the normalization is by N, the number of non-missing
        observations.
        Otherwise, the normalization is by (N-1).
    allow_masked : {True, False} optional
        If True, masked values are propagated pair-wise: if a value is masked
        in x, the corresponding value is masked in y.
        If False, raises an exception.

    See Also
    --------
    cov

    """
    # Get the data
    (x, xnotmask, rowvar) = _covhelper(x, y, rowvar, allow_masked)
    # Compute the covariance matrix
    if not rowvar:
        fact = np.dot(xnotmask.T, xnotmask)*1. - (1 - bool(bias))
        c = (dot(x.T, x.conj(), strict=False) / fact).squeeze()
    else:
        fact = np.dot(xnotmask, xnotmask.T)*1. - (1 - bool(bias))
        c = (dot(x, x.T.conj(), strict=False) / fact).squeeze()
    # Check whether we have a scalar
    try:
        diag = ma.diagonal(c)
    except ValueError:
        return 1
    #
    if xnotmask.all():
        _denom = ma.sqrt(ma.multiply.outer(diag, diag))
    else:
        _denom = diagflat(diag)
        n = x.shape[1-rowvar]
        if rowvar:
            for i in range(n-1):
                for j in range(i+1,n):
                    _x = mask_cols(vstack((x[i], x[j]))).var(axis=1,
                                                             ddof=1-bias)
                    _denom[i,j] = _denom[j,i] = ma.sqrt(ma.multiply.reduce(_x))
        else:
            for i in range(n-1):
                for j in range(i+1,n):
                    _x = mask_cols(vstack((x[:,i], x[:,j]))).var(axis=1,
                                                                 ddof=1-bias)
                    _denom[i,j] = _denom[j,i] = ma.sqrt(ma.multiply.reduce(_x))
    return c/_denom