Beispiel #1
0
 def set_K(self, fx=1, fy=1, cx=0, cy=0):
     # K is the 3x3 Camera matrix
     # fx, fy are focal lenghts expressed in pixel units
     # cx, cy is a principal point usually at image center
     self.fx = fx
     self.fy = fy
     self.cx = cx
     self.cy = cy
     self.K = np.mat([[fx, 0, cx], [0, fy, cy], [0, 0, 1.]],
                     dtype=np.float32)
     self.set_P()
Beispiel #2
0
def ensemble_transfer_matrix_pi_half(NAtoms, g1d, gprime, gm, Delta1, Deltap,
                                     Omega):
    """
    NAtoms: The number of atoms
    g1d:    \Gamma_{1D}, the decay rate into the guided mode
    gprime: \Gamma', the decay rate into all the other modes
    gm:     \Gamma_m, the decay rate from the meta-stable state
    Delta1: The detuning of the carrier frequency \omega_L of the
            quantum field from the atomic transition frequency \omega_{ab}.
            Delta1 = \omega_L - \omega_{ab}
    Deltap: The detuning of the classical drive frequency \omega_p from
            the transition bc. Deltap = \omega_p - \omega_{bc}
    """
    kd = 0.5 * np.pi

    Mf = np.mat([[np.exp(1j * kd), 0], [0, np.exp(-1j * kd)]])

    beta3 = Lambda_type_minus_r_over_t(g1d, gprime, gm, Delta1, Deltap, Omega)
    M3 = np.mat([[1 - beta3, -beta3], [beta3, 1 + beta3]])

    beta2 = two_level_minus_r_over_t(g1d, gprime, Delta1)
    M2 = np.mat([[1 - beta2, -beta2], [beta2, 1 + beta2]])

    Mcell = Mf * M2 * Mf * M3
    NCells = NAtoms / 2

    #diag, V = np.linalg.eig(Mcell)
    #DN = np.diag(diag**(NCells))
    #V_inv = np.linalg.inv(V)

    #return V*DN*V_inv

    theta = np.arccos(0.5 * np.trace(Mcell))
    Id = np.mat([[1, 0], [0, 1]])

    Mensemble\
            = np.mat([[np.cos(NCells*theta)+1j*1j*np.sin(NCells*theta)/np.sin(theta)*(Mcell[1,1]-Mcell[0,0])/2,
                 -1j*1j*np.sin(NCells*theta)/np.sin(theta)*Mcell[0,1]],
                [-1j*1j*np.sin(NCells*theta)/np.sin(theta)*Mcell[1,0],
                 np.cos(NCells*theta)-1j*1j*np.sin(NCells*theta)/np.sin(theta)*(Mcell[1,1]-Mcell[0,0])/2]])
    return Mensemble
Beispiel #3
0
    def set_R_axisAngle(self, x, y, z, alpha):
        """  Creates a 3D [R|t] matrix for rotation
        around the axis of the vector defined by (x,y,z)
        and an alpha angle."""
        #Normalize the rotation axis a
        a = np.array([x, y, z])
        a = a / np.linalg.norm(a)

        #Build the skew symetric
        a_skew = np.mat([[0, -a[2], a[1]], [a[2], 0, -a[0]], [-a[1], a[0], 0]])
        R = np.eye(4)
        R[:3, :3] = expm(a_skew * alpha)
        self.R = R
        self.update_Rt()
Beispiel #4
0
def ensemble_transfer_matrix(NAtoms, kd, g1d, gprime, gm, Delta1, Deltap,
                             Omega):
    """
    NAtoms: The number of atoms
    kd:     The product of the wavevector k of the input quantum field
            (and also approximately the wavevector of the classical drive)
            and the distance between the atoms d. For example kd=pi means
            that atoms are situated half a wavelength apart.
    g1d:    \Gamma_{1D}, the decay rate into the guided mode
    gprime: \Gamma', the decay rate into all the other modes
    gm:     \Gamma_m, the decay rate from the meta-stable state
    Delta1: The detuning of the carrier frequency \omega_L of the
            quantum field from the atomic transition frequency \omega_{ab}.
            Delta1 = \omega_L - \omega_{ab}
    Deltap: The detuning of the classical drive frequency \omega_p from
            the transition bc. Deltap = \omega_p - \omega_{bc}
    """
    Mf = np.mat([[np.exp(1j * kd), 0], [0, np.exp(-1j * kd)]])

    MensembleStandingWave = np.mat([[1, 0], [0, 1]])

    xiConstant = Lambda_type_minus_r_over_t(g1d, gprime, gm, Delta1, Deltap,
                                            Omega)
    for n in range(NAtoms):
        #This corresponds the the classical drive having the same
        #frequency as the quantum transition. Thus the intensity
        #of the classical drive oscillates with lambda/2
        OmegaStandingWave = Omega * np.cos(kd * n)
        xiStandingWave = Lambda_type_minus_r_over_t(g1d, gprime, gm, Delta1,
                                                    Deltap, OmegaStandingWave)
        #Fill in the scattering matrices for the current atom
        MatomStandingWave = np.mat([[1 - xiStandingWave, -xiStandingWave],
                                    [xiStandingWave, 1 + xiStandingWave]])
        #Multiply the scattering and free propagation matrices
        #onto the ensemble matrices
        MensembleStandingWave = Mf * MatomStandingWave * MensembleStandingWave
    return MensembleStandingWave
