Exemplo n.º 1
0
def cos_angle(y_reco, y_true):
    zep, zet, azp, azt = y_reco[:, 1], y_true[:, 1], y_reco[:, 2], y_true[:, 2]
    # cosalpha=abs(sin(zep))*cos(azp)*sin(zet)*cos(azt)+abs(sin(zep))*sin(azp)*sin(zet)*sin(azt)+cos(zep)*cos(zet)
    cosalpha = abs(sin(zep)) * abs(sin(zet)) * cos(azp - azt) + cos(zep) * cos(
        zet)  #check for double absolutes
    cosalpha -= tf.math.sign(cosalpha) * eps
    return cosalpha
Exemplo n.º 2
0
def PDF_gen_Pi_func(costk, costl, phi, Fl, P1, P2, P3, P4p, P5p, P6p, P8p):
    ##sint2k: square of sin(thetak); sin2tk: sin(2thetak); sintk: sin(thetak);
    cost2k = costk * costk
    sint2k = 1 - cost2k
    sintk = sqrt(sint2k)
    sin2tk = 2 * sintk * costk

    cost2l = costl * costl
    sint2l = 1 - cost2l
    sintl = sqrt(sint2l)
    sin2tl = 2 * sintl * costl
    cos2tl = 2 * cost2l - 1

    sinphi = sin(phi)
    cosphi = cos(phi)
    cos2phi = cos(2 * phi)
    sin2phi = sin(2 * phi)

    Ft = 1 - Fl

    dcrate = (0.75 * Ft * sint2k + Fl * cost2k + 0.25 * Ft * sint2k * cos2tl -
              Fl * cost2k * cos2tl +
              0.5 * P1 * Ft * sint2k * sint2l * cos2phi +
              sqrt(Fl * Ft) * 0.5 * P4p * sin2tk * sin2tl * cosphi +
              sqrt(Fl * Ft) * P5p * sin2tk * sintl * cosphi -
              sqrt(Fl * Ft) * P6p * sin2tk * sintl * sinphi +
              0.5 * sqrt(Fl * Ft) * P8p * sin2tk * sin2tl * sinphi +
              2 * P2 * Ft * sint2k * costl -
              P3 * Ft * sint2k * sint2l * sin2phi)

    return 9 / (32 * 3.14159265) * dcrate
Exemplo n.º 3
0
def PDF_gen_Si_func(costk, costl , phi, Fl, S3, S4, S5, AFB, S7, S8, S9):
    ##sint2k: square of sin(thetak); sin2tk: sin(2thetak); sintk: sin(thetak); 
    cost2k = costk * costk
    sint2k = 1 - cost2k
    sintk =  sqrt(sint2k)
    sin2tk = 2 * sintk * costk


    cost2l = costl * costl
    sint2l = 1 - cost2l
    sintl = sqrt(sint2l)
    sin2tl = 2 * sintl * costl
    cos2tl = 2 * cost2l - 1 

    sinphi = sin(phi)
    cosphi = cos(phi)
    cos2phi = cos(2*phi)
    sin2phi = sin(2*phi)

    dcrate = (0.75 * (1 - Fl) * sint2k + Fl * cost2k
    + 0.25 * (1 - Fl) * sint2k * cos2tl - Fl * cost2k * cos2tl
    + S3 * sint2k * sint2l * cos2phi + S4 * sin2tk * sin2tl * cosphi
    + S5 * sin2tk * sintl * cosphi + 4/3 * AFB * sint2k * costl
    + S7 * sin2tk * sintl * sinphi + S8 * sin2tk * sin2tl * sinphi
    + S9 * sint2k * sint2l * sin2phi)

    return 9 / (32 * 3.14159265) * dcrate
Exemplo n.º 4
0
def loss_funcxpos2(y_reco, y_true, re=False):
    from tensorflow.math import sin, cos, acos, abs, reduce_mean, subtract, square
    # Energy loss
    loss_energy = reduce_mean(abs(subtract(y_reco[:,0], y_true[:,0]))) #this works well but could maybe be improved

    zeni = [cos(y_true[:,1]) - y_reco[:,1] , 
            sin(y_true[:,1]) - y_reco[:,2]]

    azi  = [cos(y_true[:,2]) - y_reco[:,3] , 
            sin(y_true[:,2]) - y_reco[:,4]]

    loss_angle = reduce_mean(square(azi[0]))+reduce_mean(square(azi[1]))+reduce_mean(square(zeni[0]))+reduce_mean(square(zeni[1]))
    if not re:
        return loss_energy+loss_angle
    else:   
        return float(loss_energy+loss_angle), [float(loss_energy), float(loss_angle)]
