梯度下降法pytorch寻找superoscillation wx最新的2020-9-27useful

本文通过PyTorch介绍了如何利用梯度下降法在深度学习中寻找superoscillation现象,结合2020年9月27日的最新进展,为读者提供实用的深度学习优化技巧。
摘要由CSDN通过智能技术生成
import numpy as np
import torch
def def_k_coefficient( k_shape ):
    # 定义系数的尺寸,随机初始化系数
    k_coefficient_real_img =  np.random.rand(k_shape,2)

    # k_coefficient_img   =  np.random.rand(k_shape,1)
    # 返回值是k系数的实数部和虚数部,都是(40,1)的尺寸
    # 若要求最终的系数,可采取k_sum = k_coefficient_real*1.0 + k_coefficient_img*(1j)
    return k_coefficient_real_img # 40,2系数  80个参数

def trans_3_27_to_esum(all_point,mode_temp01_tensor , mode_temp_tensor):
    # 最后的结果想干叠加后的结果 是 3,27
    # 输入是 3,27,2
    # 返回结果是27,1 ,
    import numpy as np

    # a 3   b 27 , 2
    all_point = (all_point)

    mode_fengliang , number_of_points  ,shibu_xubu = all_point.shape
    # 3,27,1
    # mode_temp01_tensor = torch.zeros(size = (mode_fengliang, number_of_points,1),dtype=torch.float64)
    # mode_temp_tensor = torch.zeros(size = (1, number_of_points),dtype= torch.float64)

    for a1 in range(number_of_points): # 27
        for a2 in range(mode_fengliang): # 3

            mode_temp01_tensor[a2 , a1, 0 ] = torch.sqrt( (mode_temp01_tensor[a2 , a1, 0 ])**2 +(all_point[a2,a1,0])**2)

    for a1 in range(number_of_points):
        for a3 in range(mode_fengliang):
            # 3,27,1
            mode_temp_tensor[0,a1] = mode_temp_tensor[0,a1] +(mode_temp01_tensor[a3 , a1, 0 ] )**2
    # 返回值为27,1.实数矩阵
    mode_temp_tensor =mode_temp_tensor.view(number_of_points,1) # 返回值为27,1
    return  mode_temp_tensor

def distanceFrom_A_To_B(array1 ,array2 ):
    import numpy as np
    # 加一个调整系数 ,中间为1 的数值很重要
    # 此处的是27,1和27,1的系数差距
    rows ,cols = (array1.shape)
    sum =torch.tensor(0.0,dtype=torch.float64)
    for row in range(rows):
        temp_sum = array1[row ,0 ] - array2[row ,0]
        sum = sum + temp_sum**2
    sum = sum *1.0
    return  sum



def def_the_want_point_value( preSETpoint_number = 27 ,middle_point_intensity = 1):
    # 设置27个点,中心点强度设置为1
    temp  = np.zeros(shape = (preSETpoint_number,1) )
    #  中心点强度设置
    temp[0,0] = middle_point_intensity
    wanted_point = np.resize(np.array(temp), preSETpoint_number)
    # 得到[27,1]的矩阵
    print(wanted_point)
    # 27,1的实数矩阵
    return  wanted_point


def zuobiaoGet(middle_point,zhongxingdianqiangdu,banfenkuang_int):
    # 返回值是 27个点的坐标位置信息(x,y)---
    zuobiao = [(middle_point, middle_point)]
    result_wanted = [zhongxingdianqiangdu]  # 中心点强度设置

    # 预设结果初始化,想要得到的结果: (27,1)结果   (坐标为)(27个点)
    for i in range(banfenkuang_int, 3 * banfenkuang_int, 1):
        result_wanted.append(0.0)
        zuobiao_x = middle_point
        zuobiao_y = middle_point + i
        zuobiao.append((zuobiao_x, zuobiao_y))
    print(zuobiao)
    length = len(result_wanted)
    result_wanted = np.array(result_wanted)
    result_wanted = np.resize(result_wanted,new_shape=(length,1))
    return  zuobiao ,result_wanted


def 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值