コード例 #1
0
def build_(method=1, beta=None):
    tf.reset_default_graph()
    # Training
    if method == 1:
        classifier = DBN(
            hidden_act_func=['tanh', 'gauss'],
            output_act_func='affine',
            loss_func='mse',  # gauss 激活函数会自动转换为 mse 损失函数
            struct=[
                x_dim, x_dim * 40, x_dim * 20, x_dim * 10, x_dim * 2, y_dim
            ],
            lr=1e-4,
            use_for='prediction',
            bp_algorithm='rmsp',
            epochs=240,
            batch_size=32,
            dropout=0.08,
            units_type=['gauss', 'gauss'],
            rbm_lr=1e-4,
            rbm_epochs=60,
            cd_k=1,
            pre_train=True)
    elif method == 2:
        classifier = supervised_sAE(
            output_func='gauss',
            hidden_func='affine',
            loss_func='mse',
            struct=[
                x_dim, x_dim * 40, x_dim * 20, x_dim * 10, x_dim * 2, y_dim
            ],
            lr=1e-4,
            use_for='prediction',
            epochs=180,
            batch_size=32,
            dropout=0.15,
            ae_type='sae',  # ae | dae | sae
            act_type=[
                'gauss', 'affine'
            ],  # decoder:[sigmoid] with ‘cross_entropy’ | [affine] with ‘mse’
            noise_type='mn',  # Gaussian noise (gs) | Masking noise (mn)
            beta=beta,  # DAE:噪声损失系数 | SAE:稀疏损失系数 | YAE:Y系数比重
            p=0.1,  # DAE:样本该维作为噪声的概率 | SAE稀疏性参数:期望的隐层平均活跃度(在训练批次上取平均)
            ae_lr=1e-4,
            ae_epochs=60,
            pre_train=True)
    return classifier
コード例 #2
0
def run_(method=1, beta=None):
    tf.reset_default_graph()
    # Training
    if method == 1:
        classifier = DBN(
            hidden_act_func='gauss',
            output_act_func='gauss',
            loss_func='mse',  # gauss 激活函数会自动转换为 mse 损失函数
            struct=[x_dim, y_dim * 20, y_dim * 10, y_dim],
            # struct=[x_dim, int(x_dim/2), int(x_dim/4), int(x_dim/8), y_dim],
            lr=1e-4,
            use_for='classification',
            bp_algorithm='rmsp',
            epochs=240,
            batch_size=16,
            dropout=0.05,
            units_type=['gauss', 'gauss'],
            rbm_lr=1e-4,
            rbm_epochs=45,
            cd_k=1,
            pre_train=True)
    elif method == 2:
        classifier = supervised_sAE(
            output_func='gauss',
            hidden_func='gauss',
            loss_func='mse',
            struct=[x_dim, y_dim * 60, y_dim * 30, y_dim * 10, y_dim],
            lr=1e-4,
            use_for='classification',
            epochs=240,
            batch_size=32,
            dropout=0.34,
            ae_type='yae',  # ae | dae | sae
            act_type=[
                'gauss', 'affine'
            ],  # decoder:[sigmoid] with ‘cross_entropy’ | [affine] with ‘mse’
            noise_type='mn',  # Gaussian noise (gs) | Masking noise (mn)
            beta=beta,  # DAE:噪声损失系数 | SAE:稀疏损失系数 | YAE:Y系数比重
            p=0.3,  # DAE:样本该维作为噪声的概率 | SAE稀疏性参数:期望的隐层平均活跃度(在训练批次上取平均)
            ae_lr=1e-4,
            ae_epochs=30,
            pre_train=True)

    run_sess(classifier, datasets, filename, load_saver='')
    return classifier
コード例 #3
0
        epochs=20,
        img_shape=[p_dim, p_dim],
        channels=[1, 6, 6, 64, y_dim],  # 前几维给 ‘Conv’ ,后几维给 ‘Full connect’
        layer_tp=['C', 'P', 'C', 'P'],
        fsize=[[4, 4], [3, 3]],
        ksize=[[2, 2], [2, 2]],
        batch_size=32,
        dropout=0.2)