Exemplo n.º 5
0
def integralPi_costk_costl(x, limits, norm_range, params, model):
    phi = x.unstack_x()
    Fl = params['Fl']
    P1 = params['P1']
    P3 = params['P3']
    return 9. / (32 * 3.14159265) * (
        4.0 / 9.0 + (1 - Fl) / 18.0 * P1 * cos(2 * phi) * 2 * 2 +
        (Fl - 1) / 9.0 * P3 * sin(2 * phi) * 2 * 2) * (2 * 2)
Exemplo n.º 6
0
def integralPi_costl(x, limits, norm_range, params, model):
    costk, phi = x.unstack_x()
    Fl = params['Fl']
    P1 = params['P1']
    P3 = params['P3']
    P5p = params['P5p']
    P6p = params['P6p']
    K00 = assoc_legendre_tf(0, 0, costk)
    K20 = assoc_legendre_tf(2, 0, costk)
    K21 = assoc_legendre_tf(2, 1, costk)
    K22 = assoc_legendre_tf(2, 2, costk)
    return 9. / (32 * 3.14159265) * (
        (4.0 / 9.0) * K00 + (4.0 * Fl / 3.0 - 4.0 / 9.0) * K20 +
        (1 - Fl) / 18.0 * P1 * K22 * cos(2 * phi) * 2 +
        (Fl - 1) / 9.0 * P3 * K22 * sin(2 * phi) * 2 +
        (2.0 / 3.0) * sqrt(Fl - Fl * Fl) * P5p * K21 * cos(phi) * pi / 4 +
        (-2.0 / 3.0) * sqrt(Fl - Fl * Fl) * P6p * K21 * sin(phi) * pi / 4) * (
            2)
def f_model(u_model, x, y):
    u = u_model(tf.concat([x, y], 1))
    u_x = tf.gradients(u, x)[0]
    u_y = tf.gradients(u, y)[0]
    u_xx = tf.gradients(u_x, x)[0]
    u_yy = tf.gradients(u_y, y)[0]

    a1 = constant(1.0)
    a2 = constant(1.0)
    pi = constant(math.pi)

    # we use this specific forcing term because we have an exact analytical solution for this case
    # to compare the results of the PINN solution
    # note that we must use tensorflow math primitives such as sin, cos, etc!
    forcing = - sin(a1 * pi * x) * sin(a2 * pi * y)

    f_u = u_xx + u_yy - forcing  # = 0

    return f_u
Exemplo n.º 8
0
    def _convert_to_pxyz(self, x):
        from numpy import cos, sin, sinh, exp, clip, stack
        pt = exp(clip(x[:, 0], -7., 7.)) - 0.1
        pt *= self._pt_scale
        eta = x[:, 1]
        phi = x[:, 2]

        px = pt * cos(phi)
        py = pt * sin(phi)
        pz = pt * sinh(clip(eta, -5, 5))

        return stack([px, py, pz], axis=1)
Exemplo n.º 9
0
def alpha_from_angle(y_reco, y_true):
    zep, zet, azp, azt = y_reco[:, 1], y_true[:, 1], y_reco[:, 2], y_true[:, 2]
    cosalpha = abs(sin(zep)) * cos(azp) * sin(zet) * cos(azt) + abs(
        sin(zep)) * sin(azp) * sin(zet) * sin(azt) + cos(zep) * cos(zet)
    cosalpha -= tf.math.sign(cosalpha) * eps
    alpha = acos(cosalpha)
    return alpha
Exemplo n.º 10
0
    def _convert_to_pxyz(self, x):
        from tensorflow.math import cos, sin, sinh, exp
        from tensorflow import clip_by_value, stack
        pt = exp(clip_by_value(x[:, 0], -7., 7.)) - 0.1
        pt *= self._pt_scale
        eta = x[:, 1]
        phi = x[:, 2]

        px = pt * cos(phi)
        py = pt * sin(phi)
        pz = pt * sinh(clip_by_value(eta, -5, 5))

        return stack([px, py, pz], axis=1)
