├── MLP └── MLP_manual.py ├── Net └── MyNet.py ├── README.md ├── SVM ├── SVM.py ├── dataset │ └── svm │ │ ├── svm_test_data.csv │ │ ├── svm_test_label.csv │ │ ├── svm_train_data.csv │ │ └── svm_train_label.csv ├── main.py └── utils.py ├── csp ├── output │ ├── output1.txt │ └── output2.txt └── src │ ├── csp.c │ ├── input1.txt │ └── input2.txt ├── decisionTree ├── DecisionTree.py ├── dataset │ └── dt │ │ ├── dt_test.data │ │ └── dt_train.data ├── main.py └── utils.py ├── digit ├── data │ ├── input00.txt │ ├── input01.txt │ ├── input02.txt │ ├── input03.txt │ ├── input04.txt │ ├── input05.txt │ ├── input06.txt │ ├── input07.txt │ ├── input08.txt │ ├── input09.txt │ ├── input10.txt │ ├── input11.txt │ ├── target00.txt │ ├── target01.txt │ ├── target02.txt │ ├── target03.txt │ ├── target04.txt │ ├── target05.txt │ ├── target06.txt │ ├── target07.txt │ ├── target08.txt │ ├── target09.txt │ ├── target10.txt │ └── target11.txt ├── output │ ├── output_A_h1.txt │ ├── output_A_h2.txt │ ├── output_IDA_h1.txt │ └── output_IDA_h2.txt └── src │ ├── 1run.bat │ ├── 2run.bat │ ├── 3run.bat │ ├── 4run.bat │ ├── a.c │ ├── a.h │ ├── input00.txt │ ├── input01.txt │ ├── input02.txt │ ├── input03.txt │ ├── input04.txt │ ├── input05.txt │ ├── input06.txt │ ├── input07.txt │ ├── input08.txt │ ├── input09.txt │ ├── input10.txt │ ├── input11.txt │ ├── readme.md │ ├── target00.txt │ ├── target01.txt │ ├── target02.txt │ ├── target03.txt │ ├── target04.txt │ ├── target05.txt │ ├── target06.txt │ ├── target07.txt │ ├── target08.txt │ ├── target09.txt │ ├── target10.txt │ ├── target11.txt │ └── 难度说明.txt └── kmeans ├── kmeans.txt └── main.py /MLP/MLP_manual.py: -------------------------------------------------------------------------------- 1 | from numpy import tanh 2 | import torch 3 | import numpy as np 4 | from matplotlib import pyplot as plt 5 | 6 | class MLP: 7 | def __init__(self,activationFunction,activationFunctionDerivative,layerSize=[10,19,13,7,4]): 8 | self.layerSize = layerSize 9 | self.W = [None] + [np.random.normal(0,0.3,(self.layerSize[i+1],self.layerSize[i])) for i in range(len(self.layerSize)-1) ] 10 | self.biss = [None] + [ np.array([[0]*m]).T for m in self.layerSize[1:] ] 11 | self.s = activationFunction # 激活函数 s() 12 | self.sf = activationFunctionDerivative # 激活函数的导数 s'() 13 | self.h = [None]*len(self.layerSize) # 输出 h = s(z) 14 | self.z = [None]*len(self.layerSize) # 输入 z = Wx + b ,其中x为上一层输出 15 | self.dw , self.db= [None]*len(self.layerSize), [None]*len(self.layerSize) # 反向传播求得的W与biss的梯度 16 | self.Loss = 0 17 | def CrossEntropyLoss(x, y): 18 | return [-np.log(x[i][0]) for i in range(len(y)) if y[i][0] == 1].pop() 19 | self.lossFunction = CrossEntropyLoss # 损失函数 20 | def Softmax(x): 21 | x = np.exp(x) 22 | return x/np.sum(x) 23 | self.s_out = Softmax # 输出层的激活函数 24 | 25 | def forward(self, x): # 前向传播 26 | for i in range(len(self.layerSize)): # 第i层向第i+1层传播 27 | if i == 0: # 输入层 28 | self.h[i] = np.array([x]).T 29 | elif i == len(self.layerSize) - 1: # 输出层 30 | self.z[i] = self.W[i].dot(self.h[i-1]) + self.biss[i] 31 | self.h[i] = self.s_out(self.z[i]) 32 | else: 33 | self.z[i] = self.W[i].dot(self.h[i-1]) + self.biss[i] 34 | self.h[i] = self.s(self.z[i]) 35 | return self.h[i].T 36 | 37 | 38 | def backward(self, y): 39 | y = np.array([y]).T 40 | # self.Loss = 0.5 * np.sum([i**2 for i in (self.h[len(self.layerSize) - 1] - y) ] )# 反向传播, 误差值,采用 Loss = 0.5*||Δy||_2^2 41 | self.Loss = self.lossFunction(self.h[-1],y) 42 | for i in range(len(self.layerSize)-1,0,-1): # 第i层向第i-1层反向传播,用δ表示 dLoss/dW 43 | if i == len(self.layerSize)-1: 44 | delta = self.h[i] - y 45 | else: 46 | delta = self.W[i+1].T.dot(delta)*self.sf(self.z[i]) 47 | self.dw[i] = delta.dot(self.h[i-1].T) 48 | self.db[i] = delta 49 | 50 | def update(self,lr): 51 | # 更新weight与biss 52 | for i in range(1,len(self.layerSize)): 53 | self.W[i] = self.W[i] - lr*self.dw[i] 54 | self.biss[i] = self.biss[i] - lr*self.db[i] 55 | 56 | 57 | def train(mlp: MLP, epochs, lr, inputs, labels): 58 | # mlp: 传入实例化的MLP模型 59 | # epochs: 训练轮数 60 | # lr: 学习率 61 | # inputs: 生成的随机数据 62 | # labels: 生成的one-hot标签 63 | Loss = [] 64 | for epoch in range(epochs): 65 | loss = 0 66 | for i in range(len(inputs)): 67 | output = mlp.forward(inputs[i]) 68 | mlp.backward(labels[i]) 69 | mlp.update(lr) 70 | loss = loss + mlp.Loss 71 | Loss.append(loss) 72 | return Loss 73 | 74 | 75 | 76 | 77 | if __name__ == '__main__': 78 | # 设置随机种子,保证结果的可复现性 79 | np.random.seed(1) 80 | 81 | # 生成数据 82 | inputs = np.random.randn(100, 10) 83 | # 生成one-hot标签 84 | labels = np.eye(4)[np.random.randint(0, 4, size=(1, 100))].reshape(100, 4) 85 | # print(labels) 86 | 87 | def dtanxdx(x): 88 | return 1-tanh(x)**2 89 | 90 | 91 | 92 | mlp = MLP(tanh,dtanxdx,[10, 10, 8, 8, 4]) 93 | 94 | 95 | 96 | # 训练 97 | epochs = 1000 98 | lr = 0.01 99 | l = train(mlp, epochs, lr, inputs, labels) 100 | for i in range(len(l)): 101 | print(i,l[i]) 102 | -------------------------------------------------------------------------------- /Net/MyNet.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torchvision 3 | 4 | import torch.nn as nn 5 | import torch.nn.functional as F 6 | import torch.optim as optim 7 | 8 | from torchvision import transforms 9 | 10 | 11 | device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") 12 | 13 | class MyNet(nn.Module): 14 | def __init__(self): 15 | super(MyNet,self).__init__() 16 | ######################################################################## 17 | #这里需要写MyNet的卷积层、池化层和全连接层 18 | self.conv = nn.Sequential( 19 | nn.Conv2d(3,12,5),nn.ReLU(), 20 | nn.MaxPool2d(kernel_size=2,stride=2), 21 | nn.Conv2d(12,24,3),nn.ReLU(), 22 | nn.MaxPool2d(kernel_size=2,stride=2), 23 | nn.Conv2d(24,32,2),nn.ReLU() 24 | ) 25 | self.fc = nn.Sequential( 26 | nn.LazyLinear(108),nn.ReLU(), # lazy自动生成input channel 27 | # nn.Linear(800, 108),nn.ReLU(), # 800是试出来的 28 | nn.Linear(108, 84),nn.ReLU(), 29 | nn.Linear(84, 10),nn.ReLU() 30 | ) 31 | 32 | def forward(self, x): 33 | ######################################################################## 34 | #这里需要写MyNet的前向传播 35 | x = self.conv(x) 36 | x = x.view(x.size()[0],-1) 37 | out = self.fc(x) 38 | return out 39 | 40 | def train(net,train_loader,optimizer,n_epochs,loss_function): 41 | net.train() 42 | for epoch in range(n_epochs): 43 | for step, (inputs, labels) in enumerate(train_loader, start=0): 44 | # get the inputs; data is a list of [inputs, labels] 45 | inputs, labels = inputs.to(device), labels.to(device) 46 | 47 | ######################################################################## 48 | #计算loss并进行反向传播 49 | optimizer.zero_grad() 50 | outputs=net(inputs) 51 | loss=loss_function(outputs,labels) 52 | loss.backward() 53 | optimizer.step() 54 | ######################################################################## 55 | 56 | if step % 100 ==0: 57 | print('Train Epoch: {}/{} [{}/{}]\tLoss: {:.6f}'.format( 58 | epoch, n_epochs, step * len(inputs), len(train_loader.dataset), loss.item())) 59 | 60 | print('Finished Training') 61 | save_path = './MyNet.pth' 62 | torch.save(net.state_dict(), save_path) 63 | 64 | def test(net, test_loader, loss_function): 65 | net.eval() 66 | test_loss = 0. 67 | num_correct = 0 #correct的个数 68 | with torch.no_grad(): 69 | for inputs, labels in test_loader: 70 | inputs, labels = inputs.to(device), labels.to(device) 71 | ######################################################################## 72 | #需要计算测试集的loss和accuracy 73 | outputs=net(inputs) 74 | pridect=torch.max(outputs.data,1)[1] 75 | num_correct += (pridect==labels).sum().item() 76 | test_loss += loss_function(outputs,labels) 77 | accuracy = num_correct/labels.size(0)/len(test_loader) 78 | ######################################################################## 79 | print("Test set: Average loss: {:.4f}\t Acc {:.2f}".format(test_loss.item(), accuracy)) 80 | 81 | 82 | if __name__ == '__main__': 83 | n_epochs = 5 84 | train_batch_size = 128 85 | test_batch_size =5000 86 | learning_rate = 5e-4 87 | 88 | transform = transforms.Compose( 89 | [transforms.ToTensor(), 90 | transforms.Normalize((0.4914, 0.4822, 0.4465), (0.247, 0.243, 0.261))]) 91 | 92 | # 50000张训练图片 93 | train_set = torchvision.datasets.CIFAR10(root='./data', train=True, download=False, transform=transform) 94 | train_loader = torch.utils.data.DataLoader(train_set, batch_size=train_batch_size, shuffle=True, num_workers=0) 95 | 96 | # 10000张验证图片 97 | test_set = torchvision.datasets.CIFAR10(root='./data', train=False, download=False, transform=transform) 98 | test_loader = torch.utils.data.DataLoader(test_set, batch_size=test_batch_size, shuffle=False, num_workers=0) 99 | 100 | 101 | net = MyNet() 102 | 103 | # 自己设定优化器和损失函数 104 | loss_function=nn.CrossEntropyLoss() 105 | optimizer = torch.optim.SGD(net.parameters(), lr=0.1) 106 | ####################################################################### 107 | 108 | train(net,train_loader,optimizer,n_epochs,loss_function) 109 | test(net,test_loader,loss_function) 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 2022USTC-AI 2 | 3 | 2022春 xll班 ai实验 4 | 5 | 7.30 新增了kmeans算法 6 | 7 | -------------------------------------------------------------------------------- /SVM/SVM.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from cvxopt import matrix, solvers 3 | # import cvxpy as cp 4 | from utils import * 5 | 6 | solvers.options['show_progress'] = False # 关闭cvxopt求解过程 7 | 8 | class SupportVectorMachine: 9 | def __init__(self, C=1, kernel='Gauss', epsilon=1e-4): 10 | self.C = C 11 | self.epsilon = epsilon 12 | self.kernel = kernel 13 | 14 | # Hint: 你可以在训练后保存这些参数用于预测 15 | # SV即Support Vector,表示支持向量,SV_alpha为优化问题解出的alpha值, 16 | # SV_label表示支持向量样本的标签。 17 | self.SV = [] 18 | self.SV_alpha = [] 19 | self.SV_label = [] 20 | 21 | def KERNEL(self, x1, x2, d=2, sigma=1): 22 | #d for Poly, sigma for Gauss 23 | if self.kernel == 'Gauss': 24 | K = np.exp(-(np.sum((x1 - x2) ** 2)) / (2 * sigma ** 2)) 25 | elif self.kernel == 'Linear': 26 | K = np.dot(x1,x2) 27 | elif self.kernel == 'Poly': 28 | K = (np.dot(x1,x2) + 1) ** d 29 | else: 30 | raise NotImplementedError() 31 | return K 32 | 33 | def fit(self, train_features:np.ndarray, train_labels:np.ndarray): 34 | m = len(train_features) 35 | # 二次型规划 36 | # minimize (1/2)*x'*P*x + q'*x subject to G*x <= h,A*x = b 37 | P = np.array([[train_labels[i]*train_labels[j]*self.KERNEL(train_features[i],train_features[j]) for j in range(m)] for i in range(m)]) 38 | q = np.array([-1]*m) 39 | G = np.array(list(-1*np.eye(m)) + list(np.eye(m))) 40 | h = np.array([0]*m + [self.C]*m) 41 | A = np.array([train_labels]) 42 | b = np.array([0]) 43 | # cvxopt求解二次型规划 44 | Pc = matrix(P,tc='d') 45 | qc = matrix(q,tc='d') 46 | Gc = matrix(G,tc='d') 47 | hc = matrix(h,tc='d') 48 | Ac = matrix(A,tc='d') 49 | bc = matrix(b,tc='d') 50 | sol = solvers.qp(Pc,qc,Gc,hc,Ac,bc) 51 | a = sol['x'] 52 | 53 | # cvxpy求解代码, 该问题不满足DCP约束,无法用cvxpy求解 54 | # x = cp.Variable(m) 55 | # obj = cp.Minimize(0.5*x.T@P@x + q@x) 56 | # constraints = [G@x <= h, A@x == b] 57 | # prob = cp.Problem(obj,constraints) 58 | # prob.solve( ) 59 | # a = x.value 60 | 61 | for i in range(m): # a[i]不为零,则是支持向量 62 | if a[i] >= self.epsilon: 63 | self.SV.append(train_features[i]) 64 | self.SV_alpha.append(a[i]) 65 | self.SV_label.append(train_labels[i]) 66 | 67 | self.b = np.average([train_labels[j] - np.sum([a[i]*train_labels[i]*self.KERNEL(train_features[i],train_features[j]) for i in range(m) ]) for j in range(m) if 0 <= a[j] <= self.C]) 68 | 69 | def predict1(self, test_data): # 预测一个 70 | t = np.sum([self.SV_alpha[i] * self.SV_label[i]* self.KERNEL(test_data,self.SV[i]) for i in range(len(self.SV))]) + self.b 71 | if t > 0: 72 | return 1 73 | return -1 74 | 75 | def predict(self, test_data) -> np.ndarray: 76 | return np.array([self.predict1(i) for i in test_data]) 77 | 78 | if __name__=='__main__': 79 | 80 | train_features, train_labels, test_features, test_labels = load_svm_dataset() 81 | n = 137 82 | model = SupportVectorMachine(kernel='Gauss') 83 | model.fit(train_features[0:n], train_labels[0:n]) 84 | -------------------------------------------------------------------------------- /SVM/dataset/svm/svm_test_data.csv: -------------------------------------------------------------------------------- 1 | age,creatinine_phosphokinase,ejection_fraction,platelets,serum_creatinine,serum_sodium,time 2 | 0.35024580869500405,-0.4378488831283802,2.274334614958477,7.52304818605185e-09,0.10258034698884815,0.31152159010811187,-1.5494697780364683 3 | -0.9108084803335884,-0.42651204153872413,-0.00706490623433922,0.1292579047753388,-0.28407611376962083,0.08489152820464299,-1.536585539101241 4 | 1.7794406695940754,-0.20905080740986665,1.0068904365180236,-2.2121539535643517,-0.09074788339038635,-0.14173853369882586,-1.5108170612307865 5 | 2.199792099270273,-0.44609385882994823,-0.00706490623433922,-0.013885178267262361,-0.4774043441488554,0.7647817139150496,-1.4979328222955592 6 | 0.7705972383712015,-0.47082878593465244,-1.105516527549399,-0.26949782655762156,-0.3807402289592382,0.7647817139150496,-1.4850485833603317 7 | 2.031651527399794,-0.5759522261296451,0.584409043704539,0.9881164030309458,1.5525420748331071,-1.0482587813127013,-1.3175534772023767 8 | -0.9108084803335884,-0.4357876392029882,-0.6830351347359144,0.3950950589973124,-0.1874119985800037,0.31152159010811187,-1.3046692382671494 9 | 0.7705972383712015,0.00016545101742275193,-1.5279979203628835,7.52304818605185e-09,0.4215719271145852,-0.5949986575057635,-1.2789007603966946 10 | -0.07010562098119343,-0.3316948209706915,-0.00706490623433922,-0.08545671978856294,0.7792291533161692,-1.0482587813127013,-1.098521415303512 11 | -0.4904570506573909,-0.4873187373377885,-0.2605537419224299,-0.09568122572017732,-0.28407611376962083,0.5381516520115807,-0.9052578312751024 12 | 0.35024580869500405,-0.3687972116277477,1.0068904365180236,-1.169254348539686,-0.09074788339038635,0.08489152820464299,-0.7506469640523745 13 | -1.5833707678155045,-0.49453309107666055,0.16192765089105457,-0.26949782655762156,-0.1874119985800037,0.7647817139150496,-0.7248784861819199 14 | -0.32231647878691194,-0.4811350055616125,-1.105516527549399,-0.8420701587280263,-0.28407611376962083,1.671301961528925,-0.6604572915057833 15 | -0.07010562098119343,-0.44094074901646824,-1.105516527549399,-0.5455594867112096,0.2959085773680826,-0.36836859560229473,-0.6218045747001013 16 | -0.07010562098119343,-0.5007168228528366,-0.00706490623433922,-0.3615183799421509,-0.6224005169332814,0.7647817139150496,-0.45430946854214616 17 | -0.07010562098119343,0.00016545101742275193,-0.6830351347359144,-1.3941934790352022,-0.4774043441488554,1.8979320234323938,-0.45430946854214616 18 | -1.4993004818802649,-0.2306938686264828,1.0068904365180236,-0.26949782655762156,-0.09074788339038635,-0.36836859560229473,-0.4285409906716915 19 | 1.6113000977235965,0.2299941486986323,-0.00706490623433922,7.52304818605185e-09,-0.28407611376962083,-0.5949986575057635,-0.27393012344896367 20 | -1.2470896240745464,-0.29974554012711524,-0.2605537419224299,0.8654223318515734,-0.4774043441488554,0.7647817139150496,-0.27393012344896367 21 | -0.7426679084631094,-0.5398804574352849,-0.2605537419224299,0.13948241070695316,0.005916231799230793,-0.14173853369882586,-0.13220349516146312 22 | 2.031651527399794,0.33820945478171305,1.0068904365180236,-0.28994683842085034,-0.09074788339038635,-0.5949986575057635,-0.1193192562262358 23 | -0.9948787662688279,-0.5285436158456288,1.0068904365180236,-1.3430709493771302,-0.3807402289592382,0.7647817139150496,0.21567095608967454 24 | -0.4904570506573909,0.2609128075795125,0.16192765089105457,0.15993142257018192,-0.67073257452809,0.7647817139150496,0.21567095608967454 25 | 0.18210523682452506,1.221452476812191,0.584409043704539,-1.946316799342378,-0.67073257452809,0.08489152820464299,0.71815627456354 26 | 0.35024580869500405,-0.47804313967352446,1.0068904365180236,-0.7091515816170394,-0.28407611376962083,1.8979320234323938,0.8985356196567226 27 | -0.4904570506573909,-0.41414457798637205,0.584409043704539,7.52304818605185e-09,-0.20674482161792718,0.08489152820464299,1.0402622479442232 28 | 1.0228080961769201,0.6216304945231149,0.16192765089105457,-0.4433144273950658,-0.4774043441488554,0.9914117758185185,1.0660307258146777 29 | 0.35024580869500405,-0.263673771432755,-0.00706490623433922,0.31329901154439743,0.2959085773680826,0.5381516520115807,1.1562203983612689 30 | -0.9108084803335884,-0.2925311863882432,-0.2605537419224299,1.0085654148941745,-0.4774043441488554,0.7647817139150496,1.4139051770658153 31 | -0.07010562098119343,-0.3389091747095635,-0.2605537419224299,0.15993142257018192,0.2959085773680826,0.7647817139150496,1.5427475664180885 32 | -------------------------------------------------------------------------------- /SVM/dataset/svm/svm_test_label.csv: -------------------------------------------------------------------------------- 1 | DEATH_EVENT 2 | 1 3 | 1 4 | 1 5 | 1 6 | 1 7 | 1 8 | -1 9 | 1 10 | 1 11 | -1 12 | -1 13 | -1 14 | -1 15 | 1 16 | -1 17 | -1 18 | -1 19 | 1 20 | -1 21 | -1 22 | -1 23 | -1 24 | -1 25 | -1 26 | -1 27 | -1 28 | -1 29 | -1 30 | -1 31 | -1 32 | -------------------------------------------------------------------------------- /SVM/dataset/svm/svm_train_data.csv: -------------------------------------------------------------------------------- 1 | age,creatinine_phosphokinase,ejection_fraction,platelets,serum_creatinine,serum_sodium,time 2 | 1.190948668047399,0.00016545101742275193,-1.5279979203628835,0.016788339527580746,0.48923680774731715,-1.501518905119639,-1.6267752116478325 3 | -0.4904570506573909,7.502062717481657,-0.00706490623433922,7.52304818605185e-09,-0.28407611376962083,-0.14173853369882586,-1.6010067337773777 4 | 0.35024580869500405,-0.44918572471803625,-1.5279979203628835,-1.0363357714286991,-0.09074788339038635,-1.7281489670231078,-1.5881224948421504 5 | -0.9108084803335884,-0.4852574934123965,-1.5279979203628835,-0.5455594867112096,0.48923680774731715,0.08489152820464299,-1.5881224948421504 6 | 0.35024580869500405,-0.43475701724029214,-1.5279979203628835,0.6507077072876716,1.2625497292642556,-4.674339771768203,-1.5752382559069231 7 | 2.4520029570759916,-0.551217299024941,0.16192765089105457,-0.6069065223008957,0.6825650381265518,-1.0482587813127013,-1.5752382559069231 8 | 1.190948668047399,-0.3461235284484356,-1.9504793131763678,-1.3941934790352022,-0.1874119985800037,0.08489152820464299,-1.5494697780364683 9 | -0.07010562098119343,-0.2750106130224111,1.8518532221449926,1.9492199606026965,-0.28407611376962083,-1.2748888432161702,-1.5494697780364683 10 | 1.6113000977235965,-0.4728900298600444,-0.2605537419224299,1.274402569116148,7.739045446968612,-0.8216287194092324,-1.5494697780364683 11 | 1.190948668047399,-0.5161761522932767,-0.00706490623433922,1.0699124504838606,2.51918322672928,-1.2748888432161702,-1.5494697780364683 12 | 0.09803495088928556,-0.3615828578888757,-1.105516527549399,-0.10590573165179168,-0.4774043441488554,0.7647817139150496,-1.5494697780364683 13 | -1.331159910009786,0.4113836141331295,-0.6830351347359144,-1.3021729256506729,-0.28407611376962083,0.08489152820464299,-1.536585539101241 14 | -0.9948787662688279,-0.5172067742559727,-0.6830351347359144,1.6731583004491084,-0.3807402289592382,0.31152159010811187,-1.5237013001660138 15 | -1.331159910009786,0.00016545101742275193,-2.0349755917390646,-0.9954377477022418,-0.5740684593384727,-2.1814090908300456,-1.4979328222955592 16 | -1.0789490522040674,0.00016545101742275193,1.429371829331508,-1.803173716299777,0.48923680774731715,-3.5411894622508586,-1.4850485833603317 17 | 0.35024580869500405,-0.5460641892114609,-1.105516527549399,0.1292579047753388,-0.09074788339038635,0.08489152820464299,-1.4721643444251045 18 | 0.35024580869500405,-0.4677369200465644,-0.6830351347359144,0.34397252933924055,0.1992444621784655,-0.14173853369882586,-1.4206273886841951 19 | 0.6024566665007225,-0.37291969947853176,-0.2605537419224299,0.2621764818863256,-0.4774043441488554,0.7647817139150496,-1.4206273886841951 20 | -0.6585976225278699,-0.5347273476218048,1.8518532221449926,1.0699124504838606,-0.5740684593384727,-0.36836859560229473,-1.3948589108137406 21 | 1.190948668047399,0.00016545101742275193,-0.6830351347359144,7.52304818605185e-09,0.4215719271145852,-0.5949986575057635,-1.3819746718785133 22 | 1.6113000977235965,-0.4471244807926443,-0.00706490623433922,-1.169254348539686,0.48923680774731715,1.671301961528925,-1.3819746718785133 23 | 2.872354386752189,-0.4842268714497005,0.16192765089105457,-0.6887025697538107,-0.3807402289592382,0.31152159010811187,-1.369090432943286 24 | 0.7705972383712015,-0.47392065182274046,0.584409043704539,0.21105395222825374,-0.09074788339038635,-0.14173853369882586,-1.3433219550728313 25 | -0.23824619285167242,-0.5378192135098928,-0.00706490623433922,-1.1283563248132285,4.259137300142391,-0.5949986575057635,-1.3433219550728313 26 | 1.7794406695940754,-0.5275129938829328,-0.6830351347359144,-0.6478045460273533,-0.1874119985800037,-1.0482587813127013,-1.3433219550728313 27 | 2.7882841008169494,0.00016545101742275193,-0.00706490623433922,7.52304818605185e-09,0.4215719271145852,-0.5949986575057635,-1.330437716137604 28 | -0.9108084803335884,-0.34303166256034756,-0.2605537419224299,0.5689116598347567,-0.3807402289592382,-1.9547790289265767,-1.3175534772023767 29 | 0.35024580869500405,-0.5027780667782287,1.0068904365180236,-0.7704986172067256,-0.3807402289592382,0.7647817139150496,-1.3046692382671494 30 | 0.6865269524359621,0.00016545101742275193,-0.2605537419224299,-0.3615183799421509,2.0358626507811937,-0.5949986575057635,-1.291784999331922 31 | 2.4520029570759916,-0.5378192135098928,1.0068904365180236,-0.38196739180537964,-0.3807402289592382,-0.5949986575057635,-1.291784999331922 32 | 1.7794406695940754,0.28152524683343266,1.0068904365180236,0.5893606716979854,-0.3807402289592382,1.8979320234323938,-1.291784999331922 33 | -0.07010562098119343,2.1376754016489414,-0.6830351347359144,0.4257685767921555,0.8758932685057861,0.08489152820464299,-1.291784999331922 34 | -0.07010562098119343,-0.35746037003809167,-0.00706490623433922,0.6711567191509004,1.5525420748331071,1.2180418377219873,-1.291784999331922 35 | -0.9108084803335884,-0.4718594078973484,-0.6830351347359144,-1.1283563248132285,-0.1874119985800037,-0.14173853369882586,-1.2660165214614674 36 | 0.7705972383712015,-0.011171390572233325,0.584409043704539,-0.8011721350015688,-0.1874119985800037,0.5381516520115807,-1.25313228252624 37 | 0.9387378102416806,-0.4687675420092604,1.0068904365180236,-0.4637634392582946,-0.3807402289592382,-0.5949986575057635,-1.25313228252624 38 | -0.07010562098119343,0.0063491827935987935,1.8518532221449926,-0.7091515816170394,-0.28407611376962083,1.2180418377219873,-1.25313228252624 39 | -0.9108084803335884,0.00016545101742275193,-0.00706490623433922,0.47689110645022736,0.48923680774731715,-0.36836859560229473,-1.2273638046557853 40 | -0.826738194398349,0.8226017772488363,-1.105516527549399,0.07813537511726695,-0.4774043441488554,-1.501518905119639,-1.1887110878501035 41 | -0.07010562098119343,0.00016545101742275193,-0.00706490623433922,1.9185464428078534,-0.7673966897177072,0.31152159010811187,-1.1629426099796487 42 | 1.6113000977235965,-0.029722585900761447,-1.5279979203628835,-1.2612749019242153,2.9058396874877492,-0.8216287194092324,-1.1500583710444214 43 | -0.32231647878691194,-0.4667062980838684,-0.6830351347359144,1.3459741106374488,-0.3807402289592382,0.7647817139150496,-1.1371741321091942 44 | 0.6024566665007225,-0.0049876587960572824,-1.105516527549399,-0.9954377477022418,-0.3807402289592382,0.31152159010811187,-1.1242898931739669 45 | -0.6585976225278699,-0.5058699326663166,-1.5279979203628835,1.581137747064579,0.005916231799230793,0.5381516520115807,-1.1242898931739669 46 | -0.07010562098119343,3.4857289288553184,2.0208457792703864,7.52304818605185e-09,5.225778452038563,2.124562085335863,-1.1242898931739669 47 | 0.7705972383712015,-0.5285436158456288,1.0068904365180236,0.8960958496464164,-0.3807402289592382,-0.5949986575057635,-1.1114056542387396 48 | 2.872354386752189,-0.21729578311143471,-0.6830351347359144,2.020791502123997,0.5859009229369345,-1.0482587813127013,-1.0341002206273755 49 | 0.7705972383712015,-0.5223598840694528,-0.2605537419224299,-0.41264090960022276,1.2625497292642556,0.31152159010811187,-0.9825632648864663 50 | -0.07010562098119343,0.025931000084822926,0.16192765089105457,-0.48421245112152334,-0.7673966897177072,0.31152159010811187,-0.9825632648864663 51 | -0.9948787662688279,0.2135041972954962,-1.5279979203628835,0.5689116598347567,-0.28407611376962083,-0.14173853369882586,-0.969679025951239 52 | 0.9387378102416806,-0.22451013685030677,-1.5279979203628835,-0.09568122572017732,-0.09074788339038635,-0.14173853369882586,-0.9181420702103297 53 | -1.331159910009786,7.338193825412992,-1.105516527549399,1.2948515809793768,-0.3807402289592382,0.5381516520115807,-0.9052578312751024 54 | -0.9108084803335884,-0.27191874713432307,0.16192765089105457,-0.48421245112152334,0.8758932685057861,-1.2748888432161702,-0.9052578312751024 55 | -1.331159910009786,0.00016545101742275193,-0.2605537419224299,1.243729051321305,-0.3807402289592382,1.8979320234323938,-0.8923735923398751 56 | -1.331159910009786,0.00016545101742275193,3.5417787933989304,7.52304818605185e-09,-0.20674482161792718,0.08489152820464299,-0.8666051144694205 57 | -0.07010562098119343,-0.5295742378083248,-1.5279979203628835,-1.475989526488117,1.4558779596434899,-2.1814090908300456,-0.8537208755341931 58 | -1.5833707678155045,-0.3420010405976516,-1.9504793131763678,-0.5148859689163664,-0.09074788339038635,-0.14173853369882586,-0.8408366365989658 59 | 0.9387378102416806,-0.48628811537509253,-1.105516527549399,0.10880889291211006,-0.3807402289592382,0.7647817139150496,-0.8408366365989658 60 | 0.7705972383712015,-0.43372639527759616,-1.105516527549399,-0.197926285036321,-0.1874119985800037,1.2180418377219873,-0.8279523976637385 61 | 0.35024580869500405,-0.4831962494870045,-1.105516527549399,2.3888737156621143,0.4215719271145852,-0.36836859560229473,-0.8150681587285111 62 | -1.6674410537507438,-0.4471244807926443,0.16192765089105457,1.131259486073547,-0.5740684593384727,0.7647817139150496,-0.8021839197932839 63 | -0.23824619285167242,0.00016545101742275193,-0.2605537419224299,-1.445316008693274,-0.4774043441488554,0.5381516520115807,-0.7635312029876019 64 | 2.031651527399794,5.462461853306259,-0.2605537419224299,-0.20815079096793537,-0.3807402289592382,-1.0482587813127013,-0.7506469640523745 65 | 0.6865269524359621,0.00016545101742275193,-1.5279979203628835,0.027012845459195113,-0.1874119985800037,-0.5949986575057635,-0.7377627251171472 66 | -0.07010562098119343,-0.551217299024941,-1.5279979203628835,-0.6069065223008957,-0.67073257452809,0.5381516520115807,-0.7377627251171472 67 | 0.7705972383712015,-0.5048393107036206,1.8518532221449926,0.5484626479715279,-0.5740684593384727,0.7647817139150496,-0.7248784861819199 68 | 1.190948668047399,-0.3904402728443639,-0.00706490623433922,0.20082944629663937,-0.7673966897177072,-1.2748888432161702,-0.7248784861819199 69 | -0.4904570506573909,-0.25336755180579495,0.584409043704539,0.6200341894928285,-0.4774043441488554,0.7647817139150496,-0.7248784861819199 70 | 0.7705972383712015,-0.5285436158456288,0.16192765089105457,0.3030745056127831,0.2959085773680826,-0.14173853369882586,-0.7119942472466926 71 | 0.518386380565483,0.00016545101742275193,1.0068904365180236,7.52304818605185e-09,-0.20674482161792718,0.08489152820464299,-0.6991100083114653 72 | -0.07010562098119343,-0.5213292621067568,-1.105516527549399,-0.6887025697538107,1.0692214988850208,-1.0482587813127013,-0.6862257693762379 73 | 1.527229811788357,-0.5429723233233729,1.0068904365180236,-0.9340907121125556,0.3925726925577,-0.8216287194092324,-0.6733415304410106 74 | -0.15417590691643293,-0.31108238171677133,-1.105516527549399,0.3950950589973124,-0.3807402289592382,0.9914117758185185,-0.6733415304410106 75 | -0.826738194398349,-0.5192680181813647,1.0068904365180236,1.4584436758852068,-0.67073257452809,0.7647817139150496,-0.6604572915057833 76 | -0.4904570506573909,-0.551217299024941,-0.2605537419224299,-0.9238662061809412,-0.28407611376962083,0.08489152820464299,-0.6604572915057833 77 | 0.35024580869500405,-0.5295742378083248,1.8518532221449926,0.4155440708605411,-0.5740684593384727,0.7647817139150496,-0.6604572915057833 78 | -1.4152301959450253,-0.5130842864051887,0.16192765089105457,-0.28994683842085034,-0.67073257452809,0.5381516520115807,-0.6604572915057833 79 | 0.7705972383712015,-0.5316354817337168,0.584409043704539,-0.14680375537824916,-0.5740684593384727,-0.14173853369882586,-0.647573052570556 80 | -0.07010562098119343,0.32481136926666493,0.584409043704539,0.34397252933924055,-0.3807402289592382,-0.8216287194092324,-0.647573052570556 81 | -1.5833707678155045,0.00016545101742275193,1.8518532221449926,7.52304818605185e-09,-0.20674482161792718,0.08489152820464299,-0.6218045747001013 82 | -0.23824619285167242,-0.4512469686434283,-0.00706490623433922,0.6507077072876716,-0.67073257452809,1.2180418377219873,-0.608920335764874 83 | -0.23824619285167242,-0.46258381023308437,1.8518532221449926,-0.4535389333266802,-0.3807402289592382,0.9914117758185185,-0.608920335764874 84 | 0.18210523682452506,-0.06991684244590572,-1.105516527549399,-0.09568122572017732,-0.09074788339038635,-0.5949986575057635,-0.608920335764874 85 | 0.7705972383712015,-0.5388498354725889,1.8518532221449926,-0.08545671978856294,-0.28407611376962083,-0.14173853369882586,-0.5831518578944194 86 | -0.07010562098119343,-0.4388795050910762,-1.105516527549399,0.5586871539031423,-0.1874119985800037,0.08489152820464299,-0.5831518578944194 87 | 0.18210523682452506,-0.5367885915471968,0.16192765089105457,-0.4330899214634515,-0.28407611376962083,0.7647817139150496,-0.5702676189591921 88 | 0.35024580869500405,-0.2853168326493712,-1.105516527549399,0.3541970352708549,-0.28407611376962083,0.9914117758185185,-0.5573833800239647 89 | 1.190948668047399,0.00016545101742275193,0.584409043704539,7.52304818605185e-09,-0.20674482161792718,0.08489152820464299,-0.5573833800239647 90 | 1.6113000977235965,0.3258419912293609,-1.105516527549399,-1.169254348539686,-0.28407611376962083,1.671301961528925,-0.5573833800239647 91 | -1.5833707678155045,4.768853272411847,-0.6830351347359144,-0.38196739180537964,-0.3807402289592382,0.7647817139150496,-0.5573833800239647 92 | -0.07010562098119343,-0.545033567248765,1.0068904365180236,0.2315029640914825,0.8758932685057861,1.4446718996254562,-0.5573833800239647 93 | 0.9387378102416806,-0.261612527507363,-0.6830351347359144,3.656712451182296,0.2959085773680826,0.31152159010811187,-0.5444991410887374 94 | -0.4904570506573909,0.1712486968249599,0.584409043704539,-0.0036606723356479923,-0.09074788339038635,0.08489152820464299,-0.5444991410887374 95 | -1.331159910009786,1.3337902707460558,-0.2605537419224299,-0.38196739180537964,-0.4774043441488554,0.31152159010811187,-0.5444991410887374 96 | 0.18210523682452506,0.3650056258118092,-0.00706490623433922,0.4155440708605411,-0.28407611376962083,-0.8216287194092324,-0.5444991410887374 97 | -1.331159910009786,-0.29871491816441925,-0.2605537419224299,5.998124309521987,-0.09074788339038635,1.2180418377219873,-0.5444991410887374 98 | 2.031651527399794,-0.4667062980838684,1.8518532221449926,0.43599308272376985,-0.1874119985800037,-1.0482587813127013,-0.5187306632182828 99 | -0.4904570506573909,-0.5378192135098928,-0.2605537419224299,-0.3615183799421509,-0.1874119985800037,-0.36836859560229473,-0.5187306632182828 100 | -0.9108084803335884,-0.21935702703682672,-1.105516527549399,-0.11613023758340604,0.1992444621784655,-0.14173853369882586,-0.5187306632182828 101 | 0.7705972383712015,-0.45227759060612427,1.8518532221449926,0.8960958496464164,-0.09074788339038635,0.08489152820464299,-0.5187306632182828 102 | -0.07010562098119343,0.17743242860113595,0.16192765089105457,0.660932213219286,-0.1874119985800037,-2.4080391527335143,-0.5058464242830555 103 | -0.23824619285167242,-0.1874077461932505,0.16192765089105457,-1.0158867595654706,-0.3807402289592382,0.5381516520115807,-0.5058464242830555 104 | -0.07010562098119343,-0.5007168228528366,1.8518532221449926,0.07813537511726695,-0.67073257452809,-0.14173853369882586,-0.4671937074773735 105 | 2.031651527399794,-0.49453309107666055,1.8518532221449926,2.491118774978258,1.7458703052123419,0.31152159010811187,-0.4671937074773735 106 | 0.35024580869500405,-0.4831962494870045,1.8518532221449926,-0.6171310282325101,-0.4774043441488554,0.7647817139150496,-0.4671937074773735 107 | 2.1157218133350333,0.00016545101742275193,-0.00706490623433922,7.52304818605185e-09,0.4215719271145852,-0.5949986575057635,-0.45430946854214616 108 | -0.07010562098119343,0.15991185523530382,1.8518532221449926,-0.5455594867112096,0.10258034698884815,-0.36836859560229473,-0.45430946854214616 109 | 0.43431609463024357,-0.5295742378083248,-0.00706490623433922,-1.0363357714286991,-0.3807402289592382,-0.14173853369882586,-0.45430946854214616 110 | -0.07010562098119343,0.00016545101742275193,0.16192765089105457,-0.47398794518990894,2.229190881160428,-0.5949986575057635,-0.4414252296069188 111 | -1.2470896240745464,-0.42651204153872413,-1.7814867560509742,0.07813537511726695,0.6825650381265518,-2.861299276540452,-0.38988827386600955 112 | -0.23824619285167242,-0.3935321387324519,1.8518532221449926,0.37464604713408367,-0.5740684593384727,0.08489152820464299,-0.3383513181251003 113 | 0.013964664954046066,-0.34406228452304355,-0.6830351347359144,0.037237351390809484,-0.67073257452809,-0.14173853369882586,-0.3383513181251003 114 | -0.6585976225278699,-0.32138860134373143,-0.2605537419224299,-0.37174288587376525,1.939198535591576,1.8979320234323938,-0.32546707918987294 115 | -0.6585976225278699,1.2637079772827273,1.8518532221449926,-0.14680375537824916,-0.67073257452809,0.31152159010811187,-0.3125828402546456 116 | -0.07010562098119343,0.5154764323654262,0.584409043704539,-0.1365792494466348,4.5491296457112425,-1.2748888432161702,-0.2996986013194183 117 | -1.2470896240745464,0.1413606599067757,0.16192765089105457,7.52304818605185e-09,-0.20674482161792718,0.08489152820464299,-0.2996986013194183 118 | 0.18210523682452506,-0.40074649247132393,1.8518532221449926,0.3235235174760118,-0.09074788339038635,1.8979320234323938,-0.2996986013194183 119 | 1.695370383658836,4.0793671793682185,-0.2605537419224299,-0.3308448621473078,-0.20674482161792718,0.08489152820464299,-0.2996986013194183 120 | 1.190948668047399,0.00016545101742275193,0.16192765089105457,7.52304818605185e-09,-0.20674482161792718,0.08489152820464299,-0.2996986013194183 121 | 0.35024580869500405,-0.5388498354725889,1.8518532221449926,-0.9340907121125556,-0.4774043441488554,0.08489152820464299,-0.2996986013194183 122 | 0.6024566665007225,0.0661252566299672,-1.105516527549399,0.4257685767921555,0.6825650381265518,-1.501518905119639,-0.286814362384191 123 | 0.09803495088928556,-0.31005175975407534,-0.2605537419224299,-0.4330899214634515,-0.3807402289592382,-0.14173853369882586,-0.286814362384191 124 | -0.9108084803335884,0.9957462669817655,-0.6830351347359144,-0.5353349807795952,-0.5740684593384727,0.31152159010811187,-0.286814362384191 125 | -0.9108084803335884,-0.10289674525217794,-0.6830351347359144,0.6711567191509004,-0.4774043441488554,-1.0482587813127013,-0.27393012344896367 126 | 0.013964664954046066,-0.5130842864051887,0.16192765089105457,-0.3512938740105365,-0.4774043441488554,0.9914117758185185,-0.26104588451373634 127 | 0.9387378102416806,0.37221997955068126,-1.105516527549399,0.7631772725354297,0.2959085773680826,0.5381516520115807,-0.248161645578509 128 | -0.9108084803335884,-0.408991468172892,-0.6830351347359144,0.027012845459195113,-0.67073257452809,0.9914117758185185,-0.2352774066432817 129 | -0.7426679084631094,-0.46361443219578036,-0.6830351347359144,-0.4637634392582946,-0.67073257452809,-0.14173853369882586,-0.2352774066432817 130 | 0.2661755227597646,1.059644828668918,1.8518532221449926,-0.21837529689954974,-0.3807402289592382,0.08489152820464299,-0.22239316770805437 131 | 1.190948668047399,0.00016545101742275193,-0.6830351347359144,-0.39219189773699403,0.4215719271145852,-0.5949986575057635,-0.22239316770805437 132 | -0.07010562098119343,1.7305797263840186,-0.2605537419224299,-0.3615183799421509,-0.4774043441488554,-0.14173853369882586,-0.19662468983759973 133 | 0.9387378102416806,-0.35952161396348364,0.584409043704539,-0.28994683842085034,1.0692214988850208,-0.36836859560229473,-0.19662468983759973 134 | 0.09803495088928556,-0.5687378723907731,1.8518532221449926,-0.197926285036321,-0.4774043441488554,0.5381516520115807,-0.1708562119671451 135 | -0.9108084803335884,-0.4811350055616125,0.584409043704539,-0.8113966409331831,-0.4774043441488554,-0.5949986575057635,-0.15797197303191776 136 | -0.9108084803335884,1.3028716118651755,-0.2605537419224299,7.52304818605185e-09,-0.20674482161792718,0.08489152820464299,-0.14508773409669043 137 | 0.35024580869500405,-0.25439817376849094,-0.2605537419224299,-0.28994683842085034,-0.5740684593384727,-0.14173853369882586,-0.13220349516146312 138 | -0.07010562098119343,-0.3615828578888757,-1.105516527549399,-0.7091515816170394,0.2959085773680826,0.7647817139150496,-0.13220349516146312 139 | -0.9108084803335884,-0.3420010405976516,-1.105516527549399,-0.013885178267262361,-0.3807402289592382,-0.14173853369882586,-0.13220349516146312 140 | -0.15417590691643293,-0.4667062980838684,0.584409043704539,1.0085654148941745,-0.28407611376962083,0.5381516520115807,-0.1193192562262358 141 | 0.43431609463024357,-0.5254517499575407,0.16192765089105457,-0.21837529689954974,-0.1874119985800037,-0.5949986575057635,-0.1193192562262358 142 | -1.331159910009786,-0.4656756761211724,-0.2605537419224299,-0.9136417002493268,-0.5740684593384727,0.5381516520115807,-0.1193192562262358 143 | 0.18210523682452506,0.00016545101742275193,0.16192765089105457,1.8878729250130102,-0.4774043441488554,0.08489152820464299,-0.09355077835578116 144 | -0.9108084803335884,1.805815129660827,-0.2605537419224299,-1.9258677874791492,-0.4774043441488554,1.2180418377219873,-0.05489806155009919 145 | -1.331159910009786,1.9171223016319958,-0.6830351347359144,0.7222792488089722,-0.28407611376962083,0.5381516520115807,-0.01624534474441723 146 | 1.6113000977235965,0.2001061117804481,-0.00706490623433922,-0.7296005934802682,-0.09074788339038635,-0.36836859560229473,-0.003361105809189911 147 | -0.6585976225278699,-0.3976546265832359,1.8518532221449926,-0.4433144273950658,-0.67073257452809,-0.8216287194092324,0.048175849931719375 148 | -0.15417590691643293,-0.5316354817337168,-1.5279979203628835,-1.9769903171372212,0.9725573836954035,-0.5949986575057635,0.06106008886694669 149 | 0.35024580869500405,0.00016545101742275193,0.16192765089105457,0.06791086918565259,-0.3807402289592382,0.31152159010811187,0.1254812835430833 150 | 0.7705972383712015,0.2609128075795125,-0.2605537419224299,0.4257685767921555,-0.5740684593384727,-0.8216287194092324,0.1899024782192199 151 | -0.826738194398349,0.00016545101742275193,-0.2605537419224299,7.52304818605185e-09,0.10258034698884815,-0.14173853369882586,0.1899024782192199 152 | -0.7426679084631094,3.48779017278071,0.16192765089105457,0.6302586954244429,-0.4774043441488554,0.7647817139150496,0.20278671715444724 153 | 0.7705972383712015,-0.4234201756506361,1.8518532221449926,-0.8931926883860981,-0.28407611376962083,1.8979320234323938,0.20278671715444724 154 | -0.9108084803335884,-0.4811350055616125,-1.5279979203628835,-0.7602741112751112,-0.5740684593384727,0.5381516520115807,0.20278671715444724 155 | 0.35024580869500405,-0.3955933826578439,-0.2605537419224299,0.18038043443341065,-0.4774043441488554,0.08489152820464299,0.20278671715444724 156 | -0.07010562098119343,-0.5017474448155326,1.8518532221449926,0.7529527666038153,-0.3807402289592382,0.31152159010811187,0.20278671715444724 157 | 0.6865269524359621,0.8627960337939805,0.16192765089105457,-1.6191326095307184,-0.3807402289592382,-0.36836859560229473,0.21567095608967454 158 | 0.18210523682452506,-0.47392065182274046,1.8518532221449926,0.037237351390809484,-0.1874119985800037,1.8979320234323938,0.21567095608967454 159 | -1.7515113396859834,-0.10701923310296196,-0.6830351347359144,0.40531956492892673,-0.4774043441488554,-0.14173853369882586,0.22855519502490187 160 | -0.15417590691643293,-0.41826706583715606,-1.105516527549399,-0.4330899214634515,-0.3807402289592382,-0.14173853369882586,0.2543236728953565 161 | 0.35024580869500405,-0.19256085600673054,-1.105516527549399,0.016788339527580746,-0.1874119985800037,-0.14173853369882586,0.3058606286362658 162 | 1.190948668047399,-0.49762495696474857,-0.00706490623433922,-0.40241640366860837,1.0692214988850208,-0.5949986575057635,0.4089345401180844 163 | -0.23824619285167242,-0.4502163466807323,-1.105516527549399,-0.4535389333266802,-0.1874119985800037,0.08489152820464299,0.5120084515999029 164 | -0.014030740262388553,-0.49247184715126857,-0.6830351347359144,1.2846270750477624,0.10258034698884815,-0.14173853369882586,0.5248926905351302 165 | -0.9108084803335884,0.00016545101742275193,1.0068904365180236,-1.1283563248132285,-0.7673966897177072,-0.5949986575057635,0.5377769294703576 166 | -0.07010562098119343,1.354402709999976,-1.105516527549399,1.0392389326890177,0.6825650381265518,1.671301961528925,0.5377769294703576 167 | -0.014030740262388553,-0.44403261490455626,0.16192765089105457,-0.6375800400957389,-0.3807402289592382,-0.14173853369882586,0.5377769294703576 168 | -1.7515113396859834,-0.3481847723738276,0.584409043704539,0.11903339884372444,-0.4774043441488554,0.7647817139150496,0.5635454073408123 169 | 1.6113000977235965,0.00016545101742275193,-0.2605537419224299,0.8858713437148021,0.6825650381265518,-0.5949986575057635,0.5635454073408123 170 | 0.2661755227597646,-0.5357579695845008,1.8518532221449926,0.466666600518613,0.10258034698884815,-0.36836859560229473,0.5635454073408123 171 | -0.9108084803335884,-0.47495127378543645,0.16192765089105457,-0.0343341901304911,-0.67073257452809,-1.501518905119639,0.5764296462760395 172 | 1.0228080961769201,-0.3615828578888757,-0.6830351347359144,-1.056784783291928,-0.20674482161792718,1.2180418377219873,0.6408508409521761 173 | -1.331159910009786,0.00016545101742275193,-1.5279979203628835,-1.4044179849668166,0.1992444621784655,-0.36836859560229473,0.6408508409521761 174 | 1.359089239917878,-0.16885655086472237,0.584409043704539,-0.41264090960022276,0.3925726925577,1.8979320234323938,0.6408508409521761 175 | -1.331159910009786,0.00016545101742275193,-0.00706490623433922,7.52304818605185e-09,-0.20674482161792718,0.08489152820464299,0.7052720356283128 176 | 0.35024580869500405,-0.4275426635014201,-0.6830351347359144,-0.04455869606210547,-0.5740684593384727,0.31152159010811187,0.71815627456354 177 | -0.9108084803335884,0.00016545101742275193,-1.5279979203628835,0.15993142257018192,-0.3807402289592382,-0.5949986575057635,0.71815627456354 178 | -0.07010562098119343,0.6484266655532112,-0.2605537419224299,7.52304818605185e-09,0.3925726925577,-5.354229957478609,0.71815627456354 179 | -1.331159910009786,-0.28222496676128317,1.8518532221449926,1.1619330038683902,-0.3807402289592382,-0.14173853369882586,0.71815627456354 180 | 0.7705972383712015,-0.4996862008901406,1.8518532221449926,-0.4433144273950658,-0.4774043441488554,0.31152159010811187,0.71815627456354 181 | -0.07010562098119343,-0.5388498354725889,-1.105516527549399,-0.5251104748479808,2.0358626507811937,-0.14173853369882586,0.7310405134987674 182 | 1.4431595258531176,-0.5336967256591089,0.16192765089105457,0.13948241070695316,-0.67073257452809,0.08489152820464299,0.7310405134987674 183 | -0.9108084803335884,-0.4275426635014201,0.584409043704539,1.0085654148941745,-0.3807402289592382,-0.14173853369882586,0.7310405134987674 184 | -1.7515113396859834,-0.4955637130393566,0.16192765089105457,-0.38196739180537964,-0.5740684593384727,0.9914117758185185,0.7310405134987674 185 | 2.031651527399794,-0.38116467518009983,-0.00706490623433922,-0.7909476290699544,-0.4774043441488554,-0.14173853369882586,0.7310405134987674 186 | -0.07010562098119343,1.7511921656379386,0.16192765089105457,0.20082944629663937,-0.3807402289592382,0.9914117758185185,0.7310405134987674 187 | -0.9948787662688279,0.40210801646886546,-0.2605537419224299,0.047461857322423855,-0.5740684593384727,-1.501518905119639,0.7310405134987674 188 | 0.7705972383712015,-0.38116467518009983,-1.7814867560509742,1.2846270750477624,-0.3807402289592382,-0.14173853369882586,0.7439247524339947 189 | -0.9108084803335884,0.00016545101742275193,2.0208457792703864,-1.1897033604029148,-0.5740684593384727,0.7647817139150496,0.795461708174904 190 | 1.4431595258531176,-0.3687972116277477,1.0068904365180236,2.2252816207562844,0.005916231799230793,0.31152159010811187,0.795461708174904 191 | -1.0789490522040674,-0.46464505415847634,-0.6830351347359144,-0.197926285036321,0.1992444621784655,-1.501518905119639,0.8083459471101313 192 | 0.35024580869500405,-0.46052256630769234,-0.2605537419224299,0.27240098781794,-0.5740684593384727,-0.5949986575057635,0.8212301860453587 193 | 1.0228080961769201,0.00016545101742275193,-0.2605537419224299,-0.6171310282325101,-0.09074788339038635,-0.5949986575057635,0.834114424980586 194 | 0.7705972383712015,0.639151067888947,1.0068904365180236,0.967667391167717,-0.4774043441488554,0.9914117758185185,0.8469986639158132 195 | -0.5745273365926304,-0.15958095320045831,2.6968160077719614,-1.1488053366764572,7.352388986210143,0.08489152820464299,0.8469986639158132 196 | 0.6024566665007225,0.4526084926409698,-0.2605537419224299,0.07813537511726695,-0.28407611376962083,-0.5949986575057635,0.8598829028510406 197 | -0.4904570506573909,0.00016545101742275193,-0.2605537419224299,1.1005859682787038,-0.67073257452809,0.7647817139150496,0.8598829028510406 198 | 1.0228080961769201,0.00016545101742275193,-1.5279979203628835,7.52304818605185e-09,0.4215719271145852,-0.5949986575057635,0.8727671417862679 199 | -1.5833707678155045,-0.5110230424797967,-0.2605537419224299,1.0392389326890177,-0.28407611376962083,0.5381516520115807,0.9114198585919498 200 | -1.1630193381393068,0.00016545101742275193,-1.105516527549399,-1.363519961240359,-0.5740684593384727,-0.5949986575057635,0.9114198585919498 201 | -0.23824619285167242,0.00016545101742275193,-1.105516527549399,2.460445257183415,-0.3807402289592382,0.31152159010811187,0.9629568143328592 202 | 1.190948668047399,0.0960132935481514,1.8518532221449926,0.016788339527580746,0.005916231799230793,-2.6346692146369834,0.9629568143328592 203 | -0.23824619285167242,-0.5409110793979809,-1.105516527549399,-0.7602741112751112,-0.09074788339038635,-1.0482587813127013,0.9629568143328592 204 | -0.4904570506573909,2.27990123250099,-0.2605537419224299,-1.251050395992601,-0.3807402289592382,0.7647817139150496,0.9758410532680865 205 | 0.35024580869500405,-0.5419417013606769,-1.105516527549399,-0.26949782655762156,3.485824378625453,-1.501518905119639,0.9887252922033138 206 | 0.9387378102416806,-0.3821952971427958,-1.105516527549399,0.10880889291211006,-0.1874119985800037,-0.5949986575057635,0.9887252922033138 207 | -0.07010562098119343,-0.4285732854641161,-0.6830351347359144,-2.0587863645901363,0.2959085773680826,-2.1814090908300456,0.9887252922033138 208 | 0.7705972383712015,-0.5038086887409247,-0.2605537419224299,-0.8011721350015688,-0.28407611376962083,-0.5949986575057635,1.0016095311385411 209 | -1.7515113396859834,-0.4667062980838684,-0.2605537419224299,-0.08545671978856294,-0.4774043441488554,0.08489152820464299,1.0144937700737684 210 | -0.6585976225278699,0.1289931963544236,-0.00706490623433922,0.6813812250825148,0.005916231799230793,0.08489152820464299,1.0144937700737684 211 | -0.6585976225278699,0.00016545101742275193,0.584409043704539,0.4257685767921555,-0.28407611376962083,0.08489152820464299,1.0144937700737684 212 | 1.359089239917878,-0.4873187373377885,1.0068904365180236,1.4584436758852068,-0.28407611376962083,0.08489152820464299,1.0144937700737684 213 | 1.190948668047399,-0.4770125177108285,1.0068904365180236,-0.15702826130986353,-0.28407611376962083,2.5778222091428002,1.0144937700737684 214 | 0.7705972383712015,-0.3605522359261797,-0.6830351347359144,-0.9238662061809412,-0.1874119985800037,-1.0482587813127013,1.0273780090089957 215 | 0.35024580869500405,0.1423912818694717,0.16192765089105457,-0.06500770792533421,-0.3807402289592382,-0.14173853369882586,1.0273780090089957 216 | 0.7705972383712015,-0.5161761522932767,-0.2605537419224299,2.7569559292002315,-0.09074788339038635,0.5381516520115807,1.0531464868794504 217 | 0.35024580869500405,0.00016545101742275193,-0.6830351347359144,-0.14680375537824916,-0.09074788339038635,-0.14173853369882586,1.0531464868794504 218 | -1.7515113396859834,-0.5069005546290126,-0.2605537419224299,-0.08545671978856294,-0.28407611376962083,-0.14173853369882586,1.0531464868794504 219 | -0.5745273365926304,0.00016545101742275193,-0.00706490623433922,0.006563833595966377,0.3925726925577,-0.5949986575057635,1.0660307258146777 220 | 0.013964664954046066,-0.5172067742559727,-0.00706490623433922,0.190604940365025,0.005916231799230793,0.08489152820464299,1.0660307258146777 221 | -0.4904570506573909,1.4791079674861929,-1.105516527549399,0.5177891301766848,-0.28407611376962083,0.31152159010811187,1.078914964749905 222 | 0.2661755227597646,-0.45227759060612427,-1.105516527549399,-0.17747727317309225,0.9725573836954035,-0.36836859560229473,1.078914964749905 223 | -1.7515113396859834,0.04345157345065504,-0.2605537419224299,0.384870553065698,-0.3807402289592382,1.2180418377219873,1.078914964749905 224 | -0.6585976225278699,-0.3863177849935798,0.16192765089105457,-0.41264090960022276,-0.1874119985800037,-1.501518905119639,1.078914964749905 225 | -0.9108084803335884,1.9995720586476764,-0.6830351347359144,1.437994664021978,-0.8640608049073245,0.5381516520115807,1.078914964749905 226 | -0.4904570506573909,-0.010140768609537318,-0.2605537419224299,-0.3308448621473078,-0.5740684593384727,1.4446718996254562,1.0917992036851323 227 | -0.9108084803335884,-0.34715415041113157,0.584409043704539,0.10880889291211006,-0.3807402289592382,-0.8216287194092324,1.0917992036851323 228 | 0.7705972383712015,-0.5089617985544047,-0.2605537419224299,-0.27972233248923595,-0.1874119985800037,-1.0482587813127013,1.0917992036851323 229 | -0.6585976225278699,-0.13999913590923418,1.8518532221449926,7.52304818605185e-09,-0.3807402289592382,0.5381516520115807,1.0917992036851323 230 | -0.7426679084631094,-0.40280773639671597,-0.6830351347359144,0.7222792488089722,-0.3807402289592382,1.2180418377219873,1.1046834426203598 231 | -0.23824619285167242,-0.46361443219578036,-0.00706490623433922,-0.10590573165179168,-0.3807402289592382,0.5381516520115807,1.285062787713542 232 | -1.331159910009786,-0.5316354817337168,-1.105516527549399,-0.31039585028407907,-0.5740684593384727,-0.36836859560229473,1.285062787713542 233 | -0.6585976225278699,-0.5419417013606769,1.0068904365180236,0.4564420945869986,-0.67073257452809,-0.36836859560229473,1.2979470266487696 234 | -0.4904570506573909,-0.5316354817337168,0.16192765089105457,-0.6171310282325101,-0.3807402289592382,0.31152159010811187,1.3237155045192242 235 | 0.09803495088928556,0.07540085429423125,0.16192765089105457,0.20082944629663937,-0.67073257452809,-0.8216287194092324,1.3237155045192242 236 | 0.35024580869500405,-0.3337560648960835,-1.105516527549399,-0.6682535578905819,0.005916231799230793,-1.7281489670231078,1.3494839823896787 237 | 0.6024566665007225,-0.4378488831283802,1.8518532221449926,-0.5660084985744382,-0.3807402289592382,0.7647817139150496,1.3752524602601335 238 | 0.013964664954046066,0.00016545101742275193,-0.00706490623433922,-1.1897033604029148,-0.1874119985800037,0.9914117758185185,1.3752524602601335 239 | -0.4904570506573909,0.636059202000859,-1.5279979203628835,7.52304818605185e-09,0.4215719271145852,-0.5949986575057635,1.4267894160010428 240 | -0.4063867647221514,-0.46052256630769234,-0.00706490623433922,-1.3328464434455158,0.2959085773680826,0.7647817139150496,1.4654421328067246 241 | -1.331159910009786,0.00016545101742275193,-0.00706490623433922,0.3950950589973124,-0.4774043441488554,0.7647817139150496,1.4654421328067246 242 | -1.7515113396859834,0.00016545101742275193,-0.2605537419224299,-0.4228654155318371,-0.3807402289592382,-1.0482587813127013,1.4654421328067246 243 | -1.4152301959450253,0.00016545101742275193,-0.6830351347359144,7.52304818605185e-09,0.1992444621784655,-1.501518905119639,1.4654421328067246 244 | -0.826738194398349,0.00016545101742275193,0.16192765089105457,-0.4330899214634515,-0.4774043441488554,-0.5949986575057635,1.4654421328067246 245 | 0.518386380565483,-0.3801340532174038,-0.00706490623433922,-0.49443695705313767,-0.1874119985800037,-0.8216287194092324,1.478326371741952 246 | -1.5833707678155045,-0.5336967256591089,0.16192765089105457,-0.7602741112751112,-0.67073257452809,0.7647817139150496,1.478326371741952 247 | -0.07010562098119343,-0.3347866868587795,-0.6830351347359144,-1.1590298426080716,-0.3807402289592382,0.08489152820464299,1.478326371741952 248 | -1.331159910009786,0.00016545101742275193,-0.00706490623433922,1.6220357707910367,-0.5740684593384727,0.08489152820464299,1.478326371741952 249 | 0.7705972383712015,0.037267841674479,-0.2605537419224299,0.6507077072876716,-0.28407611376962083,1.2180418377219873,1.478326371741952 250 | 0.7705972383712015,0.00016545101742275193,-0.00706490623433922,-2.436070633466706,-0.28407611376962083,0.7647817139150496,1.4912106106771794 251 | -0.9108084803335884,0.48352715152185,-0.6830351347359144,-0.3206203562156934,-0.67073257452809,-0.14173853369882586,1.4912106106771794 252 | -0.4904570506573909,-0.5130842864051887,-0.00706490623433922,1.9185464428078534,-0.09074788339038635,-0.14173853369882586,1.4912106106771794 253 | 0.7705972383712015,2.1778696581940853,0.16192765089105457,-0.2285998028311641,-0.3807402289592382,0.08489152820464299,1.5040948496124067 254 | 0.7705972383712015,0.00016545101742275193,0.16192765089105457,-2.171255929837894,1.2625497292642556,-0.14173853369882586,1.5427475664180885 255 | -1.5833707678155045,-0.5336967256591089,-0.6830351347359144,-0.49443695705313767,2.3258549963500452,-1.9547790289265767,1.5427475664180885 256 | 0.35024580869500405,1.1400333417592066,-0.00706490623433922,7.52304818605185e-09,-0.28407611376962083,0.31152159010811187,1.5427475664180885 257 | -0.9108084803335884,-0.5440029452860689,0.16192765089105457,0.15993142257018192,-0.5740684593384727,0.9914117758185185,1.5427475664180885 258 | -0.4904570506573909,-0.4244507976133321,0.16192765089105457,0.7427282606722009,-0.1874119985800037,-0.36836859560229473,1.5427475664180885 259 | -1.331159910009786,0.00016545101742275193,1.429371829331508,2.8592009885163754,-0.3807402289592382,-1.0482587813127013,1.5427475664180885 260 | 0.35024580869500405,0.3196582594531849,-0.2605537419224299,7.52304818605185e-09,-0.28407611376962083,1.2180418377219873,1.6200530000294526 261 | 2.4520029570759916,-0.25233692984309897,-0.00706490623433922,1.2948515809793768,-0.4774043441488554,1.671301961528925,1.6200530000294526 262 | -1.331159910009786,0.03417597578639098,1.429371829331508,-0.4228654155318371,-0.5740684593384727,0.9914117758185185,1.63293723896468 263 | -0.07010562098119343,-0.26985750320893104,-0.2605537419224299,-1.3328464434455158,0.005916231799230793,0.5381516520115807,1.6458214778999072 264 | -0.7426679084631094,-0.40383835835941195,-0.00706490623433922,1.213055533526462,-0.3807402289592382,0.7647817139150496,1.6458214778999072 265 | 0.18210523682452506,-0.49350246911396456,-0.2605537419224299,-0.8625191705912549,-0.4774043441488554,-0.14173853369882586,1.800432345122635 266 | 0.09803495088928556,-0.5367885915471968,-0.00706490623433922,-1.10790731295,-0.28407611376962083,1.4446718996254562,1.800432345122635 267 | -0.4904570506573909,1.2760754408350794,-0.00706490623433922,0.06791086918565259,-0.1874119985800037,0.5381516520115807,1.8133165840578624 268 | -1.331159910009786,1.5234247118821211,1.8518532221449926,4.893877668907635,-0.5740684593384727,0.31152159010811187,1.9035062566044536 269 | -1.331159910009786,1.8872342647138116,-0.00706490623433922,-1.2612749019242153,0.005916231799230793,0.7647817139150496,1.9292747344749082 270 | -0.9108084803335884,-0.3976546265832359,0.584409043704539,1.3459741106374488,0.1992444621784655,-0.14173853369882586,1.9936959291510448 271 | -------------------------------------------------------------------------------- /SVM/dataset/svm/svm_train_label.csv: -------------------------------------------------------------------------------- 1 | DEATH_EVENT 2 | 1 3 | 1 4 | 1 5 | 1 6 | 1 7 | 1 8 | 1 9 | 1 10 | 1 11 | 1 12 | 1 13 | 1 14 | -1 15 | 1 16 | 1 17 | -1 18 | 1 19 | 1 20 | -1 21 | 1 22 | 1 23 | 1 24 | 1 25 | 1 26 | 1 27 | 1 28 | 1 29 | 1 30 | 1 31 | 1 32 | 1 33 | -1 34 | 1 35 | 1 36 | 1 37 | -1 38 | 1 39 | 1 40 | 1 41 | 1 42 | 1 43 | 1 44 | 1 45 | 1 46 | 1 47 | 1 48 | 1 49 | -1 50 | -1 51 | 1 52 | 1 53 | 1 54 | 1 55 | 1 56 | -1 57 | 1 58 | 1 59 | 1 60 | 1 61 | 1 62 | -1 63 | -1 64 | 1 65 | 1 66 | 1 67 | -1 68 | -1 69 | -1 70 | -1 71 | -1 72 | 1 73 | -1 74 | 1 75 | -1 76 | -1 77 | -1 78 | -1 79 | -1 80 | -1 81 | -1 82 | -1 83 | -1 84 | -1 85 | -1 86 | -1 87 | -1 88 | -1 89 | -1 90 | -1 91 | -1 92 | -1 93 | 1 94 | -1 95 | -1 96 | -1 97 | -1 98 | 1 99 | -1 100 | -1 101 | 1 102 | -1 103 | -1 104 | -1 105 | -1 106 | -1 107 | 1 108 | -1 109 | -1 110 | 1 111 | 1 112 | -1 113 | -1 114 | -1 115 | -1 116 | -1 117 | -1 118 | -1 119 | -1 120 | -1 121 | -1 122 | -1 123 | -1 124 | -1 125 | -1 126 | -1 127 | 1 128 | -1 129 | -1 130 | -1 131 | 1 132 | -1 133 | 1 134 | -1 135 | -1 136 | -1 137 | -1 138 | -1 139 | -1 140 | -1 141 | -1 142 | -1 143 | -1 144 | 1 145 | 1 146 | 1 147 | -1 148 | 1 149 | -1 150 | -1 151 | -1 152 | -1 153 | -1 154 | -1 155 | -1 156 | -1 157 | -1 158 | -1 159 | -1 160 | 1 161 | 1 162 | 1 163 | 1 164 | 1 165 | 1 166 | 1 167 | -1 168 | -1 169 | -1 170 | -1 171 | -1 172 | -1 173 | 1 174 | 1 175 | -1 176 | -1 177 | -1 178 | -1 179 | -1 180 | -1 181 | -1 182 | -1 183 | -1 184 | -1 185 | -1 186 | -1 187 | -1 188 | -1 189 | -1 190 | -1 191 | 1 192 | -1 193 | -1 194 | -1 195 | 1 196 | -1 197 | -1 198 | 1 199 | -1 200 | -1 201 | -1 202 | -1 203 | -1 204 | -1 205 | -1 206 | -1 207 | 1 208 | -1 209 | -1 210 | -1 211 | -1 212 | -1 213 | -1 214 | -1 215 | -1 216 | -1 217 | -1 218 | -1 219 | -1 220 | -1 221 | 1 222 | -1 223 | -1 224 | -1 225 | -1 226 | -1 227 | -1 228 | -1 229 | -1 230 | -1 231 | -1 232 | -1 233 | -1 234 | -1 235 | -1 236 | 1 237 | -1 238 | -1 239 | 1 240 | -1 241 | -1 242 | -1 243 | -1 244 | -1 245 | -1 246 | -1 247 | -1 248 | -1 249 | -1 250 | -1 251 | -1 252 | -1 253 | -1 254 | -1 255 | -1 256 | -1 257 | -1 258 | -1 259 | -1 260 | -1 261 | -1 262 | -1 263 | -1 264 | -1 265 | -1 266 | -1 267 | -1 268 | -1 269 | -1 270 | -1 271 | -------------------------------------------------------------------------------- /SVM/main.py: -------------------------------------------------------------------------------- 1 | from utils import * 2 | from SVM import SupportVectorMachine 3 | 4 | 5 | def test_svm(C=1, kernel='Linear', epsilon = 1e-4): 6 | train_features, train_labels, test_features, test_labels = load_svm_dataset() 7 | model = SupportVectorMachine(C, kernel, epsilon) 8 | model.fit(train_features, train_labels) 9 | pred = model.predict(test_features) 10 | print('SVM({} kernel) acc: {:.2f}%'.format(kernel, get_acc(pred, test_labels.reshape(-1,)) * 100)) 11 | 12 | 13 | if __name__=='__main__': 14 | test_svm(1, 'Linear', 1e-4) 15 | test_svm(1, 'Poly', 1e-4) 16 | test_svm(1, 'Gauss', 1e-4) 17 | 18 | -------------------------------------------------------------------------------- /SVM/utils.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | def get_acc(y, pred): 3 | return np.sum(y == pred) / len(y) 4 | 5 | def load_svm_dataset(): 6 | train_features = np.loadtxt('dataset/svm/svm_train_data.csv', delimiter=',', skiprows=1) 7 | train_labels = np.loadtxt('dataset/svm/svm_train_label.csv', delimiter=',', skiprows=1, dtype=np.int32) 8 | test_features = np.loadtxt('dataset/svm/svm_test_data.csv', delimiter=',', skiprows=1) 9 | test_labels = np.loadtxt('dataset/svm/svm_test_label.csv', delimiter=',', skiprows=1, dtype=np.int32) 10 | 11 | return train_features, train_labels, test_features, test_labels -------------------------------------------------------------------------------- /csp/output/output1.txt: -------------------------------------------------------------------------------- 1 | 2 5 6 7 2 | 2 4 6 7 3 | 1 3 5 7 4 | 2 4 6 7 5 | 2 4 5 6 6 | 1 3 5 7 7 | 2 4 5 6 -------------------------------------------------------------------------------- /csp/output/output2.txt: -------------------------------------------------------------------------------- 1 | 5 6 7 9 10 2 | 5 6 7 9 10 3 | 1 2 3 4 8 4 | 5 6 7 9 10 5 | 5 6 7 9 10 6 | 1 2 3 4 8 7 | 5 6 7 9 10 -------------------------------------------------------------------------------- /csp/src/csp.c: -------------------------------------------------------------------------------- 1 | #include 2 | // 工人最大数目 3 | #define MAXNUM 10 4 | // MRVstatus=1 开启MRV优化 MRVstatus=0,关闭MRV 5 | #define MRVstatus 1 6 | 7 | int dispatch[MAXNUM][7] = {0}; // dispatch[0][3]==1 表示工人0在周四值日 8 | int range[MAXNUM][7][2] = {0}; // range[id][day] 是dispatch[id][day] 的值域 9 | int num; // 工人数 10 | 11 | int senior[MAXNUM]; // senior[n]=id 表示id工人是第n个senior 12 | int numsen; // senior人数 13 | int AB[MAXNUM][MAXNUM] = {0}; // AB工人工作时间冲突 14 | 15 | int x; // 需要每天安排至少 x 个人值班 16 | int cnt = 0; // 每调用一次dfs,cnt+1,用于记录迭代次数 17 | 18 | /* 19 | 1. 每个工人每周必须休息2天或2天以上 20 | 2. 每个工人每周不可以连续休息3天(不考虑跨周情况) 21 | 3. 周六周天也需要有人值班,即一周7天每天都要安排工人值班 22 | 4. 需要每天安排至少 x 个人值班 23 | 5. 每天至少要有一名级别为 senior 的工人值班 24 | 6. 工人a不想与工人b同一天工作 25 | */ 26 | 27 | int dfs(int k); 28 | int prt(); 29 | 30 | int main(int argc, char* argv[]){ 31 | 32 | FILE * fp; 33 | int a,b; 34 | 35 | if(!(fp = fopen(argv[1],"r"))) return printf("文件不存在"); 36 | fscanf(fp,"num:%d,x:%d,num of senior:%d\n",&num,&x,&numsen); 37 | 38 | // 记录senior 39 | for(int i = 0; i < numsen; senior[i++]--) fscanf(fp,"%d",senior+i); 40 | 41 | // 记录员工工作时间冲突 42 | while (fscanf(fp,"%d %d",&a,&b) == 2) 43 | AB[a-1][b-1] = AB[b-1][a-1] = 1; 44 | 45 | fclose(fp); 46 | 47 | if(dfs(0)) 48 | prt(); 49 | else 50 | printf("failed\n"); 51 | return 0; 52 | } 53 | 54 | int check1(int id,int day); 55 | int check2(int id,int day); 56 | int check3(int id,int day); 57 | int check4(int id,int day); 58 | int check5(int id,int day); 59 | int check6(int id,int day); 60 | 61 | int MRVn = 0,MRV[MAXNUM*7]; // MRVn: 通过MRV赋值的格子数,MRV:通过MRV赋值的格子集合,这里仅对 约束3,6 使用MRV优化 62 | int MRVappend(int k,int status){ 63 | int id = k % num, day = k / num,j; 64 | if(dispatch[id][day] == status) 65 | MRV[MRVn++] = k; 66 | else{ 67 | for(j = 0; j < MRVn && MRV[j] != k; ++j); 68 | if(j != MRVn) 69 | return 0; // 该节点已被MRV赋值过,加入MRV数组失败,返回0 70 | dispatch[id][day] = status; 71 | MRV[MRVn++] = k; 72 | } 73 | return 1; 74 | } 75 | 76 | // 按天排班. dfs(id,day) 说明0,1,...,day-1都已经排好 77 | int dfs(int k){ 78 | cnt++; 79 | int id = k % num, day = k / num,MRVntmp = MRVn; 80 | if(day == 7) 81 | return 1; 82 | 83 | // 检查该格子有没有被MRV赋值过 84 | for(int i = 0; MRVstatus && i < MRVn; ++i) 85 | if(MRV[i] == k){ 86 | if(check1(id,day) || check2(id,day) || check4(id,day) || check5(id,day) || check6(id,day)) return 0; 87 | if(dfs(k+1)) return 1; 88 | MRVn = MRVntmp; // MRV回溯 89 | return 0; 90 | } 91 | 92 | for(int color = 0;color < 2; color++){ // 给格子上色(这里只有两种颜色,代表值日与休息) 93 | dispatch[id][day] = color; 94 | MRVn = MRVntmp; // MRV回溯 95 | if(check1(id,day) || check2(id,day) || check4(id,day) || check5(id,day) || check6(id,day)) 96 | continue; 97 | // 无冲突,下面进行dfs迭代下一个格子 98 | if(dfs(k+1)) 99 | return 1; 100 | } 101 | MRVn = MRVntmp; // MRV回溯 102 | return 0; 103 | } 104 | 105 | // 1. 每个工人每周必须休息2天或2天以上 106 | // id工人工作大于5天返回1,否则返回0 107 | int check1(int id,int day){ 108 | int s = 0; 109 | for(int i = 0; i <= day; ++i) 110 | if(dispatch[id][i]) 111 | s++; 112 | if(s > 5) 113 | return 1; 114 | 115 | // MRV 赋值 116 | if(MRVstatus && s == 5) 117 | for(int i = day+1; i < 7; ++i) 118 | if(!MRVappend(id+i*num,0)) 119 | return 1; 120 | return 0; 121 | } 122 | 123 | // 2. 每个工人每周不可以连续休息3天(不考虑跨周情况) 124 | // id工人在day之前有3天连休返回1,没有连休返回0 125 | int check2(int id,int day){ 126 | if(day <= 1) return 0; 127 | if( \ 128 | (day >= 2 && dispatch[id][0] == 0 && dispatch[id][1] == 0 && dispatch[id][2] == 0) || \ 129 | (day >= 3 && dispatch[id][1] == 0 && dispatch[id][2] == 0 && dispatch[id][3] == 0) || \ 130 | (day >= 4 && dispatch[id][2] == 0 && dispatch[id][3] == 0 && dispatch[id][4] == 0) || \ 131 | (day >= 5 && dispatch[id][3] == 0 && dispatch[id][4] == 0 && dispatch[id][5] == 0) || \ 132 | (day >= 6 && dispatch[id][4] == 0 && dispatch[id][5] == 0 && dispatch[id][6] == 0) ) 133 | return 1; 134 | 135 | // MRV 赋值 136 | if(MRVstatus && dispatch[id][day-1] == 0 && dispatch[id][day] == 0 && day < 6) 137 | if(!MRVappend(id+(day+1)*num,1)) 138 | return 1; 139 | 140 | return 0; 141 | } 142 | 143 | // 3. 周六周天也需要有人值班,即一周7天每天都要安排工人值班 144 | 145 | // 4. 需要每天安排至少 x 个人值班 146 | // day天不足x个人值班返回1,否则返回0 147 | int check4(int id, int day){ 148 | int s = 0; 149 | for(int i = 0; i <= id; ++i) 150 | if(dispatch[i][day]) 151 | s++; 152 | if(s + num - 1 - id < x) // 该天不足x人 153 | return 1; 154 | 155 | // MRV 赋值 156 | if(MRVstatus && s + num - 1 - id == x) 157 | for(int i = id + 1,k = day * num + i; i < num; ++i,++k) 158 | if(!MRVappend(k,1)) 159 | return 1; // 加入MRV数组失败,说明有冲突,不满足约束 160 | 161 | return 0; 162 | } 163 | 164 | // 5. 每天至少要有一名级别为 senior 的工人值班 165 | // 所有senior不值日返回1,否则返回0 166 | int check5(int id,int day){ 167 | int s = 0; 168 | for(int i = 0; i < numsen; ++i) 169 | if(senior[i] > id) { 170 | if(MRVstatus && i == numsen - 1 && s == 0) // MRV 赋值 171 | if(!MRVappend(day * num + senior[i],1)) 172 | return 1; 173 | return 0; 174 | } 175 | else if(dispatch[senior[i]][day]) 176 | s++; 177 | if(s == 0) 178 | return 1; 179 | return 0; 180 | } 181 | 182 | // 6. 工人a不想与工人b同一天工作 183 | // 工人id有冲突返回1,否则返回0 184 | int check6(int id,int day){ 185 | if(!dispatch[id][day]) return 0; // 工人id没排班,不存在冲突 186 | for(int i = 0; i < id; ++i) 187 | if(dispatch[i][day] && AB[i][id]) 188 | return 1; 189 | 190 | // MRV 赋值 191 | for(int i = id,k = day * num + i;MRVstatus && i < num; ++i,++k) 192 | if(AB[i][id]){ 193 | if(!MRVappend(k,0)) 194 | return 1; 195 | } 196 | 197 | return 0; 198 | } 199 | 200 | int prt(){ // 输出 201 | for(int i = 0; i < 7; ++i,printf("\n")) 202 | for(int j = 0; j < num; ++j) 203 | if(dispatch[j][i]) 204 | printf("%d ",j+1); 205 | return 0; 206 | } 207 | 208 | -------------------------------------------------------------------------------- /csp/src/input1.txt: -------------------------------------------------------------------------------- 1 | num:7,x:4,num of senior:2 2 | 1 3 | 2 4 | 1 4 5 | 2 3 6 | 3 6 -------------------------------------------------------------------------------- /csp/src/input2.txt: -------------------------------------------------------------------------------- 1 | num:10,x:5,num of senior:4 2 | 1 3 | 2 4 | 8 5 | 10 6 | 1 5 7 | 2 6 8 | 8 10 -------------------------------------------------------------------------------- /decisionTree/DecisionTree.py: -------------------------------------------------------------------------------- 1 | from math import log2 2 | import numpy as np 3 | 4 | # 信息熵 5 | # 输入:随机变量的分布 6 | # 返回:该随机变量的信息熵 7 | def entropy(Pr): 8 | if max(Pr) < 1: 9 | return np.sum(-p*log2(p) for p in Pr) 10 | else: 11 | return 0 12 | 13 | def Bool(p): 14 | return entropy([p,1-p]) 15 | 16 | def Remainder(A,train_features,train_labels): # 对样本求经过A划分后的剩余熵,返回剩余熵 17 | # A的值域 18 | rangeA = set([i[A] for i in train_features]) 19 | # 按照属性A划分样本 20 | divide = [ [ [train_features[i],train_labels[i]] for i in range(len(train_features)) if train_features[i][A] == l] for l in rangeA ] 21 | # 各组正例个数 22 | pk = [np.sum([0] + [1 for l in d if l[1] == 1]) for d in divide] 23 | # 各组反例个数 24 | nk = [len(divide[i]) - pk[i] for i in range(len(divide))] 25 | # 正反例总数 26 | p , n = np.sum(pk) , np.sum(nk) 27 | return np.sum([ (pk[i] + nk[i])*Bool(pk[i]/(pk[i] + nk[i])) for i in range(len(divide))] )/(p + n) 28 | 29 | 30 | class Treenode: 31 | def __init__(self) -> None: 32 | self.child = [] 33 | self.attr = None 34 | self.isleaf = True 35 | self.label = None 36 | 37 | class DecisionTree: 38 | def TreeGenerate(self,train_features,train_labels,A): 39 | node = Treenode() 40 | if len(A) == 0 or len(set(train_labels)) <= 1 or len(train_features) <= 1: # label均相同,或无可划分的属性集 41 | node.label = np.argmax(np.bincount(train_labels)) # 返回 train_labels 的众数 42 | return node 43 | # 选择期望剩余熵最小的作为最优划分 44 | av = A[np.argmin([Remainder(i,train_features,train_labels) for i in A])] 45 | # 属性a的值域 46 | range_av = set([i[av] for i in train_features]) 47 | 48 | for l in range_av: 49 | Dvfeatures = [ feat for feat in train_features if feat[av] == l] 50 | Dvlabels = [ train_labels[i] for i in range(len(train_labels)) if train_features[i][av] == l] 51 | # Dv不会是空集 52 | node.child.append([ l, self.TreeGenerate(Dvfeatures,Dvlabels,[a for a in A if a != av])]) 53 | 54 | node.isleaf = False # 改为不是叶子 55 | node.attr = av # 该节点是依据attr划分的 56 | return node 57 | 58 | def fit(self, train_features, train_labels): 59 | self.root = self.TreeGenerate(train_features,train_labels,list(set(train_labels))) 60 | 61 | def predict1(self, features): # 预测一个 62 | node = self.root 63 | while node.isleaf == False: 64 | av = features[node.attr] 65 | for i in node.child: # 找到相应的孩子 66 | if i[0] == av: 67 | node = i[1] 68 | break 69 | return node.label 70 | 71 | def predict(self,test_features) -> np.ndarray: 72 | return np.array([self.predict1(feat) for feat in test_features ]) 73 | 74 | 75 | if __name__=='__main__': 76 | # 测试熵 77 | print(entropy([0.5]*2)) # 2面骰子 78 | print(entropy([0.25]*4)) # 4面骰子 79 | print(Bool(0.137)) 80 | print(Bool(0.19)) 81 | 82 | 83 | -------------------------------------------------------------------------------- /decisionTree/dataset/dt/dt_test.data: -------------------------------------------------------------------------------- 1 | 1,4,0,4,0,0,2,0,3,1 2 | 0,1,2,5,0,0,2,0,1,0 3 | 1,1,2,3,4,1,1,0,1,0 4 | 1,3,0,5,4,0,2,1,2,0 5 | 1,4,0,3,4,0,1,0,1,1 6 | 0,4,0,4,0,0,1,1,1,0 7 | 0,4,0,9,0,0,0,0,0,0 8 | 0,1,2,7,4,0,2,1,4,1 9 | 1,2,2,5,4,1,1,0,4,0 10 | 0,3,2,4,0,0,1,0,1,0 11 | 0,4,0,5,0,0,2,0,1,0 12 | 0,3,0,1,0,0,0,0,1,0 13 | 0,4,0,3,0,0,0,0,1,0 14 | 0,2,2,1,0,0,1,1,1,0 15 | 0,3,2,1,0,0,1,1,2,0 16 | 0,3,0,5,0,0,0,1,4,0 17 | 0,2,2,2,0,0,1,0,1,0 18 | 1,3,2,4,0,0,0,1,2,0 19 | 0,2,2,6,6,1,1,1,2,1 20 | 1,2,2,5,0,0,0,0,1,1 21 | 1,3,0,3,0,0,1,0,2,0 22 | 1,1,2,7,0,0,0,0,2,0 23 | 0,3,1,5,0,0,2,1,2,0 24 | 0,4,0,2,0,0,2,1,2,1 25 | 0,2,2,4,0,0,1,1,1,0 26 | 1,2,2,4,0,0,1,1,1,0 27 | 1,3,0,3,0,0,1,1,0,0 28 | 0,3,0,4,0,0,1,0,1,0 29 | 0,3,2,4,0,0,1,0,1,0 30 | 0,1,2,7,0,0,1,1,4,0 31 | 0,2,0,5,0,0,1,0,2,1 32 | 1,4,0,8,0,0,0,1,4,1 33 | 0,2,2,9,0,0,0,0,1,1 34 | 0,3,0,3,4,1,1,1,2,0 35 | 0,3,0,3,0,0,0,1,1,0 36 | 1,1,2,2,5,1,2,0,1,1 37 | 1,4,0,6,5,1,2,0,1,0 38 | 0,2,2,10,0,0,1,0,1,0 39 | 0,3,0,1,0,0,0,1,2,0 40 | 0,2,2,2,1,0,2,1,3,1 41 | 0,5,0,7,0,0,0,1,4,0 42 | 0,2,2,3,4,0,1,1,1,0 43 | 0,4,0,3,0,0,1,0,2,0 44 | 0,2,2,0,0,0,1,1,3,0 45 | 0,2,2,5,4,1,1,1,1,0 46 | 0,4,0,7,4,0,1,1,2,1 47 | 0,2,2,5,0,0,1,1,4,1 48 | 1,3,0,5,4,0,2,0,1,0 49 | 0,1,2,5,0,0,1,0,2,0 50 | 0,5,0,3,0,0,2,0,2,0 51 | 0,3,0,4,0,0,0,0,1,0 52 | 0,3,0,1,0,0,0,0,2,0 53 | 0,4,0,1,0,0,0,0,2,0 54 | 0,3,2,3,4,1,1,0,1,0 55 | 0,2,0,4,0,0,1,0,1,0 56 | 0,1,2,4,0,0,1,1,1,0 57 | -------------------------------------------------------------------------------- /decisionTree/dataset/dt/dt_train.data: -------------------------------------------------------------------------------- 1 | 0,3,0,4,0,0,1,1,2,0 2 | 0,2,2,3,0,0,2,1,1,1 3 | 0,4,0,2,0,0,0,1,2,0 4 | 0,5,0,7,0,0,0,1,2,0 5 | 0,3,0,3,0,0,2,0,2,0 6 | 0,1,2,3,0,0,1,0,3,0 7 | 0,3,0,5,0,0,0,1,1,0 8 | 0,4,0,5,0,0,0,0,2,0 9 | 0,3,2,2,0,0,1,1,1,0 10 | 0,3,0,0,0,0,0,0,1,0 11 | 0,2,2,5,0,0,2,0,2,0 12 | 0,3,0,7,0,0,2,0,4,0 13 | 0,4,0,2,0,0,1,1,1,0 14 | 0,2,2,0,0,0,2,0,0,0 15 | 0,2,2,4,0,0,2,1,2,1 16 | 1,2,0,3,0,0,1,1,2,0 17 | 0,2,2,1,0,0,1,0,1,1 18 | 0,4,0,5,4,1,2,0,1,0 19 | 0,4,0,4,0,0,1,0,1,0 20 | 1,1,2,6,6,1,2,0,1,0 21 | 0,3,0,6,2,0,2,0,1,0 22 | 0,2,2,1,0,0,0,1,3,0 23 | 1,3,2,6,2,1,2,1,4,0 24 | 1,1,2,6,0,0,2,0,1,0 25 | 0,2,2,1,0,0,1,0,1,0 26 | 0,4,0,1,0,0,1,1,2,1 27 | 0,1,2,1,0,0,0,1,1,0 28 | 0,2,2,7,0,0,0,1,2,0 29 | 0,1,2,4,5,1,1,1,2,1 30 | 0,3,0,6,0,0,1,0,2,0 31 | 0,3,0,4,0,0,2,0,4,0 32 | 0,4,0,3,0,0,1,1,2,0 33 | 1,2,2,5,1,1,2,0,2,1 34 | 1,3,2,4,0,0,2,1,1,1 35 | 0,3,0,3,0,0,1,1,2,0 36 | 0,2,2,1,0,0,0,1,2,0 37 | 1,1,2,4,4,1,2,0,1,1 38 | 0,2,2,7,0,0,1,1,1,0 39 | 0,2,2,5,5,0,1,0,2,0 40 | 0,3,2,2,0,0,0,0,1,0 41 | 0,3,2,10,0,1,1,1,2,1 42 | 0,2,2,4,0,0,0,1,3,0 43 | 0,3,0,0,0,0,1,0,0,0 44 | 0,3,0,2,0,0,1,1,1,0 45 | 1,3,0,5,5,1,1,0,3,1 46 | 0,2,2,3,0,0,1,1,2,0 47 | 1,2,2,5,2,1,2,0,1,0 48 | 1,2,2,10,0,0,1,1,1,1 49 | 1,3,2,4,0,0,1,0,4,0 50 | 0,3,2,6,0,0,1,1,2,0 51 | 0,2,2,6,0,1,2,1,1,1 52 | 1,1,2,2,0,0,0,1,1,0 53 | 0,1,1,2,0,0,2,1,2,0 54 | 0,2,2,5,0,0,1,0,3,0 55 | 1,2,0,5,4,0,2,0,1,0 56 | 0,2,2,7,4,1,2,1,2,1 57 | 0,4,0,10,0,0,1,1,2,1 58 | 0,2,2,5,0,0,0,1,2,0 59 | 0,4,0,5,0,0,1,0,1,1 60 | 1,2,2,4,0,0,1,0,1,1 61 | 0,3,0,4,0,0,0,0,3,0 62 | 0,3,0,7,4,1,1,0,1,0 63 | 1,2,2,2,2,1,2,0,1,0 64 | 0,2,2,3,0,0,0,1,4,0 65 | 0,2,2,4,0,0,1,1,0,0 66 | 1,1,2,5,0,0,1,0,2,0 67 | 0,4,0,2,0,0,1,0,2,1 68 | 1,2,2,2,0,0,1,0,2,0 69 | 0,1,2,3,4,0,1,1,0,0 70 | 0,2,2,1,0,0,1,0,2,0 71 | 0,4,0,2,0,0,1,1,2,0 72 | 1,4,0,3,0,0,2,1,1,0 73 | 1,2,2,5,5,1,2,1,2,0 74 | 0,2,0,7,2,1,1,1,2,1 75 | 1,2,0,4,1,1,2,0,3,1 76 | 1,4,0,4,4,0,1,1,4,0 77 | 0,3,2,4,4,1,1,0,1,1 78 | 0,3,2,5,0,0,0,0,0,0 79 | 1,3,0,5,6,1,2,0,3,1 80 | 0,2,2,6,0,0,1,1,4,0 81 | 1,2,2,2,0,1,2,1,2,0 82 | 0,2,2,6,0,0,0,0,1,0 83 | 1,1,2,6,0,0,2,0,1,0 84 | 0,3,2,1,0,0,0,0,1,0 85 | 1,2,2,5,4,0,1,1,2,0 86 | 1,4,0,4,0,0,2,0,2,0 87 | 0,1,2,0,0,0,1,1,0,0 88 | 0,2,2,3,5,0,1,1,1,1 89 | 0,2,2,4,0,0,1,0,2,0 90 | 0,4,0,4,0,0,2,1,2,0 91 | 0,3,2,5,4,1,1,0,1,1 92 | 1,3,0,7,5,1,2,0,1,1 93 | 1,3,2,10,6,1,1,1,2,0 94 | 0,3,0,5,0,0,0,1,0,0 95 | 1,4,0,3,3,1,2,0,1,1 96 | 0,1,2,9,0,0,1,0,3,0 97 | 0,2,2,3,0,0,0,0,3,0 98 | 0,4,0,5,5,1,1,1,4,0 99 | 0,1,2,4,0,0,0,0,0,0 100 | 0,3,0,1,0,0,1,0,1,0 101 | 1,2,0,3,4,0,2,1,1,1 102 | 0,3,0,3,0,0,2,1,2,0 103 | 1,3,0,4,5,0,2,0,1,1 104 | 0,4,0,10,0,0,1,0,1,0 105 | 0,2,2,3,0,0,1,0,3,0 106 | 0,3,2,7,0,0,1,0,2,0 107 | 0,4,0,5,0,0,1,0,1,0 108 | 1,4,0,3,0,0,0,1,2,0 109 | 1,3,2,4,4,1,2,0,1,1 110 | 0,2,2,3,0,0,1,0,1,0 111 | 0,1,2,7,0,0,1,0,1,1 112 | 1,4,0,5,0,0,2,1,2,1 113 | 1,2,2,4,0,0,1,1,1,0 114 | 1,3,2,2,0,0,1,0,1,0 115 | 1,3,0,5,5,1,2,0,3,0 116 | 0,4,0,1,0,0,0,0,1,0 117 | 0,4,0,5,0,0,1,0,2,0 118 | 0,3,0,5,5,1,1,0,1,0 119 | 0,2,2,5,0,0,0,0,4,0 120 | 1,3,2,5,0,0,2,1,2,1 121 | 0,2,2,6,6,1,1,1,4,1 122 | 1,4,0,5,4,1,1,0,0,1 123 | 0,2,2,5,0,0,0,0,1,0 124 | 1,4,0,1,5,1,2,0,2,1 125 | 0,5,0,0,0,0,0,0,3,0 126 | 0,4,0,2,0,0,0,0,3,0 127 | 1,2,2,7,0,0,0,0,1,0 128 | 1,2,2,3,4,1,1,0,1,1 129 | 0,2,2,1,0,0,0,1,2,0 130 | 0,4,0,1,0,0,0,0,2,0 131 | 0,3,2,5,0,0,2,0,1,0 132 | 1,4,0,7,0,0,1,1,1,0 133 | 0,2,2,3,0,0,0,1,1,0 134 | 1,1,2,4,5,1,2,0,3,1 135 | 0,2,2,6,0,1,2,1,2,1 136 | 1,2,2,5,0,1,2,1,4,0 137 | 1,4,0,10,0,0,2,1,2,0 138 | 0,3,0,0,0,0,0,1,0,0 139 | 0,4,0,2,0,0,1,1,2,0 140 | 1,4,0,5,0,0,2,1,0,0 141 | 1,4,0,7,4,1,2,1,1,0 142 | 1,1,2,5,6,0,1,1,2,1 143 | 0,4,1,5,0,0,0,0,1,0 144 | 0,3,2,4,0,0,0,1,2,0 145 | 1,3,2,5,0,0,2,0,4,0 146 | 0,2,0,3,0,0,2,0,1,0 147 | 0,2,0,3,0,0,2,0,2,0 148 | 0,3,2,1,4,0,0,1,2,0 149 | 1,3,0,7,5,1,2,0,1,1 150 | 0,4,0,4,0,0,2,1,1,0 151 | 0,1,2,2,0,0,0,0,1,0 152 | 1,2,2,3,4,1,1,1,4,1 153 | 0,4,0,1,0,0,1,0,1,0 154 | 1,2,2,3,0,0,1,0,1,0 155 | 0,1,2,5,5,1,1,1,4,0 156 | 0,3,0,5,0,0,0,0,2,0 157 | 1,3,0,6,0,0,1,0,1,0 158 | 0,2,2,4,0,0,1,1,2,0 159 | 0,1,2,4,0,0,1,0,1,0 160 | 0,2,2,4,0,0,0,1,1,1 161 | 1,2,2,4,0,0,2,0,2,0 162 | 0,2,2,4,0,0,1,0,2,1 163 | 1,1,2,5,4,0,2,1,2,1 164 | 0,3,0,2,0,0,0,1,0,0 165 | 0,4,0,2,0,0,1,0,1,0 166 | 0,3,0,2,0,0,1,1,4,0 167 | 0,2,2,8,0,0,1,0,1,1 168 | 0,3,0,2,0,0,0,1,0,0 169 | 0,5,0,1,0,0,1,0,0,0 170 | 0,2,2,5,0,0,1,1,3,0 171 | 0,2,2,3,0,0,1,0,0,0 172 | 0,3,0,1,0,0,1,1,1,0 173 | 1,1,2,3,0,0,2,0,2,1 174 | 0,3,0,3,0,1,1,1,2,0 175 | 1,4,0,5,0,1,1,1,4,1 176 | 0,3,0,7,0,0,1,0,1,0 177 | 0,0,2,6,0,0,1,1,4,0 178 | 1,1,2,5,0,0,0,1,2,0 179 | 1,2,2,5,0,0,2,1,4,0 180 | 0,1,2,3,0,0,2,0,0,0 181 | 0,2,2,3,0,0,1,1,4,0 182 | 0,4,0,5,0,0,0,1,2,0 183 | 0,3,0,10,0,0,0,1,4,0 184 | 0,1,2,1,0,0,1,0,3,0 185 | 1,3,2,4,0,0,1,0,4,0 186 | 0,3,0,6,0,0,2,0,2,0 187 | 0,3,2,2,0,0,1,1,3,0 188 | 1,2,2,4,6,1,2,1,2,0 189 | 0,1,2,2,0,0,0,0,1,0 190 | 0,3,0,4,4,1,2,1,2,0 191 | 0,3,2,4,0,1,1,0,2,0 192 | 0,3,2,4,0,0,1,1,3,0 193 | 1,3,0,3,4,1,2,1,4,0 194 | 0,3,0,3,0,0,2,0,2,0 195 | 0,3,0,7,0,0,2,1,2,0 196 | 0,3,0,2,0,1,1,0,0,1 197 | 0,2,2,3,0,0,1,0,2,0 198 | 0,3,2,4,4,0,1,1,2,1 199 | 0,3,0,7,0,0,2,0,2,0 200 | 0,4,0,2,0,0,1,0,1,0 201 | 0,3,2,1,0,0,2,0,1,0 202 | 0,3,0,5,0,0,2,1,1,0 203 | 0,2,2,5,0,0,2,1,4,0 204 | 0,2,2,3,4,0,1,1,2,0 205 | 0,3,0,6,0,0,2,0,1,0 206 | 0,3,0,4,2,1,2,1,2,0 207 | 0,4,1,1,0,0,0,0,4,0 208 | 0,3,0,9,0,0,1,1,4,0 209 | 0,1,2,3,4,1,1,1,2,1 210 | 0,2,2,3,0,0,1,1,2,0 211 | 1,1,2,0,0,0,1,1,0,0 212 | 1,2,2,4,0,0,2,0,4,0 213 | 0,4,0,3,0,0,0,0,1,0 214 | 0,2,2,4,0,0,0,0,3,0 215 | 0,4,0,8,5,1,2,0,0,0 216 | 0,3,2,4,0,0,0,0,1,0 217 | 0,2,2,1,0,0,1,1,2,0 218 | 0,3,2,3,0,0,0,0,1,0 219 | 1,2,2,6,0,0,0,1,2,0 220 | 0,3,1,2,0,0,1,0,1,0 221 | 0,4,0,1,0,0,0,1,1,0 222 | -------------------------------------------------------------------------------- /decisionTree/main.py: -------------------------------------------------------------------------------- 1 | from utils import * 2 | from DecisionTree import DecisionTree 3 | 4 | 5 | def test_decisiontree(): 6 | train_features, train_labels, test_features, test_labels = load_decisiontree_dataset() 7 | model = DecisionTree() 8 | model.fit(train_features, train_labels) 9 | results = model.predict(test_features) 10 | # results = np.random.randint(2, size=56) 11 | print('DecisionTree acc: {:.2f}%'.format(get_acc(results, test_labels) * 100)) 12 | 13 | if __name__=='__main__': 14 | test_decisiontree() 15 | 16 | -------------------------------------------------------------------------------- /decisionTree/utils.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | def get_acc(y, pred): 3 | return np.sum(y == pred) / len(y) 4 | 5 | 6 | def load_decisiontree_dataset(): 7 | train_data = np.loadtxt('dataset/dt/dt_train.data', delimiter=',', dtype='int64') 8 | test_data = np.loadtxt('dataset/dt/dt_test.data', delimiter=',', dtype='int64') 9 | train_features = train_data[:,1:] 10 | train_labels = train_data[:,0] 11 | test_features = test_data[:,1:] 12 | test_labels = test_data[:,0] 13 | 14 | return train_features, train_labels, test_features, test_labels -------------------------------------------------------------------------------- /digit/data/input00.txt: -------------------------------------------------------------------------------- 1 | 1 2 7 4 5 2 | 6 12 0 9 10 3 | 11 -8 14 18 15 4 | 16 17 23 13 20 5 | 21 22 3 19 24 -------------------------------------------------------------------------------- /digit/data/input01.txt: -------------------------------------------------------------------------------- 1 | 1 2 0 4 5 2 | 6 7 8 9 10 3 | 16 12 -13 14 11 4 | 21 17 18 19 15 5 | 22 23 3 24 20 -------------------------------------------------------------------------------- /digit/data/input02.txt: -------------------------------------------------------------------------------- 1 | 0 -2 4 5 10 2 | 1 -7 8 -9 15 3 | 6 -12 13 -14 11 4 | -16 17 18 19 -20 5 | 21 22 3 23 24 6 | -------------------------------------------------------------------------------- /digit/data/input03.txt: -------------------------------------------------------------------------------- 1 | 1 2 8 4 5 2 | 6 7 13 0 -10 3 | 15 11 14 9 20 4 | -16 17 12 18 19 5 | 21 22 3 23 24 -------------------------------------------------------------------------------- /digit/data/input04.txt: -------------------------------------------------------------------------------- 1 | 1 2 7 4 5 2 | 6 12 9 0 10 3 | 11 8 14 18 -15 4 | 16 17 23 13 20 5 | 21 22 3 19 24 -------------------------------------------------------------------------------- /digit/data/input05.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 9 4 2 | 6 7 8 19 5 3 | 16 11 12 13 10 4 | 21 17 18 24 14 5 | 22 23 0 20 15 6 | -------------------------------------------------------------------------------- /digit/data/input06.txt: -------------------------------------------------------------------------------- 1 | 0 2 4 9 5 2 | 1 6 -8 10 20 3 | 12 7 18 13 15 4 | 11 16 22 14 19 5 | 21 17 3 23 24 -------------------------------------------------------------------------------- /digit/data/input07.txt: -------------------------------------------------------------------------------- 1 | 7 1 2 3 4 2 | 0 8 9 10 5 3 | 6 11 12 13 14 4 | 17 18 19 20 15 5 | 16 21 22 23 24 -------------------------------------------------------------------------------- /digit/data/input08.txt: -------------------------------------------------------------------------------- 1 | 2 6 -3 5 10 2 | 1 12 7 8 4 3 | -11 17 13 0 -15 4 | 22 18 14 9 24 5 | 16 21 -23 20 19 -------------------------------------------------------------------------------- /digit/data/input09.txt: -------------------------------------------------------------------------------- 1 | 6 1 2 5 10 2 | 11 7 9 4 15 3 | 20 12 13 8 0 4 | 16 21 18 14 19 5 | 22 17 3 23 24 6 | -------------------------------------------------------------------------------- /digit/data/input10.txt: -------------------------------------------------------------------------------- 1 | 6 1 4 5 10 2 | 11 -7 3 -9 12 3 | 16 8 0 15 20 4 | 21 -17 14 -19 24 5 | 22 18 13 2 23 -------------------------------------------------------------------------------- /digit/data/input11.txt: -------------------------------------------------------------------------------- 1 | 7 1 8 5 10 2 | 6 3 2 9 0 3 | 14 11 -13 4 15 4 | 22 12 17 24 19 5 | 16 21 18 23 20 -------------------------------------------------------------------------------- /digit/data/target00.txt: -------------------------------------------------------------------------------- 1 | 1 2 7 4 5 2 | 6 12 14 9 10 3 | 11 -8 23 15 0 4 | 16 17 13 18 20 5 | 21 22 3 19 24 -------------------------------------------------------------------------------- /digit/data/target01.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 2 | 6 7 8 9 10 3 | 11 12 -13 14 15 4 | 16 17 18 19 20 5 | 21 22 23 24 0 -------------------------------------------------------------------------------- /digit/data/target02.txt: -------------------------------------------------------------------------------- 1 | 1 -2 3 4 5 2 | 6 -7 8 -9 10 3 | 11 -12 13 -14 15 4 | -16 17 18 19 -20 5 | 21 22 23 24 0 6 | -------------------------------------------------------------------------------- /digit/data/target03.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 2 | 6 7 8 9 -10 3 | 11 12 13 14 15 4 | -16 17 18 19 20 5 | 21 22 23 24 0 -------------------------------------------------------------------------------- /digit/data/target04.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 2 | 6 7 8 9 10 3 | 11 12 13 14 -15 4 | 16 17 18 19 20 5 | 21 22 23 24 0 -------------------------------------------------------------------------------- /digit/data/target05.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 2 | 6 7 8 9 10 3 | 11 12 13 14 15 4 | 16 17 18 19 20 5 | 21 22 23 24 0 -------------------------------------------------------------------------------- /digit/data/target06.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 2 | 6 7 -8 9 10 3 | 11 12 13 14 15 4 | 16 17 18 19 20 5 | 21 22 23 24 0 -------------------------------------------------------------------------------- /digit/data/target07.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 2 | 6 7 8 9 10 3 | 11 12 13 14 15 4 | 16 17 18 19 20 5 | 21 22 23 24 0 -------------------------------------------------------------------------------- /digit/data/target08.txt: -------------------------------------------------------------------------------- 1 | 1 2 -3 4 5 2 | 6 7 8 9 10 3 | -11 12 13 14 -15 4 | 16 17 18 19 20 5 | 21 22 -23 24 0 -------------------------------------------------------------------------------- /digit/data/target09.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 2 | 6 7 8 9 10 3 | 11 12 13 14 15 4 | 16 17 18 19 20 5 | 21 22 23 24 0 6 | -------------------------------------------------------------------------------- /digit/data/target10.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 2 | 6 -7 8 -9 10 3 | 11 12 13 14 15 4 | 16 -17 18 -19 20 5 | 21 22 23 24 0 -------------------------------------------------------------------------------- /digit/data/target11.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 2 | 6 7 8 9 10 3 | 11 12 -13 14 15 4 | 16 17 18 19 20 5 | 21 22 23 24 0 -------------------------------------------------------------------------------- /digit/output/output_A_h1.txt: -------------------------------------------------------------------------------- 1 | DDRUR 7.68E-06 2 | ULLUULDD 1.06E-05 3 | DDLUULLURR 1.06E-05 4 | DLDRRURRRUUURR 5.73E-05 5 | LUUURULLURDDRDR 1.52E-04 6 | LLUURRRUURDDDDLUURDD 3.07E-04 7 | DRDLLULULUUURDRURDRDRRR 6.12E-04 8 | URRRRDLLLLDRRRRDLLLLDRRRR 7.74E-05 9 | DDRULLLLDRUUUULDRRRRULDDDDR 2.41E-03 10 | RDRURRDRUUULDLDLDDLUUUURRURR 4.96E-02 11 | DDRRUUUULLULLUULLLLLUURRDDDDRR 1.91E-03 12 | DRUURDRRDRUULDLULDLDRDLDRURDRURD 1.50E-01 -------------------------------------------------------------------------------- /digit/output/output_A_h2.txt: -------------------------------------------------------------------------------- 1 | DDRUR 1.06E-05 2 | ULLUULDD 2.01E-05 3 | DDLUULLURR 1.42E-05 4 | DLDRRURRRUUURR 7.86E-05 5 | LUUURULLURDDRDR 4.25E-05 6 | LLUURRRUURDDDDLUURDD 4.25E-05 7 | DRDLLULULUUURDRURDRDRRR 2.90E-04 8 | URRRRDLLLLDRRRRDLLLLDRRRR 1.09E-04 9 | DDRULLLLDRUUUULDRRRRULDDDDR 1.48E-04 10 | RDRURRDRUUULDLDLDDLUUUURRURR 8.96E-03 11 | DDRRUUUULLULLUULLLLLUURRDDDDRR 1.68E-04 12 | DRUURDRRDRUULDLULDLDRDLDRURDRURD 2.55E-03 -------------------------------------------------------------------------------- /digit/output/output_IDA_h1.txt: -------------------------------------------------------------------------------- 1 | DDRUR 5.91E-06 2 | ULLUULDD 5.91E-06 3 | DDLUULLURR 7.09E-06 4 | DLDRRURRRUUURR 4.49E-05 5 | LUUURULLURDDRDR 1.73E-04 6 | LLUURRRUURDDDDLUURDD 2.58E-04 7 | DRDLLULULUUURDRURDRDRRR 6.34E-04 8 | URRRRDLLLLDRRRRDLLLLDRRRR 3.13E-05 9 | DDRULLLLDRUUUULDRRRRULDDDDR 3.20E-03 10 | RDRURRDRUUULDLDLDDLUUUURRURR 5.43E-02 11 | DDRRUUUULLULLUULLLLLUURRDDDDRR 3.27E-03 12 | DRUURDRRDRUULDLULDLDRDLDRURDRURD 1.64E-01 -------------------------------------------------------------------------------- /digit/output/output_IDA_h2.txt: -------------------------------------------------------------------------------- 1 | DDRUR 7.09E-06 2 | ULLUULDD 2.19E-05 3 | DDLUULLURR 2.13E-05 4 | DLDRRURRRUUURR 1.09E-04 5 | LUUURULLURDDRDR 3.25E-05 6 | LLUURRRUURDDDDLUURDD 2.60E-05 7 | DRDLLULULUUURDRURDRDRRR 5.05E-04 8 | URRRRDLLLLDRRRRDLLLLDRRRR 5.79E-05 9 | DDRULLLLDRUUUULDRRRRULDDDDR 9.92E-05 10 | RDRURRDRUUULDLDLDDLUUUURRURR 1.45E-02 11 | DDRRUUUULLULLUULLLLLUURRDDDDRR 2.55E-04 12 | DRUURDRRDRUULDLULDLDRDLDRURDRURD 3.63E-03 -------------------------------------------------------------------------------- /digit/src/1run.bat: -------------------------------------------------------------------------------- 1 | a.exe A_h1 input00.txt target00.txt 2 | a.exe A_h1 input01.txt target01.txt 3 | a.exe A_h1 input02.txt target02.txt 4 | a.exe A_h1 input03.txt target03.txt 5 | a.exe A_h1 input04.txt target04.txt 6 | a.exe A_h1 input05.txt target05.txt 7 | a.exe A_h1 input06.txt target06.txt 8 | a.exe A_h1 input07.txt target07.txt 9 | a.exe A_h1 input08.txt target08.txt 10 | a.exe A_h1 input09.txt target09.txt 11 | a.exe A_h1 input10.txt target10.txt 12 | a.exe A_h1 input11.txt target11.txt -------------------------------------------------------------------------------- /digit/src/2run.bat: -------------------------------------------------------------------------------- 1 | a.exe A_h2 input00.txt target00.txt 2 | a.exe A_h2 input01.txt target01.txt 3 | a.exe A_h2 input02.txt target02.txt 4 | a.exe A_h2 input03.txt target03.txt 5 | a.exe A_h2 input04.txt target04.txt 6 | a.exe A_h2 input05.txt target05.txt 7 | a.exe A_h2 input06.txt target06.txt 8 | a.exe A_h2 input07.txt target07.txt 9 | a.exe A_h2 input08.txt target08.txt 10 | a.exe A_h2 input09.txt target09.txt 11 | a.exe A_h2 input10.txt target10.txt 12 | a.exe A_h2 input11.txt target11.txt -------------------------------------------------------------------------------- /digit/src/3run.bat: -------------------------------------------------------------------------------- 1 | a.exe IDA_h1 input00.txt target00.txt 2 | a.exe IDA_h1 input01.txt target01.txt 3 | a.exe IDA_h1 input02.txt target02.txt 4 | a.exe IDA_h1 input03.txt target03.txt 5 | a.exe IDA_h1 input04.txt target04.txt 6 | a.exe IDA_h1 input05.txt target05.txt 7 | a.exe IDA_h1 input06.txt target06.txt 8 | a.exe IDA_h1 input07.txt target07.txt 9 | a.exe IDA_h1 input08.txt target08.txt 10 | a.exe IDA_h1 input09.txt target09.txt 11 | a.exe IDA_h1 input10.txt target10.txt 12 | a.exe IDA_h1 input11.txt target11.txt -------------------------------------------------------------------------------- /digit/src/4run.bat: -------------------------------------------------------------------------------- 1 | a.exe IDA_h2 input00.txt target00.txt 2 | a.exe IDA_h2 input01.txt target01.txt 3 | a.exe IDA_h2 input02.txt target02.txt 4 | a.exe IDA_h2 input03.txt target03.txt 5 | a.exe IDA_h2 input04.txt target04.txt 6 | a.exe IDA_h2 input05.txt target05.txt 7 | a.exe IDA_h2 input06.txt target06.txt 8 | a.exe IDA_h2 input07.txt target07.txt 9 | a.exe IDA_h2 input08.txt target08.txt 10 | a.exe IDA_h2 input09.txt target09.txt 11 | a.exe IDA_h2 input10.txt target10.txt 12 | a.exe IDA_h2 input11.txt target11.txt -------------------------------------------------------------------------------- /digit/src/a.c: -------------------------------------------------------------------------------- 1 | #include "a.h" 2 | #include 3 | #include 4 | // rd(x,y,i,j) 计算(x,y)到(i,j)的路程 5 | #define rd(x,y,i,j) ((x > i ? x - i : i - x) + (y > j ? y - j : j - y)) 6 | 7 | // 算法 8 | void A_h1(int start[5][5], int target[5][5]); 9 | void A_h2(int start[5][5], int target[5][5]); 10 | void IDA_h1(int start[5][5], int target[5][5]); 11 | void IDA_h2(int start[5][5], int target[5][5]); 12 | void (* func)(int start[5][5], int target[5][5]); 13 | // 启发函数 14 | int h1(int start[5][5], int target[5][5]); 15 | int h2(int start[5][5], int target[5][5]); 16 | // 四个转移函数,shift_func存储该4个转移函数 17 | int up(int start[5][5],int status[5][5]); 18 | int down(int start[5][5],int status[5][5]); 19 | int left(int start[5][5],int status[5][5]); 20 | int right(int start[5][5],int status[5][5]); 21 | 22 | int ((*shift_func[4])(int start[5][5],int status[5][5])) = {up,down,left,right}; // 4个转移函数 23 | 24 | int main(int argc, char* argv[]){ 25 | if(argc != 4) return printf("输入参数个数有误!\n"); 26 | 27 | // 选择算法 28 | if(!strcmp(argv[1], "A_h1")) 29 | func = A_h1; 30 | else if(!strcmp(argv[1], "A_h2")) 31 | func = A_h2; 32 | else if(!strcmp(argv[1], "IDA_h1")) 33 | func = IDA_h1; 34 | else if(!strcmp(argv[1], "IDA_h2")) 35 | func = IDA_h2; 36 | else return printf("输入了未知参数\n"); 37 | 38 | int start[5][5], target[5][5]; 39 | // 读取初始状态与最终状态 40 | FILE * fp; 41 | if(!(fp = fopen(argv[2],"r"))) return printf("没有这个文件:%s\n",argv[2]); 42 | for(int i = 0; i < 5; ++i) fscanf(fp,"%d %d %d %d %d\n", start[i], start[i]+1, start[i]+2, start[i]+3, start[i]+4); 43 | fclose(fp); 44 | if(!(fp = fopen(argv[3],"r"))) return printf("没有这个文件:%s\n",argv[3]); 45 | for(int i = 0; i < 5; ++i) fscanf(fp,"%d %d %d %d %d\n",target[i],target[i]+1,target[i]+2,target[i]+3,target[i]+4); 46 | fclose(fp); 47 | 48 | func(start,target); 49 | return 0; 50 | } 51 | // A_star IDA_star 在 a.h 完成 52 | void A_h1(int start[5][5], int target[5][5]){ 53 | A_star(start,target,h1); 54 | } 55 | void A_h2(int start[5][5], int target[5][5]){ 56 | A_star(start,target,h2); 57 | } 58 | void IDA_h1(int start[5][5], int target[5][5]){ 59 | IDA_star(start,target,h1); 60 | } 61 | void IDA_h2(int start[5][5], int target[5][5]){ 62 | IDA_star(start,target,h2); 63 | } 64 | int h1(int start[5][5], int target[5][5]){ // 返回错位的星球个数 65 | int s = 0; 66 | for(int i = 0; i < 5; ++i) 67 | for(int j = 0; j < 5; ++j) 68 | if(start[i][j] != target[i][j] && target[i][j]) 69 | if(target[i][j] < 0) 70 | exit(printf("黑洞错位")); 71 | else 72 | s++; 73 | return s; 74 | } 75 | int h2(int start[5][5], int target[5][5]){ // 自定义的耗散函数 76 | int s = 0; 77 | int r[5],minr;// r[5] 存储了5种路线 78 | for(int i = 0; i < 5; ++i) 79 | for(int j = 0; j < 5; ++j) 80 | if(start[i][j] != target[i][j] && start[i][j]){ 81 | if(target[i][j] < 0) 82 | exit(printf("黑洞错位")); 83 | int x = 0, y = 0; 84 | while (start[i][j] != target[x][y]) // 找到target中此星球的位置 85 | y == 4 ? (x++, y = 0) : y++; 86 | minr = r[0] = rd(x,y,i,j); // 不通过星际航道的路程 87 | r[1] = rd(x,y,0,2) + rd(4,2,i,j) + 1; 88 | r[2] = rd(x,y,4,2) + rd(0,2,i,j) + 1; 89 | r[3] = rd(x,y,2,0) + rd(2,4,i,j) + 1; 90 | r[4] = rd(x,y,2,4) + rd(2,0,i,j) + 1; 91 | for(int i = 1; i < 5; ++i) // 找出 r[5] 最小值 92 | if(minr > r[i]) minr = r[i]; 93 | s += minr; 94 | } 95 | return s; 96 | } 97 | int up(int start[5][5],int status[5][5]){ // 输入初始状态,返回转移后的状态status,转移失败返回0,转移成功返回1 98 | int x,y; 99 | for(int i = 0; i < 5; ++i) 100 | for(int j = 0; j < 5; ++j) 101 | if(!(status[i][j] = start[i][j])){ 102 | x = i; y = j; // 找到飞船 103 | } 104 | if(x == 0 && y != 2) return 0; // 这几个位置不能使用up转移,转移失败,返回0 105 | if(start[x?x-1:4][y] < 0) return 0; // 遇见黑洞,不能转移,返回0 106 | status[x?x-1:4][y] = start[x][y]; 107 | status[x][y] = start[x?x-1:4][y]; 108 | return 1; 109 | } 110 | int down(int start[5][5],int status[5][5]){ 111 | int x,y; 112 | for(int i = 0; i < 5; ++i) 113 | for(int j = 0; j < 5; ++j) 114 | if(!(status[i][j] = start[i][j])){ 115 | x = i; y = j; 116 | } 117 | if(x == 4 && y != 2) return 0; // 这几个位置不能使用up转移 118 | if(start[x!=4?x+1:0][y] < 0) return 0; // 遇见黑洞,不能转移 119 | status[x!=4?x+1:0][y] = start[x][y]; 120 | status[x][y] = start[x!=4?x+1:0][y]; 121 | return 1; 122 | } 123 | int left(int start[5][5],int status[5][5]){ 124 | int x,y; 125 | for(int i = 0; i < 5; ++i) 126 | for(int j = 0; j < 5; ++j) 127 | if(!(status[i][j] = start[i][j])){ 128 | x = i; y = j; 129 | } 130 | if(y == 0 && x != 2) return 0; // 这几个位置不能使用up转移 131 | if(start[x][y?y-1:4] < 0) return 0; // 遇见黑洞,不能转移 132 | status[x][y?y-1:4] = start[x][y]; 133 | status[x][y] = start[x][y?y-1:4]; 134 | return 1; 135 | } 136 | int right(int start[5][5],int status[5][5]){ 137 | int x,y; 138 | for(int i = 0; i < 5; ++i) 139 | for(int j = 0; j < 5; ++j) 140 | if(!(status[i][j] = start[i][j])){ 141 | x = i; y = j; 142 | } 143 | if(y == 4 && x != 2) return 0; // 这几个位置不能使用up转移 144 | if(start[x][y!=4?y+1:0] < 0) return 0; // 遇见黑洞,不能转移 145 | status[x][y!=4?y+1:0] = start[x][y]; 146 | status[x][y] = start[x][y!=4?y+1:0]; 147 | return 1; 148 | } -------------------------------------------------------------------------------- /digit/src/a.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // 定义 INT_MAX (Ubuntu下INT_MAX是没有定义的,windows下mingw是定义的,这里用 ifndef 防止重定义) 4 | #ifndef INT_MAX 5 | #define INT_MAX 2147483647 6 | #endif 7 | typedef struct Tree{ // A*搜索采用树结构 保存搜索路径 8 | int gn; // 起点到此位置的 实际耗散 9 | int hn; // 此位置到终点的 预估耗散 10 | int fn; // 预估总耗散:A*中 gn+hn,IDA*中作为next_limit 11 | int status[5][5]; // 该节点状态 12 | struct Tree *child[4];// 孩子(最多4个,因为只有上下左右四个状态转移函数,每个转移函数对应一个孩子) 13 | int n; // 孩子数目 14 | struct Tree *father;// 父节点 15 | int action; // 转移函数, 父节点通过 shift_func[action] 得到此节点 16 | struct Tree *tminfn;// 以该节点为根的子树中fn最小的节点,minfn()函数中使用与维护 17 | // 在IDA*中 n, tminfn,child中的3个 不会用到 18 | }Tree; 19 | // 初始化一个树,根节点由初始状态数组 start[5][5] 生成 20 | Tree* initA_star(int start[5][5],int gn, int hn); 21 | // 返回以t为根的子树中fn最小的节点 22 | Tree* minfn(Tree* t); 23 | // 按照转移函数,扩展节点t 24 | void extendTree(Tree* t,int target[5][5], int h(int start[5][5], int target[5][5])); 25 | // 输出转移步骤 26 | void prt(Tree *tmp); 27 | 28 | void A_star(int start[5][5], int target[5][5],int h(int start[5][5], int target[5][5])){ 29 | Tree* root = initA_star(start,0,h(start,target)),*tmp; 30 | while ((tmp = minfn(root))->hn) // while (tmp is not 终点) 31 | extendTree(tmp,target,h); // 扩展最小fn的叶节点 32 | prt(tmp); 33 | } 34 | 35 | // IDA* 的搜索迭代函数 36 | Tree* search(Tree* t, int bound,int target[5][5],int h(int start[5][5], int target[5][5])); 37 | 38 | void IDA_star(int start[5][5], int target[5][5],int h(int start[5][5], int target[5][5])){ 39 | Tree* root = initA_star(start,0,h(start,target)),*tmp; 40 | int bound = root->fn; 41 | while ((tmp = search(root,bound,target,h))->hn){ // while(tmp is not 终点) tmp是在bound限制下的迭代深度搜索 42 | bound = tmp->fn; // 放松限制 43 | if(bound >= 100000){ 44 | printf("failed"); 45 | return; 46 | } 47 | } 48 | prt(tmp); 49 | } 50 | 51 | Tree* initA_star(int start[5][5],int gn, int hn){ 52 | Tree* t = (Tree*)malloc(sizeof(Tree)); 53 | if(!t) exit(printf("initA_star分配空间失败")); 54 | t->gn = gn; 55 | t->hn = hn; 56 | t->fn = gn + hn; 57 | t->n = 0; 58 | t->father = NULL; 59 | t->action = -1; 60 | minfn(t); 61 | for(int i = 0; i < 5; ++i) 62 | for(int j = 0; j < 5; ++j) 63 | t->status[i][j] = start[i][j]; 64 | return t; 65 | } 66 | Tree* minfn(Tree* t){ // 更新祖宗节点的最小fn,返回以t为根的子树的最小fn的叶节点 67 | if(!t) return NULL; // t是NULL 68 | if(t->n) return t->tminfn; // t->n 不为0,说明非叶子节点,直接返回 t->tminfn 69 | // t是叶子节点,下面是做维护 70 | t->tminfn = t; 71 | for(Tree *tmp = t; tmp; tmp = tmp->father) // 从叶子到根结点,依次维护 72 | if(t->fn < tmp->tminfn->fn) 73 | tmp->tminfn = t; 74 | else if (tmp->tminfn->n){ // 此结点的tminfn不再是叶子,则从此结点孩子里的tminfn选取一个作为tminfn 75 | tmp->tminfn = t; 76 | for(int i = 0; i < tmp->n; ++i) 77 | if(tmp->tminfn->fn > tmp->child[i]->tminfn->fn) 78 | tmp->tminfn = tmp->child[i]->tminfn; 79 | } 80 | return t->tminfn; 81 | } 82 | void extendTree(Tree* t,int target[5][5], int h(int start[5][5], int target[5][5])){ // 延展节点t 83 | extern int ((*shift_func[4])(int start[5][5],int status[5][5])); 84 | for(int i = 0; i < 4; ++i){ 85 | // 去除 A->B->A 这种转移 (仅这一步能够减少非常非常多的重复状态,时间减少两到三倍) 86 | if(i == 0 && t->action == 1) continue; 87 | if(i == 1 && t->action == 0) continue; 88 | if(i == 2 && t->action == 3) continue; 89 | if(i == 3 && t->action == 2) continue; 90 | 91 | Tree * tmp = (Tree*)malloc(sizeof(Tree)); 92 | if(!tmp) exit(printf("extendTree分配空间失败")); 93 | if(shift_func[i](t->status,tmp->status)){ // 可通过 转移函数i 转移 94 | t->child[t->n++] = tmp; 95 | tmp->gn = t->gn + 1; 96 | tmp->hn = h(tmp->status,target); 97 | tmp->fn = tmp->gn + tmp->hn; 98 | tmp->n = 0; 99 | tmp->father = t; 100 | tmp->action = i; 101 | minfn(tmp); // tmp是叶子结点,这里调用minfn()是起维护作用,详细请看该函数 102 | } 103 | else 104 | free(tmp); 105 | } 106 | } 107 | void prt(Tree *tmp){ // 输出路径 108 | int actions[1000], i = 0, steps = tmp->gn; 109 | while (i < steps){ 110 | actions[steps - i - 1] = tmp->action; 111 | tmp = tmp->father; 112 | i++; 113 | } 114 | for(i = 0; i < steps ; ++i) 115 | switch (actions[i]){ 116 | case 0:printf("U");break; 117 | case 1:printf("D");break; 118 | case 2:printf("L");break; 119 | case 3:printf("R");break; 120 | default:break; 121 | } 122 | } 123 | 124 | 125 | // IDA*用 126 | Tree* search(Tree* t, int bound,int target[5][5],int h(int start[5][5], int target[5][5])){ 127 | extern int ((*shift_func[4])(int start[5][5],int status[5][5])); 128 | if(t->fn > bound) return t; 129 | if(!t->hn) return t; 130 | int min = INT_MAX; 131 | for(int i = 0; i < 4; ++i){ 132 | // 去除 A->B->A 这种转移 (仅这一步能够减少非常非常多的重复状态,时间减少两到三倍) 133 | if(i == 0 && t->action == 1) continue; 134 | if(i == 1 && t->action == 0) continue; 135 | if(i == 2 && t->action == 3) continue; 136 | if(i == 3 && t->action == 2) continue; 137 | 138 | Tree * tmp = (Tree*)malloc(sizeof(Tree)); 139 | if(!tmp) exit(printf("extendTree分配空间失败")); 140 | if(shift_func[i](t->status,tmp->status)){ // 可通过 转移函数i 转移 141 | t->child[i] = tmp; 142 | tmp->gn = t->gn + 1; 143 | tmp->hn = h(tmp->status,target); 144 | tmp->fn = tmp->gn + tmp->hn; 145 | tmp->father = t; 146 | tmp->action = i; 147 | tmp = search(tmp,bound,target,h); // ***迭代深搜*** 148 | if(!tmp->hn) return tmp; // 找到终点 149 | if(tmp->fn < min) min = tmp->fn; 150 | free(t->child[i]); 151 | } 152 | else 153 | free(tmp); 154 | } 155 | t->fn = min; // 存储下一个limit限制,这里虽然打破了fn=gn+hn的规则,但赋值给fn没有问题,因为fn本意是对耗散的总估值,gn+hn只是其中一种表示, 156 | return t; 157 | } -------------------------------------------------------------------------------- /digit/src/input00.txt: -------------------------------------------------------------------------------- 1 | 1 2 7 4 5 2 | 6 12 0 9 10 3 | 11 -8 14 18 15 4 | 16 17 23 13 20 5 | 21 22 3 19 24 -------------------------------------------------------------------------------- /digit/src/input01.txt: -------------------------------------------------------------------------------- 1 | 1 2 0 4 5 2 | 6 7 8 9 10 3 | 16 12 -13 14 11 4 | 21 17 18 19 15 5 | 22 23 3 24 20 -------------------------------------------------------------------------------- /digit/src/input02.txt: -------------------------------------------------------------------------------- 1 | 0 -2 4 5 10 2 | 1 -7 8 -9 15 3 | 6 -12 13 -14 11 4 | -16 17 18 19 -20 5 | 21 22 3 23 24 6 | -------------------------------------------------------------------------------- /digit/src/input03.txt: -------------------------------------------------------------------------------- 1 | 1 2 8 4 5 2 | 6 7 13 0 -10 3 | 15 11 14 9 20 4 | -16 17 12 18 19 5 | 21 22 3 23 24 -------------------------------------------------------------------------------- /digit/src/input04.txt: -------------------------------------------------------------------------------- 1 | 1 2 7 4 5 2 | 6 12 9 0 10 3 | 11 8 14 18 -15 4 | 16 17 23 13 20 5 | 21 22 3 19 24 -------------------------------------------------------------------------------- /digit/src/input05.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 9 4 2 | 6 7 8 19 5 3 | 16 11 12 13 10 4 | 21 17 18 24 14 5 | 22 23 0 20 15 6 | -------------------------------------------------------------------------------- /digit/src/input06.txt: -------------------------------------------------------------------------------- 1 | 0 2 4 9 5 2 | 1 6 -8 10 20 3 | 12 7 18 13 15 4 | 11 16 22 14 19 5 | 21 17 3 23 24 -------------------------------------------------------------------------------- /digit/src/input07.txt: -------------------------------------------------------------------------------- 1 | 7 1 2 3 4 2 | 0 8 9 10 5 3 | 6 11 12 13 14 4 | 17 18 19 20 15 5 | 16 21 22 23 24 -------------------------------------------------------------------------------- /digit/src/input08.txt: -------------------------------------------------------------------------------- 1 | 2 6 -3 5 10 2 | 1 12 7 8 4 3 | -11 17 13 0 -15 4 | 22 18 14 9 24 5 | 16 21 -23 20 19 -------------------------------------------------------------------------------- /digit/src/input09.txt: -------------------------------------------------------------------------------- 1 | 6 1 2 5 10 2 | 11 7 9 4 15 3 | 20 12 13 8 0 4 | 16 21 18 14 19 5 | 22 17 3 23 24 6 | -------------------------------------------------------------------------------- /digit/src/input10.txt: -------------------------------------------------------------------------------- 1 | 6 1 4 5 10 2 | 11 -7 3 -9 12 3 | 16 8 0 15 20 4 | 21 -17 14 -19 24 5 | 22 18 13 2 23 -------------------------------------------------------------------------------- /digit/src/input11.txt: -------------------------------------------------------------------------------- 1 | 7 1 8 5 10 2 | 6 3 2 9 0 3 | 14 11 -13 4 15 4 | 22 12 17 24 19 5 | 16 21 18 23 20 -------------------------------------------------------------------------------- /digit/src/readme.md: -------------------------------------------------------------------------------- 1 | 直接在windows环境下运行1run.bat即可 2 | -------------------------------------------------------------------------------- /digit/src/target00.txt: -------------------------------------------------------------------------------- 1 | 1 2 7 4 5 2 | 6 12 14 9 10 3 | 11 -8 23 15 0 4 | 16 17 13 18 20 5 | 21 22 3 19 24 -------------------------------------------------------------------------------- /digit/src/target01.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 2 | 6 7 8 9 10 3 | 11 12 -13 14 15 4 | 16 17 18 19 20 5 | 21 22 23 24 0 -------------------------------------------------------------------------------- /digit/src/target02.txt: -------------------------------------------------------------------------------- 1 | 1 -2 3 4 5 2 | 6 -7 8 -9 10 3 | 11 -12 13 -14 15 4 | -16 17 18 19 -20 5 | 21 22 23 24 0 6 | -------------------------------------------------------------------------------- /digit/src/target03.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 2 | 6 7 8 9 -10 3 | 11 12 13 14 15 4 | -16 17 18 19 20 5 | 21 22 23 24 0 -------------------------------------------------------------------------------- /digit/src/target04.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 2 | 6 7 8 9 10 3 | 11 12 13 14 -15 4 | 16 17 18 19 20 5 | 21 22 23 24 0 -------------------------------------------------------------------------------- /digit/src/target05.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 2 | 6 7 8 9 10 3 | 11 12 13 14 15 4 | 16 17 18 19 20 5 | 21 22 23 24 0 -------------------------------------------------------------------------------- /digit/src/target06.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 2 | 6 7 -8 9 10 3 | 11 12 13 14 15 4 | 16 17 18 19 20 5 | 21 22 23 24 0 -------------------------------------------------------------------------------- /digit/src/target07.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 2 | 6 7 8 9 10 3 | 11 12 13 14 15 4 | 16 17 18 19 20 5 | 21 22 23 24 0 -------------------------------------------------------------------------------- /digit/src/target08.txt: -------------------------------------------------------------------------------- 1 | 1 2 -3 4 5 2 | 6 7 8 9 10 3 | -11 12 13 14 -15 4 | 16 17 18 19 20 5 | 21 22 -23 24 0 -------------------------------------------------------------------------------- /digit/src/target09.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 2 | 6 7 8 9 10 3 | 11 12 13 14 15 4 | 16 17 18 19 20 5 | 21 22 23 24 0 6 | -------------------------------------------------------------------------------- /digit/src/target10.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 2 | 6 -7 8 -9 10 3 | 11 12 13 14 15 4 | 16 -17 18 -19 20 5 | 21 22 23 24 0 -------------------------------------------------------------------------------- /digit/src/target11.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 2 | 6 7 8 9 10 3 | 11 12 -13 14 15 4 | 16 17 18 19 20 5 | 21 22 23 24 0 -------------------------------------------------------------------------------- /digit/src/难度说明.txt: -------------------------------------------------------------------------------- 1 | input00-target00 难度:5 步 参考时间:1.009000 s 2 | input01-target01 难度:8 步 参考时间:0.035000 s 3 | input02-target02 难度:10步 参考时间:0.052000 s 4 | input03-target03 难度:14步 参考时间:0.059000 s 5 | input04-target04 难度:17步 参考时间:0.088000 s 6 | input05-target05 难度:20步 参考时间:0.123000 s 7 | input06-target06 难度:23步 参考时间:5.812000 s 8 | input07-target07 难度:25步 参考时间:45.995000 s 9 | input08-target08 难度:27步 参考时间:大于 60s 10 | input09-target09 难度:28步 参考时间:大于 60s 11 | input10-target10 难度:30步 参考时间:大于 60s 12 | input11-target11 难度:32步 参考时间:大于 60s -------------------------------------------------------------------------------- /kmeans/kmeans.txt: -------------------------------------------------------------------------------- 1 | 1.658985 4.285136 2 | -3.453687 3.424321 3 | 4.838138 -1.151539 4 | -5.379713 -3.362104 5 | 0.972564 2.924086 6 | -3.567919 1.531611 7 | 0.450614 -3.302219 8 | -3.487105 -1.724432 9 | 2.668759 1.594842 10 | -3.156485 3.191137 11 | 3.165506 -3.999838 12 | -2.786837 -3.099354 13 | 4.208187 2.984927 14 | -2.123337 2.943366 15 | 0.704199 -0.479481 16 | -0.392370 -3.963704 17 | 2.831667 1.574018 18 | -0.790153 3.343144 19 | 2.943496 -3.357075 20 | -3.195883 -2.283926 21 | 2.336445 2.875106 22 | -1.786345 2.554248 23 | 2.190101 -1.906020 24 | -3.403367 -2.778288 25 | 1.778124 3.880832 26 | -1.688346 2.230267 27 | 2.592976 -2.054368 28 | -4.007257 -3.207066 29 | 2.257734 3.387564 30 | -2.679011 0.785119 31 | 0.939512 -4.023563 32 | -3.674424 -2.261084 33 | 2.046259 2.735279 34 | -3.189470 1.780269 35 | 4.372646 -0.822248 36 | -2.579316 -3.497576 37 | 1.889034 5.190400 38 | -0.798747 2.185588 39 | 2.836520 -2.658556 40 | -3.837877 -3.253815 41 | 2.096701 3.886007 42 | -2.709034 2.923887 43 | 3.367037 -3.184789 44 | -2.121479 -4.232586 45 | 2.329546 3.179764 46 | -3.284816 3.273099 47 | 3.091414 -3.815232 48 | -3.762093 -2.432191 49 | 3.542056 2.778832 50 | -1.736822 4.241041 51 | 2.127073 -2.983680 52 | -4.323818 -3.938116 53 | 3.792121 5.135768 54 | -4.786473 3.358547 55 | 2.624081 -3.260715 56 | -4.009299 -2.978115 57 | 2.493525 1.963710 58 | -2.513661 2.642162 59 | 1.864375 -3.176309 60 | -3.171184 -3.572452 61 | 2.894220 2.489128 62 | -2.562539 2.884438 63 | 3.491078 -3.947487 64 | -2.565729 -2.012114 65 | 3.332948 3.983102 66 | -1.616805 3.573188 67 | 2.280615 -2.559444 68 | -2.651229 -3.103198 69 | 2.321395 3.154987 70 | -1.685703 2.939697 71 | 3.031012 -3.620252 72 | -4.599622 -2.185829 73 | 4.196223 1.126677 74 | -2.133863 3.093686 75 | 4.668892 -2.562705 76 | -2.793241 -2.149706 77 | 2.884105 3.043438 78 | -2.967647 2.848696 79 | 4.479332 -1.764772 80 | -4.905566 -2.911070 -------------------------------------------------------------------------------- /kmeans/main.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | import utils 4 | 5 | #载入数据 6 | data = np.genfromtxt("kmeans.txt") 7 | plt.scatter(data[:, 0], data[:, 1]) 8 | plt.show() 9 | 10 | print(data.shape) 11 | 12 | 13 | # 训练模型 14 | # 计算距离 15 | def euclDistance(vector1, vector2): 16 | return np.sqrt(sum((vector2 - vector1) ** 2)) 17 | 18 | 19 | # 初始化质心 20 | def initCentroids(data, k): 21 | numSamples, dim = data.shape 22 | # k个质心,列数跟样本的列数一样 23 | centroids = np.zeros((k, dim)) 24 | # 随机选出k个质心 25 | for i in range(k): 26 | # 随机选取一个样本的索引 27 | index = int(np.random.uniform(0, numSamples)) 28 | # 作为初始化的质心 29 | centroids[i, :] = data[index, :] 30 | return centroids 31 | 32 | 33 | # 传入数据集和k值 34 | def kmeans(data, k): 35 | # 计算样本个数 36 | numSamples = data.shape[0] 37 | # 样本的属性,第一列保存该样本属于哪个簇,第二列保存该样本跟它所属簇的误差 38 | clusterData = np.array(np.zeros((numSamples, 2))) 39 | # 决定质心是否要改变的质量 40 | clusterChanged = True 41 | # 初始化质心 42 | centroids = initCentroids(data, k) 43 | while clusterChanged: 44 | clusterChanged = False 45 | # 循环每一个样本 46 | for i in range(numSamples): 47 | # 最小距离 48 | minDist = 100000.0 49 | # 定义样本所属的簇 50 | minIndex = 0 51 | # 循环计算每一个质心与该样本的距离 52 | for j in range(k): 53 | # 循环每一个质心和样本,计算距离 54 | distance = euclDistance(centroids[j, :], data[i, :]) 55 | # 如果计算的距离小于最小距离,则更新最小距离 56 | if distance < minDist: 57 | minDist = distance 58 | # 更新最小距离 59 | clusterData[i, 1] = minDist 60 | # 更新样本所属的簇 61 | minIndex = j 62 | # 如果样本的所属的簇发生了变化 63 | if clusterData[i, 0] != minIndex: 64 | # 质心要重新计算 65 | clusterChanged = True 66 | # 更新样本的簇 67 | clusterData[i, 0] = minIndex 68 | # 更新质心 69 | for j in range(k): 70 | # 获取第j个簇所有的样本所在的索引 71 | cluster_index = np.nonzero(clusterData[:, 0] == j) 72 | # 第j个簇所有的样本点 73 | pointsInCluster = data[cluster_index] 74 | # 计算质心 75 | centroids[j, :] = np.mean(pointsInCluster, axis=0) 76 | return centroids, clusterData 77 | 78 | 79 | # 显示结果 80 | def showCluster(data, k, centroids, clusterData): 81 | numSamples, dim = data.shape 82 | if dim != 2: 83 | print('dimension of your data is not 2!') 84 | return 1 85 | # 用不同颜色形状来表示各个类别 86 | mark = ['or', 'ob', 'og', 'ok', '^r', '+r', 'dr', ' len(mark): 88 | print('your k is too large!') 89 | return 1 90 | # 画样本点 91 | for i in range(numSamples): 92 | markIndex = int(clusterData[i, 0]) 93 | plt.plot(data[i, 0], data[i, 1], mark[markIndex]) 94 | # 用不同颜色形状来表示各个类别 95 | mark = ['*r', '*b', '*g', '*k', '^b', '+b', 'sb', 'db', '