if select_case == 3:
    classifier = supervised_sAE(
        output_func='softmax',
        hidden_func='sigmoid',
        loss_func='cross_entropy',
        struct=[x_dim, 400, 200, 100, y_dim],
        lr=1e-3,
        use_for='classification',
        epochs=10,
        batch_size=32,
        dropout=0.12,
        ae_type='ae',  # ae | dae | sae
        act_type=[
            'sigmoid', 'sigmoid'
        ],  # decoder:[sigmoid] with ‘cross_entropy’ | [affine] with ‘mse’
        noise_type='mn',  # Gaussian noise (gs) | Masking noise (mn)
        beta=0.5,  # DAE:噪声损失系数 | SAE:稀疏损失系数
        p=0.3,  # DAE:样本该维作为噪声的概率 / SAE稀疏性参数:期望的隐层平均活跃度(在训练批次上取平均)
        ae_lr=1e-3,
        ae_epochs=5,
        pre_train=True)
run_sess(classifier, datasets, filename, load_saver='')
label_distribution = classifier.label_distribution
コード例 #4
0
        img_shape=[p_dim, p_dim],
        channels=[1, 6, 6, 64, y_dim],  # 前几维给 ‘Conv’ ,后几维给 ‘Full connect’
        layer_tp=['C', 'P', 'C', 'P'],
        fsize=[[4, 4], [3, 3]],
        ksize=[[2, 2], [2, 2]],
        batch_size=32,
        dropout=1)
if select_case == 3:
    classifier = supervised_sAE(
        out_func='softmax',
        en_func='affine',  # encoder:[sigmoid] | [affine] 
        use_for='classification',
        loss_func=
        'mse',  # decoder:[sigmoid] with ‘cross_entropy’ | [affine] with ‘mse’
        ae_type='ae',  # ae | dae | sae
        noise_type='gs',  # Gaussian noise (gs) | Masking noise (mn)
        beta=0.6,  # 惩罚因子权重(KL项 | 非噪声样本项)
        p=0.01,  # DAE:样本该维作为噪声的概率 / SAE稀疏性参数:期望的隐层平均活跃度(在训练批次上取平均)
        sup_ae_struct=[x_dim, 200, 50, y_dim],
        sup_ae_epochs=100,
        ae_epochs=30,
        batch_size=32,
        ae_lr=1e-3,
        dropout=1)

Initializer.sess_init_all(sess)  # 初始化变量
summ = Summaries(os.path.basename(__file__), sess=sess)
classifier.train_model(X_train, Y_train, sess, summ)

# Test
print("[Test data...]")
Y_pred = classifier.test_model(X_test, Y_test, sess)
コード例 #5
0
    p_dim = int(np.sqrt(x_dim))

    tf.reset_default_graph()
    # Training
    select_case = 3
    if select_case == 3:
        classifier = supervised_sAE(
            output_func='softmax',
            hidden_func='sigmoid',  # encoder:[sigmoid] | [affine]
            use_for='classification',
            loss_func=
            'cross_entropy',  # decoder:[sigmoid] with ‘cross_entropy’ | [affine] with ‘mse’
            struct=[196, 2000, 2000, 2],
            lr=1e-3,
            epochs=1645,
            batch_size=1024,
            dropout=0.01,
            ae_type='ae',  # ae | dae | sae
            act_type=['sigmoid', 'affine'],
            noise_type='mn',  # Gaussian n oise (gs) | Masking noise (mn)
            beta=0.25,  # 惩罚因子权重(KL项 | 非噪声样本项)
            p=0.5,  # DAE:样本该维作为噪声的概率 / SAE稀疏性参数:期望的隐层平均活跃度(在训练批次上取平均)
            ae_lr=1e-3,
            ae_epochs=2000,
            pre_train=True)
    # run_sess(classifier,datasets,filename,load_saver='')#验证
    # print("***********************")
    run_sess(classifier, datasets1, filename, load_saver='f')  # 测试
    # label_distribution = classifier.label_distribution
    # data = pd.read_csv(r"D:\gao\jinzhou\code1\saver\label_distribution.csv")
    # data.to_csv(r"D:\gao\jinzhou\code1\saver\label_distribution_2_"+str(units[i])+"_"+str(random[j])+".csv",sep=",",index=False)