Beispiel #5
0
    def update_conic_matrix(self):
        xo = self.center[0]
        yo = self.center[1]
        r = self.r
        self.Aq = np.mat([[1, 0, -xo], [0, 1, -yo],
                          [-xo, -yo, xo**2 + yo**2 - r**2]])

        self.a = self.Aq[0, 0]
        self.c = self.Aq[1, 1]
        self.f = self.Aq[2, 2]
        self.b = self.Aq[0, 1] * 2.
        self.d = self.Aq[0, 2] * 2.
        self.e = self.Aq[1, 2] * 2.

        return self.Aq
Beispiel #6
0
def impurity_unit_cell_pi_half(g1d, gprime, gm, Delta1, Deltap, Omega):
    """
    NAtoms: The number of atoms
    g1d:    \Gamma_{1D}, the decay rate into the guided mode
    gprime: \Gamma', the decay rate into all the other modes
    gm:     \Gamma_m, the decay rate from the meta-stable state
    Delta1: The detuning of the carrier frequency \omega_L of the
            quantum field from the atomic transition frequency \omega_{ab}.
            Delta1 = \omega_L - \omega_{ab}
    Deltap: The detuning of the classical drive frequency \omega_p from
            the transition bc. Deltap = \omega_p - \omega_{bc}
    """
    kd = 0.5 * np.pi

    Mf = np.mat([[np.exp(1j * kd), 0], [0, np.exp(-1j * kd)]])

    beta2_imp = two_level_minus_r_over_t(g1d, gprime, 0)
    M2_imp = np.mat([[1 - beta2_imp, -beta2_imp], [beta2_imp, 1 + beta2_imp]])

    beta2 = two_level_minus_r_over_t(g1d, gprime, Delta1)
    M2 = np.mat([[1 - beta2, -beta2], [beta2, 1 + beta2]])

    M_impurity_cell = Mf * M2 * Mf * M2_imp
    return M_impurity_cell
Beispiel #7
0
    def project(self, H):
        H = np.mat(H)
        Hinv = np.linalg.inv(H)
        Q = (Hinv.T) * self.Aq * Hinv

        projected_circle = Ellipse()
        projected_circle.a = Q[0, 0]
        projected_circle.c = Q[1, 1]
        projected_circle.f = Q[2, 2]
        projected_circle.b = Q[0, 1] * 2.
        projected_circle.d = Q[0, 2] * 2.
        projected_circle.e = Q[1, 2] * 2.
        projected_circle.Aq = Q
        projected_circle.r = self.r

        return projected_circle
Beispiel #8
0
        loss_temp_2_p = loss_temp_2_p + temp
    loss_temp_2_q = -1.0 * n / 2 * np.log(2 * np.pi) - 1.0 / 2 * np.log(
        np.linalg.det(np.dot(L_temp, np.transpose(
            L_temp)))) - 1.0 / 2 * np.dot(np.transpose(epsilon), epsilon)
    loss_temp = loss_temp_1 + loss_temp_2_p - loss_temp_2_q
    return loss_temp


# load data
data = scio.loadmat(
    "/Users/yawei/Documents/MATLAB/simulation based algorithm test library/simulation_based_machine_learning_library/dataset/heart/test_heart.mat"
)
data = data['yy']
label = data[:, 0]
[n, d] = np.shape(data)
training_data = np.mat(data[:, 1:d])
[n, d] = np.shape(training_data)

# initialize parameters
T = 10
alpha_0 = 1e-5  # learning rate for the primal update
beta_0 = 1e-5  # learning rate for the dual update
theta_sum_old = np.mat(np.zeros((n + n * n, 1)))
loss = np.mat(np.zeros((T, 1)))
theta = np.mat(np.ones((n + n * n, 1)))  # primal variable, mu + L
y = np.mat(np.ones((2, 1)))  # dual variable
pair_dist = np.mat(np.zeros((n * n, 1)))
for i in range(1, n):
    for j in range(1, n):
        if i == j:
            continue
Beispiel #9
0
 def project(self,H):
   H = np.mat(H)
   Hinv = np.linalg.inv(H)
   self.Q = (Hinv.T)*self.Aq*Hinv
   return Q
Beispiel #10
0
 def update_conic_matrix(self):
     self.Aq = np.mat([[self.a, self.b / 2., self.d / 2.],
                       [self.b / 2., self.c, self.e / 2.],
                       [self.d / 2., self.e / 2., self.f]])