Beispiel #1
0
 def update_wings(self, sb_p, port_p):
     sb_p = deg2rad(sb_p)
     port_p = deg2rad(port_p)
     a1 = -self.hinge1.getAngle()
     a2 = -self.hinge2.getAngle()
     d1 = limit(a1 - sb_p, -2, 2) * 10
     d2 = limit(a2 - port_p, -2, 2) * 10
     self.hinge1.getMotor1D().setSpeed(d1)
     self.hinge2.getMotor1D().setSpeed(d2)
Beispiel #2
0
def factorize_deg_real_pole(pole, T, conv="doubled_up"):
    """
    Function for factorizing a degenerate real pole.

    It is similar to the non-degenerate real case, but the same pole appears twice.
    """

    L = (limit(lambda z: (z - pole) * T(z), pole))
    _, vecs = la.eig(L)
    u1 = vecs[:, 0]
    u2 = vecs[:, 1]
    w1 = scale_vector_doubled_up(u1)
    w2 = scale_vector_doubled_up(u2)
    v2, v1 = real_scaling(w1, w2)
    M = v1.shape[0] / 2
    Jv = make_Jv(M, conv=conv)
    J1 = make_Jv(1, conv=conv)

    U = numpy.matrix([[1, 1], [-1j, 1j]])
    V = numpy.hstack([v1, v2]) * U

    V_flat = J1 * V.H * Jv

    if (V * V_flat)[0, 0] < 0:
        v1, v2 = v2, v1
        V = numpy.hstack([v1, v2]) * U
        V_flat = J1 * V.H * Jv

    F1 = lambda z: (numpy.matrix([[(z + pole) / (z - pole), 0],
                                  [0, (z + pole) / (z - pole)]]))

    return lambda z: numpy.matrix(numpy.eye(2)) - V * V_flat + V * F1(
        z) * V_flat
Beispiel #3
0
def new_f_frac_safe(f_frac,z0,residues,roots,max_ok,val=None,verbose=False):
    '''
    Functions that evaluate the f_frac after some roots and their residues are subtracted.
    The safe version checks for large values and division by zero.
    If the value of f_frac(z0) is too large, subtracting the roots of f becomes
    numerically unstable. In this case, we approximate the new function f_frac
    by using the limit function.

    We assume here that the poles are of order 1.

    Args:
        f_frac (function): function for which roots will be subtracted.

        z0 (complex number): point where new_f_frac is evaluated.

        residues (list of complex numbers): The corresponding residues to
            subtract.

        roots (list of complex numbers): The corresponding roots to subtract.

        val (optional[complex number]): We can impose a value f_frac(z0) if
            we wish.

        max_ok (float) Maximum absolute value of f_frac(z0 to use).

        verbose (optional[boolean]): print warnings.

    Returns:
        The new value of f_frac(z0) once the chosen poles have been subtracted.
    '''
    try:
        if val == None:
            val = f_frac(z0)
        if abs(val) < max_ok:
            return new_f_frac(f_frac,z0,residues,roots,val)
        else:
            return limit(lambda z: new_f_frac(f_frac,z,residues,roots),z0)
    except ZeroDivisionError:
        if verbose:
            print 'division by zero in new_f_frac_safe'
        return limit(lambda z: new_f_frac(f_frac,z,residues,roots),z0)
Beispiel #4
0
def residues(f_frac,roots):
    '''
    Finds the resides of :math:`f_{frac} = f'/f` given the location of some roots of f.
    The roots of f are the poles of f_frac.

    Args:
        f_frac (function): a complex.

        roots (a list of complex numbers): the roots of f; poles of f_frac.

    Returns:
        A list of residues of f_frac.

    '''
    return [limit(lambda z: (z-root)*f_frac(z),root) for root in roots]
def get_Potapov_vecs(T,poles):
    '''
    Given a transfer function T and some poles, compute the residues about the
    poles and generate the eigenvectors to use for constructing the projectors
    in the Blaschke-Potapov factorization.
    '''
    N = T(0).shape[0]
    found_vecs = []
    for pole in poles:
        L = (la.inv(Potapov_prod(pole,poles,found_vecs,N)) *
            f.limit(lambda z: (z-pole)*T(z),pole) ) ## Current bottleneck O(n^2).
        [eigvals,eigvecs] = la.eig(L)
        index = np.argmax(map(abs,eigvals))
        big_vec = np.asmatrix(eigvecs[:,index])
        found_vecs.append(big_vec)
    return found_vecs
Beispiel #6
0
def get_Potapov_vecs(T, poles):
    '''
    Given a transfer function T and some poles, compute the residues about the
    poles and generate the eigenvectors to use for constructing the projectors
    in the Blaschke-Potapov factorization.
    '''
    N = T(0).shape[0]
    found_vecs = []
    for pole in poles:
        L = (la.inv(Potapov_prod(pole, poles, found_vecs, N)) *
             f.limit(lambda z:
                     (z - pole) * T(z), pole))  ## Current bottleneck O(n^2).
        [eigvals, eigvecs] = la.eig(L)
        index = np.argmax(map(abs, eigvals))
        big_vec = np.asmatrix(eigvecs[:, index])
        found_vecs.append(big_vec)
    return found_vecs
Beispiel #7
0
def factorize_complex_poles(poles,
                            T_tilde,
                            verbose=False,
                            conv="doubled_up",
                            eps=0.):
    """
    Find the vectors at a given list of complex poles.
    """
    dim = T_tilde(0).shape[0]
    found_vecs = []
    for i, p in enumerate(poles):
        if type(eps) == list:
            current_eps = eps[i]
        else:  ## if not a list assume a number:
            current_eps = eps
        R = complex_prod_deg(p,
                             poles,
                             found_vecs,
                             dim,
                             verbose=verbose,
                             conv=conv,
                             eps=current_eps)

        if verbose:
            print("R = %s" % R)

        L = la.inv(R) * limit(lambda z: (z - p) * T_tilde(z), p)
        [eigvals, eigvecs] = la.eig(L)
        if verbose:
            print("Eigenvalues: ")
            print(eigvals)
            print("eigenvectors")
            print(eigvecs)
        index = numpy.argmax(map(abs, eigvals))
        big_vec = numpy.asmatrix(eigvecs[:, index])
        big_val = eigvals[index]
        found_vecs.append((big_vec, big_val))
    return found_vecs
Beispiel #8
0
class PredictView(ModelView):
    datamodel = SQLAInterface(Predict)
    list_columns = [
        'date_nice', 'flg1_img', 'team1', 'flg2_img', 'team2',
        'team1.groups.name', 'stadium', 'goal1', 'goal2', 'round'
    ]
    label_columns = {
        'date_nice': 'Date',
        'team1.groups.name': 'Group',
        'team1': 'Team 1',
        'team2': 'Team 2',
        'goal1': 'Goals T1',
        'goal2': 'Goals T2',
        'flg1_img': ' ',
        'flg2_img': ' '
    }
    base_filters = [['round', FilterStartsWith, "Round of 32"],
                    ['user_id', FilterEqualFunction, get_user]]
    base_order = ['date', 'asc']
    order_columns = ['date', 'stadium']
    base_permissions = limit()
    edit_columns = ['goal1', 'goal2']
    edit_widget = FormInlineWidget
    page_size = 48