Exemplo n.º 11
0
def integralPi_costk(x, limits, norm_range, params, model):
    costl, phi = x.unstack_x()
    Fl = params['Fl']
    P2 = params['P2']
    P1 = params['P1']
    P3 = params['P3']
    L00 = assoc_legendre_tf(0, 0, costl)
    L10 = assoc_legendre_tf(1, 0, costl)
    L20 = assoc_legendre_tf(2, 0, costl)
    L22 = assoc_legendre_tf(2, 2, costl)
    return 9. / (32 * 3.14159265) * (
        (4.0 / 9.0) * L00 + (2.0 / 9.0 - 2.0 * Fl / 3.0) * L20 +
        (4.0 / 3.0) * P2 * (1 - Fl) * L10 +
        (1 - Fl) / 18.0 * P1 * L22 * cos(2 * phi) * 2 +
        (Fl - 1) / 9.0 * P3 * L22 * sin(2 * phi) * 2) * (2)
def rotate_tensor_by_angle_xyz(input_data, graph, angle_x=0, angle_y=0, angle_z=0):
    """ Rotate the point cloud along up direction with certain angle.
        Rotate in the order of x, y and then z.
        Input:
          input_data: Nx3 tensor, original batch of point clouds
          angle_x: tf constant
          angle_y: tf constant
          angle_z: tf constant
        Return:
          Nx3 tensor, rotated batch of point clouds
    """
    with graph.as_default():
        # print('angle_x', angle_x)
        if angle_x == 0:
            angle_x = tflt(0)
        if angle_y == 0:
            angle_y = tflt(0)
        if angle_z == 0:
            angle_z = tflt(0)
    
        input_data = tf.cast(input_data, tf.float32)
        rotation_matrix1 = tf.stack([1, 0, 0,
                                0, tm.cos(angle_x), -tm.sin(angle_x),  
                                0, tm.sin(angle_x), tm.cos(angle_x)])
        rotation_matrix1 = tf.reshape(rotation_matrix1, (3,3))
        rotation_matrix1 = tf.cast(rotation_matrix1, tf.float32)
        shape_pc = tf.matmul(input_data, rotation_matrix1)

        rotation_matrix2 = tf.stack([tm.cos(angle_y), 0, tm.sin(angle_y),
                                    0, 1, 0,
                                    -tm.sin(angle_y), 0, tm.cos(angle_y)])
        rotation_matrix2 = tf.reshape(rotation_matrix2, (3,3))
        rotation_matrix2 = tf.cast(rotation_matrix2, tf.float32)
        shape_pc = tf.matmul(shape_pc, rotation_matrix2)

        rotation_matrix3 = tf.stack([tm.cos(angle_z), -tm.sin(angle_z), 0,
                                    tm.sin(angle_z), tm.cos(angle_z), 0,
                                    0, 0, 1])
        rotation_matrix3 = tf.reshape(rotation_matrix3, (3,3))    
        rotation_matrix3 = tf.cast(rotation_matrix3, tf.float32)
        shape_pc = tf.matmul(shape_pc, rotation_matrix3)
        return shape_pc
Exemplo n.º 13
0
def angle_loss_fn_batch(y_true, y_pred):
    x_p = math.sin(y_pred[:, 0]) * math.cos(y_pred[:, 1])
    y_p = math.sin(y_pred[:, 0]) * math.sin(y_pred[:, 1])
    z_p = math.cos(y_pred[:, 0])

    x_t = math.sin(y_true[:, 0]) * math.cos(y_true[:, 1])
    y_t = math.sin(y_true[:, 0]) * math.sin(y_true[:, 1])
    z_t = math.cos(y_true[:, 0])

    norm_p = math.sqrt(x_p * x_p + y_p * y_p + z_p * z_p)
    norm_t = math.sqrt(x_t * x_t + y_t * y_t + z_t * z_t)

    dot_pt = x_p * x_t + y_p * y_t + z_p * z_t

    angle_value = dot_pt / (norm_p * norm_t)
    angle_value = tf.clip_by_value(angle_value, -0.99999, 0.99999)

    loss_val = (math.acos(angle_value))

    return loss_val
