├── DAN ├── DAN.py ├── MyNet.py ├── data_loader.py ├── mmd.py ├── source_datasets_Eq_shuffle.mat └── target_datasets_Eq_shuffle.mat ├── DANN ├── CNN1d.py ├── D_res_test_a-w.csv ├── D_res_train_a-w.csv ├── Generate_datasets.m ├── MyCNN.py ├── __pycache__ │ ├── CNN1d.cpython-37.pyc │ ├── data_loader.cpython-37.pyc │ └── mmd_pytorch.cpython-37.pyc ├── data_loader.py ├── generate.m ├── main.py ├── mmd.py ├── mmd_pytorch.py ├── pytorch搭建卷积迁移模型.docx ├── res_test_a-w.csv ├── res_train_a-w.csv ├── source_datasets.mat ├── source_datasets_D.mat ├── target_datasets.mat ├── target_datasets_D.mat └── 备注.txt ├── LICENSE └── README.md /DAN/DAN.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import math 4 | import numpy as np 5 | import torch 6 | import torch.nn.functional as F 7 | from torch.autograd import Variable 8 | 9 | import MyNet 10 | import data_loader 11 | 12 | DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu') 13 | 14 | # Training settings 15 | Classes = 4 16 | batch_size = 100 17 | lr = 0.01 18 | # 设置随机种子 19 | seed = 16 20 | torch.manual_seed(seed) 21 | if torch.cuda.is_available(): 22 | torch.cuda.manual_seed(seed) 23 | 24 | # momentum = 0.9 25 | momentum = 2 26 | l2_decay = 5e-4 27 | # l2_decay = 1e-4 28 | 29 | # src_dir = './source_datasets_UN.mat' 30 | # tar_dir = './target_datasets_UN.mat' 31 | 32 | src_dir = './source_datasets_Eq_shuffle_HHT.mat' 33 | tar_dir = './target_datasets_Eq_shuffle_HHT.mat' 34 | 35 | src_name = "source_data_train" 36 | tgt_train_name = "target_data_train" 37 | tgt_test_name = "target_data_test" 38 | 39 | src_loader = data_loader.load_training(src_dir, src_name, batch_size) 40 | tgt_train_loader = data_loader.load_training(tar_dir, tgt_train_name, batch_size) 41 | tgt_test_loader = data_loader.load_testing(tar_dir, tgt_train_name, batch_size) 42 | 43 | src_dataset_len = len(src_loader.dataset) 44 | tgt_train_dataset_len = len(tgt_train_loader.dataset) 45 | tgt_test_dataset_len = len(tgt_test_loader.dataset) 46 | src_loader_len = len(src_loader) 47 | tgt_loader_len = len(tgt_train_loader) 48 | 49 | print('源域训练集个数:%d'%src_dataset_len) 50 | print('目标域训练集个数:%d'%tgt_train_dataset_len) 51 | print('源域训练集个数:%d'%tgt_test_dataset_len) 52 | 53 | print("源域批次个数:%d"%src_loader_len) 54 | print("目标域批次个数:%d"%tgt_loader_len) 55 | 56 | # 设置迭代次数iteration和训练完一次所有数据(log_interval批)展示一下损失值 57 | log_interval = src_loader_len 58 | iteration = 1000*src_loader_len 59 | RESULT_Test = [] 60 | 61 | 62 | def train(model): 63 | src_iter = iter(src_loader) 64 | tgt_iter = iter(tgt_train_loader) 65 | correct = 0 66 | for i in range(1, iteration + 1): 67 | model.train() 68 | # LEARNING_RATE = lr 69 | LEARNING_RATE = lr / math.pow((1 + 10 * (i - 1) / (iteration)), 0.75) 70 | if (i - 1) % (10*log_interval) == 0: 71 | print('learning rate{: .4f}'.format(LEARNING_RATE)) 72 | 73 | # optimizer = torch.optim.SGD([ 74 | # {'params': model.sharedNet.parameters()}, 75 | # {'params': model.cls_fc.parameters(), 'lr': LEARNING_RATE}, 76 | # ], lr=LEARNING_RATE / 10, momentum=momentum, weight_decay=l2_decay) 77 | 78 | optimizer = torch.optim.SGD([ 79 | {'params': model.featureCap.parameters()}, 80 | {'params': model.fc2.parameters(), 'lr': LEARNING_RATE}, 81 | ], lr=LEARNING_RATE / 10, momentum=momentum, weight_decay=l2_decay,nesterov=True) 82 | 83 | # optimizer = torch.optim.SGD( 84 | # model.parameters(), lr=LEARNING_RATE , momentum=momentum, weight_decay=l2_decay, nesterov=True) 85 | 86 | # optimizer = torch.optim.Adamax([ 87 | # {'params': model.featureCap.parameters()}, 88 | # {'params': model.fc2.parameters(), 'lr': LEARNING_RATE}, 89 | # ], lr=LEARNING_RATE / 10, weight_decay=l2_decay) 90 | 91 | try: 92 | src_data, src_label = src_iter.next() 93 | except Exception as err: 94 | src_iter = iter(src_loader) 95 | src_data, src_label = src_iter.next() 96 | 97 | try: 98 | tgt_data, _ = tgt_iter.next() 99 | except Exception as err: 100 | tgt_iter = iter(tgt_train_loader) 101 | tgt_data, _ = tgt_iter.next() 102 | 103 | if torch.cuda.is_available(): 104 | src_data, src_label = src_data.cuda(), src_label.cuda() 105 | tgt_data = tgt_data.cuda() 106 | # print(src_data.shape) 107 | optimizer.zero_grad() 108 | src_pred, mmd_loss = model(src_data, tgt_data) 109 | 110 | cls_loss = F.nll_loss(F.log_softmax(src_pred, dim=1), src_label) 111 | 112 | lambd = 2 / (1 + math.exp(-10 * (i) / iteration)) - 1 113 | # lambd = 10 114 | loss = cls_loss + lambd * mmd_loss 115 | loss.backward() 116 | optimizer.step() 117 | 118 | # 每隔10次显示一次损失值 119 | if i % log_interval == 0: 120 | print('Train iter: {} [({:.0f}%)]\tLoss: {:.6f}\tsoft_Loss: {:.6f}\tmmd_Loss: {:.6f}'.format( 121 | i, 100. * i / iteration, loss.item(), cls_loss.item(), mmd_loss.item())) 122 | 123 | # 每隔10*20次计算目标域测试集准确率,并更新迁移学习的最大准确率 124 | if i % (log_interval * 20) == 0: 125 | t_correct = test(model) 126 | if t_correct > correct: 127 | correct = t_correct 128 | print('src: {} to tgt: {} max correct: {} max accuracy{: .2f}%\n'.format( 129 | src_name, tgt_train_name, correct, 100. * correct / tgt_test_dataset_len)) 130 | # RESULT_Train.append(100. * correct / tgt_dataset_len) 131 | 132 | 133 | def test(model): 134 | model.eval() 135 | test_loss = 0 136 | correct = 0 137 | with torch.no_grad(): 138 | for tgt_test_data, tgt_test_label in tgt_test_loader: 139 | 140 | if torch.cuda.is_available(): 141 | tgt_test_data, tgt_test_label = tgt_test_data.cuda(), tgt_test_label.cuda() 142 | 143 | tgt_test_data, tgt_test_label = Variable(tgt_test_data), Variable(tgt_test_label) 144 | 145 | tgt_pred, mmd_loss = model(tgt_test_data, tgt_test_data) 146 | 147 | test_loss += F.nll_loss(F.log_softmax(tgt_pred, dim=1), tgt_test_label, 148 | reduction='sum').item() # sum up batch loss 149 | 150 | pred = tgt_pred.data.max(1)[1] # get the index of the max log-probability 151 | correct += pred.eq(tgt_test_label.data.view_as(pred)).cpu().sum() 152 | 153 | test_loss /= tgt_test_dataset_len 154 | print('\n{} set: Average loss: {:.4f}, Accuracy: {}/{} ({:.2f}%)\n'.format( 155 | tgt_test_name, test_loss, correct, tgt_test_dataset_len, 100. * correct / tgt_test_dataset_len)) 156 | 157 | RESULT_Test.append(100. * correct / tgt_test_dataset_len) 158 | return correct 159 | 160 | 161 | if __name__ == '__main__': 162 | # model = models.DANNet(num_classes=31) 163 | model = MyNet.CNN1d(n_hidden=120, n_class=Classes) 164 | print(model) 165 | model = model.to(DEVICE) 166 | train(model) 167 | res_test = np.asarray(RESULT_Test) 168 | 169 | 170 | # np.savetxt('test_acc_UN.csv', res_test, fmt='%.6f ', delimiter=',') 171 | np.savetxt('test_acc_Eq_HHT.csv', res_test, fmt='%.6f ', delimiter=' ') 172 | -------------------------------------------------------------------------------- /DAN/MyNet.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | import mmd 3 | # m = nn.Conv1d(in_channels=Ci, out_channels=Co, kernel_size=K, stride=s) = output[N,Co,Lo] 4 | 5 | # 正常卷积层输出大小计算方法: 6 | # 其中Lo = [(Li-(K-1)+1)/s]+1 向下取整 7 | 8 | class CNN1d(nn.Module): 9 | def __init__(self,n_hidden=60 ,n_class=3): 10 | 11 | super(CNN1d, self).__init__() 12 | 13 | self.featureCap = nn.Sequential( 14 | nn.Conv1d(in_channels=1, out_channels=30, kernel_size=16, stride=2), 15 | nn.BatchNorm1d(30), 16 | nn.ReLU(), 17 | nn.MaxPool1d(2), 18 | # [~,20,256] -> [480,32,128] 19 | nn.Conv1d(in_channels=30, out_channels=20, kernel_size=8, stride=2), 20 | nn.BatchNorm1d(20), 21 | nn.ReLU(), 22 | nn.MaxPool1d(2) 23 | # [480,8,125] -> [480,8,62] 24 | ) 25 | 26 | # self.fc1 = nn.Linear(680 ,n_hidden) 27 | self.fc1 = nn.Linear(560 ,n_hidden) 28 | self.fc2 = nn.Linear(n_hidden, n_class) 29 | # self.sigmoid = nn.Sigmoid() 30 | 31 | 32 | 33 | def forward(self, src, tar): 34 | loss = 0 35 | x_src = self.featureCap(src) 36 | 37 | x_src_mmd = x_src.view(x_src.size(0), -1) 38 | # 这里为了设置全连接层的输入神经元个数,故需要展示平坦层的特征数(=全连接层输入神经元个数) 39 | # print(x_src_mmd.size(1)) 40 | 41 | if self.training == True: 42 | x_tar = self.featureCap(tar) 43 | 44 | x_tar_mmd = x_tar.view(x_tar.size(0), -1) 45 | #loss += mmd.mmd_rbf_accelerate(source, target) 46 | loss += mmd.mmd_rbf_noaccelerate(x_src_mmd, x_tar_mmd) 47 | 48 | y_src = self.fc1(x_src_mmd) 49 | y_src = self.fc2(y_src) 50 | #target = self.cls_fc(target) 51 | 52 | return y_src, loss 53 | 54 | 55 | -------------------------------------------------------------------------------- /DAN/data_loader.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from torch.utils.data import TensorDataset,DataLoader 3 | import scipy.io as io 4 | 5 | 6 | def load_training(root_dir,domain,batch_size): 7 | df_data = io.loadmat(root_dir) 8 | datas = df_data[domain] 9 | # 将数据转变成 Tensor 类型 10 | x, y= torch.from_numpy(datas[:, 1:]).type(torch.FloatTensor).cuda(), torch.from_numpy(datas[:, 0:1]).type(torch.LongTensor).cuda() 11 | 12 | data = x.unsqueeze(1) # 将数据增加维度变为 [batch_size, 1, n_length] 13 | label= y.squeeze() # 将标签的维度减少 [batch_size,1] -> [batch_size] 14 | # 这里这样做的原因: 15 | # 1.y_pred是classes的 OneHot编码方式 16 | # 2.label必须是[0, #classes] 区间的一个数字 17 | 18 | data_set = TensorDataset(data, label) # 输入变量在前,输出变量在后 19 | # 采用 DataLoader 封装 data_set 即可得到能够用于训练神经网络的 data_loader 20 | data_loader = DataLoader(dataset=data_set ,batch_size=batch_size, shuffle=False, num_workers=0, drop_last=True) 21 | 22 | return data_loader 23 | 24 | def load_testing(root_dir,domain,batch_size): 25 | df_data = io.loadmat(root_dir) 26 | datas = df_data[domain] 27 | # 将数据转变成 Tensor 类型 28 | x, y = torch.from_numpy(datas[:, 1:]).type(torch.FloatTensor).cuda(), torch.from_numpy(datas[:, 0:1]).type(torch.LongTensor).cuda() 29 | 30 | data = x.unsqueeze(1) # 将数据增加维度变为 [batch_size, 1, n_length] 31 | label = y.squeeze() # 将标签的维度减少 [batch_size,1] -> [batch_size] 32 | 33 | data_set = TensorDataset(data, label) # 输入变量在前,输出变量在后 34 | # 采用 DataLoader 封装 data_set 即可得到能够用于训练神经网络的 data_loader 35 | data_loader = DataLoader(dataset=data_set, batch_size=batch_size, shuffle=False, num_workers=0, drop_last=True) 36 | 37 | return data_loader 38 | # # 39 | if __name__ == '__main__': 40 | src_dir = './source_datasets_Eq_shuffle.mat' 41 | tar_dir = './target_datasets_Eq_shuffle.mat' 42 | 43 | src_name = "source_data_train" 44 | tgt_train_name = "target_data_train" 45 | tgt_test_name = "target_data_test" 46 | torch.manual_seed(1) 47 | data_src = load_training(root_dir=src_dir, domain=src_name, batch_size=30) 48 | tgt_train_loader = load_training(tar_dir, tgt_train_name, batch_size=30) 49 | tgt_test_loader = load_testing(tar_dir, tgt_test_name, batch_size=30) 50 | 51 | for i_batch, batch_data in enumerate(data_src): 52 | if i_batch < 1: 53 | data, label = batch_data 54 | print(i_batch) # 打印batch编号 55 | print(label) 56 | else: 57 | 58 | break 59 | print("======================") 60 | for i_batch, batch_data in enumerate(tgt_train_loader): 61 | if i_batch < 1: 62 | data, label = batch_data 63 | print(i_batch) # 打印batch编号 64 | print(label) 65 | else: 66 | 67 | break 68 | 69 | # for i_batch, batch_data in enumerate(tgt_test_loader): 70 | # if i_batch < 4: 71 | # data, label = batch_data 72 | # print(i_batch) # 打印batch编号 73 | # print(label) 74 | # else: 75 | # 76 | # break -------------------------------------------------------------------------------- /DAN/mmd.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # encoding: utf-8 3 | 4 | import torch 5 | 6 | def guassian_kernel(source, target, kernel_mul=2.0, kernel_num=5, fix_sigma=None): 7 | n_samples = int(source.size()[0])+int(target.size()[0]) 8 | total = torch.cat([source, target], dim=0) 9 | total0 = total.unsqueeze(0).expand(int(total.size(0)), int(total.size(0)), int(total.size(1))) 10 | total1 = total.unsqueeze(1).expand(int(total.size(0)), int(total.size(0)), int(total.size(1))) 11 | L2_distance = ((total0-total1)**2).sum(2) 12 | if fix_sigma: 13 | bandwidth = fix_sigma 14 | else: 15 | bandwidth = torch.sum(L2_distance.data) / (n_samples**2-n_samples) 16 | bandwidth /= kernel_mul ** (kernel_num // 2) 17 | bandwidth_list = [bandwidth * (kernel_mul**i) for i in range(kernel_num)] 18 | kernel_val = [torch.exp(-L2_distance / bandwidth_temp) for bandwidth_temp in bandwidth_list] 19 | return sum(kernel_val)#/len(kernel_val) 20 | 21 | 22 | def mmd_rbf_accelerate(source, target, kernel_mul=2.0, kernel_num=5, fix_sigma=None): 23 | batch_size = int(source.size()[0]) 24 | kernels = guassian_kernel(source, target, 25 | kernel_mul=kernel_mul, kernel_num=kernel_num, fix_sigma=fix_sigma) 26 | loss = 0 27 | for i in range(batch_size): 28 | s1, s2 = i, (i+1)%batch_size 29 | t1, t2 = s1+batch_size, s2+batch_size 30 | loss += kernels[s1, s2] + kernels[t1, t2] 31 | loss -= kernels[s1, t2] + kernels[s2, t1] 32 | return loss / float(batch_size) 33 | 34 | def mmd_rbf_noaccelerate(source, target, kernel_mul=2.0, kernel_num=5, fix_sigma=None): 35 | batch_size = int(source.size()[0]) 36 | kernels = guassian_kernel(source, target, 37 | kernel_mul=kernel_mul, kernel_num=kernel_num, fix_sigma=fix_sigma) 38 | XX = kernels[:batch_size, :batch_size] 39 | YY = kernels[batch_size:, batch_size:] 40 | XY = kernels[:batch_size, batch_size:] 41 | YX = kernels[batch_size:, :batch_size] 42 | loss = torch.mean(XX + YY - XY -YX) 43 | return loss 44 | 45 | -------------------------------------------------------------------------------- /DAN/source_datasets_Eq_shuffle.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CadeHu/Transfer-Learning/28be451893cee0486132f53fddc7ab7778648303/DAN/source_datasets_Eq_shuffle.mat -------------------------------------------------------------------------------- /DAN/target_datasets_Eq_shuffle.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CadeHu/Transfer-Learning/28be451893cee0486132f53fddc7ab7778648303/DAN/target_datasets_Eq_shuffle.mat -------------------------------------------------------------------------------- /DANN/CNN1d.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | 3 | # m = nn.Conv1d(in_channels=Ci, out_channels=Co, kernel_size=K, stride=s) = output[N,Co,Lo] 4 | 5 | # 正常卷积层输出大小计算方法: 6 | # 其中Lo = [(Li-(K-1)+1)/s]+1 向下取整 7 | 8 | class CNN1d(nn.Module): 9 | def __init__(self,n_hidden=160 ,n_class=12): 10 | 11 | super(CNN1d, self).__init__() 12 | 13 | self.layer1 = nn.Sequential( 14 | # [480,1,2048] -> [480,32,256] 15 | nn.Conv1d(in_channels=1, out_channels=40, kernel_size=32, stride=2), 16 | nn.BatchNorm1d(40), 17 | nn.ReLU(), 18 | # [480,32,256] -> [480,32,128] 19 | nn.MaxPool1d(2) 20 | ) 21 | 22 | self.layer2 = nn.Sequential( 23 | # [480,32,128] -> [480,8,125] 24 | nn.Conv1d(in_channels=40, out_channels=20, kernel_size=16, stride=2), 25 | nn.BatchNorm1d(20), 26 | nn.ReLU(), 27 | # [480,8,125] -> [480,8,62] 28 | nn.MaxPool1d(2) 29 | ) 30 | 31 | self.fc1 = nn.Linear(2380 ,n_hidden) 32 | self.fc2 = nn.Linear(n_hidden, n_class) 33 | self.sigmoid = nn.Sigmoid() 34 | 35 | def forward(self, src,tar): 36 | # input.shape:(N,1,n_input) 37 | x_src = self.layer1(src) 38 | x_src = self.layer2(x_src) 39 | # print(x_src.size()) 40 | x_src_mmd = x_src.view(x_src.size(0), -1) 41 | # 这里为了设置全连接层的输入神经元个数,故需要展示平坦层的特征数(=全连接层输入神经元个数) 42 | # print(x_src_mmd.size(1)) 43 | 44 | x_tar = self.layer1(tar) 45 | x_tar = self.layer2(x_tar) 46 | x_tar_mmd = x_tar.view(x_tar.size(0), -1) 47 | 48 | 49 | y_src = self.fc1(x_src_mmd) 50 | y_src = self.fc2(y_src) 51 | y_src = self.sigmoid(y_src) 52 | 53 | return y_src,x_src_mmd,x_tar_mmd 54 | 55 | -------------------------------------------------------------------------------- /DANN/D_res_test_a-w.csv: -------------------------------------------------------------------------------- 1 | 1,51.303932,35.171261,33.333332 2 | 2,43.157619,32.748539,33.751045 3 | 3,42.225304,33.166248,32.414368 4 | 4,45.144947,33.333332,32.832081 5 | 5,43.330276,33.667503,47.953217 6 | 6,46.492252,33.166248,56.056808 7 | 7,41.388725,62.071846,65.831245 8 | 8,40.096046,63.909775,63.826233 9 | 9,42.198574,61.82122,64.076859 10 | 10,41.444786,64.494568,67.000839 11 | 11,42.72398,60.484543,74.770256 12 | 12,44.648975,52.548038,77.109444 13 | 13,47.649712,52.213867,90.476189 14 | 14,45.818607,48.538013,96.073517 15 | 15,50.367077,31.746031,96.240601 16 | 16,43.435158,61.570595,96.240601 17 | 17,49.06324,35.923141,96.240601 18 | 18,46.384026,51.963242,96.073517 19 | 19,49.364208,36.925648,96.240601 20 | 20,51.953293,25.56391,96.240601 21 | 21,42.660294,63.241436,96.240601 22 | 22,46.230392,57.142857,96.157059 23 | 23,43.44524,61.152882,95.989975 24 | 24,46.857079,49.122807,96.240601 25 | 25,47.602493,43.358395,96.240601 26 | 26,46.348949,50.71011,96.240601 27 | 27,47.635944,41.353382,96.240601 28 | 28,46.602547,47.284878,96.240601 29 | 29,47.220409,42.43943,96.240601 30 | 30,42.135639,64.995819,96.240601 31 | 31,44.067688,57.477024,96.240601 32 | 32,47.625977,43.609024,96.240601 33 | 33,47.032322,49.206348,96.157059 34 | 34,47.912289,39.34837,95.822891 35 | 35,46.70079,49.456974,96.157059 36 | 36,48.433338,40.10025,96.240601 37 | 37,45.53289,51.545532,96.240601 38 | 38,44.915005,53.80117,96.240601 39 | 39,46.19857,48.036758,96.240601 40 | 40,48.717903,35.672516,96.157059 41 | 41,43.026131,61.319965,95.989975 42 | 42,41.964775,64.57811,96.240601 43 | 43,47.719112,42.105263,96.240601 44 | 44,44.983551,53.717628,96.240601 45 | 45,44.675365,53.634087,96.240601 46 | 46,47.109772,46.282372,96.240601 47 | 47,44.050354,57.30994,96.240601 48 | 48,47.155052,45.530495,96.240601 49 | 49,52.630829,33.751045,96.240601 50 | 50,44.952469,54.21888,96.240601 51 | 51,44.409351,59.398495,96.240601 52 | 52,44.29982,53.80117,96.240601 53 | 53,44.804741,55.38847,96.240601 54 | 54,44.418808,55.806183,96.240601 55 | 55,49.384987,38.93066,96.157059 56 | 56,44.347729,56.892231,96.073517 57 | 57,44.246311,56.808689,96.157059 58 | 58,45.026508,52.380951,96.240601 59 | 59,43.398834,60.902256,96.240601 60 | 60,43.631741,55.38847,96.240601 61 | 61,44.065559,58.145363,96.240601 62 | 62,42.727367,62.406013,96.240601 63 | 63,45.890755,49.54052,96.240601 64 | 64,43.798782,55.472012,96.240601 65 | 65,48.951836,39.014202,96.240601 66 | 66,52.214569,36.340851,95.906433 67 | 67,52.574005,33.667503,96.157059 68 | 68,45.163441,52.297409,96.157059 69 | 69,49.939606,34.168755,96.157059 70 | 70,44.72496,52.380951,96.240601 71 | 71,46.766312,45.864662,96.240601 72 | 72,44.953159,51.044277,96.240601 73 | 73,44.572163,53.550545,96.240601 74 | 74,44.19891,54.302422,96.240601 75 | 75,46.009369,47.619049,96.240601 76 | 76,45.435814,49.791145,96.240601 77 | 77,43.34745,56.390976,96.240601 78 | 78,45.096786,51.8797,96.240601 79 | 79,43.576576,58.47953,96.240601 80 | 80,51.126186,35.923141,96.240601 81 | 81,44.16407,58.312447,95.906433 82 | 82,44.889416,52.882206,96.073517 83 | 83,51.292774,35.421886,96.240601 84 | 84,49.531734,40.685047,95.989975 85 | 85,42.082687,64.411026,96.240601 86 | 86,43.946022,56.223892,96.240601 87 | 87,49.355267,36.507938,96.157059 88 | 88,44.436344,53.550545,96.240601 89 | 89,44.407272,54.720135,96.240601 90 | 90,43.612125,56.808689,96.240601 91 | 91,44.42469,54.135338,96.240601 92 | 92,44.189587,55.38847,96.240601 93 | 93,43.219387,56.808689,96.240601 94 | 94,43.743656,57.226398,96.240601 95 | 95,42.98053,59.147869,96.240601 96 | 96,43.174084,57.644112,96.240601 97 | 97,42.997948,55.639099,96.240601 98 | 98,43.12088,58.228905,96.240601 99 | 99,44.480103,53.466999,96.240601 100 | 100,43.454353,62.823727,96.240601 101 | -------------------------------------------------------------------------------- /DANN/D_res_train_a-w.csv: -------------------------------------------------------------------------------- 1 | 1.000000,1.504514,33.333332 2 | 2.000000,1.434549,33.751045 3 | 3.000000,1.461412,32.414368 4 | 4.000000,1.475172,32.832081 5 | 5.000000,1.508087,47.953217 6 | 6.000000,1.525855,56.056808 7 | 7.000000,1.398943,65.831245 8 | 8.000000,1.263300,63.826233 9 | 9.000000,1.254044,64.076859 10 | 10.000000,1.256679,67.000839 11 | 11.000000,1.259156,74.770256 12 | 12.000000,1.273570,77.109444 13 | 13.000000,1.245816,90.476189 14 | 14.000000,1.177826,96.073517 15 | 15.000000,1.189050,96.240601 16 | 16.000000,1.191813,96.240601 17 | 17.000000,1.216078,96.240601 18 | 18.000000,1.213703,96.073517 19 | 19.000000,1.203652,96.240601 20 | 20.000000,1.221895,96.240601 21 | 21.000000,1.240840,96.240601 22 | 22.000000,1.238416,96.157059 23 | 23.000000,1.245793,95.989975 24 | 24.000000,1.261459,96.240601 25 | 25.000000,1.237581,96.240601 26 | 26.000000,1.249445,96.240601 27 | 27.000000,1.248930,96.240601 28 | 28.000000,1.269839,96.240601 29 | 29.000000,1.265831,96.240601 30 | 30.000000,1.273697,96.240601 31 | 31.000000,1.272483,96.240601 32 | 32.000000,1.246513,96.240601 33 | 33.000000,1.256207,96.157059 34 | 34.000000,1.240541,95.822891 35 | 35.000000,1.227599,96.157059 36 | 36.000000,1.283827,96.240601 37 | 37.000000,1.283287,96.240601 38 | 38.000000,1.291326,96.240601 39 | 39.000000,1.284536,96.240601 40 | 40.000000,1.286112,96.157059 41 | 41.000000,1.227916,95.989975 42 | 42.000000,1.263158,96.240601 43 | 43.000000,1.267237,96.240601 44 | 44.000000,1.297978,96.240601 45 | 45.000000,1.296803,96.240601 46 | 46.000000,1.312180,96.240601 47 | 47.000000,1.313581,96.240601 48 | 48.000000,1.314246,96.240601 49 | 49.000000,1.315823,96.240601 50 | 50.000000,1.254396,96.240601 51 | 51.000000,1.303107,96.240601 52 | 52.000000,1.289765,96.240601 53 | 53.000000,1.305733,96.240601 54 | 54.000000,1.312817,96.240601 55 | 55.000000,1.307003,96.157059 56 | 56.000000,1.298003,96.073517 57 | 57.000000,1.272041,96.157059 58 | 58.000000,1.299856,96.240601 59 | 59.000000,1.300073,96.240601 60 | 60.000000,1.324131,96.240601 61 | 61.000000,1.307621,96.240601 62 | 62.000000,1.327662,96.240601 63 | 63.000000,1.323582,96.240601 64 | 64.000000,1.338857,96.240601 65 | 65.000000,1.340675,96.240601 66 | 66.000000,1.335211,95.906433 67 | 67.000000,1.240572,96.157059 68 | 68.000000,1.254087,96.157059 69 | 69.000000,1.275457,96.157059 70 | 70.000000,1.333345,96.240601 71 | 71.000000,1.301405,96.240601 72 | 72.000000,1.323680,96.240601 73 | 73.000000,1.309767,96.240601 74 | 74.000000,1.356536,96.240601 75 | 75.000000,1.320476,96.240601 76 | 76.000000,1.330495,96.240601 77 | 77.000000,1.353234,96.240601 78 | 78.000000,1.332939,96.240601 79 | 79.000000,1.347477,96.240601 80 | 80.000000,1.350631,96.240601 81 | 81.000000,1.305003,95.906433 82 | 82.000000,1.311219,96.073517 83 | 83.000000,1.290784,96.240601 84 | 84.000000,1.270372,95.989975 85 | 85.000000,1.310443,96.240601 86 | 86.000000,1.314836,96.240601 87 | 87.000000,1.300587,96.157059 88 | 88.000000,1.310373,96.240601 89 | 89.000000,1.312962,96.240601 90 | 90.000000,1.343025,96.240601 91 | 91.000000,1.351491,96.240601 92 | 92.000000,1.350649,96.240601 93 | 93.000000,1.357551,96.240601 94 | 94.000000,1.355922,96.240601 95 | 95.000000,1.364326,96.240601 96 | 96.000000,1.370437,96.240601 97 | 97.000000,1.352417,96.240601 98 | 98.000000,1.384313,96.240601 99 | 99.000000,1.360281,96.240601 100 | 100.000000,1.347049,96.240601 101 | -------------------------------------------------------------------------------- /DANN/Generate_datasets.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CadeHu/Transfer-Learning/28be451893cee0486132f53fddc7ab7778648303/DANN/Generate_datasets.m -------------------------------------------------------------------------------- /DANN/MyCNN.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | 4 | ''' 5 | m = nn.Conv1d(in_channels=Ci, out_channels=Co, kernel_size=K, stride=s)使用介绍: 6 | 7 | 对于输入网络的数据: 8 | 9 | input=torch.randn(N,Ci,Li) 10 | 11 | 网络参数的结构: 12 | 13 | Weight[Co,Ci,K] 14 | 15 | Bias[Co] 16 | 17 | 网络输出与参数和输入之间的关系: 18 | 19 | output[N,Co,Lo] , 其中Lo = [(Li-(K-1)+1)/s]+1 向下取整 20 | 21 | Ni = 0,1,2...N-1, Coi = 0,1,2...Co-1, 22 | 23 | output[Ni][Coi][Loi] = m.bias[Coi] 24 | for i in range(m.weight.size(2)): 25 | for j in range(m.weight.size(1)): 26 | output[Ni][Coi][Loi] += m.weight[Coi][j][i] * input[Ni][j][i] 27 | 28 | 这里变换后的每个样本的特征向量(一行)output[Ni][Coi][Lo]还有待弄清楚。 29 | ''' 30 | 31 | m = nn.Conv1d(in_channels=2, out_channels=5, kernel_size=8, stride=1) 32 | print(m) 33 | print("==================") 34 | input = torch.randn(10, 10, 2) # 1 为样本个数,3为特征向量长度 , 2 为 输入通道数 35 | input = input.permute(0, 2, 1) 36 | print("样本输入大小:{}".format(input.shape)) 37 | print("==================") 38 | 39 | output = m(input) 40 | print("权值大小:{}".format(m.weight.shape)) 41 | print("偏置:{}".format(m.bias.shape)) 42 | print("==================") 43 | print("输出大小:{}".format(output.shape)) 44 | print("==================") 45 | ### 展示样本输出个别元素 及其与 输入和参数之间的关系 46 | Ni = 9 47 | Coi = 1 48 | Loi = 0 49 | print(output[Ni][Coi][Loi]) 50 | res = m.bias[Coi] 51 | for i in range(m.weight.size(2)): 52 | for j in range(m.weight.size(1)): 53 | res += m.weight[Coi][j][i] * input[Ni][j][i] 54 | print(res) 55 | 56 | # 57 | # N = 2 , K = kernel_size 58 | # Ci = 2, Co = 5 59 | # Li = 5, Lo = ((5-(2-1)-1)/2) + 1 = 2 60 | # input[N,Ci,Li] = [2,2,5] 61 | # output[N,Co,Lo] = [2,5,2] 62 | # weight[Co,Ci,K] = [5,2,2] 63 | # bias [5] 64 | # output[0][0][0] = (m.weight[0][0][0] * input[0][0][0] + m.weight[0][0][1] * input[0][0][1] 65 | # m.weight[0][1][0] * input[0][1][0] + m.weight[0][1][1] * input[0][1][1] + m.bias[0]) -------------------------------------------------------------------------------- /DANN/__pycache__/CNN1d.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CadeHu/Transfer-Learning/28be451893cee0486132f53fddc7ab7778648303/DANN/__pycache__/CNN1d.cpython-37.pyc -------------------------------------------------------------------------------- /DANN/__pycache__/data_loader.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CadeHu/Transfer-Learning/28be451893cee0486132f53fddc7ab7778648303/DANN/__pycache__/data_loader.cpython-37.pyc -------------------------------------------------------------------------------- /DANN/__pycache__/mmd_pytorch.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CadeHu/Transfer-Learning/28be451893cee0486132f53fddc7ab7778648303/DANN/__pycache__/mmd_pytorch.cpython-37.pyc -------------------------------------------------------------------------------- /DANN/data_loader.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from torch.utils.data import TensorDataset,DataLoader 3 | import scipy.io as io 4 | 5 | 6 | 7 | def load_data(root_dir,domain,batch_size): 8 | df_data = io.loadmat(root_dir) 9 | datas = df_data[domain] 10 | # 将数据转变成 Tensor 类型 11 | x, y= torch.from_numpy(datas[:, 1:]).type(torch.FloatTensor).cuda(), torch.from_numpy(datas[:, 0:1]).type(torch.LongTensor).cuda() 12 | 13 | data = x.unsqueeze(1) # 将数据增加维度变为 [batch_size, 1, n_length] 14 | label= y.squeeze() # 将标签的维度减少 [batch_size,1] -> [batch_size] 15 | # 这里这样做的原因: 16 | # 1.y_pred是classes的 OneHot编码方式 17 | # 2.label必须是[0, #classes] 区间的一个数字 18 | 19 | data_set = TensorDataset(data, label) # 输入变量在前,输出变量在后 20 | # 采用 DataLoader 封装 data_set 即可得到能够用于训练神经网络的 data_loader 21 | data_loader = DataLoader(dataset=data_set ,batch_size=batch_size, shuffle=True, num_workers=0, drop_last=True) 22 | 23 | return data_loader 24 | 25 | def load_test(root_dir,domain,batch_size): 26 | df_data = io.loadmat(root_dir) 27 | datas = df_data[domain] 28 | # 将数据转变成 Tensor 类型 29 | x, y = torch.from_numpy(datas[:, 1:]).type(torch.FloatTensor).cuda(), torch.from_numpy(datas[:, 0:1]).type(torch.LongTensor).cuda() 30 | 31 | 32 | data = x.unsqueeze(1) # 将数据增加维度变为 [batch_size, 1, n_length] 33 | label = y.squeeze() # 将标签的维度减少 [batch_size,1] -> [batch_size] 34 | # x, label = torch.from_numpy(data[:, 1:]).type(torch.FloatTensor).cuda(), torch.from_numpy(data[:, 0:1]) # 将数据转变成 Tensor 类型 35 | # x = x.unsqueeze(1) 36 | # label = label.long().squeeze() 37 | 38 | data_set = TensorDataset(data, label) # 输入变量在前,输出变量在后 39 | # 采用 DataLoader 封装 data_set 即可得到能够用于训练神经网络的 data_loader 40 | data_loader = DataLoader(dataset=data_set, batch_size=batch_size, shuffle=False, num_workers=0) 41 | return data_loader 42 | # 43 | # if __name__ == '__main__': 44 | # src_dir = './train_dingzai_data_jiaoyu.mat' 45 | # tar_dir = './train_dingzai_data.mat' 46 | # torch.manual_seed(1) 47 | # data_src = load_data( 48 | # root_dir=src_dir, domain='train_dingzai_data_jiaoyu', batch_size=480) 49 | # 50 | # for i_batch, batch_data in enumerate(data_src): 51 | # if i_batch < 1: 52 | # data, label = batch_data 53 | # print(i_batch) # 打印batch编号 54 | # print(label[:10]) 55 | # else: 56 | # break -------------------------------------------------------------------------------- /DANN/generate.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CadeHu/Transfer-Learning/28be451893cee0486132f53fddc7ab7778648303/DANN/generate.m -------------------------------------------------------------------------------- /DANN/main.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import torch 3 | import torch.nn as nn 4 | import torch.optim as optim 5 | from tqdm import tqdm 6 | 7 | import data_loader 8 | # import mmd 9 | import mmd_pytorch 10 | import CNN1d 11 | 12 | mmd = mmd_pytorch.MMD_loss( kernel_type='rbf', kernel_mul=2.0, kernel_num=5) 13 | 14 | DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu') 15 | LEARNING_RATE = 0.01 16 | MOMEMTUN = 0.05 17 | L2_WEIGHT = 0.003 18 | Classes = 4 19 | N_EPOCH = 100 20 | BATCH_SIZE = [64, 32] 21 | LAMBDA = 0.2 22 | # GAMMA = 10 ^ 3 23 | RESULT_TRAIN = [] 24 | RESULT_TEST = [] 25 | # log_train = open('log_train_a-w.txt', 'w') 26 | # log_test = open('log_test_a-w.txt', 'w') 27 | 28 | 29 | # 求出领域之间的最大均值距离 30 | # def mmd_loss(x_src, x_tar): 31 | # return mmd.mix_rbf_mmd2(x_src, x_tar, [GAMMA]) 32 | 33 | def train(model, optimizer, epoch, data_src, data_tar): 34 | total_loss_train = 0 35 | criterion = nn.CrossEntropyLoss() 36 | correct = 0 37 | batch_j = 0 38 | list_src, list_tar = list(enumerate(data_src)), list(enumerate(data_tar)) 39 | 40 | for batch_id, (data, target) in enumerate(data_src): 41 | # 目标域数据集 42 | _, (x_tar, y_target) = list_tar[batch_j] 43 | x_tar, y_target = x_tar.to(DEVICE), y_target.to(DEVICE) 44 | # 源域数据集 45 | data, target = data.to(DEVICE), target.to(DEVICE) 46 | # print(target.size()) 47 | model.train() 48 | 49 | # 源域数据预测输出 y_src [batch_size,n_classes] 50 | # 源域数据平坦层 x_src_mmd [batch_size,] 51 | # 目标数据平坦层 x_tar_mmd [] 52 | y_src, x_src_mmd, x_tar_mmd = model(data, x_tar) 53 | # print(y_src.size()) # [480, 12] 54 | 55 | # 前向传播求出预测的值 56 | loss_c = criterion(y_src, target) 57 | # 求出领域之间的最大均值距离 58 | loss_mmd = mmd(x_src_mmd, x_tar_mmd) 59 | # print(loss_mmd) 60 | pred = y_src.data.max(1)[1] # get the index of the max log-probability 61 | 62 | correct += pred.eq(target.data.view_as(pred)).cpu().sum() 63 | 64 | loss = loss_c + LAMBDA * loss_mmd 65 | # 梯度初始化为零 66 | optimizer.zero_grad() 67 | # 反向传播求梯度 68 | loss.backward() 69 | # 更新所有参数 70 | optimizer.step() 71 | 72 | total_loss_train += loss.data 73 | # res_i = 'Epoch: [{}/{}], Batch: [{}/{}], loss: {:.6f}'.format( 74 | # epoch, N_EPOCH, batch_id + 1, len(data_src), loss.data 75 | # ) 76 | batch_j += 1 77 | if batch_j >= len(list_tar): 78 | batch_j = 0 79 | 80 | total_loss_train /= len(data_src) 81 | acc = correct * 100. / len(data_src.dataset) 82 | res_e = 'Epoch: [{}/{}], training loss: {:.6f}, correct: [{}/{}], training accuracy: {:.4f}%'.format( 83 | epoch, N_EPOCH, total_loss_train, correct, len(data_src.dataset), acc ) 84 | tqdm.write(res_e) 85 | # log_train.write(res_e + '\n') 86 | RESULT_TRAIN.append([epoch, total_loss_train, acc]) 87 | return model 88 | 89 | 90 | def test(model, data_tar, e): 91 | total_loss_test = 0 92 | correct = 0 93 | criterion = nn.CrossEntropyLoss() 94 | with torch.no_grad(): 95 | for batch_id, (data, target) in enumerate(data_tar): 96 | data, target = data.to(DEVICE),target.to(DEVICE) 97 | model.eval() 98 | ypred, _, _ = model(data, data) 99 | loss = criterion(ypred, target) 100 | pred = ypred.data.max(1)[1] # get the index of the max log-probability 101 | correct += pred.eq(target.data.view_as(pred)).cpu().sum() 102 | total_loss_test += loss.data 103 | accuracy = correct * 100. / len(data_tar.dataset) 104 | res = 'Test: total loss: {:.6f}, correct: [{}/{}], testing accuracy: {:.4f}%'.format( 105 | total_loss_test, correct, len(data_tar.dataset), accuracy 106 | ) 107 | tqdm.write(res) 108 | RESULT_TEST.append([e, total_loss_test, accuracy]) 109 | # log_test.write(res + '\n') 110 | 111 | if __name__ == '__main__': 112 | ''' 113 | 源域和目标域数据集要求: 114 | 1.每个样本数据长度一致 115 | 2.样本种类一致 116 | 另外,每类样本数据个数可以不一样 ,也就是两个数据集的样本个数可以不一样 117 | ''' 118 | # src_dir = './source_datasets.mat' 119 | # tar_dir = './target_datasets.mat' 120 | src_dir = './source_datasets_Eq_shuffle.mat' 121 | tar_dir = './target_datasets_Eq_shuffle.mat' 122 | torch.manual_seed(1) 123 | data_src = data_loader.load_data( 124 | root_dir=src_dir, domain='source_data_train', batch_size=BATCH_SIZE[0]) 125 | 126 | # root_dir=src_dir, domain='source_data', batch_size=BATCH_SIZE[0]) 127 | # root_dir=src_dir, domain='source_data_device', batch_size=BATCH_SIZE[0]) 128 | data_tar = data_loader.load_test( 129 | root_dir=tar_dir, domain='target_data_train', batch_size=BATCH_SIZE[1]) 130 | 131 | # root_dir=tar_dir, domain='target_data', batch_size=BATCH_SIZE[1]) 132 | # root_dir=tar_dir, domain='target_data_device', batch_size=BATCH_SIZE[1]) 133 | # print(data_src.size()) 134 | model = CNN1d.CNN1d( n_hidden=100, n_class= Classes) 135 | # 打印输出模型结构 136 | print(model) 137 | model = model.to(DEVICE) 138 | 139 | # 定义优化器 140 | optimizer = optim.Adamax( 141 | model.parameters(), 142 | lr=LEARNING_RATE, 143 | # momentum=MOMEMTUN, 144 | weight_decay=L2_WEIGHT 145 | ) 146 | 147 | # 迭代训练网络模型 148 | for e in tqdm(range(1, N_EPOCH + 1)): 149 | model = train(model=model, optimizer=optimizer, 150 | epoch=e, data_src=data_src, data_tar=data_tar) 151 | test(model, data_tar, e) 152 | # torch.save(model, 'model_CNN1d_D.pkl') 153 | # log_train.close() 154 | # log_test.close() 155 | # 保存网络输出结果 156 | res_train = np.asarray(RESULT_TRAIN) 157 | res_test = np.asarray(RESULT_TEST) 158 | np.savetxt('res_train_a-w.csv', res_train, fmt='%.6f', delimiter=',') 159 | np.savetxt('res_test_a-w.csv', res_test, fmt='%.6f', delimiter=',') 160 | 161 | -------------------------------------------------------------------------------- /DANN/mmd.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # encoding: utf-8 3 | 4 | 5 | import torch 6 | 7 | min_var_est = 1e-8 8 | 9 | 10 | # Consider linear time MMD with a linear kernel: 11 | # K(f(x), f(y)) = f(x)^Tf(y) 12 | # h(z_i, z_j) = k(x_i, x_j) + k(y_i, y_j) - k(x_i, y_j) - k(x_j, y_i) 13 | # = [f(x_i) - f(y_i)]^T[f(x_j) - f(y_j)] 14 | # 15 | # f_of_X: batch_size * k 16 | # f_of_Y: batch_size * k 17 | def linear_mmd2(f_of_X, f_of_Y): 18 | loss = 0.0 19 | delta = f_of_X - f_of_Y 20 | #loss = torch.mean((delta[:-1] * delta[1:]).sum(1)) 21 | loss = torch.mean(torch.mm(delta, torch.transpose(delta, 0, 1))) 22 | #delta = f_of_X - f_of_Y 23 | #loss = torch.mean((delta * delta).sum(1)) 24 | #print(loss) 25 | return loss 26 | 27 | 28 | # Consider linear time MMD with a polynomial kernel: 29 | # K(f(x), f(y)) = (alpha*f(x)^Tf(y) + c)^d 30 | # f_of_X: batch_size * k 31 | # f_of_Y: batch_size * k 32 | def poly_mmd2(f_of_X, f_of_Y, d=1, alpha=1.0, c=2.0): 33 | K_XX = (alpha * (f_of_X[:-1] * f_of_X[1:]).sum(1) + c) 34 | #print(K_XX) 35 | K_XX_mean = torch.mean(K_XX.pow(d)) 36 | 37 | K_YY = (alpha * (f_of_Y[:-1] * f_of_Y[1:]).sum(1) + c) 38 | K_YY_mean = torch.mean(K_YY.pow(d)) 39 | 40 | K_XY = (alpha * (f_of_X[:-1] * f_of_Y[1:]).sum(1) + c) 41 | K_XY_mean = torch.mean(K_XY.pow(d)) 42 | 43 | K_YX = (alpha * (f_of_Y[:-1] * f_of_X[1:]).sum(1) + c) 44 | K_YX_mean = torch.mean(K_YX.pow(d)) 45 | #print(K_XX_mean + K_YY_mean - K_XY_mean - K_YX_mean) 46 | return K_XX_mean + K_YY_mean - K_XY_mean - K_YX_mean 47 | 48 | ''' 作用: 计算矩阵K ''' 49 | def _mix_rbf_kernel(X, Y, sigma_list): 50 | assert(X.size(1) == Y.size(1)) 51 | m = X.size(0) # 64 52 | ## X [64,256] 53 | Z = torch.cat((X, Y), 0) #[128,256] 54 | ZZT = torch.mm(Z, Z.t())# [128,128] 55 | diag_ZZT = torch.diag(ZZT).unsqueeze(1)#[128,1,128] 56 | Z_norm_sqr = diag_ZZT.expand_as(ZZT) #[128,128] 57 | exponent = Z_norm_sqr - 2 * ZZT + Z_norm_sqr.t() #[] 58 | 59 | K = 0.0 60 | for sigma in sigma_list: 61 | gamma = 1.0 / (2 * sigma**2) 62 | K += torch.exp(-gamma * exponent) 63 | 64 | return K[:m, :m], K[:m, m:], K[m:, m:], len(sigma_list) 65 | 66 | ''' 作用: ''' 67 | def mix_rbf_mmd2(X, Y, sigma_list, biased=True): 68 | K_XX, K_XY, K_YY, d = _mix_rbf_kernel(X, Y, sigma_list) 69 | # return _mmd2(K_XX, K_XY, K_YY, const_diagonal=d, biased=biased) 70 | return _mmd2(K_XX, K_XY, K_YY, const_diagonal=False, biased=biased) 71 | 72 | 73 | def mix_rbf_mmd2_and_ratio(X, Y, sigma_list, biased=True): 74 | K_XX, K_XY, K_YY, d = _mix_rbf_kernel(X, Y, sigma_list) 75 | # return _mmd2_and_ratio(K_XX, K_XY, K_YY, const_diagonal=d, biased=biased) 76 | return _mmd2_and_ratio(K_XX, K_XY, K_YY, const_diagonal=False, biased=biased) 77 | 78 | 79 | ################################################################################ 80 | # Helper functions to compute variances based on kernel matrices 81 | ################################################################################ 82 | 83 | ''' 作用: 计算领域距离mmd ''' 84 | def _mmd2(K_XX, K_XY, K_YY, const_diagonal=False, biased=False): 85 | m = K_XX.size(0) # assume X, Y are same shape 86 | 87 | # Get the various sums of kernels that we'll use 88 | # Kts drop the diagonal, but we don't need to compute them explicitly 89 | if const_diagonal is not False: 90 | diag_X = diag_Y = const_diagonal 91 | sum_diag_X = sum_diag_Y = m * const_diagonal 92 | else: 93 | diag_X = torch.diag(K_XX) # (m,) 94 | diag_Y = torch.diag(K_YY) # (m,) 95 | sum_diag_X = torch.sum(diag_X) 96 | sum_diag_Y = torch.sum(diag_Y) 97 | 98 | Kt_XX_sums = K_XX.sum(dim=1) - diag_X # \tilde{K}_XX * e = K_XX * e - diag_X 99 | Kt_YY_sums = K_YY.sum(dim=1) - diag_Y # \tilde{K}_YY * e = K_YY * e - diag_Y 100 | K_XY_sums_0 = K_XY.sum(dim=0) # K_{XY}^T * e 101 | 102 | Kt_XX_sum = Kt_XX_sums.sum() # e^T * \tilde{K}_XX * e 103 | Kt_YY_sum = Kt_YY_sums.sum() # e^T * \tilde{K}_YY * e 104 | K_XY_sum = K_XY_sums_0.sum() # e^T * K_{XY} * e 105 | 106 | if biased: 107 | mmd2 = ((Kt_XX_sum + sum_diag_X) / (m * m) 108 | + (Kt_YY_sum + sum_diag_Y) / (m * m) 109 | - 2.0 * K_XY_sum / (m * m)) 110 | else: 111 | mmd2 = (Kt_XX_sum / (m * (m - 1)) 112 | + Kt_YY_sum / (m * (m - 1)) 113 | - 2.0 * K_XY_sum / (m * m)) 114 | 115 | return mmd2 116 | 117 | 118 | def _mmd2_and_ratio(K_XX, K_XY, K_YY, const_diagonal=False, biased=False): 119 | mmd2, var_est = _mmd2_and_variance(K_XX, K_XY, K_YY, const_diagonal=const_diagonal, biased=biased) 120 | loss = mmd2 / torch.sqrt(torch.clamp(var_est, min=min_var_est)) 121 | return loss, mmd2, var_est 122 | 123 | 124 | def _mmd2_and_variance(K_XX, K_XY, K_YY, const_diagonal=False, biased=False): 125 | m = K_XX.size(0) # assume X, Y are same shape 126 | 127 | # Get the various sums of kernels that we'll use 128 | # Kts drop the diagonal, but we don't need to compute them explicitly 129 | if const_diagonal is not False: 130 | diag_X = diag_Y = const_diagonal 131 | sum_diag_X = sum_diag_Y = m * const_diagonal 132 | sum_diag2_X = sum_diag2_Y = m * const_diagonal**2 133 | else: 134 | diag_X = torch.diag(K_XX) # (m,) 135 | diag_Y = torch.diag(K_YY) # (m,) 136 | sum_diag_X = torch.sum(diag_X) 137 | sum_diag_Y = torch.sum(diag_Y) 138 | sum_diag2_X = diag_X.dot(diag_X) 139 | sum_diag2_Y = diag_Y.dot(diag_Y) 140 | 141 | Kt_XX_sums = K_XX.sum(dim=1) - diag_X # \tilde{K}_XX * e = K_XX * e - diag_X 142 | Kt_YY_sums = K_YY.sum(dim=1) - diag_Y # \tilde{K}_YY * e = K_YY * e - diag_Y 143 | K_XY_sums_0 = K_XY.sum(dim=0) # K_{XY}^T * e 144 | K_XY_sums_1 = K_XY.sum(dim=1) # K_{XY} * e 145 | 146 | Kt_XX_sum = Kt_XX_sums.sum() # e^T * \tilde{K}_XX * e 147 | Kt_YY_sum = Kt_YY_sums.sum() # e^T * \tilde{K}_YY * e 148 | K_XY_sum = K_XY_sums_0.sum() # e^T * K_{XY} * e 149 | 150 | Kt_XX_2_sum = (K_XX ** 2).sum() - sum_diag2_X # \| \tilde{K}_XX \|_F^2 151 | Kt_YY_2_sum = (K_YY ** 2).sum() - sum_diag2_Y # \| \tilde{K}_YY \|_F^2 152 | K_XY_2_sum = (K_XY ** 2).sum() # \| K_{XY} \|_F^2 153 | 154 | if biased: 155 | mmd2 = ((Kt_XX_sum + sum_diag_X) / (m * m) 156 | + (Kt_YY_sum + sum_diag_Y) / (m * m) 157 | - 2.0 * K_XY_sum / (m * m)) 158 | else: 159 | mmd2 = (Kt_XX_sum / (m * (m - 1)) 160 | + Kt_YY_sum / (m * (m - 1)) 161 | - 2.0 * K_XY_sum / (m * m)) 162 | 163 | var_est = ( 164 | 2.0 / (m**2 * (m - 1.0)**2) * (2 * Kt_XX_sums.dot(Kt_XX_sums) - Kt_XX_2_sum + 2 * Kt_YY_sums.dot(Kt_YY_sums) - Kt_YY_2_sum) 165 | - (4.0*m - 6.0) / (m**3 * (m - 1.0)**3) * (Kt_XX_sum**2 + Kt_YY_sum**2) 166 | + 4.0*(m - 2.0) / (m**3 * (m - 1.0)**2) * (K_XY_sums_1.dot(K_XY_sums_1) + K_XY_sums_0.dot(K_XY_sums_0)) 167 | - 4.0*(m - 3.0) / (m**3 * (m - 1.0)**2) * (K_XY_2_sum) - (8 * m - 12) / (m**5 * (m - 1)) * K_XY_sum**2 168 | + 8.0 / (m**3 * (m - 1.0)) * ( 169 | 1.0 / m * (Kt_XX_sum + Kt_YY_sum) * K_XY_sum 170 | - Kt_XX_sums.dot(K_XY_sums_1) 171 | - Kt_YY_sums.dot(K_XY_sums_0)) 172 | ) 173 | return mmd2, var_est 174 | 175 | -------------------------------------------------------------------------------- /DANN/mmd_pytorch.py: -------------------------------------------------------------------------------- 1 | # Compute MMD distance using pytorch 2 | 3 | import torch 4 | import torch.nn as nn 5 | 6 | 7 | class MMD_loss(nn.Module): 8 | def __init__(self, kernel_type='rbf', kernel_mul=2.0, kernel_num=5): 9 | super(MMD_loss, self).__init__() 10 | self.kernel_num = kernel_num 11 | self.kernel_mul = kernel_mul 12 | self.fix_sigma = None 13 | self.kernel_type = kernel_type 14 | 15 | def guassian_kernel(self, source, target, kernel_mul=2.0, kernel_num=5, fix_sigma=None): 16 | n_samples = int(source.size()[0]) + int(target.size()[0]) 17 | total = torch.cat([source, target], dim=0) 18 | total0 = total.unsqueeze(0).expand( 19 | int(total.size(0)), int(total.size(0)), int(total.size(1))) 20 | total1 = total.unsqueeze(1).expand( 21 | int(total.size(0)), int(total.size(0)), int(total.size(1))) 22 | L2_distance = ((total0-total1)**2).sum(2) 23 | if fix_sigma: 24 | bandwidth = fix_sigma 25 | else: 26 | bandwidth = torch.sum(L2_distance.data) / (n_samples**2-n_samples) 27 | bandwidth /= kernel_mul ** (kernel_num // 2) 28 | bandwidth_list = [bandwidth * (kernel_mul**i) 29 | for i in range(kernel_num)] 30 | kernel_val = [torch.exp(-L2_distance / bandwidth_temp) 31 | for bandwidth_temp in bandwidth_list] 32 | return sum(kernel_val) 33 | 34 | def linear_mmd2(self, f_of_X, f_of_Y): 35 | loss = 0.0 36 | delta = f_of_X.float().mean(0) - f_of_Y.float().mean(0) 37 | loss = delta.dot(delta.T) 38 | return loss 39 | 40 | def forward(self, source, target): 41 | if self.kernel_type == 'linear': 42 | return self.linear_mmd2(source, target) 43 | elif self.kernel_type == 'rbf': 44 | batch_size = int(source.size()[0]) 45 | kernels = self.guassian_kernel( 46 | source, target, kernel_mul=self.kernel_mul, kernel_num=self.kernel_num, fix_sigma=self.fix_sigma) 47 | with torch.no_grad(): 48 | XX = torch.mean(kernels[:batch_size, :batch_size]) 49 | YY = torch.mean(kernels[batch_size:, batch_size:]) 50 | XY = torch.mean(kernels[:batch_size, batch_size:]) 51 | YX = torch.mean(kernels[batch_size:, :batch_size]) 52 | loss = torch.mean(XX + YY - XY - YX) 53 | torch.cuda.empty_cache() 54 | return loss 55 | -------------------------------------------------------------------------------- /DANN/pytorch搭建卷积迁移模型.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CadeHu/Transfer-Learning/28be451893cee0486132f53fddc7ab7778648303/DANN/pytorch搭建卷积迁移模型.docx -------------------------------------------------------------------------------- /DANN/res_test_a-w.csv: -------------------------------------------------------------------------------- 1 | 1.000000,23.967123,18.849207 2 | 2.000000,23.967123,24.007936 3 | 3.000000,23.966879,27.182539 4 | 4.000000,23.412033,27.182539 5 | 5.000000,23.586184,27.182539 6 | 6.000000,23.497555,27.182539 7 | 7.000000,23.584890,27.182539 8 | 8.000000,23.565184,27.182539 9 | 9.000000,23.570694,27.182539 10 | 10.000000,23.403698,27.182539 11 | 11.000000,23.542995,27.182539 12 | 12.000000,22.387892,27.182539 13 | 13.000000,20.211754,51.190475 14 | 14.000000,23.557814,27.182539 15 | 15.000000,22.597942,27.182539 16 | 16.000000,21.987513,29.761906 17 | 17.000000,23.059431,27.182539 18 | 18.000000,23.055717,27.182539 19 | 19.000000,22.685452,27.182539 20 | 20.000000,23.178383,27.182539 21 | 21.000000,23.133146,27.182539 22 | 22.000000,23.008005,27.182539 23 | 23.000000,23.088541,27.182539 24 | 24.000000,23.251688,27.182539 25 | 25.000000,23.330376,27.182539 26 | 26.000000,23.524555,27.182539 27 | 27.000000,23.271641,27.182539 28 | 28.000000,23.296078,27.182539 29 | 29.000000,23.470545,27.182539 30 | 30.000000,23.351643,27.182539 31 | 31.000000,23.420763,27.182539 32 | 32.000000,23.470615,27.182539 33 | 33.000000,22.223919,27.579365 34 | 34.000000,23.558548,27.182539 35 | 35.000000,23.560379,27.182539 36 | 36.000000,23.527225,27.182539 37 | 37.000000,23.526360,27.182539 38 | 38.000000,23.378290,27.182539 39 | 39.000000,23.441925,27.182539 40 | 40.000000,23.312708,27.182539 41 | 41.000000,22.617712,27.182539 42 | 42.000000,22.609213,27.182539 43 | 43.000000,23.202051,27.182539 44 | 44.000000,22.953680,27.182539 45 | 45.000000,23.343317,27.182539 46 | 46.000000,22.403994,27.182539 47 | 47.000000,23.290224,27.182539 48 | 48.000000,23.257603,27.182539 49 | 49.000000,23.377756,27.182539 50 | 50.000000,23.365536,27.182539 51 | 51.000000,23.320072,27.182539 52 | 52.000000,23.303205,27.182539 53 | 53.000000,23.036205,27.182539 54 | 54.000000,22.281977,27.579365 55 | 55.000000,22.462355,27.182539 56 | 56.000000,23.271929,27.182539 57 | 57.000000,23.132057,27.182539 58 | 58.000000,22.717030,27.182539 59 | 59.000000,23.038420,27.182539 60 | 60.000000,22.990128,27.182539 61 | 61.000000,23.058254,27.182539 62 | 62.000000,22.666878,27.182539 63 | 63.000000,22.937418,27.182539 64 | 64.000000,23.528032,27.182539 65 | 65.000000,23.314041,27.182539 66 | 66.000000,22.255651,28.571428 67 | 67.000000,22.879183,27.182539 68 | 68.000000,22.482388,27.380953 69 | 69.000000,23.080547,27.182539 70 | 70.000000,22.889811,27.182539 71 | 71.000000,23.160925,27.182539 72 | 72.000000,22.202166,29.563492 73 | 73.000000,22.317669,27.976191 74 | 74.000000,22.842859,27.182539 75 | 75.000000,22.294868,28.174603 76 | 76.000000,22.551975,27.182539 77 | 77.000000,23.547386,27.182539 78 | 78.000000,23.344200,27.182539 79 | 79.000000,23.033340,27.182539 80 | 80.000000,22.543304,27.182539 81 | 81.000000,22.882599,27.182539 82 | 82.000000,22.653101,27.182539 83 | 83.000000,22.902962,27.182539 84 | 84.000000,22.962830,27.182539 85 | 85.000000,22.645283,27.182539 86 | 86.000000,22.658985,27.182539 87 | 87.000000,22.755276,27.182539 88 | 88.000000,22.889410,27.182539 89 | 89.000000,22.650656,27.380953 90 | 90.000000,23.141232,27.182539 91 | 91.000000,23.325146,27.182539 92 | 92.000000,22.312716,27.976191 93 | 93.000000,22.567551,41.071430 94 | 94.000000,23.551062,27.182539 95 | 95.000000,23.568579,27.182539 96 | 96.000000,23.201672,27.182539 97 | 97.000000,23.348768,27.182539 98 | 98.000000,23.300837,27.182539 99 | 99.000000,23.387861,27.182539 100 | 100.000000,23.045628,27.182539 101 | -------------------------------------------------------------------------------- /DANN/res_train_a-w.csv: -------------------------------------------------------------------------------- 1 | 1.000000,1.814204,33.544304 2 | 2.000000,1.539027,40.348103 3 | 3.000000,1.574751,43.275318 4 | 4.000000,1.503754,43.354431 5 | 5.000000,1.393658,56.012657 6 | 6.000000,1.286028,71.439873 7 | 7.000000,1.317429,73.180382 8 | 8.000000,1.282029,72.943039 9 | 9.000000,1.250199,72.468353 10 | 10.000000,1.232564,71.835442 11 | 11.000000,1.230919,73.971519 12 | 12.000000,1.213008,86.392403 13 | 13.000000,1.133651,96.123421 14 | 14.000000,1.108628,96.202530 15 | 15.000000,1.110865,96.202530 16 | 16.000000,1.102081,96.202530 17 | 17.000000,1.102321,96.202530 18 | 18.000000,1.112476,96.202530 19 | 19.000000,1.110476,96.202530 20 | 20.000000,1.108251,96.202530 21 | 21.000000,1.117070,96.202530 22 | 22.000000,1.118262,96.202530 23 | 23.000000,1.119649,96.202530 24 | 24.000000,1.124340,96.202530 25 | 25.000000,1.133361,96.202530 26 | 26.000000,1.126184,96.123421 27 | 27.000000,1.139963,96.202530 28 | 28.000000,1.137607,96.202530 29 | 29.000000,1.121072,96.202530 30 | 30.000000,1.132673,96.202530 31 | 31.000000,1.132962,96.202530 32 | 32.000000,1.135080,96.202530 33 | 33.000000,1.171538,96.123421 34 | 34.000000,1.142994,96.202530 35 | 35.000000,1.114320,96.202530 36 | 36.000000,1.117433,96.202530 37 | 37.000000,1.115528,96.202530 38 | 38.000000,1.132354,96.202530 39 | 39.000000,1.125837,96.202530 40 | 40.000000,1.116909,96.202530 41 | 41.000000,1.151326,96.202530 42 | 42.000000,1.154452,96.202530 43 | 43.000000,1.133909,96.202530 44 | 44.000000,1.157322,96.202530 45 | 45.000000,1.134533,96.202530 46 | 46.000000,1.167562,96.202530 47 | 47.000000,1.153587,96.202530 48 | 48.000000,1.151077,96.202530 49 | 49.000000,1.155432,96.202530 50 | 50.000000,1.168355,96.202530 51 | 51.000000,1.163420,96.202530 52 | 52.000000,1.168254,96.202530 53 | 53.000000,1.170538,96.202530 54 | 54.000000,1.138154,96.202530 55 | 55.000000,1.154830,96.202530 56 | 56.000000,1.158690,96.202530 57 | 57.000000,1.163323,96.202530 58 | 58.000000,1.167437,96.202530 59 | 59.000000,1.166676,96.202530 60 | 60.000000,1.183304,96.202530 61 | 61.000000,1.138771,96.202530 62 | 62.000000,1.150368,96.123421 63 | 63.000000,1.131410,96.202530 64 | 64.000000,1.132401,96.202530 65 | 65.000000,1.152751,96.202530 66 | 66.000000,1.161815,96.202530 67 | 67.000000,1.165505,96.202530 68 | 68.000000,1.183534,96.202530 69 | 69.000000,1.178790,96.202530 70 | 70.000000,1.179123,96.202530 71 | 71.000000,1.152979,96.202530 72 | 72.000000,1.169684,96.202530 73 | 73.000000,1.182138,96.202530 74 | 74.000000,1.187024,96.202530 75 | 75.000000,1.183651,96.202530 76 | 76.000000,1.174904,96.202530 77 | 77.000000,1.169888,96.123421 78 | 78.000000,1.168618,96.202530 79 | 79.000000,1.153545,96.202530 80 | 80.000000,1.160936,96.202530 81 | 81.000000,1.154887,96.202530 82 | 82.000000,1.156146,96.202530 83 | 83.000000,1.166641,96.202530 84 | 84.000000,1.168628,96.202530 85 | 85.000000,1.169933,96.202530 86 | 86.000000,1.183582,96.202530 87 | 87.000000,1.182176,96.202530 88 | 88.000000,1.174586,96.202530 89 | 89.000000,1.183585,96.202530 90 | 90.000000,1.176478,96.202530 91 | 91.000000,1.182581,96.202530 92 | 92.000000,1.150091,96.202530 93 | 93.000000,1.147413,95.886078 94 | 94.000000,1.149572,96.202530 95 | 95.000000,1.134424,96.123421 96 | 96.000000,1.146998,96.202530 97 | 97.000000,1.156914,96.202530 98 | 98.000000,1.162647,96.202530 99 | 99.000000,1.164230,96.202530 100 | 100.000000,1.162325,96.202530 101 | -------------------------------------------------------------------------------- /DANN/source_datasets.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CadeHu/Transfer-Learning/28be451893cee0486132f53fddc7ab7778648303/DANN/source_datasets.mat -------------------------------------------------------------------------------- /DANN/source_datasets_D.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CadeHu/Transfer-Learning/28be451893cee0486132f53fddc7ab7778648303/DANN/source_datasets_D.mat -------------------------------------------------------------------------------- /DANN/target_datasets.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CadeHu/Transfer-Learning/28be451893cee0486132f53fddc7ab7778648303/DANN/target_datasets.mat -------------------------------------------------------------------------------- /DANN/target_datasets_D.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CadeHu/Transfer-Learning/28be451893cee0486132f53fddc7ab7778648303/DANN/target_datasets_D.mat -------------------------------------------------------------------------------- /DANN/备注.txt: -------------------------------------------------------------------------------- 1 | DANN数据集介绍: 2 | 不同工况下 3 | source_datasets.mat 1200rpm转速下行星齿轮箱太阳轮裂纹、断齿、缺齿样本,每类样本399个,每个样本640个数据点 4 | target_datasets.mat 1380rpm转速下 5 | 不同部位 6 | source_datasets_D.mat 1200rpm转速下行星齿轮箱太阳轮裂纹、断齿、缺齿样本 7 | target_datasets_D.mat 1200rpm转速下行星齿轮箱行星轮裂纹、断齿、缺齿样本 8 | 9 | 结果展示: 10 | res_train_a-w.csv 不同工况下的每次迭代训练准确率及损失值 11 | res_test_a-w.csv 不同工况下的每次迭代测试准确率及损失值 12 | 13 | D_res_train_a-w.csv 不同部位下的每次迭代训练准确率及损失值 14 | D_res_test_a-w.csv 不同部位下的每次迭代测试准确率及损失值 15 | 16 | 17 | model_CNN1d.pkl 不同工况下的网络模型参数 18 | model_CNN1d_D.pkl 不同部位下的网络模型参数 19 | 20 | py文件: 21 | main.py 主程序 22 | mmd_pytorch.py 计算mmd距离 23 | data_loader.py 导入.mat格式文件数据集 24 | CNN1d.py 网络模型 25 | 26 | 环境配置:MX350显卡+I7-10510U 27 | Python3.7.3 28 | 29 | cuda 10.1 30 | 31 | cuDNN 7.6.5 32 | 33 | pip install torch==1.7.1+cu101 torchvision==0.8.2+cu101 torchaudio===0.7.2 -f https://download.pytorch.org/whl/torch_stable.html 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Transfer-Learning 2 | 迁移学习(故障诊断)上的一点探索 3 | --------------------------------------------------------------------------------