Exemplo n.º 14
0
    def angle_loss_fn(self, y_true, y_pred):
        x_p = math.sin(y_pred[:, 0]) * math.cos(y_pred[:, 1])
        y_p = math.sin(y_pred[:, 0]) * math.sin(y_pred[:, 1])
        z_p = math.cos(y_pred[:, 0])

        x_t = math.sin(y_true[:, 0]) * math.cos(y_true[:, 1])
        y_t = math.sin(y_true[:, 0]) * math.sin(y_true[:, 1])
        z_t = math.cos(y_true[:, 0])

        norm_p = math.sqrt(x_p * x_p + y_p * y_p + z_p * z_p)
        norm_t = math.sqrt(x_t * x_t + y_t * y_t + z_t * z_t)

        dot_pt = x_p * x_t + y_p * y_t + z_p * z_t

        angle_value = dot_pt / (norm_p * norm_t)
        angle_value = tf.clip_by_value(angle_value, -0.99999, 0.99999)

        loss_val = (math.acos(angle_value))

        # tf.debugging.check_numerics(
        #     loss_val, "Vse propalo", name=None
        # )
        # print(loss_val.shape)
        return loss_val
Exemplo n.º 15
0
def snake_(X, beta):

    return X + (1 / beta) * math.square(math.sin(beta * X))
Exemplo n.º 16
0
def w1(z):
    z1 = z[:, 0]
    return math.sin(2 * pi * z1 / 4)
Exemplo n.º 17
0
    def sinusoids(self, t, c1, c2=1):
        sig =tf_math.scalar_mul( c2 , tf_math.sin(2 * math.pi * 10 * c1 * t) )

        return sig
Exemplo n.º 18
0
def func_upper_y(x):
    return -sin(constant(math.pi) * x) * sin(constant(math.pi))
Exemplo n.º 19
0
def func_upper_x(y):
    return -sin(constant(math.pi) * y) * sin(constant(math.pi))
Exemplo n.º 20
0
def integralSi_costk_costl(x, limits, norm_range , params , model):
    phi = x.unstack_x()
    S3 = params['S3']
    S9 = params['S9']
    return 9./(32 * 3.14159265) * ( 4.0/9.0 + 1/18.0*2*S3*cos(2*phi)*2*2 + 1/9.0*S9*sin(2*phi)*2*2 ) * (2 * 2)
Exemplo n.º 21
0
def integralSi_costk(x, limits, norm_range, params, model):
    costl, phi = x.unstack_x()
    Fl = params['Fl']
    S3 = params['S3']
    S9 = params['S9']
    AFB = params['AFB']
    L00 = assoc_legendre_tf(0,0,costl)
    L10 = assoc_legendre_tf(1,0,costl)
    L20 = assoc_legendre_tf(2,0,costl)
    L22 = assoc_legendre_tf(2,2,costl)
    return 9./(32 * 3.14159265) * ( (4.0/9.0)*L00 + (2.0/9.0-2.0*Fl/3.0)*L20 + (4.0/3.0)*(3.0/2.0)*AFB*L10 + 1/18.0*2*S3*L22*cos(2*phi)*2 + 1/9.0*S9*L22*sin(2*phi)*2) * (2)
Exemplo n.º 22
0
def integralSi_costl(x, limits, norm_range, params, model):
    costk, phi = x.unstack_x()
    Fl = params['Fl']
    S3 = params['S3']
    S9 = params['S9']
    S5 = params['S5']
    S7 = params['S7']    
    K00 = assoc_legendre_tf(0,0,costk)
    K20 = assoc_legendre_tf(2,0,costk)
    K21 = assoc_legendre_tf(2,1,costk)
    K22 = assoc_legendre_tf(2,2,costk)
    return 9./(32 * 3.14159265) * ( (4.0/9.0)*K00 + (4.0*Fl/3.0-4.0/9.0)*K20 + 1/18.0*2*S3*K22*cos(2*phi)*2 + 1/9.0*S9*K22*sin(2*phi)*2 + (2.0/3.0)*S5*K21*cos(phi)*pi/4 + (-2.0/3.0)*S7*K21*sin(phi)*pi/4 ) * (2)