[
  {
    "path": "Adaboost/README.md",
    "content": "Adaboost 算法实现。\n\n更多机器学习深度学习博客请关注CSDN博客：[LiuLongpo](http://blog.csdn.net/llp1992)\n"
  },
  {
    "path": "Adaboost/adaboost.py",
    "content": "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu Jun 11 12:42:48 2015\n\n@author: liu\n\"\"\"\nfrom numpy import *\n\ndef loadSimpData():\n\n    dataMat = array([[1.,2.1],[1.5,1.6],[1.3,1.],[1.,1.],[2.,1.],[1.2,1.1],\\\n    [1.1,0.4],[0.9,1.3],[0.86,1.2],[1.8,1.8],[1.7,1.5],[1.9,1.8]])\n    classLabels = array([1.0,1.0,-1.0,-1.0,1.0,-1.0,-1.0,-1.0,\\\n    -1.0,1.0,1.0,1.0])\n    return dataMat,classLabels\n\n# 单树桩分类器，也就是简单的单层决策树弱分类器\n# 该函数根据某个最好的特征的最好划分点对数据进行分类\n# demen就是特征，threshVal就是划分点，retArray就是返回的分类结果\ndef stumpClassify(dataMatrix,dimen,threshVal,threshIneq):\n    retArray = ones((shape(dataMatrix)[0],1))\n    if threshIneq == 'lt':\n        retArray[dataMatrix[:,dimen]<=threshVal] = -1.0\n    else:\n        retArray[dataMatrix[:,dimen]>threshVal] = -1.0\n    return retArray\n        \n# 创建树桩，返回最好的树桩和该树桩的分类最小误差以及分类结果\n# 该函数用于从数据集中找到最好的划分特征以及该特征的最好划分点\ndef buildStump(dataArr,classLabels,D):\n    # 建立备份的数据\n    dataMatrix = mat(dataArr);\n    labelMat = mat(classLabels).T\n    # m 是行，也就是每个样本，n是列，也就是每个特征\n    m,n = shape(dataMatrix)\n    # 步数的设置，也就是在每个特征的最大值和最小值中分几次设置阈值进行数据划分\n    # 也就是获取这个特征的最佳划分点，步数越高，特征点寻找得越精细，但耗时更多\n    # 用字典来存储bestStump的数据\n    numSteps = 10.0;bestStump = {};bestClassEst = mat(zeros((m,1)))\n    minError = inf\n    # 对每个特征\n    for i in range(n):\n        # 获取每个特征的最小值和最大值\n        rangeMin = dataMatrix[:,i].min();\n        rangeMax = dataMatrix[:,i].max();\n        stepSize = (rangeMax-rangeMin)/numSteps\n        for j in range(-1,int(numSteps)+1):\n            for inequal in ['lt','gt']:\n                threshVal = (rangeMin + float(j) * stepSize)\n                # 预测值\n                predictedVals = stumpClassify(dataMatrix,i,threshVal,inequal)\n                errArr = mat(ones((m,1)))\n                errArr[predictedVals == labelMat] = 0\n                # 样本权重乘以样本误差\n                weightedError = D.T * errArr\n                # 下面的 .2f 表示浮点数小数殿后两位， .3f 表示小数点后3位\n                print \"split:dim %d,thresh %.2f, thresh ineqal: %s,the weighted eror is %.3f\" %\\\n                (i,threshVal,inequal,weightedError)\n                if weightedError < minError:\n                    minError = weightedError\n                    # 最好的分类结果\n                    bestClassEst = predictedVals.copy()\n                    bestStump['dim'] = i\n                    bestStump['thresh'] = threshVal\n                    bestStump['ineq'] = inequal\n    return bestStump,minError,bestClassEst\n        \ndef adaBoostTrainDS(dataArr,classLabels,numIt = 40):\n    weakClassArr = []\n    m = shape(dataArr)[0]\n    D = mat(ones((m,1))/m)\n    # 创建矩阵 mat\n    aggClassEst = mat(zeros((m,1)))\n    for i in range(numIt):\n        bestStump,error,classEst = buildStump(dataArr,classLabels,D)\n        print 'D:',D.T\n        # log 就是 ln 公式： a = 0.5*ln((1-e)/e)\n        alpha = float(0.5*log((1.0-error)/max(error,1e-16)))\n        bestStump['alpha'] = alpha\n        # 将当前的最好的树桩添加到弱分类其数组中\n        weakClassArr.append(bestStump)\n        print 'classEst:',classEst.T\n        # D权重的更新公式，利用原本的类别classLabels与划分的类别classEst做乘积\n        # 用来同时计算正确划分和错误划分的公式，也就是自动确定正负号\n        expon = multiply(-1*alpha*mat(classLabels).T,classEst)\n        # 更新权重D\n        D = multiply(D,exp(expon))\n        D = D/D.sum()\n        aggClassEst += alpha*classEst\n        print 'aggClassEst:',aggClassEst.T\n        aggErrors = multiply(sign(aggClassEst)!=mat(classLabels).T,ones((m,1)))\n        errorRate = aggErrors.sum()/m\n        print 'total error:',errorRate,\"\\n\"\n        if errorRate == 0.0:break;\n    return weakClassArr\n    \n    # 利用学习得到的多个级联弱分类器进行数据分类\ndef adaClassify(datToClass,classifierArr):\n    dataMatrix = mat(datToClass)\n    m = shape(dataMatrix)[0]\n    aggClassEst = mat(zeros((m,1)))\n    for i in range(len(classifierArr)):\n        classEst = stumpClassify(dataMatrix,classifierArr[i]['dim'],\\\n        classifierArr[i]['thresh'],classifierArr[i]['ineq'])\n        aggClassEst += classifierArr[i]['alpha'] * classEst\n        print aggClassEst\n    return sign(aggClassEst)\n"
  },
  {
    "path": "Adaboost/testAdaboost.py",
    "content": "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu Jun 11 12:57:27 2015\n\n@author: LiuLongpo\n\"\"\"\nimport optunity\nimport adaboost\nimport matplotlib.pyplot as plt\nfrom numpy import *\ndataMat,classLabels = adaboost.loadSimpData()\n\n#plt.scatter(dataMat[:,0],dataMat[:,1])\n# D是样本的权重矩阵\nD = mat(ones((5,1))/5)\n#adaboost.buildStump(dataMat,classLabels,D)\nprint 'data train...'\nclassifierArr = adaboost.adaBoostTrainDS(dataMat,classLabels,30)\nprint 'getClassifier:',classifierArr\nprint 'data predict...'\n# 学习得到3个分类器，predict时，每一个分类器级联分类得到的预测累加值 \n# aggClassEst越来越远离0，也就是正越大或负越大，也就是分类结果越来越强\nadaboost.adaClassify([[1,0.8],[1.8,2]],classifierArr)\n# 0,lt,1.3   1,lt,1.0   0,lt,0.9\nplt.figure()\nI = nonzero(classLabels>0)[0]\nplt.scatter(dataMat[I,0],dataMat[I,1],s=60,c=u'r',marker=u'o')\nI = nonzero(classLabels<0)[0]\nplt.scatter(dataMat[I,0],dataMat[I,1],s=60,c=u'b',marker=u'o')\n\n\nplt.plot([1.32,1.32],[0.5,2.5])\nplt.plot([0.5,2.5],[1.42,1.42])\nplt.plot([0.97,0.97],[0.5,2.5])\n\n'''\nplt.figure()\nI = nonzero(classLabels>0)[0]\nplt.scatter(dataMat[I,0],dataMat[I,1],s=60,c=u'r',marker=u'o')\nI = nonzero(classLabels<0)[0]\nplt.scatter(dataMat[I,0],dataMat[I,1],s=60,c=u'b',marker=u'o')\nplt.plot([1.32*1.19,1.32*1.19],[0.5,2.5])\nplt.plot([0.5,2.5],[1.42*1.52,1.42*1.52])\nplt.plot([0.97*1.13,0.97*1.13],[0.5,2.5])\n#plt.scatter([0,5],[0,5])\n\n'''\n"
  },
  {
    "path": "Decision-Tree/README.md",
    "content": "决策树算法实现。\n\n更多机器学习深度学习博客请关注CSDN博客：[LiuLongpo](http://blog.csdn.net/llp1992)\n"
  },
  {
    "path": "Decision-Tree/TestTree.py",
    "content": "import Tree\n\ndataSet,label = Tree.createDataSet()\nprint 'dataSet:' , dataSet\n#Tree.createTree(dataSet,label)\n"
  },
  {
    "path": "Decision-Tree/Tree.py",
    "content": "from math import log\n# 计算熵\ndef calcShannonEnt(dataSet):\n    numEntries = len(dataSet)\n    labelCounts = {}\n    for featVec in dataSet:\n        currentLabel = featVec[-1]\n        if currentLabel not in labelCounts.keys():\n            labelCounts[currentLabel] = 0\n        labelCounts[currentLabel] += 1\n    shannoEnt = 0.0\n    for key in labelCounts:\n        prob = float(labelCounts[key])/numEntries\n        shannoEnt -= prob * log(prob,2)\n    return shannoEnt\ndef createDataSet():\n    dataSet = [[1,1,0,'yes'],[1,1,1,'yes'],[1,0,1,'no'],[0,1,0,'no'],[0,1,0,'no']]\n    label = ['no surfacing','flippers']\n    return dataSet,label\n# 划分数据集\n# axis为特征，也就是对某一个特征进行判定，比如身高\n# value为特征的值，也就是说，某一个特征的不同值，\n# 比如身高这个特征有高和矮之分，高跟矮就是这个value\n# 数据集为 [ [1,1,0,'yes'],[1,1,1,'yes'],[1,0,1,'no'],[0,1,0,'no'],[0,1,0,'no'] ]\n# 每一个 feaVec 就是一行，也就是一个样本数据\ndef spiltDataSet(dataSet,axis,value):\n    retDataSet = []\n    for featVec in dataSet:\n        # 如果当前样本数据的特征 axis 的值 featVec[axis] 与我们要求的value相等\n        # 也就是我们认为当前的样本符合我们的要求\n        if featVec[axis] == value:\n        # 对于符合要求的样本数据\n        # 我们将这个特征剪掉，剩下的数据组成一个新的子样本并返回\n            redecedFeatVec = featVec[:axis]\n            redecedFeatVec.extend(featVec[axis+1:])\n            retDataSet.append(redecedFeatVec)\n    return retDataSet\n# 寻找最优的划分特征\ndef chooseBestFeatureToSplit(dataSet):\n    # 为什么减一？\n    numFeatures = len(dataSet[0])-1\n    # 计算源数据的熵\n    baseEntropy = calcShannonEnt(dataSet)\n    bestInfoGain = 0.0\n    bestFeature = -1\n    for i in xrange(numFeatures):\n        # 获取每一列，因为每一列都属于一个特征的不同value\n        featList = [example[i] for example in dataSet]\n        # 确保每个值都是唯一的\n        uniqueVals = set(featList)\n        newEntorpy = 0.0\n        print 'spilt feature ', i\n        # 对每个value进行划分\n        for value in uniqueVals:\n            subDataSet = spiltDataSet(dataSet,i,value)\n            print 'subDataSet:' , subDataSet\n            prob = len(subDataSet)/float(len(dataSet))\n                # 计算该特征进行划分后的信息\n            newEntorpy += prob * calcShannonEnt(subDataSet)\n            # 计算该特征进行划分后的信息增益\n        infoGain = baseEntropy - newEntorpy\n            # 寻找信息增益最大的特征就是最好划分的特征\n        if (infoGain > bestInfoGain):\n            bestInfoGain = infoGain\n            bestFeature = i\n    print 'BestFeatureToSplit' \n    print bestFeature\n    return bestFeature\n# 投票表决，获取概率最大的那个分类\ndef majorityCnt(classList):\n    classCount = {}\n    for vote in classList:\n        if vote not in classCount.keys():classCount[vote] = 0\n        classCount[vote] += 1\n# 反向排序，也就是从大到小\n    sortedClassCount = sorted(classCount.iteritems(),key = operator.itemgetter(1),reverse=True)\n    return sortedClassCount[0][0]\ndef createTree(dataSet,labels):\n    # 获取每个样本数据的分类\n    classList = [example[-1] for example in dataSet]\n        # 第一个迭代终止条件：选取第一个classList中的类，判断它出现的次数是否与\n        # classList的长度相等，如果相等，证明classList中的所有类已经被分为同一种类\n        # 则返回该类\n    if classList.count(classList[0]) == len(classList):\n        return classList[0]\n        #如果所有特征都迭代完了，此时还没返回，\n        # 说明当前仍然不能讲数据集划分为仅包含唯一类别的分组\n        # 此时则返回次数出现最多的那个类别最为当前数据集的类别\n    if len(dataSet[0]) == 1:\n        return majorityCnt(classList)\n        # 寻找最优的划分特征\n    bestFeat = chooseBestFeatureToSplit(dataSet)\n    bestFeatLabel = labels[bestFeat]\n    myTree = {bestFeatLabel:{}}\n    del(labels[bestFeat])\n        # 获取最优特征的各个属性\n    featValues = [example[bestFeat] for example in dataSet]        \n    uniqueVals = set(featValues)\n    for value in uniqueVals:\n        subLabels = labels[:]\n                # 迭代创建决策树\n        myTree[bestFeatLabel][value] = createTree(spiltDataSet(dataSet,bestFeat,value),subLabels)\n    return myTree\n"
  },
  {
    "path": "DeepLearning/CNN_cifar-10/cifar.py",
    "content": "\n# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu Aug 27 11:27:34 2015\n\n@author: lab-liu.longpo\n\"\"\"\n\n\nfrom __future__ import absolute_import\nfrom __future__ import print_function\nfrom keras.models import Sequential\nfrom keras.layers.core import Dense, Dropout, Activation, Flatten\nfrom keras.layers.convolutional import Convolution2D, MaxPooling2D\nfrom keras.optimizers import SGD, Adadelta, Adagrad\nfrom keras.utils import np_utils, generic_utils\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport scipy.io as sio\n\nd = sio.loadmat('data.mat')\ndata = d['d']\nlabel = d['l']\ndata = np.reshape(data,(50000,3,32,32))\nlabel = np_utils.to_categorical(label, 10)\n\nprint ('finish loading data')\n\nmodel = Sequential()\n\nmodel.add(Convolution2D(32, 3, 5, 5, border_mode='valid')) \nmodel.add(Activation('relu'))\n#model.add(MaxPooling2D(poolsize=(2, 2)))\nmodel.add(Dropout(0.25))\n\nmodel.add(Convolution2D(32, 32, 5, 5, border_mode='valid')) \nmodel.add(Activation('relu'))\nmodel.add(MaxPooling2D(poolsize=(2, 2)))\nmodel.add(Dropout(0.25))\n\nmodel.add(Convolution2D(64, 32, 3, 3, border_mode='valid')) \nmodel.add(Activation('relu'))\nmodel.add(MaxPooling2D(poolsize=(2, 2)))\nmodel.add(Dropout(0.25))\n\nmodel.add(Flatten())\nmodel.add(Dense(64*5*5, 512, init='normal'))\nmodel.add(Activation('tanh'))\n\nmodel.add(Dense(512, 10, init='normal'))\nmodel.add(Activation('softmax'))\n\nsgd = SGD(l2=0.001,lr=0.0065, decay=1e-6, momentum=0.9, nesterov=True)\nmodel.compile(loss='categorical_crossentropy', optimizer=sgd,class_mode=\"categorical\")\n\n#checkpointer = ModelCheckpoint(filepath=\"weight.hdf5\",verbose=1,save_best_only=True)\n#model.fit(data, label, batch_size=100,nb_epoch=10,shuffle=True,verbose=1,show_accuracy=True,validation_split=0.2,callbacks=[checkpointer])\nresult = model.fit(data, label, batch_size=50,nb_epoch=35,shuffle=True,verbose=1,show_accuracy=True,validation_split=0.2)\n#model.save_weights(weights,accuracy=False)\n\n# plot the result\n\nplt.figure\nplt.plot(result.epoch,result.history['acc'],label=\"acc\")\nplt.plot(result.epoch,result.history['val_acc'],label=\"val_acc\")\nplt.scatter(result.epoch,result.history['acc'],marker='*')\nplt.scatter(result.epoch,result.history['val_acc'])\nplt.legend(loc='under right')\nplt.show()\n\nplt.figure\nplt.plot(result.epoch,result.history['loss'],label=\"loss\")\nplt.plot(result.epoch,result.history['val_loss'],label=\"val_loss\")\nplt.scatter(result.epoch,result.history['loss'],marker='*')\nplt.scatter(result.epoch,result.history['val_loss'],marker='*')\nplt.legend(loc='upper right')\nplt.show()\n"
  },
  {
    "path": "DeepLearning/CNN_mnist/cnn.py",
    "content": "# -*- coding: utf-8 -*-\n\nfrom __future__ import absolute_import\nfrom __future__ import print_function\nfrom keras.preprocessing.image import ImageDataGenerator\nfrom keras.models import Sequential\nfrom keras.layers.core import Dense, Dropout, Activation, Flatten\nfrom keras.layers.advanced_activations import PReLU\nfrom keras.layers.convolutional import Convolution2D, MaxPooling2D\nfrom keras.optimizers import SGD, Adadelta, Adagrad\nfrom keras.utils import np_utils, generic_utils\nfrom data import load_data\n\nimport matplotlib.pyplot as plt\n\n'''\ntrain the dataset of face 42000 image\nlearning rate : 0.0015\npathc size:100\ndropout :0.25\nl2 = 0.01\n'''\n\ndef funcnn(LR,BS):\n    data, label = load_data()\n    label = np_utils.to_categorical(label, 10)\n    \n    model = Sequential()\n    \n    model.add(Convolution2D(4, 1, 5, 5, border_mode='valid')) \n    model.add(Activation('relu'))\n    model.add(Dropout(0.25))\n    \n    model.add(Convolution2D(8,4, 3, 3, border_mode='valid'))\n    model.add(Activation('relu'))\n    model.add(MaxPooling2D(poolsize=(2, 2)))\n    model.add(Dropout(0.25))\n    \n    model.add(Convolution2D(16, 8, 3, 3, border_mode='valid')) \n    model.add(Activation('relu'))\n    model.add(MaxPooling2D(poolsize=(2, 2)))\n    model.add(Dropout(0.25))\n    \n    model.add(Flatten())\n    model.add(Dense(16*4*4, 256, init='normal'))\n    model.add(Activation('tanh'))\n    \n    model.add(Dense(256, 10, init='normal'))\n    model.add(Activation('softmax'))\n    \n    sgd = SGD(l2=0.001,lr=LR, decay=1e-6, momentum=0.9, nesterov=True)\n    model.compile(loss='categorical_crossentropy', optimizer=sgd,class_mode=\"categorical\")\n    \n    #checkpointer = ModelCheckpoint(filepath=\"weight.hdf5\",verbose=1,save_best_only=True)\n    #model.fit(data, label, batch_size=100,nb_epoch=10,shuffle=True,verbose=1,show_accuracy=True,validation_split=0.2,callbacks=[checkpointer])\n    result = model.fit(data, label, batch_size=BS,nb_epoch=20,shuffle=True,verbose=1,show_accuracy=True,validation_split=0.2)\n    #model.save_weights(weights,accuracy=False)\n    \n    # plot the result\n    \n    plt.figure\n    plt.plot(result.epoch,result.history['acc'],label=\"acc\")\n    plt.plot(result.epoch,result.history['val_acc'],label=\"val_acc\")\n    plt.scatter(result.epoch,result.history['acc'],marker='*')\n    plt.scatter(result.epoch,result.history['val_acc'])\n    plt.legend(loc='under right')\n    plt.show()\n    \n    plt.figure\n    plt.plot(result.epoch,result.history['loss'],label=\"loss\")\n    plt.plot(result.epoch,result.history['val_loss'],label=\"val_loss\")\n    plt.scatter(result.epoch,result.history['loss'],marker='*')\n    plt.scatter(result.epoch,result.history['val_loss'],marker='*')\n    plt.legend(loc='upper right')\n    plt.show()\n    \n\n"
  },
  {
    "path": "DeepLearning/CNN_mnist/data.py",
    "content": "# -*- coding: utf-8 -*-\nimport os\nfrom PIL import Image\nimport numpy as np\n\ndef load_data():\n    print 'start loading data...'\n    data = np.empty((42000,1,28,28),dtype=\"float32\")\n    label = np.empty((42000,),dtype=\"uint8\")\n\n    imgs = os.listdir(\"./mnist\")\n    num = len(imgs)\n    for i in range(num):\n        img = Image.open(\"./mnist/\"+imgs[i])\n        arr = np.asarray(img,dtype=\"float32\")\n        data[i,:,:,:] = arr\n        label[i] = int(imgs[i].split('.')[0])\n    return data,label\n\n"
  },
  {
    "path": "DeepLearning/CNN_mnist/trainCNN.py",
    "content": "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Tue Aug 25 10:59:38 2015\n\n@author: lab-liu.longpo\n\"\"\"\n\nfrom cnn import funcnn\nimport numpy as np\n\n\ndef floatrange(start,stop,steps):\n    return [start+float(i) * (stop-start)/(float(steps)-1) for i in range(steps)]\n\n\n#LR = [0.03]\n#LR = floatrange(0.033,0.036,10)\nLR = [0.0015]\nBS = [100]\n#result = np.empty((3,8,10),dtype=\"float32\")\nk = 0;\nfor i in range(1):\n    for j in range(1):\n        print 'test',k\n        k = k+1\n        tmp = funcnn(LR[i],BS[j])\n        #result[i,j,:] = tmp.history['val_acc']\n        print 'learning rate:',LR[i],'batch size:',BS[j]\n        \n"
  },
  {
    "path": "DeepLearning/UFLDL/Vectorization_sparseae_exercise/checkNumericalGradient.m",
    "content": "function [] = checkNumericalGradient()\n% This code can be used to check your numerical gradient implementation \n% in computeNumericalGradient.m\n% It analytically evaluates the gradient of a very simple function called\n% simpleQuadraticFunction (see below) and compares the result with your numerical\n% solution. Your numerical gradient implementation is incorrect if\n% your numerical solution deviates too much from the analytical solution.\n  \n% Evaluate the function and gradient at x = [4; 10]; (Here, x is a 2d vector.)\nx = [4; 10];\n[value, grad] = simpleQuadraticFunction(x);\n\n% Use your code to numerically compute the gradient of simpleQuadraticFunction at x.\n% (The notation \"@simpleQuadraticFunction\" denotes a pointer to a function.)\nnumgrad = computeNumericalGradient(@simpleQuadraticFunction, x);\n\n% Visually examine the two gradient computations.  The two columns\n% you get should be very similar. \ndisp([numgrad grad]);\nfprintf('The above two columns you get should be very similar.\\n(Left-Your Numerical Gradient, Right-Analytical Gradient)\\n\\n');\n\n% Evaluate the norm of the difference between two solutions.  \n% If you have a correct implementation, and assuming you used EPSILON = 0.0001 \n% in computeNumericalGradient.m, then diff below should be 2.1452e-12 \ndiff = norm(numgrad-grad)/norm(numgrad+grad);\ndisp(diff); \nfprintf('Norm of the difference between numerical and analytical gradient (should be < 1e-9)\\n\\n');\nend\n\n\n  \nfunction [value,grad] = simpleQuadraticFunction(x)\n% this function accepts a 2D vector as input. \n% Its outputs are:\n%   value: h(x1, x2) = x1^2 + 3*x1*x2\n%   grad: A 2x1 vector that gives the partial derivatives of h with respect to x1 and x2 \n% Note that when we pass @simpleQuadraticFunction(x) to computeNumericalGradients, we're assuming\n% that computeNumericalGradients will use only the first returned value of this function.\n\nvalue = x(1)^2 + 3*x(1)*x(2);\n\ngrad = zeros(2, 1);\n% 对X1 求偏导\ngrad(1)  = 2*x(1) + 3*x(2);\n% 对X2 求偏导\ngrad(2)  = 3*x(1);\n\nend\n"
  },
  {
    "path": "DeepLearning/UFLDL/Vectorization_sparseae_exercise/computeNumericalGradient.m",
    "content": "function numgrad = computeNumericalGradient(J, theta)\n% numgrad = computeNumericalGradient(J, theta)\n% theta: a vector of parameters\n% J: a function that outputs a real-number. Calling y = J(theta) will return the\n% function value at theta. \n  \n% Initialize numgrad with zeros   2x1  这是输入X的行数，其实也就是参数W的个数\nnumgrad = zeros(size(theta));\n\n%% ---------- YOUR CODE HERE --------------------------------------\n% Instructions: \n% Implement numerical gradient checking, and return the result in numgrad.  \n% (See Section 2.3 of the lecture notes.)\n% You should write code so that numgrad(i) is (the numerical approximation to) the \n% partial derivative of J with respect to the i-th input argument, evaluated at theta.  \n% I.e., numgrad(i) should be the (approximately) the partial derivative of J with \n% respect to theta(i).\n%                \n% Hint: You will probably want to compute the elements of numgrad one at a time. \n\n\nepsilon = 0.000001;\n% 2 x2  得到参数的个数\nnumW = size(theta,1);\nI = eye(numW);\nI =  I * epsilon;\nfor j = 1:numW\n    numgrad(j) = (J(theta+I(:,j)) - J(theta-I(:,j))) / (2 * epsilon);\nend\n\n\n\n\n\n\n%% ---------------------------------------------------------------\nend\n"
  },
  {
    "path": "DeepLearning/UFLDL/Vectorization_sparseae_exercise/display_network.m",
    "content": "function [h, array] = display_network(A, opt_normalize, opt_graycolor, cols, opt_colmajor)\n% This function visualizes filters in matrix A. Each column of A is a\n% filter. We will reshape each column into a square image and visualizes\n% on each cell of the visualization panel. \n% All other parameters are optional, usually you do not need to worry\n% about it.\n% opt_normalize: whether we need to normalize the filter so that all of\n% them can have similar contrast. Default value is true.\n% opt_graycolor: whether we use gray as the heat map. Default is true.\n% cols: how many columns are there in the display. Default value is the\n% squareroot of the number of columns in A.\n% opt_colmajor: you can switch convention to row major for A. In that\n% case, each row of A is a filter. Default value is false.\nwarning off all\n\nif ~exist('opt_normalize', 'var') || isempty(opt_normalize)\n    opt_normalize= true;\nend\n\nif ~exist('opt_graycolor', 'var') || isempty(opt_graycolor)\n    opt_graycolor= true;\nend\n\nif ~exist('opt_colmajor', 'var') || isempty(opt_colmajor)\n    opt_colmajor = false;\nend\n\n% rescale\nA = A - mean(A(:));\n\nif opt_graycolor, colormap(gray); end\n\n% compute rows, cols\n[L M]=size(A);\nsz=sqrt(L);\nbuf=1;\nif ~exist('cols', 'var')\n    if floor(sqrt(M))^2 ~= M\n        n=ceil(sqrt(M));\n        while mod(M, n)~=0 && n<1.2*sqrt(M), n=n+1; end\n        m=ceil(M/n);\n    else\n        n=sqrt(M);\n        m=n;\n    end\nelse\n    n = cols;\n    m = ceil(M/n);\nend\n\narray=-ones(buf+m*(sz+buf),buf+n*(sz+buf));\n\nif ~opt_graycolor\n    array = 0.1.* array;\nend\n\n\nif ~opt_colmajor\n    k=1;\n    for i=1:m\n        for j=1:n\n            if k>M, \n                continue; \n            end\n            clim=max(abs(A(:,k)));\n            if opt_normalize\n                array(buf+(i-1)*(sz+buf)+(1:sz),buf+(j-1)*(sz+buf)+(1:sz))=reshape(A(:,k),sz,sz)/clim;\n            else\n                array(buf+(i-1)*(sz+buf)+(1:sz),buf+(j-1)*(sz+buf)+(1:sz))=reshape(A(:,k),sz,sz)/max(abs(A(:)));\n            end\n            k=k+1;\n        end\n    end\nelse\n    k=1;\n    for j=1:n\n        for i=1:m\n            if k>M, \n                continue; \n            end\n            clim=max(abs(A(:,k)));\n            if opt_normalize\n                array(buf+(i-1)*(sz+buf)+(1:sz),buf+(j-1)*(sz+buf)+(1:sz))=reshape(A(:,k),sz,sz)/clim;\n            else\n                array(buf+(i-1)*(sz+buf)+(1:sz),buf+(j-1)*(sz+buf)+(1:sz))=reshape(A(:,k),sz,sz);\n            end\n            k=k+1;\n        end\n    end\nend\n\nif opt_graycolor\n    h=imagesc(array,'EraseMode','none',[-1 1]);\nelse\n    h=imagesc(array,'EraseMode','none',[-1 1]);\nend\naxis image off\n\ndrawnow;\n\nwarning on all\n"
  },
  {
    "path": "DeepLearning/UFLDL/Vectorization_sparseae_exercise/initializeParameters.m",
    "content": "function theta = initializeParameters(hiddenSize, visibleSize)\n\n%% Initialize parameters randomly based on layer sizes.\nr  = sqrt(6) / sqrt(hiddenSize+visibleSize+1);   % we'll choose weights uniformly from the interval [-r, r]\nW1 = rand(hiddenSize, visibleSize) * 2 * r - r;\nW2 = rand(visibleSize, hiddenSize) * 2 * r - r;\n\nb1 = zeros(hiddenSize, 1);\nb2 = zeros(visibleSize, 1);\n\n% Convert weights and bias gradients to the vector form.\n% This step will \"unroll\" (flatten and concatenate together) all \n% your parameters into a vector, which can then be used with minFunc. \ntheta = [W1(:) ; W2(:) ; b1(:) ; b2(:)];\n\nend\n\n"
  },
  {
    "path": "DeepLearning/UFLDL/stl_exercise/display_network.m",
    "content": "function [h, array] = display_network(A, opt_normalize, opt_graycolor, cols, opt_colmajor)\n% This function visualizes filters in matrix A. Each column of A is a\n% filter. We will reshape each column into a square image and visualizes\n% on each cell of the visualization panel. \n% All other parameters are optional, usually you do not need to worry\n% about it.\n% opt_normalize: whether we need to normalize the filter so that all of\n% them can have similar contrast. Default value is true.\n% opt_graycolor: whether we use gray as the heat map. Default is true.\n% cols: how many columns are there in the display. Default value is the\n% squareroot of the number of columns in A.\n% opt_colmajor: you can switch convention to row major for A. In that\n% case, each row of A is a filter. Default value is false.\nwarning off all\n\nif ~exist('opt_normalize', 'var') || isempty(opt_normalize)\n    opt_normalize= true;\nend\n\nif ~exist('opt_graycolor', 'var') || isempty(opt_graycolor)\n    opt_graycolor= true;\nend\n\nif ~exist('opt_colmajor', 'var') || isempty(opt_colmajor)\n    opt_colmajor = false;\nend\n\n% rescale\nA = A - mean(A(:));\n\nif opt_graycolor, colormap(gray); end\n\n% compute rows, cols\n[L M]=size(A);\nsz=sqrt(L);\nbuf=1;\nif ~exist('cols', 'var')\n    if floor(sqrt(M))^2 ~= M\n        n=ceil(sqrt(M));\n        while mod(M, n)~=0 && n<1.2*sqrt(M), n=n+1; end\n        m=ceil(M/n);\n    else\n        n=sqrt(M);\n        m=n;\n    end\nelse\n    n = cols;\n    m = ceil(M/n);\nend\n\narray=-ones(buf+m*(sz+buf),buf+n*(sz+buf));\n\nif ~opt_graycolor\n    array = 0.1.* array;\nend\n\n\nif ~opt_colmajor\n    k=1;\n    for i=1:m\n        for j=1:n\n            if k>M, \n                continue; \n            end\n            clim=max(abs(A(:,k)));\n            if opt_normalize\n                array(buf+(i-1)*(sz+buf)+(1:sz),buf+(j-1)*(sz+buf)+(1:sz))=reshape(A(:,k),sz,sz)/clim;\n            else\n                array(buf+(i-1)*(sz+buf)+(1:sz),buf+(j-1)*(sz+buf)+(1:sz))=reshape(A(:,k),sz,sz)/max(abs(A(:)));\n            end\n            k=k+1;\n        end\n    end\nelse\n    k=1;\n    for j=1:n\n        for i=1:m\n            if k>M, \n                continue; \n            end\n            clim=max(abs(A(:,k)));\n            if opt_normalize\n                array(buf+(i-1)*(sz+buf)+(1:sz),buf+(j-1)*(sz+buf)+(1:sz))=reshape(A(:,k),sz,sz)/clim;\n            else\n                array(buf+(i-1)*(sz+buf)+(1:sz),buf+(j-1)*(sz+buf)+(1:sz))=reshape(A(:,k),sz,sz);\n            end\n            k=k+1;\n        end\n    end\nend\n\nif opt_graycolor\n    h=imagesc(array,'EraseMode','none',[-1 1]);\nelse\n    h=imagesc(array,'EraseMode','none',[-1 1]);\nend\naxis image off\n\ndrawnow;\n\nwarning on all\n"
  },
  {
    "path": "DeepLearning/UFLDL/stl_exercise/feedForwardAutoencoder.m",
    "content": "function [activation] = feedForwardAutoencoder(theta, hiddenSize, visibleSize, data)\n\n% theta: trained weights from the autoencoder\n% visibleSize: the number of input units (probably 64) \n% hiddenSize: the number of hidden units (probably 25) \n% data: Our matrix containing the training data as columns.  So, data(:,i) is the i-th training example. \n  \n% We first convert theta to the (W1, W2, b1, b2) matrix/vector format, so that this \n% follows the notation convention of the lecture notes. \n%200 x 784\nW1 = reshape(theta(1:hiddenSize*visibleSize), hiddenSize, visibleSize);\n% 200 x 1\nb1 = theta(2*hiddenSize*visibleSize+1:2*hiddenSize*visibleSize+hiddenSize);\n%% ---------- YOUR CODE HERE --------------------------------------\n%  Instructions: Compute the activation of the hidden layer for the Sparse Autoencoder.\nactivation = sigmoid(bsxfun(@plus,W1 * data,b1)) ;\n%-------------------------------------------------------------------\n\nend\n\n%-------------------------------------------------------------------\n% Here's an implementation of the sigmoid function, which you may find useful\n% in your computation of the costs and the gradients.  This inputs a (row or\n% column) vector (say (z1, z2, z3)) and returns (f(z1), f(z2), f(z3)). \n\nfunction sigm = sigmoid(x)\n    sigm = 1 ./ (1 + exp(-x));\nend\n"
  },
  {
    "path": "DeepLearning/UFLDL/stl_exercise/initializeParameters.m",
    "content": "function theta = initializeParameters(hiddenSize, visibleSize)\n\n%% Initialize parameters randomly based on layer sizes.\nr  = sqrt(6) / sqrt(hiddenSize+visibleSize+1);   % we'll choose weights uniformly from the interval [-r, r]\nW1 = rand(hiddenSize, visibleSize) * 2 * r - r;\nW2 = rand(visibleSize, hiddenSize) * 2 * r - r;\n\nb1 = zeros(hiddenSize, 1);\nb2 = zeros(visibleSize, 1);\n\n% Convert weights and bias gradients to the vector form.\n% This step will \"unroll\" (flatten and concatenate together) all \n% your parameters into a vector, which can then be used with minFunc. \ntheta = [W1(:) ; W2(:) ; b1(:) ; b2(:)];\n\nend\n\n"
  },
  {
    "path": "DeepLearning/UFLDL/stl_exercise/loadMNISTImages.m",
    "content": "function images = loadMNISTImages(filename)\n%loadMNISTImages returns a 28x28x[number of MNIST images] matrix containing\n%the raw MNIST images\n\nfp = fopen(filename, 'rb');\nassert(fp ~= -1, ['Could not open ', filename, '']);\n\nmagic = fread(fp, 1, 'int32', 0, 'ieee-be');\nassert(magic == 2051, ['Bad magic number in ', filename, '']);\n\nnumImages = fread(fp, 1, 'int32', 0, 'ieee-be');\nnumRows = fread(fp, 1, 'int32', 0, 'ieee-be');\nnumCols = fread(fp, 1, 'int32', 0, 'ieee-be');\n\nimages = fread(fp, inf, 'unsigned char');\nimages = reshape(images, numCols, numRows, numImages);\nimages = permute(images,[2 1 3]);\n\nfclose(fp);\n\n% Reshape to #pixels x #examples\nimages = reshape(images, size(images, 1) * size(images, 2), size(images, 3));\n% Convert to double and rescale to [0,1]\nimages = double(images) / 255;\n\nend\n"
  },
  {
    "path": "DeepLearning/UFLDL/stl_exercise/loadMNISTLabels.m",
    "content": "function labels = loadMNISTLabels(filename)\n%loadMNISTLabels returns a [number of MNIST images]x1 matrix containing\n%the labels for the MNIST images\n\nfp = fopen(filename, 'rb');\nassert(fp ~= -1, ['Could not open ', filename, '']);\n\nmagic = fread(fp, 1, 'int32', 0, 'ieee-be');\nassert(magic == 2049, ['Bad magic number in ', filename, '']);\n\nnumLabels = fread(fp, 1, 'int32', 0, 'ieee-be');\n\nlabels = fread(fp, inf, 'unsigned char');\n\nassert(size(labels,1) == numLabels, 'Mismatch in label count');\n\nfclose(fp);\n\nend\n"
  },
  {
    "path": "DeepLearning/UFLDL/stl_exercise/softmaxCost.m",
    "content": "function [cost, grad] = softmaxCost(theta, numClasses, inputSize, lambda, data, labels)\n\n% numClasses - the number of classes \n% inputSize - the size N of the input vector\n% lambda - weight decay parameter\n% data - the N x M input matrix, where each column data(:, i) corresponds to\n%        a single test set\n% labels - an M x 1 matrix containing the labels corresponding for the input data\n%\n\n% Unroll the parameters from theta\n% 10x8\ntheta = reshape(theta, numClasses, inputSize);\n%100  data 8x100\nnumCases = size(data, 2);\n%sparse(r,c,v) =  [r(i),c(i)] = v(i)\n% 每一列的第 label 行 设置为i，也就是，每个样本属于哪个label，该位置就是1，其他的均为0\n% 10 x 100\ngroundTruth = full(sparse(labels, 1:numCases, 1));\ncost = 0;\n%10 x 8\nthetagrad = zeros(numClasses, inputSize);\n\n%% ---------- YOUR CODE HERE --------------------------------------\n%  Instructions: Compute the cost and gradient for softmax regression.\n%                You need to compute thetagrad and cost.\n%                The groundTruth matrix might come in handy.\n\n% 10x100  10x8  8x100   100个样本，每个样本属于每个label的概率\nM = theta * data;\nM = exp(bsxfun(@minus,M,max(M,[],1)));\nH = bsxfun(@rdivide,M,sum(M));\ncost = - sum(sum((groundTruth .* log(H)))) / size(data,2) + lambda * sum(sum(theta.^2)) / 2 ;\n% 10x8      10x100   100x8\nthetagrad = - ((groundTruth - H)) * data' /size(data,2) +lambda * theta;\n\n\n\n\n\n\n\n\n\n% ------------------------------------------------------------------\n% Unroll the gradient matrices into a vector for minFunc\ngrad = [thetagrad(:)];\nend\n\n"
  },
  {
    "path": "DeepLearning/UFLDL/stl_exercise/softmaxPredict.m",
    "content": "function [pred] = softmaxPredict(softmaxModel, data)\n\n% softmaxModel - model trained using softmaxTrain\n% data - the N x M input matrix, where each column data(:, i) corresponds to\n%        a single test set\n%\n% Your code should produce the prediction matrix \n% pred, where pred(i) is argmax_c P(y(c) | x(i)).\n \n% Unroll the parameters from theta\ntheta = softmaxModel.optTheta;  % this provides a numClasses x inputSize matrix\npred = zeros(1, size(data, 2));\n\n%% ---------- YOUR CODE HERE --------------------------------------\n%  Instructions: Compute pred using theta assuming that the labels start \n%                from 1.\n[Val , pred] = max(theta*data);\n\n\n\n\n\n\n% ---------------------------------------------------------------------\n\nend\n\n"
  },
  {
    "path": "DeepLearning/UFLDL/stl_exercise/softmaxTrain.m",
    "content": "function [softmaxModel] = softmaxTrain(inputSize, numClasses, lambda, inputData, labels, options)\n%softmaxTrain Train a softmax model with the given parameters on the given\n% data. Returns softmaxOptTheta, a vector containing the trained parameters\n% for the model.\n%\n% inputSize: the size of an input vector x^(i)\n% numClasses: the number of classes \n% lambda: weight decay parameter\n% inputData: an N by M matrix containing the input data, such that\n%            inputData(:, c) is the cth input\n% labels: M by 1 matrix containing the class labels for the\n%            corresponding inputs. labels(c) is the class label for\n%            the cth input\n% options (optional): options\n%   options.maxIter: number of iterations to train for\n\nif ~exist('options', 'var')\n    options = struct;\nend\n\nif ~isfield(options, 'maxIter')\n    options.maxIter = 400;\nend\n\n% initialize parameters\ntheta = 0.005 * randn(numClasses * inputSize, 1);\n\n% Use minFunc to minimize the function\naddpath minFunc/\noptions.Method = 'lbfgs'; % Here, we use L-BFGS to optimize our cost\n                          % function. Generally, for minFunc to work, you\n                          % need a function pointer with two outputs: the\n                          % function value and the gradient. In our problem,\n                          % softmaxCost.m satisfies this.\nminFuncOptions.display = 'on';\n\n[softmaxOptTheta, cost] = minFunc( @(p) softmaxCost(p, ...\n                                   numClasses, inputSize, lambda, ...\n                                   inputData, labels), ...                                   \n                              theta, options);\n\n% Fold softmaxOptTheta into a nicer format\nsoftmaxModel.optTheta = reshape(softmaxOptTheta, numClasses, inputSize);\nsoftmaxModel.inputSize = inputSize;\nsoftmaxModel.numClasses = numClasses;\n                          \nend                          \n"
  },
  {
    "path": "DeepLearning/UFLDL/stl_exercise/sparseAutoencoderCost.m",
    "content": "function [cost,grad] = sparseAutoencoderCost(theta, visibleSize, hiddenSize, ...\n                                             lambda, sparsityParam, beta, data)\n%lambda = 0;\n%beta = 0;\n% visibleSize: the number of input units (probably 64) \n% hiddenSize: the number of hidden units (probably 25) \n% lambda: weight decay parameter\n% sparsityParam: The desired average activation for the hidden units (denoted in the lecture\n%                           notes by the greek alphabet rho, which looks like a lower-case \"p\").\n% beta: weight of sparsity penalty term\n% data: Our 64x10000 matrix containing the training data.  So, data(:,i) is the i-th training example. \n  \n% The input theta is a vector (because minFunc expects the parameters to be a vector). \n\n% We first convert theta to the (W1, W2, b1, b2) matrix/vector format, so that this \n% follows the notation convention of the lecture notes. \n\n% 学习率 自己定义的\nalpha = 0.03;\n\n% 计算隐藏层神经元的激活度\np = zeros(hiddenSize,1);\n\nW1 = reshape(theta(1:hiddenSize*visibleSize), hiddenSize, visibleSize);\nW2 = reshape(theta(hiddenSize*visibleSize+1:2*hiddenSize*visibleSize), visibleSize, hiddenSize);\nb1 = theta(2*hiddenSize*visibleSize+1:2*hiddenSize*visibleSize+hiddenSize);\nb2 = theta(2*hiddenSize*visibleSize+hiddenSize+1:end);\n\n% Cost and gradient variables (your code needs to compute these values). \n% Here, we initialize them to zeros. \n\n%% ---------- YOUR CODE HERE --------------------------------------\n%  Instructions: Compute the cost/optimization objective J_sparse(W,b) for the Sparse Autoencoder,\n%                and the corresponding gradients W1grad, W2grad, b1grad, b2grad.\n%\n% W1grad, W2grad, b1grad and b2grad should be computed using backpropagation.\n% Note that W1grad has the same dimensions as W1, b1grad has the same dimensions\n% as b1, etc.  Your code should set W1grad to be the partial derivative of J_sparse(W,b) with\n% respect to W1.  I.e., W1grad(i,j) should be the partial derivative of J_sparse(W,b) \n% with respect to the input parameter W1(i,j).  Thus, W1grad should be equal to the term \n% [(1/m) \\Delta W^{(1)} + \\lambda W^{(1)}] in the last block of pseudo-code in Section 2.2 \n% of the lecture notes (and similarly for W2grad, b1grad, b2grad).\n% \n% Stated differently, if we were using batch gradient descent to optimize the parameters,\n% the gradient descent update to W1 would be W1 := W1 - alpha * W1grad, and similarly for W2, b1, b2. \n% \nnumPatches = size(data,2);\nKLdist = 0;\n\n%% 向前传输\n\na2 = sigmoid(W1*data+repmat(b1,[1,numPatches]));\np = sum(a2,2);\na3 = sigmoid(W2 * a2 + repmat(b2,[1,numPatches]));\nJ_sparse = 0.5 * sum(sum((a3-data).^2));\n\n%% 计算 隐藏层的平均激活度\np = p /  numPatches ;\n\n%% 向后传输 \n\n    residual3 = -(data-a3).*a3.*(1-a3);\n    tmp = beta * ( - sparsityParam ./ p + (1-sparsityParam) ./ (1-p));\n    residual2 = (W2' * residual3 + repmat(tmp,[1,numPatches])) .* a2.*(1-a2);\n    \n    W2grad = residual3 * a2' / numPatches + lambda * W2 ;\n    W1grad = residual2 * data'  / numPatches + lambda * W1 ;\n    b2grad = sum(residual3,2) / numPatches; \n    b1grad = sum(residual2,2) / numPatches; \n\n%% 更新权重参数   加上 lambda  权重衰减\nW2 = W2 - alpha * ( W2grad  );\nW1 = W1 - alpha * ( W1grad );\n\nb2 = b2 - alpha * (b2grad );\nb1 = b1 - alpha * (b1grad );\n\n%% 计算KL相对熵\nfor j = 1:hiddenSize\n    KLdist = KLdist + sparsityParam *log( sparsityParam / p(j) )   +   (1 - sparsityParam) * log((1-sparsityParam) / (1 - p(j)));\nend\n\n%% costFunction 加上 lambda 权重衰减\ncost = J_sparse / numPatches + (sum(sum(W1.^2)) + sum(sum(W2.^2))) * lambda / 2  + beta * KLdist;\n\n%-------------------------------------------------------------------\n% After computing the cost and gradient, we will convert the gradients back\n% to a vector format (suitable for minFunc).  Specifically, we will unroll\n% your gradient matrices into a vector.\n\ngrad = [W1grad(:) ; W2grad(:) ; b1grad(:) ; b2grad(:)];\n\nend\n\n%-------------------------------------------------------------------\n% Here's an implementation of the sigmoid function, which you may find useful\n% in your computation of the costs and the gradients.  This inputs a (row or\n% column) vector (say (z1, z2, z3)) and returns (f(z1), f(z2), f(z3)). \n\nfunction sigm = sigmoid(x)\n  \n    sigm = 1 ./ (1 + exp(-x));\nend\n\n\n"
  },
  {
    "path": "DeepLearning/UFLDL/stl_exercise/stlExercise.m",
    "content": "%% CS294A/CS294W Self-taught Learning Exercise\n\n%  Instructions\n%  ------------\n% \n%  This file contains code that helps you get started on the\n%  self-taught learning. You will need to complete code in feedForwardAutoencoder.m\n%  You will also need to have implemented sparseAutoencoderCost.m and \n%  softmaxCost.m from previous exercises.\n%\n%% ======================================================================\n%  STEP 0: Here we provide the relevant parameters values that will\n%  allow your sparse autoencoder to get good filters; you do not need to \n%  change the parameters below.\nclc\nclear \n\ninputSize  = 28 * 28;\nnumLabels  = 5;\nhiddenSize = 200;\nsparsityParam = 0.1; % desired average activation of the hidden units.\n                     % (This was denoted by the Greek alphabet rho, which looks like a lower-case \"p\",\n\t\t             %  in the lecture notes). \nlambda = 3e-3;       % weight decay parameter       \nbeta = 3;            % weight of sparsity penalty term   \nmaxIter = 400;\n\n%% ======================================================================\n%  STEP 1: Load data from the MNIST database\n%\n%  This loads our training and test data from the MNIST database files.\n%  We have sorted the data for you in this so that you will not have to\n%  change it.\n\n% Load MNIST database files\nmnistData   = loadMNISTImages('train-images.idx3-ubyte');\nmnistLabels = loadMNISTLabels('train-labels.idx1-ubyte');\n\n% Set Unlabeled Set (All Images)\n\n% Simulate a Labeled and Unlabeled set\nlabeledSet   = find(mnistLabels >= 0 & mnistLabels <= 4);\nunlabeledSet = find(mnistLabels >= 5);\n\nnumTrain = round(numel(labeledSet)/2);\ntrainSet = labeledSet(1:numTrain);\ntestSet  = labeledSet(numTrain+1:end);\n\nunlabeledData = mnistData(:, unlabeledSet);\n\ntrainData   = mnistData(:, trainSet);\ntrainLabels = mnistLabels(trainSet)' + 1; % Shift Labels to the Range 1-5\n\ntestData   = mnistData(:, testSet);\ntestLabels = mnistLabels(testSet)' + 1;   % Shift Labels to the Range 1-5\n\n% Output Some Statistics\nfprintf('# examples in unlabeled set: %d\\n', size(unlabeledData, 2));\nfprintf('# examples in supervised training set: %d\\n\\n', size(trainData, 2));\nfprintf('# examples in supervised testing set: %d\\n\\n', size(testData, 2));\n\n%% ======================================================================\n%  STEP 2: Train the sparse autoencoder\n%  This trains the sparse autoencoder on the unlabeled training\n%  images. \n\n%  Randomly initialize the parameters\ntheta = initializeParameters(hiddenSize, inputSize);\n\n%% ----------------- YOUR CODE HERE ----------------------\n%  Find opttheta by running the sparse autoencoder on\n%  unlabeledTrainingImages\n\naddpath minFunc/\noptions.Method = 'lbfgs';                         \noptions.maxIter = 400;                                         \noptions.display = 'on';      \nvisibleSize = inputSize;\n[opttheta, cost] = minFunc( @(p) sparseAutoencoderCost(p, ...\n                                   visibleSize, hiddenSize, ...\n                                   lambda, sparsityParam, ...\n                                   beta, unlabeledData), ...\n                              theta, options);\n\n%% -----------------------------------------------------\n                          \n% Visualize weights\nW1 = reshape(opttheta(1:hiddenSize * inputSize), hiddenSize, inputSize);\ndisplay_network(W1');\n\n%%======================================================================\n%% STEP 3: Extract Features from the Supervised Dataset\n%  \n%  You need to complete the code in feedForwardAutoencoder.m so that the \n%  following command will extract features from the data.\n\ntrainFeatures = feedForwardAutoencoder(opttheta, hiddenSize, inputSize, ...\n                                       trainData);\n\ntestFeatures = feedForwardAutoencoder(opttheta, hiddenSize, inputSize, ...\n                                       testData);\n\n%%======================================================================\n%% STEP 4: Train the softmax classifier\n\nsoftmaxModel = struct;  \n%% ----------------- YOUR CODE HERE ----------------------\n%  Use softmaxTrain.m from the previous exercise to train a multi-class\n%  classifier. \noptions.maxIter = 100;\nlambda = 1e-4;\nnumClasses = 5;\ninputData = trainFeatures;\nlabels = trainLabels ;\ninputSize = hiddenSize; \nsoftmaxModel = softmaxTrain(inputSize, numClasses, lambda, inputData, labels, options);\n%  Use lambda = 1e-4 for the weight regularization for softmax\n\n% You need to compute softmaxModel using softmaxTrain on trainFeatures and\n% trainLabels\n\n%% -----------------------------------------------------\n\n\n%%======================================================================\n%% STEP 5: Testing \n\n%% ----------------- YOUR CODE HERE ----------------------\n% Compute Predictions on the test set (testFeatures) using softmaxPredict\n% and softmaxModel\n\n[pred] = softmaxPredict(softmaxModel, testFeatures);\n\n%% -----------------------------------------------------\n\n% Classification Score\nfprintf('Test Accuracy: %f%%\\n', 100*mean(pred(:) == testLabels(:)));\n\n% (note that we shift the labels by 1, so that digit 0 now corresponds to\n%  label 1)\n%\n% Accuracy is the proportion of correctly classified images\n% The results for our implementation was:\n%\n% Accuracy: 98.3%\n%\n% \n"
  },
  {
    "path": "GMM/README.md",
    "content": "博客链接：http://blog.csdn.net/llp1992/article/details/47058109\n\n更多机器学习深度学习博客请关注CSDN博客：[LiuLongpo](http://blog.csdn.net/llp1992)\n"
  },
  {
    "path": "GMM/gmm.m",
    "content": "function varargout = gmm(X, K_or_centroids)\n% ============================================================\n% Expectation-Maximization iteration implementation of\n% Gaussian Mixture Model.\n%\n% PX = GMM(X, K_OR_CENTROIDS)\n% [PX MODEL] = GMM(X, K_OR_CENTROIDS)\n%\n%  - X: N-by-D data matrix.\n%  - K_OR_CENTROIDS: either K indicating the number of\n%       components or a K-by-D matrix indicating the\n%       choosing of the initial K centroids.\n%\n%  - PX: N-by-K matrix indicating the probability of each\n%       component generating each point.\n%  - MODEL: a structure containing the parameters for a GMM:\n%       MODEL.Miu: a K-by-D matrix.\n%       MODEL.Sigma: a D-by-D-by-K matrix.\n%       MODEL.Pi: a 1-by-K vector.\n% ============================================================\n\nthreshold = 1e-15;\n[N, D] = size(X);\n% isscalar 判断是否为标量\nif isscalar(K_or_centroids)\n    K = K_or_centroids;\n    % randomly pick centroids\n    rndp = randperm(N);\n    centroids = X(rndp(1:K), :);\nelse  % 矩阵，给出每一类的初始化\n    K = size(K_or_centroids, 1);\n    centroids = K_or_centroids;\nend\n\n% initial values\n[pMiu pPi pSigma] = init_params();\n\nLprev = -inf;\nwhile true\n    %% Estiamtion Step\n    Px = calc_prob();\n\n    % new value for pGamma\n    pGamma = Px .* repmat(pPi, N, 1);\n    pGamma = pGamma ./ repmat(sum(pGamma, 2), 1, K);\n\n    %% Maximization Step\n    % new value for parameters of each Component\n    Nk = sum(pGamma, 1);\n    pMiu = diag(1./Nk) * pGamma' * X;\n    pPi = Nk/N;\n    for kk = 1:K\n        Xshift = X-repmat(pMiu(kk, :), N, 1);\n        pSigma(:, :, kk) = (Xshift' * (diag(pGamma(:, kk)) * Xshift)) / Nk(kk);\n    end\n\n    %% check for convergence\n    L = sum(log(Px*pPi'));\n    if L-Lprev < threshold\n        break;\n    end\n    Lprev = L;\nend\n\n% 输出参数判定\nif nargout == 1\n    varargout = {Px};\nelse\n    model = [];\n    model.Miu = pMiu;\n    model.Sigma = pSigma;\n    model.Pi = pPi;\n    varargout = {Px, model};\nend\n\nfunction [pMiu pPi pSigma] = init_params()\n    pMiu = centroids;  % 均值，也就是K类的中心\n    pPi = zeros(1, K); % 概率\n    pSigma = zeros(D, D, K); %协方差矩阵，每个都是 D*D\n\n    % hard assign x to each centroids \n    % (X - pMiu)^2 = X^2 + pMiu^2 - 2*X*pMiu\n    distmat = repmat(sum(X.*X, 2), 1, K) + repmat(sum(pMiu.*pMiu, 2)', N, 1) - 2*X*pMiu';\n    [dummy labels] = min(distmat, [], 2);\n\n    for k=1:K   %初始化参数\n        Xk = X(labels == k, :);\n        pPi(k) = size(Xk, 1)/N;\n        pSigma(:, :, k) = cov(Xk);\n    end\nend\n\n% 计算概率\nfunction Px = calc_prob()\n    Px = zeros(N, K);\n    for k = 1:K\n        Xshift = X-repmat(pMiu(k, :), N, 1);\n        inv_pSigma = inv(pSigma(:, :, k)+diag(repmat(threshold,1,size(pSigma(:, :, k),1)))); % 方差矩阵求逆\n        tmp = sum((Xshift*inv_pSigma) .* Xshift, 2);\n        coef = (2*pi)^(-D/2) * sqrt(det(inv_pSigma)); % det 求方差矩阵的行列式  \n        Px(:, k) = coef * exp(-0.5*tmp);\n    end\nend\nend\n"
  },
  {
    "path": "GMM/gmm.py",
    "content": "# -*- coding: utf-8 -*-\n\n'''\n Description ：GMM in Python\n Author ： LiuLongpo\n Time : 2015年7月26日16:54:48\n Source ：From pluskid\n'''\n\nimport sys;\nsys.path.append(\"E:\\Python\\MachineLearning\\PythonTools\")\nimport PythonUtils as pu\nimport matplotlib.pyplot as plt\nimport numpy as np\n'矩阵的逆矩阵需要的库'\nfrom numpy.linalg import *\n\ndef gmm(X,K):\n    threshold  = 1e-15\n    N,D = np.shape(X)\n    randV = pu.randIntList(1,N,K)\n    centroids = X[randV]\n    pMiu,pPi,pSigma = inti_params(centroids,K,X,N,D);\n    Lprev = -np.inf\n    while True:\n        'Estiamtion Step'\n        Px = calc_prop(X,N,K,pMiu,pSigma,threshold,D)\n        pGamma = Px * np.tile(pPi,(N,1))\n        pGamma = pGamma / np.tile((np.sum(pGamma,axis=1)),(K,1)).T\n        'Maximization Step'\n        Nk = np.sum(pGamma,axis=0)\n        pMiu = np.dot(np.dot(np.diag(1 / Nk),pGamma.T),X)\n        pPi = Nk / N\n        for kk in range(K):\n            Xshift = X - np.tile(pMiu[kk],(N,1))\n            pSigma[:,:,kk] = (np.dot(np.dot(Xshift.T,np.diag(pGamma[:,kk])),Xshift)) / Nk[kk]\n\n        'check for convergence'            \n        L = np.sum(np.log(np.dot(Px,pPi.T)))\n        if L-Lprev<threshold:\n            break\n        Lprev = L\n\n    return Px\n\ndef inti_params(centroids,K,X,N,D):\n    pMiu = centroids\n    pPi = np.zeros((1,K))\n    pSigma = np.zeros((D,D,K))\n    distmat = np.tile(np.sum(X * X,axis=1),(K,1)).T \\\n    + np.tile(np.sum(pMiu * pMiu,axis = 1).T,(N,1)) \\\n    - 2 * np.dot(X,pMiu.T)\n    labels = np.argmin(distmat,axis=1)\n\n    for k in range(K):\n        Xk = X[labels==k]\n        pPi[0][k] = float(np.shape(Xk)[0]) / N # 样本数除以 N 得到概率\n        pSigma[:,:,k] = np.cov(Xk.T)\n    return pMiu,pPi,pSigma\n\n    '计算概率'\ndef calc_prop(X,N,K,pMiu,pSigma,threshold,D):\n    Px = np.zeros((N,K))\n    for k in range(K):\n        Xshift = X - np.tile(pMiu[k],(N,1))\n        inv_pSigma = inv(pSigma[:,:,k]) \\\n        + np.diag(np.tile(threshold,(1,np.ndim(pSigma[:,:,k]))))\n        tmp = np.sum(np.dot(Xshift,inv_pSigma) * Xshift,axis=1)\n        coef = (2*np.pi)**(-D/2) * np.sqrt(np.linalg.det(inv_pSigma))\n        Px[:,k] = coef * np.exp(-0.5 * tmp)\n    return Px\n\ndef test():\n    X = pu.readDataFromTxt('testSet.txt')\n    num = np.size(X)\n    X = np.reshape(X,(num/2,2))\n    ppx = gmm(X,4)\n    index = np.argmax(ppx,axis=1)\n    plt.figure()\n    plt.scatter(X[index==0][:,0],X[index==0][:,1],s=60,c=u'r',marker=u'o')\n    plt.scatter(X[index==1][:,0],X[index==1][:,1],s=60,c=u'b',marker=u'o')\n    plt.scatter(X[index==2][:,0],X[index==2][:,1],s=60,c=u'y',marker=u'o')\n    plt.scatter(X[index==3][:,0],X[index==3][:,1],s=60,c=u'g',marker=u'o')\n\n\nif __name__ == '__main__':\n    test()\n"
  },
  {
    "path": "GMM/testGMM.m",
    "content": "clear all\nclc\n\ndata = load('testSet.txt');\n[PX,Model] = GMM(data,4);\n[~,index] = max(PX');\ncent = Model.Miu;\nfigure\nI = find(index == 1);\nscatter(data(I,1),data(I,2))\nhold on\nscatter(cent(1,1),cent(1,2),150,'filled')\nhold on\nI = find(index == 2);\nscatter(data(I,1),data(I,2))\nhold on\nscatter(cent(2,1),cent(2,2),150,'filled')\nhold on\nI = find(index == 3);\nscatter(data(I,1),data(I,2))\nhold on\nscatter(cent(3,1),cent(3,2),150,'filled')\nhold on\nI = find(index == 4);\nscatter(data(I,1),data(I,2))\nhold on\nscatter(cent(4,1),cent(4,2),150,'filled')\n\n"
  },
  {
    "path": "GMM/testSet.txt",
    "content": "1.658985\t4.285136\n-3.453687\t3.424321\n4.838138\t-1.151539\n-5.379713\t-3.362104\n0.972564\t2.924086\n-3.567919\t1.531611\n0.450614\t-3.302219\n-3.487105\t-1.724432\n2.668759\t1.594842\n-3.156485\t3.191137\n3.165506\t-3.999838\n-2.786837\t-3.099354\n4.208187\t2.984927\n-2.123337\t2.943366\n0.704199\t-0.479481\n-0.392370\t-3.963704\n2.831667\t1.574018\n-0.790153\t3.343144\n2.943496\t-3.357075\n-3.195883\t-2.283926\n2.336445\t2.875106\n-1.786345\t2.554248\n2.190101\t-1.906020\n-3.403367\t-2.778288\n1.778124\t3.880832\n-1.688346\t2.230267\n2.592976\t-2.054368\n-4.007257\t-3.207066\n2.257734\t3.387564\n-2.679011\t0.785119\n0.939512\t-4.023563\n-3.674424\t-2.261084\n2.046259\t2.735279\n-3.189470\t1.780269\n4.372646\t-0.822248\n-2.579316\t-3.497576\n1.889034\t5.190400\n-0.798747\t2.185588\n2.836520\t-2.658556\n-3.837877\t-3.253815\n2.096701\t3.886007\n-2.709034\t2.923887\n3.367037\t-3.184789\n-2.121479\t-4.232586\n2.329546\t3.179764\n-3.284816\t3.273099\n3.091414\t-3.815232\n-3.762093\t-2.432191\n3.542056\t2.778832\n-1.736822\t4.241041\n2.127073\t-2.983680\n-4.323818\t-3.938116\n3.792121\t5.135768\n-4.786473\t3.358547\n2.624081\t-3.260715\n-4.009299\t-2.978115\n2.493525\t1.963710\n-2.513661\t2.642162\n1.864375\t-3.176309\n-3.171184\t-3.572452\n2.894220\t2.489128\n-2.562539\t2.884438\n3.491078\t-3.947487\n-2.565729\t-2.012114\n3.332948\t3.983102\n-1.616805\t3.573188\n2.280615\t-2.559444\n-2.651229\t-3.103198\n2.321395\t3.154987\n-1.685703\t2.939697\n3.031012\t-3.620252\n-4.599622\t-2.185829\n4.196223\t1.126677\n-2.133863\t3.093686\n4.668892\t-2.562705\n-2.793241\t-2.149706\n2.884105\t3.043438\n-2.967647\t2.848696\n4.479332\t-1.764772\n-4.905566\t-2.911070\n"
  },
  {
    "path": "KNN/KNN.m",
    "content": "function relustLabel = KNN(inx,data,labels,k)\n%% \n%   inx 为 输入测试数据，data为样本数据，labels为样本标签\n%%\n\n[datarow , datacol] = size(data);\ndiffMat = repmat(inx,[datarow,1]) - data ;\ndistanceMat = sqrt(sum(diffMat.^2,2));\n[B , IX] = sort(distanceMat,'ascend');\nlen = min(k,length(B));\nrelustLabel = mode(labels(IX(1:len)));\n\nend\n"
  },
  {
    "path": "KNN/KNN.py",
    "content": "from numpy import *\nimport operator\n\ndef createDataSet():\n    group = array([[1.0,1.1],[1.0,1.0],[0,0],[0,0.1]])\n    lables = ['A','A','B','B']\n    return group,lables\n\n# KNN 分类算法\ndef classify0(inx,dataSet,labels,k):\n    dataSetSize = dataSet.shape[0] # shape[0]获取行 shape[1] 获取列\n    # 第一步，计算欧式距离\n    diffMat = tile(inx,(dataSetSize,1)) - dataSet  #tile类似于matlab中的repmat，复制矩阵\n    sqDiffMat = diffMat ** 2\n    sqDistances = sqDiffMat.sum(axis=1)\n    distance = sqDistances ** 0.5\n    sortedDistIndecies = distance.argsort()  # 增序排序\n    classCount = {}\n    for i in range(k):\n    # 获取类别 \n        voteIlabel = labels[sortedDistIndecies[i]]\n        #字典的get方法，查找classCount中是否包含voteIlabel，是则返回该值，不是则返回defValue，这里是0\n        # 其实这也就是计算K临近点中出现的类别的频率，以次数体现\n        classCount[voteIlabel] = classCount.get(voteIlabel,0) + 1\n        #  对字典中的类别出现次数进行排序，classCount中存储的事 key-value，其中key就是label，value就是出现的次数\n        #  所以key=operator.itemgetter(1)选中的事value，也就是对次数进行排序\n    sortedClassCount = sorted(classCount.iteritems(),key=operator.itemgetter(1),reverse=True)\n        #sortedClassCount[0][0]也就是排序后的次数最大的那个label\n    return sortedClassCount[0][0]\n"
  },
  {
    "path": "KNN/KNNdatgingTest.m",
    "content": "function KNNdatgingTest\n%%\nclc\nclear\nclose all\n%%\ndata = load('datingTestSet2.txt');\ndataMat = data(:,1:3);\nlabels = data(:,4);\nlen = size(dataMat,1);\nk = 4;\nerror = 0;\n% 测试数据比例\nRatio = 0.1;\nnumTest = Ratio * len;\n% 归一化处理\nmaxV = max(dataMat);\nminV = min(dataMat);\nrange = maxV-minV;\nnewdataMat = (dataMat-repmat(minV,[len,1]))./(repmat(range,[len,1]));\n\n% 测试\nfor i = 1:numTest\n    classifyresult = KNN(newdataMat(i,:),newdataMat(numTest:len,:),labels(numTest:len,:),k);\n    fprintf('测试结果为：%d  真实结果为：%d\\n',[classifyresult labels(i)])\n    if(classifyresult~=labels(i))\n        error = error+1;\n    end\nend\n  fprintf('准确率为：%f\\n',1-error/(numTest))\nend\n"
  },
  {
    "path": "KNN/README.md",
    "content": "博客链接：http://blog.csdn.net/llp1992/article/details/45040685\n\n更多机器学习深度学习博客请关注CSDN博客：[LiuLongpo](http://blog.csdn.net/llp1992)\n"
  },
  {
    "path": "KNN/datingTestSet2.txt",
    "content": "40920\t8.326976\t0.953952\t3\n14488\t7.153469\t1.673904\t2\n26052\t1.441871\t0.805124\t1\n75136\t13.147394\t0.428964\t1\n38344\t1.669788\t0.134296\t1\n72993\t10.141740\t1.032955\t1\n35948\t6.830792\t1.213192\t3\n42666\t13.276369\t0.543880\t3\n67497\t8.631577\t0.749278\t1\n35483\t12.273169\t1.508053\t3\n50242\t3.723498\t0.831917\t1\n63275\t8.385879\t1.669485\t1\n5569\t4.875435\t0.728658\t2\n51052\t4.680098\t0.625224\t1\n77372\t15.299570\t0.331351\t1\n43673\t1.889461\t0.191283\t1\n61364\t7.516754\t1.269164\t1\n69673\t14.239195\t0.261333\t1\n15669\t0.000000\t1.250185\t2\n28488\t10.528555\t1.304844\t3\n6487\t3.540265\t0.822483\t2\n37708\t2.991551\t0.833920\t1\n22620\t5.297865\t0.638306\t2\n28782\t6.593803\t0.187108\t3\n19739\t2.816760\t1.686209\t2\n36788\t12.458258\t0.649617\t3\n5741\t0.000000\t1.656418\t2\n28567\t9.968648\t0.731232\t3\n6808\t1.364838\t0.640103\t2\n41611\t0.230453\t1.151996\t1\n36661\t11.865402\t0.882810\t3\n43605\t0.120460\t1.352013\t1\n15360\t8.545204\t1.340429\t3\n63796\t5.856649\t0.160006\t1\n10743\t9.665618\t0.778626\t2\n70808\t9.778763\t1.084103\t1\n72011\t4.932976\t0.632026\t1\n5914\t2.216246\t0.587095\t2\n14851\t14.305636\t0.632317\t3\n33553\t12.591889\t0.686581\t3\n44952\t3.424649\t1.004504\t1\n17934\t0.000000\t0.147573\t2\n27738\t8.533823\t0.205324\t3\n29290\t9.829528\t0.238620\t3\n42330\t11.492186\t0.263499\t3\n36429\t3.570968\t0.832254\t1\n39623\t1.771228\t0.207612\t1\n32404\t3.513921\t0.991854\t1\n27268\t4.398172\t0.975024\t1\n5477\t4.276823\t1.174874\t2\n14254\t5.946014\t1.614244\t2\n68613\t13.798970\t0.724375\t1\n41539\t10.393591\t1.663724\t3\n7917\t3.007577\t0.297302\t2\n21331\t1.031938\t0.486174\t2\n8338\t4.751212\t0.064693\t2\n5176\t3.692269\t1.655113\t2\n18983\t10.448091\t0.267652\t3\n68837\t10.585786\t0.329557\t1\n13438\t1.604501\t0.069064\t2\n48849\t3.679497\t0.961466\t1\n12285\t3.795146\t0.696694\t2\n7826\t2.531885\t1.659173\t2\n5565\t9.733340\t0.977746\t2\n10346\t6.093067\t1.413798\t2\n1823\t7.712960\t1.054927\t2\n9744\t11.470364\t0.760461\t3\n16857\t2.886529\t0.934416\t2\n39336\t10.054373\t1.138351\t3\n65230\t9.972470\t0.881876\t1\n2463\t2.335785\t1.366145\t2\n27353\t11.375155\t1.528626\t3\n16191\t0.000000\t0.605619\t2\n12258\t4.126787\t0.357501\t2\n42377\t6.319522\t1.058602\t1\n25607\t8.680527\t0.086955\t3\n77450\t14.856391\t1.129823\t1\n58732\t2.454285\t0.222380\t1\n46426\t7.292202\t0.548607\t3\n32688\t8.745137\t0.857348\t3\n64890\t8.579001\t0.683048\t1\n8554\t2.507302\t0.869177\t2\n28861\t11.415476\t1.505466\t3\n42050\t4.838540\t1.680892\t1\n32193\t10.339507\t0.583646\t3\n64895\t6.573742\t1.151433\t1\n2355\t6.539397\t0.462065\t2\n0\t2.209159\t0.723567\t2\n70406\t11.196378\t0.836326\t1\n57399\t4.229595\t0.128253\t1\n41732\t9.505944\t0.005273\t3\n11429\t8.652725\t1.348934\t3\n75270\t17.101108\t0.490712\t1\n5459\t7.871839\t0.717662\t2\n73520\t8.262131\t1.361646\t1\n40279\t9.015635\t1.658555\t3\n21540\t9.215351\t0.806762\t3\n17694\t6.375007\t0.033678\t2\n22329\t2.262014\t1.022169\t1\n46570\t5.677110\t0.709469\t1\n42403\t11.293017\t0.207976\t3\n33654\t6.590043\t1.353117\t1\n9171\t4.711960\t0.194167\t2\n28122\t8.768099\t1.108041\t3\n34095\t11.502519\t0.545097\t3\n1774\t4.682812\t0.578112\t2\n40131\t12.446578\t0.300754\t3\n13994\t12.908384\t1.657722\t3\n77064\t12.601108\t0.974527\t1\n11210\t3.929456\t0.025466\t2\n6122\t9.751503\t1.182050\t3\n15341\t3.043767\t0.888168\t2\n44373\t4.391522\t0.807100\t1\n28454\t11.695276\t0.679015\t3\n63771\t7.879742\t0.154263\t1\n9217\t5.613163\t0.933632\t2\n69076\t9.140172\t0.851300\t1\n24489\t4.258644\t0.206892\t1\n16871\t6.799831\t1.221171\t2\n39776\t8.752758\t0.484418\t3\n5901\t1.123033\t1.180352\t2\n40987\t10.833248\t1.585426\t3\n7479\t3.051618\t0.026781\t2\n38768\t5.308409\t0.030683\t3\n4933\t1.841792\t0.028099\t2\n32311\t2.261978\t1.605603\t1\n26501\t11.573696\t1.061347\t3\n37433\t8.038764\t1.083910\t3\n23503\t10.734007\t0.103715\t3\n68607\t9.661909\t0.350772\t1\n27742\t9.005850\t0.548737\t3\n11303\t0.000000\t0.539131\t2\n0\t5.757140\t1.062373\t2\n32729\t9.164656\t1.624565\t3\n24619\t1.318340\t1.436243\t1\n42414\t14.075597\t0.695934\t3\n20210\t10.107550\t1.308398\t3\n33225\t7.960293\t1.219760\t3\n54483\t6.317292\t0.018209\t1\n18475\t12.664194\t0.595653\t3\n33926\t2.906644\t0.581657\t1\n43865\t2.388241\t0.913938\t1\n26547\t6.024471\t0.486215\t3\n44404\t7.226764\t1.255329\t3\n16674\t4.183997\t1.275290\t2\n8123\t11.850211\t1.096981\t3\n42747\t11.661797\t1.167935\t3\n56054\t3.574967\t0.494666\t1\n10933\t0.000000\t0.107475\t2\n18121\t7.937657\t0.904799\t3\n11272\t3.365027\t1.014085\t2\n16297\t0.000000\t0.367491\t2\n28168\t13.860672\t1.293270\t3\n40963\t10.306714\t1.211594\t3\n31685\t7.228002\t0.670670\t3\n55164\t4.508740\t1.036192\t1\n17595\t0.366328\t0.163652\t2\n1862\t3.299444\t0.575152\t2\n57087\t0.573287\t0.607915\t1\n63082\t9.183738\t0.012280\t1\n51213\t7.842646\t1.060636\t3\n6487\t4.750964\t0.558240\t2\n4805\t11.438702\t1.556334\t3\n30302\t8.243063\t1.122768\t3\n68680\t7.949017\t0.271865\t1\n17591\t7.875477\t0.227085\t2\n74391\t9.569087\t0.364856\t1\n37217\t7.750103\t0.869094\t3\n42814\t0.000000\t1.515293\t1\n14738\t3.396030\t0.633977\t2\n19896\t11.916091\t0.025294\t3\n14673\t0.460758\t0.689586\t2\n32011\t13.087566\t0.476002\t3\n58736\t4.589016\t1.672600\t1\n54744\t8.397217\t1.534103\t1\n29482\t5.562772\t1.689388\t1\n27698\t10.905159\t0.619091\t3\n11443\t1.311441\t1.169887\t2\n56117\t10.647170\t0.980141\t3\n39514\t0.000000\t0.481918\t1\n26627\t8.503025\t0.830861\t3\n16525\t0.436880\t1.395314\t2\n24368\t6.127867\t1.102179\t1\n22160\t12.112492\t0.359680\t3\n6030\t1.264968\t1.141582\t2\n6468\t6.067568\t1.327047\t2\n22945\t8.010964\t1.681648\t3\n18520\t3.791084\t0.304072\t2\n34914\t11.773195\t1.262621\t3\n6121\t8.339588\t1.443357\t2\n38063\t2.563092\t1.464013\t1\n23410\t5.954216\t0.953782\t1\n35073\t9.288374\t0.767318\t3\n52914\t3.976796\t1.043109\t1\n16801\t8.585227\t1.455708\t3\n9533\t1.271946\t0.796506\t2\n16721\t0.000000\t0.242778\t2\n5832\t0.000000\t0.089749\t2\n44591\t11.521298\t0.300860\t3\n10143\t1.139447\t0.415373\t2\n21609\t5.699090\t1.391892\t2\n23817\t2.449378\t1.322560\t1\n15640\t0.000000\t1.228380\t2\n8847\t3.168365\t0.053993\t2\n50939\t10.428610\t1.126257\t3\n28521\t2.943070\t1.446816\t1\n32901\t10.441348\t0.975283\t3\n42850\t12.478764\t1.628726\t3\n13499\t5.856902\t0.363883\t2\n40345\t2.476420\t0.096075\t1\n43547\t1.826637\t0.811457\t1\n70758\t4.324451\t0.328235\t1\n19780\t1.376085\t1.178359\t2\n44484\t5.342462\t0.394527\t1\n54462\t11.835521\t0.693301\t3\n20085\t12.423687\t1.424264\t3\n42291\t12.161273\t0.071131\t3\n47550\t8.148360\t1.649194\t3\n11938\t1.531067\t1.549756\t2\n40699\t3.200912\t0.309679\t1\n70908\t8.862691\t0.530506\t1\n73989\t6.370551\t0.369350\t1\n11872\t2.468841\t0.145060\t2\n48463\t11.054212\t0.141508\t3\n15987\t2.037080\t0.715243\t2\n70036\t13.364030\t0.549972\t1\n32967\t10.249135\t0.192735\t3\n63249\t10.464252\t1.669767\t1\n42795\t9.424574\t0.013725\t3\n14459\t4.458902\t0.268444\t2\n19973\t0.000000\t0.575976\t2\n5494\t9.686082\t1.029808\t3\n67902\t13.649402\t1.052618\t1\n25621\t13.181148\t0.273014\t3\n27545\t3.877472\t0.401600\t1\n58656\t1.413952\t0.451380\t1\n7327\t4.248986\t1.430249\t2\n64555\t8.779183\t0.845947\t1\n8998\t4.156252\t0.097109\t2\n11752\t5.580018\t0.158401\t2\n76319\t15.040440\t1.366898\t1\n27665\t12.793870\t1.307323\t3\n67417\t3.254877\t0.669546\t1\n21808\t10.725607\t0.588588\t3\n15326\t8.256473\t0.765891\t2\n20057\t8.033892\t1.618562\t3\n79341\t10.702532\t0.204792\t1\n15636\t5.062996\t1.132555\t2\n35602\t10.772286\t0.668721\t3\n28544\t1.892354\t0.837028\t1\n57663\t1.019966\t0.372320\t1\n78727\t15.546043\t0.729742\t1\n68255\t11.638205\t0.409125\t1\n14964\t3.427886\t0.975616\t2\n21835\t11.246174\t1.475586\t3\n7487\t0.000000\t0.645045\t2\n8700\t0.000000\t1.424017\t2\n26226\t8.242553\t0.279069\t3\n65899\t8.700060\t0.101807\t1\n6543\t0.812344\t0.260334\t2\n46556\t2.448235\t1.176829\t1\n71038\t13.230078\t0.616147\t1\n47657\t0.236133\t0.340840\t1\n19600\t11.155826\t0.335131\t3\n37422\t11.029636\t0.505769\t3\n1363\t2.901181\t1.646633\t2\n26535\t3.924594\t1.143120\t1\n47707\t2.524806\t1.292848\t1\n38055\t3.527474\t1.449158\t1\n6286\t3.384281\t0.889268\t2\n10747\t0.000000\t1.107592\t2\n44883\t11.898890\t0.406441\t3\n56823\t3.529892\t1.375844\t1\n68086\t11.442677\t0.696919\t1\n70242\t10.308145\t0.422722\t1\n11409\t8.540529\t0.727373\t2\n67671\t7.156949\t1.691682\t1\n61238\t0.720675\t0.847574\t1\n17774\t0.229405\t1.038603\t2\n53376\t3.399331\t0.077501\t1\n30930\t6.157239\t0.580133\t1\n28987\t1.239698\t0.719989\t1\n13655\t6.036854\t0.016548\t2\n7227\t5.258665\t0.933722\t2\n40409\t12.393001\t1.571281\t3\n13605\t9.627613\t0.935842\t2\n26400\t11.130453\t0.597610\t3\n13491\t8.842595\t0.349768\t3\n30232\t10.690010\t1.456595\t3\n43253\t5.714718\t1.674780\t3\n55536\t3.052505\t1.335804\t1\n8807\t0.000000\t0.059025\t2\n25783\t9.945307\t1.287952\t3\n22812\t2.719723\t1.142148\t1\n77826\t11.154055\t1.608486\t1\n38172\t2.687918\t0.660836\t1\n31676\t10.037847\t0.962245\t3\n74038\t12.404762\t1.112080\t1\n44738\t10.237305\t0.633422\t3\n17410\t4.745392\t0.662520\t2\n5688\t4.639461\t1.569431\t2\n36642\t3.149310\t0.639669\t1\n29956\t13.406875\t1.639194\t3\n60350\t6.068668\t0.881241\t1\n23758\t9.477022\t0.899002\t3\n25780\t3.897620\t0.560201\t2\n11342\t5.463615\t1.203677\t2\n36109\t3.369267\t1.575043\t1\n14292\t5.234562\t0.825954\t2\n11160\t0.000000\t0.722170\t2\n23762\t12.979069\t0.504068\t3\n39567\t5.376564\t0.557476\t1\n25647\t13.527910\t1.586732\t3\n14814\t2.196889\t0.784587\t2\n73590\t10.691748\t0.007509\t1\n35187\t1.659242\t0.447066\t1\n49459\t8.369667\t0.656697\t3\n31657\t13.157197\t0.143248\t3\n6259\t8.199667\t0.908508\t2\n33101\t4.441669\t0.439381\t3\n27107\t9.846492\t0.644523\t3\n17824\t0.019540\t0.977949\t2\n43536\t8.253774\t0.748700\t3\n67705\t6.038620\t1.509646\t1\n35283\t6.091587\t1.694641\t3\n71308\t8.986820\t1.225165\t1\n31054\t11.508473\t1.624296\t3\n52387\t8.807734\t0.713922\t3\n40328\t0.000000\t0.816676\t1\n34844\t8.889202\t1.665414\t3\n11607\t3.178117\t0.542752\t2\n64306\t7.013795\t0.139909\t1\n32721\t9.605014\t0.065254\t3\n33170\t1.230540\t1.331674\t1\n37192\t10.412811\t0.890803\t3\n13089\t0.000000\t0.567161\t2\n66491\t9.699991\t0.122011\t1\n15941\t0.000000\t0.061191\t2\n4272\t4.455293\t0.272135\t2\n48812\t3.020977\t1.502803\t1\n28818\t8.099278\t0.216317\t3\n35394\t1.157764\t1.603217\t1\n71791\t10.105396\t0.121067\t1\n40668\t11.230148\t0.408603\t3\n39580\t9.070058\t0.011379\t3\n11786\t0.566460\t0.478837\t2\n19251\t0.000000\t0.487300\t2\n56594\t8.956369\t1.193484\t3\n54495\t1.523057\t0.620528\t1\n11844\t2.749006\t0.169855\t2\n45465\t9.235393\t0.188350\t3\n31033\t10.555573\t0.403927\t3\n16633\t6.956372\t1.519308\t2\n13887\t0.636281\t1.273984\t2\n52603\t3.574737\t0.075163\t1\n72000\t9.032486\t1.461809\t1\n68497\t5.958993\t0.023012\t1\n35135\t2.435300\t1.211744\t1\n26397\t10.539731\t1.638248\t3\n7313\t7.646702\t0.056513\t2\n91273\t20.919349\t0.644571\t1\n24743\t1.424726\t0.838447\t1\n31690\t6.748663\t0.890223\t3\n15432\t2.289167\t0.114881\t2\n58394\t5.548377\t0.402238\t1\n33962\t6.057227\t0.432666\t1\n31442\t10.828595\t0.559955\t3\n31044\t11.318160\t0.271094\t3\n29938\t13.265311\t0.633903\t3\n9875\t0.000000\t1.496715\t2\n51542\t6.517133\t0.402519\t3\n11878\t4.934374\t1.520028\t2\n69241\t10.151738\t0.896433\t1\n37776\t2.425781\t1.559467\t1\n68997\t9.778962\t1.195498\t1\n67416\t12.219950\t0.657677\t1\n59225\t7.394151\t0.954434\t1\n29138\t8.518535\t0.742546\t3\n5962\t2.798700\t0.662632\t2\n10847\t0.637930\t0.617373\t2\n70527\t10.750490\t0.097415\t1\n9610\t0.625382\t0.140969\t2\n64734\t10.027968\t0.282787\t1\n25941\t9.817347\t0.364197\t3\n2763\t0.646828\t1.266069\t2\n55601\t3.347111\t0.914294\t1\n31128\t11.816892\t0.193798\t3\n5181\t0.000000\t1.480198\t2\n69982\t10.945666\t0.993219\t1\n52440\t10.244706\t0.280539\t3\n57350\t2.579801\t1.149172\t1\n57869\t2.630410\t0.098869\t1\n56557\t11.746200\t1.695517\t3\n42342\t8.104232\t1.326277\t3\n15560\t12.409743\t0.790295\t3\n34826\t12.167844\t1.328086\t3\n8569\t3.198408\t0.299287\t2\n77623\t16.055513\t0.541052\t1\n78184\t7.138659\t0.158481\t1\n7036\t4.831041\t0.761419\t2\n69616\t10.082890\t1.373611\t1\n21546\t10.066867\t0.788470\t3\n36715\t8.129538\t0.329913\t3\n20522\t3.012463\t1.138108\t2\n42349\t3.720391\t0.845974\t1\n9037\t0.773493\t1.148256\t2\n26728\t10.962941\t1.037324\t3\n587\t0.177621\t0.162614\t2\n48915\t3.085853\t0.967899\t1\n9824\t8.426781\t0.202558\t2\n4135\t1.825927\t1.128347\t2\n9666\t2.185155\t1.010173\t2\n59333\t7.184595\t1.261338\t1\n36198\t0.000000\t0.116525\t1\n34909\t8.901752\t1.033527\t3\n47516\t2.451497\t1.358795\t1\n55807\t3.213631\t0.432044\t1\n14036\t3.974739\t0.723929\t2\n42856\t9.601306\t0.619232\t3\n64007\t8.363897\t0.445341\t1\n59428\t6.381484\t1.365019\t1\n13730\t0.000000\t1.403914\t2\n41740\t9.609836\t1.438105\t3\n63546\t9.904741\t0.985862\t1\n30417\t7.185807\t1.489102\t3\n69636\t5.466703\t1.216571\t1\n64660\t0.000000\t0.915898\t1\n14883\t4.575443\t0.535671\t2\n7965\t3.277076\t1.010868\t2\n68620\t10.246623\t1.239634\t1\n8738\t2.341735\t1.060235\t2\n7544\t3.201046\t0.498843\t2\n6377\t6.066013\t0.120927\t2\n36842\t8.829379\t0.895657\t3\n81046\t15.833048\t1.568245\t1\n67736\t13.516711\t1.220153\t1\n32492\t0.664284\t1.116755\t1\n39299\t6.325139\t0.605109\t3\n77289\t8.677499\t0.344373\t1\n33835\t8.188005\t0.964896\t3\n71890\t9.414263\t0.384030\t1\n32054\t9.196547\t1.138253\t3\n38579\t10.202968\t0.452363\t3\n55984\t2.119439\t1.481661\t1\n72694\t13.635078\t0.858314\t1\n42299\t0.083443\t0.701669\t1\n26635\t9.149096\t1.051446\t3\n8579\t1.933803\t1.374388\t2\n37302\t14.115544\t0.676198\t3\n22878\t8.933736\t0.943352\t3\n4364\t2.661254\t0.946117\t2\n4985\t0.988432\t1.305027\t2\n37068\t2.063741\t1.125946\t1\n41137\t2.220590\t0.690754\t1\n67759\t6.424849\t0.806641\t1\n11831\t1.156153\t1.613674\t2\n34502\t3.032720\t0.601847\t1\n4088\t3.076828\t0.952089\t2\n15199\t0.000000\t0.318105\t2\n17309\t7.750480\t0.554015\t3\n42816\t10.958135\t1.482500\t3\n43751\t10.222018\t0.488678\t3\n58335\t2.367988\t0.435741\t1\n75039\t7.686054\t1.381455\t1\n42878\t11.464879\t1.481589\t3\n42770\t11.075735\t0.089726\t3\n8848\t3.543989\t0.345853\t2\n31340\t8.123889\t1.282880\t3\n41413\t4.331769\t0.754467\t3\n12731\t0.120865\t1.211961\t2\n22447\t6.116109\t0.701523\t3\n33564\t7.474534\t0.505790\t3\n48907\t8.819454\t0.649292\t3\n8762\t6.802144\t0.615284\t2\n46696\t12.666325\t0.931960\t3\n36851\t8.636180\t0.399333\t3\n67639\t11.730991\t1.289833\t1\n171\t8.132449\t0.039062\t2\n26674\t10.296589\t1.496144\t3\n8739\t7.583906\t1.005764\t2\n66668\t9.777806\t0.496377\t1\n68732\t8.833546\t0.513876\t1\n69995\t4.907899\t1.518036\t1\n82008\t8.362736\t1.285939\t1\n25054\t9.084726\t1.606312\t3\n33085\t14.164141\t0.560970\t3\n41379\t9.080683\t0.989920\t3\n39417\t6.522767\t0.038548\t3\n12556\t3.690342\t0.462281\t2\n39432\t3.563706\t0.242019\t1\n38010\t1.065870\t1.141569\t1\n69306\t6.683796\t1.456317\t1\n38000\t1.712874\t0.243945\t1\n46321\t13.109929\t1.280111\t3\n66293\t11.327910\t0.780977\t1\n22730\t4.545711\t1.233254\t1\n5952\t3.367889\t0.468104\t2\n72308\t8.326224\t0.567347\t1\n60338\t8.978339\t1.442034\t1\n13301\t5.655826\t1.582159\t2\n27884\t8.855312\t0.570684\t3\n11188\t6.649568\t0.544233\t2\n56796\t3.966325\t0.850410\t1\n8571\t1.924045\t1.664782\t2\n4914\t6.004812\t0.280369\t2\n10784\t0.000000\t0.375849\t2\n39296\t9.923018\t0.092192\t3\n13113\t2.389084\t0.119284\t2\n70204\t13.663189\t0.133251\t1\n46813\t11.434976\t0.321216\t3\n11697\t0.358270\t1.292858\t2\n44183\t9.598873\t0.223524\t3\n2225\t6.375275\t0.608040\t2\n29066\t11.580532\t0.458401\t3\n4245\t5.319324\t1.598070\t2\n34379\t4.324031\t1.603481\t1\n44441\t2.358370\t1.273204\t1\n2022\t0.000000\t1.182708\t2\n26866\t12.824376\t0.890411\t3\n57070\t1.587247\t1.456982\t1\n32932\t8.510324\t1.520683\t3\n51967\t10.428884\t1.187734\t3\n44432\t8.346618\t0.042318\t3\n67066\t7.541444\t0.809226\t1\n17262\t2.540946\t1.583286\t2\n79728\t9.473047\t0.692513\t1\n14259\t0.352284\t0.474080\t2\n6122\t0.000000\t0.589826\t2\n76879\t12.405171\t0.567201\t1\n11426\t4.126775\t0.871452\t2\n2493\t0.034087\t0.335848\t2\n19910\t1.177634\t0.075106\t2\n10939\t0.000000\t0.479996\t2\n17716\t0.994909\t0.611135\t2\n31390\t11.053664\t1.180117\t3\n20375\t0.000000\t1.679729\t2\n26309\t2.495011\t1.459589\t1\n33484\t11.516831\t0.001156\t3\n45944\t9.213215\t0.797743\t3\n4249\t5.332865\t0.109288\t2\n6089\t0.000000\t1.689771\t2\n7513\t0.000000\t1.126053\t2\n27862\t12.640062\t1.690903\t3\n39038\t2.693142\t1.317518\t1\n19218\t3.328969\t0.268271\t2\n62911\t7.193166\t1.117456\t1\n77758\t6.615512\t1.521012\t1\n27940\t8.000567\t0.835341\t3\n2194\t4.017541\t0.512104\t2\n37072\t13.245859\t0.927465\t3\n15585\t5.970616\t0.813624\t2\n25577\t11.668719\t0.886902\t3\n8777\t4.283237\t1.272728\t2\n29016\t10.742963\t0.971401\t3\n21910\t12.326672\t1.592608\t3\n12916\t0.000000\t0.344622\t2\n10976\t0.000000\t0.922846\t2\n79065\t10.602095\t0.573686\t1\n36759\t10.861859\t1.155054\t3\n50011\t1.229094\t1.638690\t1\n1155\t0.410392\t1.313401\t2\n71600\t14.552711\t0.616162\t1\n30817\t14.178043\t0.616313\t3\n54559\t14.136260\t0.362388\t1\n29764\t0.093534\t1.207194\t1\n69100\t10.929021\t0.403110\t1\n47324\t11.432919\t0.825959\t3\n73199\t9.134527\t0.586846\t1\n44461\t5.071432\t1.421420\t1\n45617\t11.460254\t1.541749\t3\n28221\t11.620039\t1.103553\t3\n7091\t4.022079\t0.207307\t2\n6110\t3.057842\t1.631262\t2\n79016\t7.782169\t0.404385\t1\n18289\t7.981741\t0.929789\t3\n43679\t4.601363\t0.268326\t1\n22075\t2.595564\t1.115375\t1\n23535\t10.049077\t0.391045\t3\n25301\t3.265444\t1.572970\t2\n32256\t11.780282\t1.511014\t3\n36951\t3.075975\t0.286284\t1\n31290\t1.795307\t0.194343\t1\n38953\t11.106979\t0.202415\t3\n35257\t5.994413\t0.800021\t1\n25847\t9.706062\t1.012182\t3\n32680\t10.582992\t0.836025\t3\n62018\t7.038266\t1.458979\t1\n9074\t0.023771\t0.015314\t2\n33004\t12.823982\t0.676371\t3\n44588\t3.617770\t0.493483\t1\n32565\t8.346684\t0.253317\t3\n38563\t6.104317\t0.099207\t1\n75668\t16.207776\t0.584973\t1\n9069\t6.401969\t1.691873\t2\n53395\t2.298696\t0.559757\t1\n28631\t7.661515\t0.055981\t3\n71036\t6.353608\t1.645301\t1\n71142\t10.442780\t0.335870\t1\n37653\t3.834509\t1.346121\t1\n76839\t10.998587\t0.584555\t1\n9916\t2.695935\t1.512111\t2\n38889\t3.356646\t0.324230\t1\n39075\t14.677836\t0.793183\t3\n48071\t1.551934\t0.130902\t1\n7275\t2.464739\t0.223502\t2\n41804\t1.533216\t1.007481\t1\n35665\t12.473921\t0.162910\t3\n67956\t6.491596\t0.032576\t1\n41892\t10.506276\t1.510747\t3\n38844\t4.380388\t0.748506\t1\n74197\t13.670988\t1.687944\t1\n14201\t8.317599\t0.390409\t2\n3908\t0.000000\t0.556245\t2\n2459\t0.000000\t0.290218\t2\n32027\t10.095799\t1.188148\t3\n12870\t0.860695\t1.482632\t2\n9880\t1.557564\t0.711278\t2\n72784\t10.072779\t0.756030\t1\n17521\t0.000000\t0.431468\t2\n50283\t7.140817\t0.883813\t3\n33536\t11.384548\t1.438307\t3\n9452\t3.214568\t1.083536\t2\n37457\t11.720655\t0.301636\t3\n17724\t6.374475\t1.475925\t3\n43869\t5.749684\t0.198875\t3\n264\t3.871808\t0.552602\t2\n25736\t8.336309\t0.636238\t3\n39584\t9.710442\t1.503735\t3\n31246\t1.532611\t1.433898\t1\n49567\t9.785785\t0.984614\t3\n7052\t2.633627\t1.097866\t2\n35493\t9.238935\t0.494701\t3\n10986\t1.205656\t1.398803\t2\n49508\t3.124909\t1.670121\t1\n5734\t7.935489\t1.585044\t2\n65479\t12.746636\t1.560352\t1\n77268\t10.732563\t0.545321\t1\n28490\t3.977403\t0.766103\t1\n13546\t4.194426\t0.450663\t2\n37166\t9.610286\t0.142912\t3\n16381\t4.797555\t1.260455\t2\n10848\t1.615279\t0.093002\t2\n35405\t4.614771\t1.027105\t1\n15917\t0.000000\t1.369726\t2\n6131\t0.608457\t0.512220\t2\n67432\t6.558239\t0.667579\t1\n30354\t12.315116\t0.197068\t3\n69696\t7.014973\t1.494616\t1\n33481\t8.822304\t1.194177\t3\n43075\t10.086796\t0.570455\t3\n38343\t7.241614\t1.661627\t3\n14318\t4.602395\t1.511768\t2\n5367\t7.434921\t0.079792\t2\n37894\t10.467570\t1.595418\t3\n36172\t9.948127\t0.003663\t3\n40123\t2.478529\t1.568987\t1\n10976\t5.938545\t0.878540\t2\n12705\t0.000000\t0.948004\t2\n12495\t5.559181\t1.357926\t2\n35681\t9.776654\t0.535966\t3\n46202\t3.092056\t0.490906\t1\n11505\t0.000000\t1.623311\t2\n22834\t4.459495\t0.538867\t1\n49901\t8.334306\t1.646600\t3\n71932\t11.226654\t0.384686\t1\n13279\t3.904737\t1.597294\t2\n49112\t7.038205\t1.211329\t3\n77129\t9.836120\t1.054340\t1\n37447\t1.990976\t0.378081\t1\n62397\t9.005302\t0.485385\t1\n0\t1.772510\t1.039873\t2\n15476\t0.458674\t0.819560\t2\n40625\t10.003919\t0.231658\t3\n36706\t0.520807\t1.476008\t1\n28580\t10.678214\t1.431837\t3\n25862\t4.425992\t1.363842\t1\n63488\t12.035355\t0.831222\t1\n33944\t10.606732\t1.253858\t3\n30099\t1.568653\t0.684264\t1\n13725\t2.545434\t0.024271\t2\n36768\t10.264062\t0.982593\t3\n64656\t9.866276\t0.685218\t1\n14927\t0.142704\t0.057455\t2\n43231\t9.853270\t1.521432\t3\n66087\t6.596604\t1.653574\t1\n19806\t2.602287\t1.321481\t2\n41081\t10.411776\t0.664168\t3\n10277\t7.083449\t0.622589\t2\n7014\t2.080068\t1.254441\t2\n17275\t0.522844\t1.622458\t2\n31600\t10.362000\t1.544827\t3\n59956\t3.412967\t1.035410\t1\n42181\t6.796548\t1.112153\t3\n51743\t4.092035\t0.075804\t1\n5194\t2.763811\t1.564325\t2\n30832\t12.547439\t1.402443\t3\n7976\t5.708052\t1.596152\t2\n14602\t4.558025\t0.375806\t2\n41571\t11.642307\t0.438553\t3\n55028\t3.222443\t0.121399\t1\n5837\t4.736156\t0.029871\t2\n39808\t10.839526\t0.836323\t3\n20944\t4.194791\t0.235483\t2\n22146\t14.936259\t0.888582\t3\n42169\t3.310699\t1.521855\t1\n7010\t2.971931\t0.034321\t2\n3807\t9.261667\t0.537807\t2\n29241\t7.791833\t1.111416\t3\n52696\t1.480470\t1.028750\t1\n42545\t3.677287\t0.244167\t1\n24437\t2.202967\t1.370399\t1\n16037\t5.796735\t0.935893\t2\n8493\t3.063333\t0.144089\t2\n68080\t11.233094\t0.492487\t1\n59016\t1.965570\t0.005697\t1\n11810\t8.616719\t0.137419\t2\n68630\t6.609989\t1.083505\t1\n7629\t1.712639\t1.086297\t2\n71992\t10.117445\t1.299319\t1\n13398\t0.000000\t1.104178\t2\n26241\t9.824777\t1.346821\t3\n11160\t1.653089\t0.980949\t2\n76701\t18.178822\t1.473671\t1\n32174\t6.781126\t0.885340\t3\n45043\t8.206750\t1.549223\t3\n42173\t10.081853\t1.376745\t3\n69801\t6.288742\t0.112799\t1\n41737\t3.695937\t1.543589\t1\n46979\t6.726151\t1.069380\t3\n79267\t12.969999\t1.568223\t1\n4615\t2.661390\t1.531933\t2\n32907\t7.072764\t1.117386\t3\n37444\t9.123366\t1.318988\t3\n569\t3.743946\t1.039546\t2\n8723\t2.341300\t0.219361\t2\n6024\t0.541913\t0.592348\t2\n52252\t2.310828\t1.436753\t1\n8358\t6.226597\t1.427316\t2\n26166\t7.277876\t0.489252\t3\n18471\t0.000000\t0.389459\t2\n3386\t7.218221\t1.098828\t2\n41544\t8.777129\t1.111464\t3\n10480\t2.813428\t0.819419\t2\n5894\t2.268766\t1.412130\t2\n7273\t6.283627\t0.571292\t2\n22272\t7.520081\t1.626868\t3\n31369\t11.739225\t0.027138\t3\n10708\t3.746883\t0.877350\t2\n69364\t12.089835\t0.521631\t1\n37760\t12.310404\t0.259339\t3\n13004\t0.000000\t0.671355\t2\n37885\t2.728800\t0.331502\t1\n52555\t10.814342\t0.607652\t3\n38997\t12.170268\t0.844205\t3\n69698\t6.698371\t0.240084\t1\n11783\t3.632672\t1.643479\t2\n47636\t10.059991\t0.892361\t3\n15744\t1.887674\t0.756162\t2\n69058\t8.229125\t0.195886\t1\n33057\t7.817082\t0.476102\t3\n28681\t12.277230\t0.076805\t3\n34042\t10.055337\t1.115778\t3\n29928\t3.596002\t1.485952\t1\n9734\t2.755530\t1.420655\t2\n7344\t7.780991\t0.513048\t2\n7387\t0.093705\t0.391834\t2\n33957\t8.481567\t0.520078\t3\n9936\t3.865584\t0.110062\t2\n36094\t9.683709\t0.779984\t3\n39835\t10.617255\t1.359970\t3\n64486\t7.203216\t1.624762\t1\n0\t7.601414\t1.215605\t2\n39539\t1.386107\t1.417070\t1\n66972\t9.129253\t0.594089\t1\n15029\t1.363447\t0.620841\t2\n44909\t3.181399\t0.359329\t1\n38183\t13.365414\t0.217011\t3\n37372\t4.207717\t1.289767\t1\n0\t4.088395\t0.870075\t2\n17786\t3.327371\t1.142505\t2\n39055\t1.303323\t1.235650\t1\n37045\t7.999279\t1.581763\t3\n6435\t2.217488\t0.864536\t2\n72265\t7.751808\t0.192451\t1\n28152\t14.149305\t1.591532\t3\n25931\t8.765721\t0.152808\t3\n7538\t3.408996\t0.184896\t2\n1315\t1.251021\t0.112340\t2\n12292\t6.160619\t1.537165\t2\n49248\t1.034538\t1.585162\t1\n9025\t0.000000\t1.034635\t2\n13438\t2.355051\t0.542603\t2\n69683\t6.614543\t0.153771\t1\n25374\t10.245062\t1.450903\t3\n55264\t3.467074\t1.231019\t1\n38324\t7.487678\t1.572293\t3\n69643\t4.624115\t1.185192\t1\n44058\t8.995957\t1.436479\t3\n41316\t11.564476\t0.007195\t3\n29119\t3.440948\t0.078331\t1\n51656\t1.673603\t0.732746\t1\n3030\t4.719341\t0.699755\t2\n35695\t10.304798\t1.576488\t3\n1537\t2.086915\t1.199312\t2\n9083\t6.338220\t1.131305\t2\n47744\t8.254926\t0.710694\t3\n71372\t16.067108\t0.974142\t1\n37980\t1.723201\t0.310488\t1\n42385\t3.785045\t0.876904\t1\n22687\t2.557561\t0.123738\t1\n39512\t9.852220\t1.095171\t3\n11885\t3.679147\t1.557205\t2\n4944\t9.789681\t0.852971\t2\n73230\t14.958998\t0.526707\t1\n17585\t11.182148\t1.288459\t3\n68737\t7.528533\t1.657487\t1\n13818\t5.253802\t1.378603\t2\n31662\t13.946752\t1.426657\t3\n86686\t15.557263\t1.430029\t1\n43214\t12.483550\t0.688513\t3\n24091\t2.317302\t1.411137\t1\n52544\t10.069724\t0.766119\t3\n61861\t5.792231\t1.615483\t1\n47903\t4.138435\t0.475994\t1\n37190\t12.929517\t0.304378\t3\n6013\t9.378238\t0.307392\t2\n27223\t8.361362\t1.643204\t3\n69027\t7.939406\t1.325042\t1\n78642\t10.735384\t0.705788\t1\n30254\t11.592723\t0.286188\t3\n21704\t10.098356\t0.704748\t3\n34985\t9.299025\t0.545337\t3\n31316\t11.158297\t0.218067\t3\n76368\t16.143900\t0.558388\t1\n27953\t10.971700\t1.221787\t3\n152\t0.000000\t0.681478\t2\n9146\t3.178961\t1.292692\t2\n75346\t17.625350\t0.339926\t1\n26376\t1.995833\t0.267826\t1\n35255\t10.640467\t0.416181\t3\n19198\t9.628339\t0.985462\t3\n12518\t4.662664\t0.495403\t2\n25453\t5.754047\t1.382742\t2\n12530\t0.000000\t0.037146\t2\n62230\t9.334332\t0.198118\t1\n9517\t3.846162\t0.619968\t2\n71161\t10.685084\t0.678179\t1\n1593\t4.752134\t0.359205\t2\n33794\t0.697630\t0.966786\t1\n39710\t10.365836\t0.505898\t3\n16941\t0.461478\t0.352865\t2\n69209\t11.339537\t1.068740\t1\n4446\t5.420280\t0.127310\t2\n9347\t3.469955\t1.619947\t2\n55635\t8.517067\t0.994858\t3\n65889\t8.306512\t0.413690\t1\n10753\t2.628690\t0.444320\t2\n7055\t0.000000\t0.802985\t2\n7905\t0.000000\t1.170397\t2\n53447\t7.298767\t1.582346\t3\n9194\t7.331319\t1.277988\t2\n61914\t9.392269\t0.151617\t1\n15630\t5.541201\t1.180596\t2\n79194\t15.149460\t0.537540\t1\n12268\t5.515189\t0.250562\t2\n33682\t7.728898\t0.920494\t3\n26080\t11.318785\t1.510979\t3\n19119\t3.574709\t1.531514\t2\n30902\t7.350965\t0.026332\t3\n63039\t7.122363\t1.630177\t1\n51136\t1.828412\t1.013702\t1\n35262\t10.117989\t1.156862\t3\n42776\t11.309897\t0.086291\t3\n64191\t8.342034\t1.388569\t1\n15436\t0.241714\t0.715577\t2\n14402\t10.482619\t1.694972\t2\n6341\t9.289510\t1.428879\t2\n14113\t4.269419\t0.134181\t2\n6390\t0.000000\t0.189456\t2\n8794\t0.817119\t0.143668\t2\n43432\t1.508394\t0.652651\t1\n38334\t9.359918\t0.052262\t3\n34068\t10.052333\t0.550423\t3\n30819\t11.111660\t0.989159\t3\n22239\t11.265971\t0.724054\t3\n28725\t10.383830\t0.254836\t3\n57071\t3.878569\t1.377983\t1\n72420\t13.679237\t0.025346\t1\n28294\t10.526846\t0.781569\t3\n9896\t0.000000\t0.924198\t2\n65821\t4.106727\t1.085669\t1\n7645\t8.118856\t1.470686\t2\n71289\t7.796874\t0.052336\t1\n5128\t2.789669\t1.093070\t2\n13711\t6.226962\t0.287251\t2\n22240\t10.169548\t1.660104\t3\n15092\t0.000000\t1.370549\t2\n5017\t7.513353\t0.137348\t2\n10141\t8.240793\t0.099735\t2\n35570\t14.612797\t1.247390\t3\n46893\t3.562976\t0.445386\t1\n8178\t3.230482\t1.331698\t2\n55783\t3.612548\t1.551911\t1\n1148\t0.000000\t0.332365\t2\n10062\t3.931299\t0.487577\t2\n74124\t14.752342\t1.155160\t1\n66603\t10.261887\t1.628085\t1\n11893\t2.787266\t1.570402\t2\n50908\t15.112319\t1.324132\t3\n39891\t5.184553\t0.223382\t3\n65915\t3.868359\t0.128078\t1\n65678\t3.507965\t0.028904\t1\n62996\t11.019254\t0.427554\t1\n36851\t3.812387\t0.655245\t1\n36669\t11.056784\t0.378725\t3\n38876\t8.826880\t1.002328\t3\n26878\t11.173861\t1.478244\t3\n46246\t11.506465\t0.421993\t3\n12761\t7.798138\t0.147917\t3\n35282\t10.155081\t1.370039\t3\n68306\t10.645275\t0.693453\t1\n31262\t9.663200\t1.521541\t3\n34754\t10.790404\t1.312679\t3\n13408\t2.810534\t0.219962\t2\n30365\t9.825999\t1.388500\t3\n10709\t1.421316\t0.677603\t2\n24332\t11.123219\t0.809107\t3\n45517\t13.402206\t0.661524\t3\n6178\t1.212255\t0.836807\t2\n10639\t1.568446\t1.297469\t2\n29613\t3.343473\t1.312266\t1\n22392\t5.400155\t0.193494\t1\n51126\t3.818754\t0.590905\t1\n53644\t7.973845\t0.307364\t3\n51417\t9.078824\t0.734876\t3\n24859\t0.153467\t0.766619\t1\n61732\t8.325167\t0.028479\t1\n71128\t7.092089\t1.216733\t1\n27276\t5.192485\t1.094409\t3\n30453\t10.340791\t1.087721\t3\n18670\t2.077169\t1.019775\t2\n70600\t10.151966\t0.993105\t1\n12683\t0.046826\t0.809614\t2\n81597\t11.221874\t1.395015\t1\n69959\t14.497963\t1.019254\t1\n8124\t3.554508\t0.533462\t2\n18867\t3.522673\t0.086725\t2\n80886\t14.531655\t0.380172\t1\n55895\t3.027528\t0.885457\t1\n31587\t1.845967\t0.488985\t1\n10591\t10.226164\t0.804403\t3\n70096\t10.965926\t1.212328\t1\n53151\t2.129921\t1.477378\t1\n11992\t0.000000\t1.606849\t2\n33114\t9.489005\t0.827814\t3\n7413\t0.000000\t1.020797\t2\n10583\t0.000000\t1.270167\t2\n58668\t6.556676\t0.055183\t1\n35018\t9.959588\t0.060020\t3\n70843\t7.436056\t1.479856\t1\n14011\t0.404888\t0.459517\t2\n35015\t9.952942\t1.650279\t3\n70839\t15.600252\t0.021935\t1\n3024\t2.723846\t0.387455\t2\n5526\t0.513866\t1.323448\t2\n5113\t0.000000\t0.861859\t2\n20851\t7.280602\t1.438470\t2\n40999\t9.161978\t1.110180\t3\n15823\t0.991725\t0.730979\t2\n35432\t7.398380\t0.684218\t3\n53711\t12.149747\t1.389088\t3\n64371\t9.149678\t0.874905\t1\n9289\t9.666576\t1.370330\t2\n60613\t3.620110\t0.287767\t1\n18338\t5.238800\t1.253646\t2\n22845\t14.715782\t1.503758\t3\n74676\t14.445740\t1.211160\t1\n34143\t13.609528\t0.364240\t3\n14153\t3.141585\t0.424280\t2\n9327\t0.000000\t0.120947\t2\n18991\t0.454750\t1.033280\t2\n9193\t0.510310\t0.016395\t2\n2285\t3.864171\t0.616349\t2\n9493\t6.724021\t0.563044\t2\n2371\t4.289375\t0.012563\t2\n13963\t0.000000\t1.437030\t2\n2299\t3.733617\t0.698269\t2\n5262\t2.002589\t1.380184\t2\n4659\t2.502627\t0.184223\t2\n17582\t6.382129\t0.876581\t2\n27750\t8.546741\t0.128706\t3\n9868\t2.694977\t0.432818\t2\n18333\t3.951256\t0.333300\t2\n3780\t9.856183\t0.329181\t2\n18190\t2.068962\t0.429927\t2\n11145\t3.410627\t0.631838\t2\n68846\t9.974715\t0.669787\t1\n26575\t10.650102\t0.866627\t3\n48111\t9.134528\t0.728045\t3\n43757\t7.882601\t1.332446\t3\n"
  },
  {
    "path": "KNN/handWritingTest.m",
    "content": "function handWritingTest\n%%\nclc\nclear\nclose all\n%% 获取目录下的所有txt文件名称\nd = dir(['digits/trainingDigits/' '*.txt']); % struct 类型\ndircell = struct2cell(d); %cell 类型\ntrainSetLen = size(dircell,2);\nK = 4;\ndataSize = 1024;\ntrainLabels = zeros(trainSetLen,1);\ntrainSet = [];\nsimpleTrainSet = zeros(1,dataSize);\nsimpleTestSet = zeros(1,dataSize);\n\n%% 加载数据\nfprintf('loading data...')\nfor i = 1:trainSetLen\n    trainName =  dircell(1,i);\n    trainFilename = cell2mat(trainName);\n    trainLabels(i) = str2num(trainFilename(1));\n\n    fid = fopen(['digits/trainingDigits/' trainFilename],'r');\n    traindata = fscanf(fid,'%s');\n    for j = 1:dataSize\n        simpleTrainSet(j) =  str2num(traindata(j));\n    end\n    trainSet = [trainSet ; simpleTrainSet];\n    fclose(fid);\nend\n\nd = dir(['digits/testDigits/' '*.txt']); % struct 类型\ndircell = struct2cell(d); %cell 类型\ntestSetLen = size(dircell,2);\nerror = 0;\n%% 测试数据\nfor k = 1:testSetLen\n    testName =  dircell(1,k);\n    testFilename = cell2mat(testName);\n    testLabels = str2num(testFilename(1));\n\n    fid = fopen(['digits/testDigits/' testFilename],'r');\n    testdata = fscanf(fid,'%s');\n    for j = 1:dataSize\n        simpleTestSet(j) =  str2num(testdata(j));\n    end\n    classifyResult = KNN(simpleTestSet,trainSet,trainLabels,K);\n    fprintf('识别数字为：%d  真实数字为：%d\\n' , [classifyResult , testLabels])\n    if(classifyResult~=testLabels)\n        error = error+1;\n    end\n    fclose(fid);\nend\n\nfprintf('识别准确率为：%f\\n',1-error/testSetLen)\n\nend\n"
  },
  {
    "path": "Kmeans/README.md",
    "content": "博客链接：http://blog.csdn.net/llp1992/article/details/45095935\n\n更多机器学习深度学习博客请关注CSDN博客：[LiuLongpo](http://blog.csdn.net/llp1992)\n"
  },
  {
    "path": "Kmeans/distEclud.m",
    "content": "% 计算欧式距离\nfunction dist = distEclud(vecA,vecB)\n    dist  = sum(power((vecA-vecB),2));\nend\n\n\nfunction dist = softDist(vecA,vecB)\n    dist = sum(abs(vecB-vecA));\nend\n"
  },
  {
    "path": "Kmeans/kMeans.m",
    "content": "% K-means算法\nfunction [centSet,clusterAssment] = kMeans(dataSet,K)\n\n[row,col] = size(dataSet);\n% 存储质心矩阵\ncentSet = zeros(K,col);\n% 随机初始化质心\nfor i= 1:col\n    minV = min(dataSet(:,i));\n    rangV = max(dataSet(:,i)) - minV;\n    centSet(:,i) = bsxfun(@plus,minV,rangV*rand(K,1));\n    %centSet(:,i) = repmat(minV,[K,1]) + rangV*rand(K,1);\nend\n\n% 用于存储每个点被分配的cluster以及到质心的距离\nclusterAssment = zeros(row,2);\nclusterChange = true;\nwhile clusterChange\n    clusterChange = false;\n    % 计算每个点应该被分配的cluster\n    for i = 1:row\n        % 这部分可能可以优化\n        minDist = inf;\n        minIndex = 0;\n        for j = 1:K\n            distCal = distEclud(dataSet(i,:) , centSet(j,:));\n            if (distCal < minDist)\n                minDist = distCal;\n                minIndex = j;\n            end\n        end\n        if minIndex ~= clusterAssment(i,1)            \n            clusterChange = true;\n        end\n        clusterAssment(i,1) = minIndex;\n        clusterAssment(i,2) = minDist;\n    end\n    \n    % 更新每个cluster 的质心\n    for j = 1:K\n        simpleCluster = find(clusterAssment(:,1) == j);\n        centSet(j,:) = mean(dataSet(simpleCluster',:));\n    end\nend\nend\n"
  },
  {
    "path": "Kmeans/testSet.txt",
    "content": "1.658985\t4.285136\n-3.453687\t3.424321\n4.838138\t-1.151539\n-5.379713\t-3.362104\n0.972564\t2.924086\n-3.567919\t1.531611\n0.450614\t-3.302219\n-3.487105\t-1.724432\n2.668759\t1.594842\n-3.156485\t3.191137\n3.165506\t-3.999838\n-2.786837\t-3.099354\n4.208187\t2.984927\n-2.123337\t2.943366\n0.704199\t-0.479481\n-0.392370\t-3.963704\n2.831667\t1.574018\n-0.790153\t3.343144\n2.943496\t-3.357075\n-3.195883\t-2.283926\n2.336445\t2.875106\n-1.786345\t2.554248\n2.190101\t-1.906020\n-3.403367\t-2.778288\n1.778124\t3.880832\n-1.688346\t2.230267\n2.592976\t-2.054368\n-4.007257\t-3.207066\n2.257734\t3.387564\n-2.679011\t0.785119\n0.939512\t-4.023563\n-3.674424\t-2.261084\n2.046259\t2.735279\n-3.189470\t1.780269\n4.372646\t-0.822248\n-2.579316\t-3.497576\n1.889034\t5.190400\n-0.798747\t2.185588\n2.836520\t-2.658556\n-3.837877\t-3.253815\n2.096701\t3.886007\n-2.709034\t2.923887\n3.367037\t-3.184789\n-2.121479\t-4.232586\n2.329546\t3.179764\n-3.284816\t3.273099\n3.091414\t-3.815232\n-3.762093\t-2.432191\n3.542056\t2.778832\n-1.736822\t4.241041\n2.127073\t-2.983680\n-4.323818\t-3.938116\n3.792121\t5.135768\n-4.786473\t3.358547\n2.624081\t-3.260715\n-4.009299\t-2.978115\n2.493525\t1.963710\n-2.513661\t2.642162\n1.864375\t-3.176309\n-3.171184\t-3.572452\n2.894220\t2.489128\n-2.562539\t2.884438\n3.491078\t-3.947487\n-2.565729\t-2.012114\n3.332948\t3.983102\n-1.616805\t3.573188\n2.280615\t-2.559444\n-2.651229\t-3.103198\n2.321395\t3.154987\n-1.685703\t2.939697\n3.031012\t-3.620252\n-4.599622\t-2.185829\n4.196223\t1.126677\n-2.133863\t3.093686\n4.668892\t-2.562705\n-2.793241\t-2.149706\n2.884105\t3.043438\n-2.967647\t2.848696\n4.479332\t-1.764772\n-4.905566\t-2.911070\n"
  },
  {
    "path": "Kmeans/testkMeans.m",
    "content": "function testkMeans\nclc\nclear all\nclose all\nK = 4;\ndataSet = load('testSet.txt');\nfigure \nscatter(dataSet(:,1),dataSet(:,2))\n[row,col] = size(dataSet);\n% 存储质心矩阵\ncentSet = zeros(K,col);\n% 随机初始化质心\nfor i= 1:col\n    minV = min(dataSet(:,i));\n    rangV = max(dataSet(:,i)) - minV;\n    centSet(:,i) = repmat(minV,[K,1]) + rangV*rand(K,1);\nend\n\n% 用于存储每个点被分配的cluster以及到质心的距离\nclusterAssment = zeros(row,2);\nclusterChange = true;\nwhile clusterChange\n    clusterChange = false;\n    % 计算每个点应该被分配的cluster\n    for i = 1:row\n        % 这部分可能可以优化\n        minDist = 10000;\n        minIndex = 0;\n        for j = 1:K\n            distCal = distEclud(dataSet(i,:) , centSet(j,:));\n            if (distCal < minDist)\n                minDist = distCal;\n                minIndex = j;\n            end\n        end\n        if minIndex ~= clusterAssment(i,1)            \n            clusterChange = true;\n        end\n        clusterAssment(i,1) = minIndex;\n        clusterAssment(i,2) = minDist;\n    end\n    \n    % 更新每个cluster 的质心\n    for j = 1:K\n        simpleCluster = find(clusterAssment(:,1) == j);\n        centSet(j,:) = mean(dataSet(simpleCluster',:));\n    end\n     centSet\nend\nfigure\n%scatter(dataSet(:,1),dataSet(:,2),5)\nfor i = 1:K\n    pointCluster = find(clusterAssment(:,1) == i);\n    scatter(dataSet(pointCluster,1),dataSet(pointCluster,2),5)\n    hold on\nend\n%hold on\nscatter(centSet(:,1),centSet(:,2),300,'+')\nhold off\n\nend\n\n% 计算欧式距离\nfunction dist = distEclud(vecA,vecB)\n    dist  = sum(power((vecA-vecB),2));\nend\n"
  },
  {
    "path": "Logistic-regression/ImproveStocGradAscent.m",
    "content": "function ImproveStocGradAscent\n%%\n%\n%   Description : LogisticRegression using stocGradAsscent\n%   Author : Liulongpo\n%   Time：2015-4-18 10:57:25\n%\n%%\nclc\nclear \nclose all\n%%\ndata = load('testSet.txt');\n[row , col] = size(data);\ndataMat = [ones(row,1) data(:,1:col-1)];\n%alpha = 0.01;\nnumIter = 20;\nlabelMat = data(:,col);\nweightVal = zeros(3,numIter*row);\nweight = ones(col,1);\nj = 0;\n\nfor k = 1:numIter\n     randIndex = randperm(row);\n    for i = 1:row\n        % 改进点 1\n        alpha = 4/(1.0+i+k)+0.01; \n        j = j+1;\n        % 改进点 2 \n        h = sigmoid(dataMat(randIndex(i),:)*weight);\n         % 改进点 2\n        error = labelMat(randIndex(i)) - h;\n        % 改进点 2\n        weight = weight + alpha * error * dataMat(randIndex(i),:)';\n        weightVal(1,j) = weight(1);\n        weightVal(2,j) = weight(2);\n        weightVal(3,j) = weight(3);\n    end\nend\n\nfigure\ni = 1:numIter*row;\nsubplot(3,1,1)\nplot(i,weightVal(1,:)),title('weight0')%,axis([0 numIter*row 0.8 7])\nj = 1:numIter*row;\nsubplot(3,1,2)\nplot(j,weightVal(2,:)),title('weight1')%,axis([0 numIter*row 0.3 1.2])\nk = 1:numIter*row;\nsubplot(3,1,3)\nplot(k,weightVal(3,:)),title('weight2')%,axis([0 numIter*row -1.2 -0.1])\n\nfigure\nscatter(dataMat(find(labelMat(:)==0),2),dataMat(find(labelMat(:)==0),3),5);\nhold on\nscatter(dataMat(find(labelMat(:) == 1),2),dataMat(find(labelMat(:) == 1),3),5);\nhold on\nx = -3:0.1:3;\ny = -(weight(1)+weight(2)*x)/weight(3);\nplot(x,y,'r')\nhold off\n\n\nend\n\nfunction returnVals = sigmoid(inX)\n    % 注意这里的sigmoid函数要用点除\n    returnVals = 1.0./(1.0+exp(-inX));\nend\n"
  },
  {
    "path": "Logistic-regression/README.md",
    "content": "博客链接：http://blog.csdn.net/llp1992/article/details/45114421\n\n更多机器学习深度学习博客请关注CSDN博客：[LiuLongpo](http://blog.csdn.net/llp1992)\n"
  },
  {
    "path": "Logistic-regression/gradAscent.m",
    "content": "function weight = gradAscent\n%%\n%\n%   Description : LogisticRegression using gradAsscent\n%   Author : Liulongpo\n%   Time：2015-4-18 10:57:25\n%\n%%\nclc\nclose all\nclear\n%%\n\ndata = load('testSet.txt');\n[row , col] = size(data);\ndataMat = data(:,1:col-1);\ndataMat = [ones(row,1) dataMat] ;\nlabelMat = data(:,col);\nalpha = 0.001;\nmaxCycle = 500;\nweight = ones(col,1);\nfor i = 1:maxCycle\n    h = sigmoid((dataMat * weight)');\n    error = (labelMat - h');\n    weight = weight + alpha * dataMat' * error;\nend\n\nfigure\nscatter(dataMat(find(labelMat(:) == 0),2),dataMat(find(labelMat(:) == 0),3),3);\nhold on\nscatter(dataMat(find(labelMat(:) == 1),2),dataMat(find(labelMat(:) == 1),3),5);\nhold on\nx = -3:0.1:3;\ny = (-weight(1)-weight(2)*x)/weight(3);\nplot(x,y)\nhold off\n\nend\n\nfunction returnVals = sigmoid(inX)\n    % 注意这里的sigmoid函数要用点除\n    returnVals = 1.0./(1.0+exp(-inX));\nend\n"
  },
  {
    "path": "Logistic-regression/stocGradAscent.m",
    "content": "function stocGradAscent\n%%\n%\n%   Description : LogisticRegression using stocGradAsscent\n%   Author : Liulongpo\n%   Time：2015-4-18 10:57:25\n%\n%%\nclc\nclear \nclose all\n%%\ndata = load('testSet.txt');\n[row , col] = size(data);\ndataMat = [ones(row,1) data(:,1:col-1)];\nalpha = 0.01;\nlabelMat = data(:,col);\nweight = ones(col,1);\nfor i = 1:row\n    h = sigmoid(dataMat(i,:)*weight);\n    error = labelMat(i) - h;\n    dataMat(i,:)\n    weight = weight + alpha * error * dataMat(i,:)'\nend\n\nfigure\nscatter(dataMat(find(labelMat(:)==0),2),dataMat(find(labelMat(:)==0),3),5);\nhold on\nscatter(dataMat(find(labelMat(:) == 1),2),dataMat(find(labelMat(:) == 1),3),5);\nhold on\nx = -3:0.1:3;\ny = -(weight(1)+weight(2)*x)/weight(3);\nplot(x,y)\nhold off\n\n\nend\n\nfunction returnVals = sigmoid(inX)\n    % 注意这里的sigmoid函数要用点除\n    returnVals = 1.0./(1.0+exp(-inX));\nend\n"
  },
  {
    "path": "Logistic-regression/testSet.txt",
    "content": "-0.017612\t14.053064\t0\n-1.395634\t4.662541\t1\n-0.752157\t6.538620\t0\n-1.322371\t7.152853\t0\n0.423363\t11.054677\t0\n0.406704\t7.067335\t1\n0.667394\t12.741452\t0\n-2.460150\t6.866805\t1\n0.569411\t9.548755\t0\n-0.026632\t10.427743\t0\n0.850433\t6.920334\t1\n1.347183\t13.175500\t0\n1.176813\t3.167020\t1\n-1.781871\t9.097953\t0\n-0.566606\t5.749003\t1\n0.931635\t1.589505\t1\n-0.024205\t6.151823\t1\n-0.036453\t2.690988\t1\n-0.196949\t0.444165\t1\n1.014459\t5.754399\t1\n1.985298\t3.230619\t1\n-1.693453\t-0.557540\t1\n-0.576525\t11.778922\t0\n-0.346811\t-1.678730\t1\n-2.124484\t2.672471\t1\n1.217916\t9.597015\t0\n-0.733928\t9.098687\t0\n-3.642001\t-1.618087\t1\n0.315985\t3.523953\t1\n1.416614\t9.619232\t0\n-0.386323\t3.989286\t1\n0.556921\t8.294984\t1\n1.224863\t11.587360\t0\n-1.347803\t-2.406051\t1\n1.196604\t4.951851\t1\n0.275221\t9.543647\t0\n0.470575\t9.332488\t0\n-1.889567\t9.542662\t0\n-1.527893\t12.150579\t0\n-1.185247\t11.309318\t0\n-0.445678\t3.297303\t1\n1.042222\t6.105155\t1\n-0.618787\t10.320986\t0\n1.152083\t0.548467\t1\n0.828534\t2.676045\t1\n-1.237728\t10.549033\t0\n-0.683565\t-2.166125\t1\n0.229456\t5.921938\t1\n-0.959885\t11.555336\t0\n0.492911\t10.993324\t0\n0.184992\t8.721488\t0\n-0.355715\t10.325976\t0\n-0.397822\t8.058397\t0\n0.824839\t13.730343\t0\n1.507278\t5.027866\t1\n0.099671\t6.835839\t1\n-0.344008\t10.717485\t0\n1.785928\t7.718645\t1\n-0.918801\t11.560217\t0\n-0.364009\t4.747300\t1\n-0.841722\t4.119083\t1\n0.490426\t1.960539\t1\n-0.007194\t9.075792\t0\n0.356107\t12.447863\t0\n0.342578\t12.281162\t0\n-0.810823\t-1.466018\t1\n2.530777\t6.476801\t1\n1.296683\t11.607559\t0\n0.475487\t12.040035\t0\n-0.783277\t11.009725\t0\n0.074798\t11.023650\t0\n-1.337472\t0.468339\t1\n-0.102781\t13.763651\t0\n-0.147324\t2.874846\t1\n0.518389\t9.887035\t0\n1.015399\t7.571882\t0\n-1.658086\t-0.027255\t1\n1.319944\t2.171228\t1\n2.056216\t5.019981\t1\n-0.851633\t4.375691\t1\n-1.510047\t6.061992\t0\n-1.076637\t-3.181888\t1\n1.821096\t10.283990\t0\n3.010150\t8.401766\t1\n-1.099458\t1.688274\t1\n-0.834872\t-1.733869\t1\n-0.846637\t3.849075\t1\n1.400102\t12.628781\t0\n1.752842\t5.468166\t1\n0.078557\t0.059736\t1\n0.089392\t-0.715300\t1\n1.825662\t12.693808\t0\n0.197445\t9.744638\t0\n0.126117\t0.922311\t1\n-0.679797\t1.220530\t1\n0.677983\t2.556666\t1\n0.761349\t10.693862\t0\n-2.168791\t0.143632\t1\n1.388610\t9.341997\t0\n0.317029\t14.739025\t0\n"
  },
  {
    "path": "MLP/dualperceptron.py",
    "content": "# -*- coding: utf-8 -*-\n'''    \n    @Description : dualperceptron by python\n    @Author: Liu_Longpo\n    @Time: Sun Dec 20 12:57:00 2015\n'''\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport time\n \ntrainSet = []\n \nw = []\na = []\nb = 0\nlens = 0\nalpha = 0\nGram = []\ntrainLoss = []\n \ndef calInnerProduct(i, j):\n    global lens\n    res = 0\n    for p in range(lens):\n        res += trainSet[i][0][p] * trainSet[j][0][p]\n    return res\n\ndef AddVector(vec1, vec2):\n    retvec = []\n    for i in range(len(vec1)):\n        retvec.append(vec1[i] + vec2[i])\n    return retvec\n    \ndef NumProduct(num, vec):\n    retvec = []\n    for i in range(len(vec)):\n        retvec.append(num * vec[i])\n    return retvec \n\ndef createGram():\n    global lens\n    for i in range(len(trainSet)):\n        tmp = []\n        for j in range(0, len(trainSet)):\n            tmp.append(calInnerProduct(i, j))\n        Gram.append(tmp)\n\n# update parameters using stochastic gradient descent\ndef updateParm(k):\n    global a, b, alpha\n    a[k] += alpha\n    b = b + alpha * trainSet[k][1] \n    #print a, b # you can uncomment this line to check the process of stochastic gradient descent\n \ndef calDistance(k):\n    global a, b\n    res = 0\n    for i in range(len(trainSet)):\n        res += a[i] * int(trainSet[i][1]) * Gram[i][k]\n    res += b\n    res *= trainSet[k][1]\n    return res\n \ndef trainModel(Iter):\n    print \"training MLP...\"\n    print \"-\"*40\n    epoch = 0\n    for i in range(Iter):\n        train_loss = 0\n        global w, a\n        update = False\n        print \"epoch\",epoch, \"  w: \",w,\"b:\",b,\n        for j in range(len(trainSet)):\n            res = calDistance(j)\n            if res <= 0:\n                train_loss += -res\n                update = True\n                updateParm(j)\n        print 'train loss:',train_loss\n        trainLoss.append(train_loss)\n        if update:\n            epoch = epoch+1\n        else:\n            for k in range(len(trainSet)):\n                w = AddVector(w, NumProduct(a[k] * int(trainSet[k][1]), trainSet[k][0]))\n            print \"result: w: \", w, \" b: \", b\n        update = False\n        if epoch==Iter:\n            print 'reach max trian epoch'\n            for j in range(len(trainSet)):\n                w = AddVector(w, NumProduct(a[j] * int(trainSet[j][1]), trainSet[j][0]))\n            print \"RESULT: w: \", w, \" b: \", b\n \nif __name__==\"__main__\":\n    if len(sys.argv)!=4:\n        print \"Usage: python MLP.py trainFile modelFile\"\n        exit(0)\n    alpha = float(sys.argv[1])\n    trainFile = open(sys.argv[2])\n    modelPath = sys.argv[3]\n    #modelPath = 'model'\n    lens = 0\n    # load data  trainSet[i][0]:data,trainSet[i][1]:label\n    for line in trainFile:\n        data = line.strip().split('\\t')\n        lens = len(data) - 1\n        sample_all = []\n        sample_data = []\n        for i in range(0,lens):\n            sample_data.append(float(data[i]))\n        sample_all.append(sample_data) # add data\n        if int(data[lens]) == 1:\n            sample_all.append(int(data[lens])) # add label\n        else:\n            sample_all.append(-1) # add label\n        trainSet.append(sample_all)\n    trainFile.close()\n    createGram()\n    for i in range(len(trainSet)):\n        a.append(0)\n    for i in range(lens):\n        w.append(0)\n    start = time.clock()\n    trainModel(500)\n    end = time.clock()\n    print 'train time is %f s' % (end - start)\n    x = np.linspace(-5,5,10)\n    plt.figure()\n    for i in range(len(trainSet)):\n        if trainSet[i][1] == 1:\n            plt.scatter(trainSet[i][0][0],trainSet[i][0][1],c=u'b')\n        else:\n            plt.scatter(trainSet[i][0][0],trainSet[i][0][1],c=u'r')\n    plt.plot(x,-(w[0]*x+b)/w[1],c=u'r')\n    plt.show()\n    trainIter = range(len(trainLoss))\n    plt.figure()    \n    plt.scatter(trainIter,trainLoss,c=u'r')\n    plt.plot(trainIter,trainLoss)\n    plt.xlabel('Epoch')\n    plt.ylabel('trainLoss')\n    plt.show()\n    \n"
  },
  {
    "path": "MLP/perceptron.py",
    "content": "# -*- coding: utf-8 -*-\n\"\"\"\n    @Description : perceptron by python\n    @Author: Liu_Longpo\n    @Time: Sun Dec 20 12:57:00 2015\n\"\"\"\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport time\n\ntrainSet = []\nw = []\nb = 0\nlens = 0\nalpha = 0  # learn rate , default 1\ntrainLoss = []\n    \ndef updateParm(sample):\n    global w,b,lens,alpha\n    for i in range(lens):\n        w[i] = w[i] + alpha*sample[1]*sample[0][i]\n    b = b + alpha*sample[1]\n        \ndef calDistance(sample):\n    global w,b\n    res = 0\n    for i in range(len(sample[0])):\n        res += sample[0][i] * w[i]\n    res += b\n    res *= int(sample[1])\n    return res\n\ndef trainMLP(Iter):\n    print \"training MLP...\"\n    print \"-\"*40\n    epoch = 0\n    for i in range(Iter):\n        train_loss = 0\n        update = False\n        print \"epoch\",epoch, \"  w: \",w,\"b:\",b,\n        for sample in trainSet:\n            res = calDistance(sample)\n            if res <= 0:\n                train_loss += -res\n                update = True\n                updateParm(sample)\n        print 'train loss:',train_loss\n        trainLoss.append(train_loss)\n        if update:\n            epoch = epoch+1\n        else:\n            print \"The training have convergenced,stop trianing \"\n            print \"Optimum W:\",w,\" Optimum b:\",b\n            #os._exit(0)\n            break # early stop\n        update = False\n        \nif __name__==\"__main__\":\n    if len(sys.argv)!=4:\n        print \"Usage: python MLP.py trainFile modelFile\"\n        exit(0)\n    alpha = float(sys.argv[1])\n    trainFile = open(sys.argv[2])\n    modelPath = sys.argv[3]\n    #modelPath = 'model'\n    lens = 0\n    # load data  trainSet[i][0]:data,trainSet[i][1]:label\n    for line in trainFile:\n        data = line.strip().split(' ') # train ' ' ,testSet '/t'\n        lens = len(data) - 1\n        sample_all = []\n        sample_data = []\n        for i in range(0,lens):\n            sample_data.append(float(data[i]))\n        sample_all.append(sample_data) # add data\n        if int(data[lens]) == 1:\n            sample_all.append(int(data[lens])) # add label\n        else:\n            sample_all.append(-1) # add label\n        trainSet.append(sample_all)\n    trainFile.close()\n    # initialize w by 0 \n    for i in range(lens):\n        w.append(0)\n    # train model for max 100 Iteration\n    start = time.clock()\n    trainMLP(500)\n    end = time.clock()\n    print 'train time is %f s.' % (end - start)\n    x = np.linspace(-5,5,10)\n    plt.figure()\n    for i in range(len(trainSet)):\n        if trainSet[i][1] == 1:\n            plt.scatter(trainSet[i][0][0],trainSet[i][0][1],c=u'b')\n        else:\n            plt.scatter(trainSet[i][0][0],trainSet[i][0][1],c=u'r')\n    plt.plot(x,-(w[0]*x+b)/w[1],c=u'r')\n    plt.show()\n    trainIter = range(len(trainLoss))\n    plt.figure()    \n    plt.scatter(trainIter,trainLoss,c=u'r')\n    plt.plot(trainIter,trainLoss)\n    plt.xlabel('Epoch')\n    plt.ylabel('trainLoss')\n    plt.show()\n    \n\n        \n"
  },
  {
    "path": "MLP/testSet.txt",
    "content": "-0.017612\t14.053064\t0\n-1.395634\t4.662541\t1\n-0.752157\t6.538620\t0\n-1.322371\t7.152853\t0\n0.423363\t11.054677\t0\n0.406704\t7.067335\t1\n0.667394\t12.741452\t0\n-2.460150\t6.866805\t1\n0.569411\t9.548755\t0\n-0.026632\t10.427743\t0\n0.850433\t6.920334\t1\n1.347183\t13.175500\t0\n1.176813\t3.167020\t1\n-1.781871\t9.097953\t0\n-0.566606\t5.749003\t1\n0.931635\t1.589505\t1\n-0.024205\t6.151823\t1\n-0.036453\t2.690988\t1\n-0.196949\t0.444165\t1\n1.014459\t5.754399\t1\n1.985298\t3.230619\t1\n-1.693453\t-0.557540\t1\n-0.576525\t11.778922\t0\n-0.346811\t-1.678730\t1\n-2.124484\t2.672471\t1\n1.217916\t9.597015\t0\n-0.733928\t9.098687\t0\n-3.642001\t-1.618087\t1\n0.315985\t3.523953\t1\n1.416614\t9.619232\t0\n-0.386323\t3.989286\t1\n0.556921\t8.294984\t1\n1.224863\t11.587360\t0\n-1.347803\t-2.406051\t1\n1.196604\t4.951851\t1\n0.275221\t9.543647\t0\n0.470575\t9.332488\t0\n-1.889567\t9.542662\t0\n-1.527893\t12.150579\t0\n-1.185247\t11.309318\t0\n-0.445678\t3.297303\t1\n1.042222\t6.105155\t1\n-0.618787\t10.320986\t0\n1.152083\t0.548467\t1\n0.828534\t2.676045\t1\n-1.237728\t10.549033\t0\n-0.683565\t-2.166125\t1\n0.229456\t5.921938\t1\n-0.959885\t11.555336\t0\n0.492911\t10.993324\t0\n0.184992\t8.721488\t0\n-0.355715\t10.325976\t0\n-0.397822\t8.058397\t0\n0.824839\t13.730343\t0\n1.507278\t5.027866\t1\n0.099671\t6.835839\t1\n-0.344008\t10.717485\t0\n1.785928\t7.718645\t1\n-0.918801\t11.560217\t0\n-0.364009\t4.747300\t1\n-0.841722\t4.119083\t1\n0.490426\t1.960539\t1\n-0.007194\t9.075792\t0\n0.356107\t12.447863\t0\n0.342578\t12.281162\t0\n-0.810823\t-1.466018\t1\n2.530777\t6.476801\t1\n1.296683\t11.607559\t0\n0.475487\t12.040035\t0\n-0.783277\t11.009725\t0\n0.074798\t11.023650\t0\n-1.337472\t0.468339\t1\n-0.102781\t13.763651\t0\n-0.147324\t2.874846\t1\n0.518389\t9.887035\t0\n1.015399\t7.571882\t0\n-1.658086\t-0.027255\t1\n1.319944\t2.171228\t1\n2.056216\t5.019981\t1\n-0.851633\t4.375691\t1\n-1.510047\t6.061992\t0\n-1.076637\t-3.181888\t1\n1.821096\t10.283990\t0\n3.010150\t8.401766\t1\n-1.099458\t1.688274\t1\n-0.834872\t-1.733869\t1\n-0.846637\t3.849075\t1\n1.400102\t12.628781\t0\n1.752842\t5.468166\t1\n0.078557\t0.059736\t1\n0.089392\t-0.715300\t1\n1.825662\t12.693808\t0\n0.197445\t9.744638\t0\n0.126117\t0.922311\t1\n-0.679797\t1.220530\t1\n0.677983\t2.556666\t1\n0.761349\t10.693862\t0\n-2.168791\t0.143632\t1\n1.388610\t9.341997\t0\n0.317029\t14.739025\t0\n"
  },
  {
    "path": "PCA/PCA.m",
    "content": "function [lowData,reconMat] = PCA(data,K)\n\n[row , col] = size(data);\nmeanValue = mean(data);\n%varData = var(data,1,1);\nnormData = data - repmat(meanValue,[row,1]);\ncovMat = cov(normData(:,1),normData(:,2));%求取协方差矩阵\n[eigVect,eigVal] = eig(covMat);%求取特征值和特征向量\n[sortMat, sortIX] = sort(eigVal,'descend');\n[B,IX] = sort(sortMat(1,:),'descend');\nlen = min(K,length(IX));\neigVect(:,IX(1:1:len));\nlowData =  normData * eigVect(:,IX(1:1:len));\nreconMat = (lowData * eigVect(:,IX(1:1:len))') + repmat(meanValue,[row,1]);  % 将降维后的数据转换到新空间\n\nend\n"
  },
  {
    "path": "PCA/README.md",
    "content": "博客链接：http://blog.csdn.net/llp1992/article/details/45065609\n\n更多机器学习深度学习博客请关注CSDN博客：[LiuLongpo](http://blog.csdn.net/llp1992)\n"
  },
  {
    "path": "PCA/testPCA.m",
    "content": "function testPCA\n%%\nclc\nclear\nclose all\n%%\n\nfilename = 'testSet.txt';\nK = 1;\ndata = load(filename);\n[lowData,reconMat] = PCA(data,K);\nfigure\nscatter(data(:,1),data(:,2),5,'r')\nhold on\nscatter(reconMat(:,1),reconMat(:,2),5)\nhold off\n\nend\n"
  },
  {
    "path": "PCA/testSet.txt",
    "content": "10.235186\t11.321997\n10.122339\t11.810993\n9.190236\t8.904943\n9.306371\t9.847394\n8.330131\t8.340352\n10.152785\t10.123532\n10.408540\t10.821986\n9.003615\t10.039206\n9.534872\t10.096991\n9.498181\t10.825446\n9.875271\t9.233426\n10.362276\t9.376892\n10.191204\t11.250851\n7.720499\t6.476300\n9.334379\t8.471268\n7.963186\t6.731333\n8.244973\t9.013785\n9.569196\t10.568949\n8.854793\t9.076536\n9.382171\t7.240862\n8.179055\t8.944502\n8.267896\t8.797017\n9.047165\t8.725068\n8.741043\t7.901385\n7.190216\t7.804587\n8.081227\t9.314431\n8.047460\t5.720780\n7.917584\t7.543254\n8.676942\t10.102220\n9.210251\t9.424717\n7.732998\t9.840202\n7.681754\t8.609897\n7.925863\t10.079159\n8.261509\t8.242080\n8.514872\t7.527561\n10.324450\t10.804481\n7.856710\t7.931543\n7.858608\t7.995340\n9.196808\t6.577598\n9.644415\t10.935081\n9.579833\t9.085021\n7.888484\t5.976428\n9.072624\t9.703344\n8.914184\t9.298515\n7.822869\t7.086663\n10.538554\t11.061464\n8.280187\t8.709012\n8.884223\t8.670105\n9.359927\t10.575055\n9.078611\t9.710833\n7.935134\t8.586173\n8.805945\t10.575145\n9.584316\t9.614076\n11.269714\t11.717254\n9.120444\t9.019774\n7.977520\t8.313923\n8.104648\t9.456128\n8.617126\t7.331723\n9.033811\t9.469706\n8.327680\t5.122092\n8.532272\t10.100909\n9.295434\t8.933824\n9.905202\t9.027559\n10.585764\t10.912733\n10.427584\t11.532578\n9.072767\t9.960144\n9.164275\t8.645121\n9.746058\t10.717080\n9.286072\t9.340024\n8.188233\t7.432415\n7.948598\t8.445419\n7.563350\t5.656178\n8.972405\t8.801869\n9.980868\t8.788996\n7.753490\t7.714248\n7.431143\t9.032819\n8.943403\t8.359354\n10.481890\t9.988969\n9.150454\t10.278760\n8.123894\t9.060351\n8.626164\t8.469342\n7.354185\t7.631252\n11.323046\t11.015032\n8.190008\t6.860792\n8.412598\t7.661358\n9.258404\t8.580382\n11.007915\t11.443881\n8.279403\t8.347003\n8.931149\t10.105221\n10.239245\t10.077473\n8.129346\t7.096877\n8.485823\t9.373561\n10.703640\t11.651618\n9.500728\t8.150228\n9.712414\t9.910445\n9.333374\t9.407557\n8.787865\t10.168021\n9.238180\t10.253478\n9.577388\t8.895150\n10.447753\t10.318227\n9.303944\t9.223136\n9.883268\t11.662945\n9.471921\t10.443792\n10.007753\t9.579912\n8.110298\t7.106263\n6.964069\t6.585040\n10.413499\t9.649309\n8.032629\t7.053254\n8.015549\t9.166753\n10.462924\t8.656612\n9.530788\t10.134130\n9.202658\t9.314222\n10.103241\t10.235159\n7.849264\t6.624856\n9.059071\t7.992555\n10.172889\t10.724789\n9.528439\t6.420990\n7.190422\t6.789792\n9.085716\t9.846328\n9.452887\t8.735386\n7.417322\t7.348594\n8.468639\t8.715086\n8.303642\t9.463231\n9.939052\t10.026771\n8.701989\t7.516978\n9.737541\t10.587281\n8.280233\t7.852444\n10.648386\t10.259203\n9.173893\t10.520372\n9.135397\t10.751406\n7.594580\t8.488833\n8.587520\t8.463406\n8.581887\t7.888644\n9.448768\t8.707422\n7.882664\t7.772030\n10.050635\t9.859720\n9.012078\t9.533899\n8.770020\t8.882996\n9.428804\t9.446306\n8.504209\t8.319693\n9.800003\t10.964667\n8.069660\t7.683099\n10.012217\t10.320644\n8.704677\t8.918146\n8.198722\t7.297786\n9.868322\t9.901657\n9.426997\t11.480353\n9.228767\t9.262976\n8.952359\t9.528471\n8.186847\t8.600587\n9.026371\t8.705143\n9.483364\t9.807079\n7.826587\t7.975401\n11.197846\t10.959298\n7.632421\t8.769745\n8.761605\t8.309365\n9.353670\t8.728758\n6.466637\t6.038996\n8.370634\t9.178830\n10.337451\t11.075600\n8.917679\t8.288367\n9.076621\t8.487626\n7.278948\t4.634097\n10.153017\t11.219183\n7.132603\t5.853118\n9.338644\t9.805940\n9.878602\t9.187000\n10.009505\t10.924505\n9.384438\t10.691860\n7.535322\t8.160481\n6.808732\t8.268469\n8.302965\t8.075009\n8.345379\t8.305356\n9.517530\t8.249839\n9.267825\t9.999109\n10.291511\t11.032664\n8.605909\t8.705207\n8.331145\t7.812295\n8.632412\t10.574287\n8.766397\t8.712107\n9.407070\t9.732756\n9.709495\t9.729569\n10.422201\t11.070360\n6.831495\t6.466763\n8.187122\t8.405929\n8.523093\t9.041844\n7.952394\t6.801220\n10.490780\t10.001468\n10.813791\t9.802494\n7.861113\t7.541475\n8.800399\t8.738974\n7.542152\t6.612838\n9.446981\t9.378659\n8.281684\t7.358572\n8.473801\t8.208343\n11.736767\t11.022029\n8.379578\t8.714348\n8.313718\t8.832381\n9.342589\t10.416659\n7.560710\t6.889648\n9.295344\t9.739040\n9.176612\t9.718781\n8.614385\t10.150521\n9.079373\t8.839794\n10.333289\t10.921255\n9.453502\t7.335134\n10.174590\t10.292500\n9.693713\t9.793636\n7.474925\t7.751391\n10.107905\t10.156997\n9.257241\t7.854266\n10.209794\t11.410157\n7.248050\t6.433676\n10.150091\t9.288597\n10.077713\t10.321500\n8.191122\t8.931519\n8.791469\t10.287216\n9.229434\t9.095193\n8.682571\t8.546005\n7.524099\t7.709751\n8.442410\t8.326037\n9.364851\t9.095989\n9.061222\t7.557899\n7.989999\t8.555363\n8.801275\t8.868732\n10.351932\t9.497796\n10.230710\t10.496151\n9.783163\t9.891408\n10.651481\t9.431617\n8.387393\t6.400507\n9.003921\t7.050003\n8.483723\t8.314886\n9.020501\t7.545771\n9.329105\t11.095661\n9.583687\t9.271929\n8.908705\t8.407529\n8.835406\t8.083517\n9.736362\t8.296735\n10.030302\t9.737178\n8.287142\t6.993460\n9.173211\t9.306335\n9.026355\t9.696531\n9.128391\t9.921247\n11.486346\t12.910777\n11.519458\t11.472111\n9.027707\t10.263974\n9.351935\t8.542200\n9.421701\t11.403201\n9.005687\t8.100969\n7.015279\t6.614278\n8.213607\t8.340948\n8.226646\t8.718997\n8.144753\t8.366877\n10.133642\t12.790169\n10.763481\t10.847016\n10.003622\t10.337716\n9.007955\t9.792482\n8.670506\t10.782931\n10.386414\t9.956162\n10.104761\t10.123044\n8.079502\t8.304075\n9.945424\t11.855409\n8.642497\t9.998066\n9.349722\t8.690328\n9.034991\t8.826490\n8.738746\t7.518464\n8.919532\t9.740312\n9.464136\t10.444588\n10.710057\t12.666857\n10.042007\t10.532091\n8.447996\t7.426363\n9.509351\t9.030516\n11.946359\t10.553075\n9.981617\t9.912651\n9.853876\t9.632967\n10.560648\t11.881714\n8.370952\t9.989491\n8.323209\t10.102529\n9.828359\t11.702462\n8.515623\t8.426754\n9.004363\t9.628036\n10.529847\t10.458031\n10.028765\t10.624880\n9.448114\t9.313227\n8.332617\t7.382295\n8.323006\t8.276608\n7.740771\t8.799750\n8.379615\t8.146192\n8.340764\t9.184458\n9.863614\t8.254694\n9.969563\t9.405134\n9.164394\t9.182127\n10.622098\t9.722592\n9.592072\t10.029446\n8.212027\t7.477366\n9.080225\t8.244448\n8.555774\t7.842325\n9.958046\t9.696221\n8.972573\t9.797128\n9.213223\t7.128437\n8.737239\t9.385138\n10.333907\t10.994856\n8.797511\t8.643075\n11.044848\t9.623160\n8.539260\t9.097113\n11.582163\t11.884333\n7.863848\t7.176199\n6.218103\t5.283562\n9.120602\t7.250190\n9.001166\t9.635203\n8.081476\t8.844224\n9.369802\t8.230911\n8.768925\t8.666987\n9.841098\t8.543896\n10.451522\t9.549511\n9.755402\t9.117522\n7.988961\t6.869854\n8.872507\t9.787118\n10.363980\t10.716608\n6.315671\t5.765953\n9.638879\t9.202355\n8.588126\t8.037966\n8.947408\t9.144386\n9.051130\t7.195132\n9.321709\t8.380668\n10.146531\t9.754745\n9.843373\t8.891437\n9.213148\t11.700632\n7.630078\t7.294753\n8.093088\t7.967590\n7.488915\t6.090652\n8.126036\t8.586472\n8.760350\t7.268987\n10.201347\t9.141013\n7.838208\t7.307700\n6.155653\t5.563997\n7.767841\t6.254528\n8.425656\t8.615832\n10.362168\t10.886815\n10.180024\t10.378934\n9.794665\t10.047812\n9.970394\t9.668279\n7.030217\t7.060471\n9.275414\t9.095738\n10.314911\t10.456539\n9.259774\t8.204851\n10.023919\t9.558307\n8.887540\t9.866704\n9.851608\t9.410989\n8.710882\t7.268012\n9.017007\t10.217673\n7.976369\t9.000979\n8.738332\t8.664734\n8.344510\t8.977600\n8.959613\t12.324240\n9.169982\t8.624635\n7.487451\t8.154859\n8.706316\t7.719455\n9.564832\t8.940403\n8.327775\t9.044509\n9.734032\t10.195255\n8.021343\t6.445092\n9.081048\t11.024397\n7.626651\t6.549263\n10.725858\t8.575374\n8.731381\t8.307788\n10.394237\t10.596874\n7.029311\t7.658832\n9.517907\t7.509904\n10.394064\t10.060898\n10.752500\t9.431601\n9.692431\t10.332130\n9.651897\t7.876862\n8.592329\t10.096837\n10.212801\t10.827496\n9.045043\t9.265524\n8.901643\t8.036115\n10.794525\t9.318830\n11.040915\t12.021746\n8.390836\t9.672469\n9.840166\t11.226568\n10.806810\t12.205633\n8.924285\t10.934056\n8.411251\t8.289672\n7.808891\t9.663290\n9.733437\t8.486958\n8.300026\t7.477374\n8.221756\t10.278308\n9.096867\t9.619677\n9.410116\t9.289188\n10.097176\t9.768470\n9.387954\t8.844855\n9.376134\t7.704630\n8.231599\t9.101203\n9.910738\t10.694855\n8.645689\t7.764589\n8.090245\t7.109596\n9.253483\t9.813672\n9.331546\t8.039386\n9.843256\t10.208792\n9.713131\t9.247665\n9.259369\t10.704622\n10.243948\t9.695883\n6.396262\t6.456390\n8.936289\t8.703871\n8.750846\t9.347273\n6.497155\t4.130251\n9.516552\t10.164848\n9.125766\t8.858775\n8.374387\t7.300114\n8.132816\t7.621107\n10.099505\t9.159134\n9.356477\t6.869999\n8.112934\t7.587547\n7.265396\t6.987031\n11.950505\t13.715109\n10.745959\t10.822171\n8.893270\t7.887332\n6.003473\t4.960219\n7.498851\t6.451334\n10.162072\t9.935954\n8.732617\t9.177679\n9.300827\t9.952360\n11.908436\t12.256801\n9.371215\t9.188645\n9.943640\t9.245037\n7.386450\t7.046819\n8.410374\t8.293218\n7.830419\t6.440253\n8.263140\t8.279446\n11.448164\t12.192363\n8.216533\t9.186628\n9.316128\t10.046697\n8.156927\t6.834792\n9.951421\t11.240598\n9.059607\t8.458446\n10.476339\t10.560461\n7.548200\t7.227127\n9.432204\t7.236705\n9.402750\t9.126413\n11.188095\t13.853426\n9.520201\t11.028131\n8.884154\t9.764071\n8.961105\t8.833117\n8.549663\t8.865765\n10.111708\t10.515462\n9.024761\t9.169368\n7.904149\t8.048756\n9.240995\t7.796142\n8.126538\t6.116125\n7.442148\t7.931335\n9.486821\t10.091359\n9.834289\t11.694720\n9.009714\t11.599170\n9.761314\t11.344083\n6.993941\t6.562988\n8.659524\t8.410107\n7.685363\t8.097297\n7.793217\t6.519109\n8.883454\t9.257347\n8.781821\t9.231980\n7.946281\t7.658978\n8.523959\t10.646480\n9.031525\t8.649648\n8.317140\t7.758978\n9.192417\t11.151218\n8.408486\t8.282182\n10.327702\t11.459048\n8.389687\t8.548727\n8.642250\t7.056870\n8.833447\t9.267638\n8.805261\t8.320281\n9.726211\t9.095997\n8.477631\t9.507530\n9.738838\t9.652110\n8.272108\t7.582696\n9.258089\t8.495931\n8.334144\t8.810766\n8.150904\t6.486032\n7.259669\t7.270156\n11.034180\t11.519954\n10.705432\t10.642527\n8.388814\t7.159137\n8.559369\t7.846284\n7.187988\t6.519313\n8.811453\t7.765900\n8.492762\t7.992941\n8.739752\t8.502909\n10.150752\t10.420295\n7.062378\t5.365289\n8.448195\t7.480000\n10.224333\t11.592750\n9.533795\t9.212845\n9.519492\t7.690501\n9.661847\t10.376189\n7.963877\t8.597193\n10.184486\t9.136709\n8.505234\t9.159210\n8.187646\t8.518690\n9.167590\t9.405917\n8.612162\t8.518755\n10.970868\t10.392229\n9.603649\t9.141095\n9.704263\t8.830178\n9.657506\t8.132449\n9.337882\t11.045306\n9.521722\t9.537764\n8.954197\t8.728179\n8.635658\t10.352662\n8.910816\t9.020317\n9.900933\t9.392002\n10.247105\t8.289649\n9.571690\t8.171237\n7.388627\t7.668071\n8.354008\t10.074590\n9.775598\t8.835696\n8.768913\t7.983604\n8.330199\t8.474098\n8.169356\t9.361172\n10.346522\t10.086434\n7.976144\t9.266702\n8.429648\t7.865824\n11.261674\t11.788587\n10.051066\t10.112425\n8.954626\t9.789343\n8.382220\t8.121012\n9.820642\t9.426441\n8.125950\t9.695087\n8.646465\t7.291808\n8.190202\t8.003737\n8.773887\t7.306175\n8.731000\t10.300436\n9.163098\t7.816769\n9.456346\t9.223922\n9.645180\t9.324053\n8.835060\t8.966915\n9.325950\t10.943248\n9.941912\t9.548535\n9.282799\t10.119488\n9.567591\t9.462164\n8.529019\t9.768001\n9.314824\t10.153727\n8.264439\t8.273860\n8.307262\t8.214036\n9.122041\t8.657861\n8.404258\t8.389365\n7.828355\t8.419433\n9.803180\t10.108286\n8.662439\t8.581953\n8.883265\t8.978377\n8.012330\t8.262451\n9.420258\t8.974878\n7.015415\t6.365940\n9.888832\t11.163036\n9.677549\t10.346431\n8.410158\t7.912899\n9.464147\t10.762900\n7.067227\t7.035717\n9.320923\t10.583089\n9.056917\t8.771241\n8.110004\t8.387789\n10.310021\t10.970014\n8.211185\t8.809627\n8.942883\t8.840746\n9.479958\t8.328700\n8.973982\t8.702291\n8.519257\t8.764855\n9.424556\t8.956911\n7.222919\t8.177787\n8.257007\t9.700619\n9.778795\t9.296134\n8.028806\t8.575974\n9.886464\t9.965076\n9.090552\t6.978930\n9.605548\t10.256751\n9.959004\t9.610229\n8.308701\t9.509124\n7.748293\t9.685933\n8.311108\t9.428114\n9.697068\t10.217956\n9.582991\t9.478773\n9.167265\t10.198412\n10.329753\t10.406602\n8.908819\t7.428789\n10.072908\t10.393294\n7.992905\t9.226629\n8.907696\t7.269366\n8.421948\t9.342968\n7.481399\t7.225033\n10.358408\t10.166130\n8.786556\t10.279943\n9.658701\t11.379367\n10.167807\t9.417552\n8.653449\t8.656681\n8.020304\t8.671270\n8.364348\t10.004068\n9.119183\t9.788199\n8.405504\t9.740580\n11.020930\t11.904350\n9.755232\t9.515713\n10.059542\t9.589748\n8.727131\t9.777998\n7.666182\t6.028642\n8.870733\t8.367501\n9.340446\t7.707269\n9.919283\t10.796813\n7.905837\t8.326034\n10.181187\t10.089865\n8.797328\t8.981988\n8.466272\t7.765032\n10.335914\t12.620539\n9.365003\t8.609115\n8.011017\t7.249489\n10.923993\t13.901513\n7.074631\t7.558720\n9.824598\t8.851297\n8.861026\t8.370857\n10.127296\t10.861535\n10.548377\t10.855695\n8.880470\t7.948761\n8.901619\t9.674705\n7.813710\t9.246912\n10.128808\t10.560668\n11.096699\t10.911644\n8.551471\t6.871514\n8.907241\t8.677815\n10.571647\t10.294838\n8.815314\t8.810725\n8.453396\t8.339296\n9.594819\t11.487580\n10.714211\t9.628908\n7.428788\t7.712869\n10.892119\t12.747752\n9.024071\t11.112692\n7.803375\t7.847038\n8.521558\t8.881848\n9.742818\t11.520203\n9.832836\t9.180396\n8.703132\t10.028498\n9.905029\t11.347606\n10.037536\t8.882688\n8.629995\t8.392863\n9.583497\t9.219663\n8.781687\t9.650598\n9.344119\t9.537024\n10.407510\t9.223929\n7.244488\t6.559021\n10.643616\t10.288383\n8.757557\t6.947901\n10.784590\t11.233350\n10.028427\t11.330033\n7.968361\t6.830308\n8.925954\t8.539113\n7.738692\t7.114987\n8.192398\t8.352016\n10.412017\t12.431122\n8.208801\t5.777678\n7.820077\t7.790720\n9.542754\t11.542541\n6.817938\t7.429229\n7.365218\t7.956797\n9.274391\t7.932700\n9.546475\t8.803412\n7.471734\t6.797870\n8.016969\t7.848070\n8.852701\t8.458114\n8.215012\t8.468330\n6.975507\t6.846980\n9.435134\t10.609700\n9.228075\t9.342622\n8.388410\t7.637856\n7.111456\t9.289163\n9.403508\t8.482654\n9.133894\t8.343575\n10.670801\t9.750821\n9.983542\t10.074537\n10.012865\t8.537017\n8.929895\t8.951909\n7.666951\t7.473615\n9.493839\t7.821783\n8.894081\t7.059413\n9.593382\t9.859732\n9.126847\t8.395700\n9.532945\t9.850696\n9.459384\t9.384213\n8.982743\t8.217062\n10.107798\t8.790772\n10.563574\t9.044890\n8.278963\t9.518790\n8.734960\t10.494129\n9.597940\t9.530895\n10.025478\t9.508270\n10.335922\t10.974063\n8.404390\t8.146748\n7.108699\t6.038469\n8.873951\t7.474227\n8.731459\t8.154455\n8.795146\t7.534687\n6.407165\t6.810352\n9.979312\t10.287430\n8.786715\t8.396736\n10.753339\t10.360567\n10.508031\t10.321976\n10.636925\t10.193797\n10.614322\t11.215420\n8.916411\t8.965286\n8.112756\t8.304769\n10.833109\t10.497542\n8.319758\t9.727691\n9.945336\t11.820097\n10.150461\t9.914715\n10.185024\t10.388722\n9.793569\t9.079955\n10.590128\t11.811596\n8.505584\t6.884282\n10.461428\t10.745439\n8.755781\t9.418427\n7.488249\t7.172072\n10.238905\t10.428659\n9.887827\t10.427821\n8.529971\t8.838217\n8.375208\t10.242837\n8.901724\t8.398304\n8.607694\t9.173198\n8.691369\t9.964261\n9.584578\t9.641546\n10.265792\t11.405078\n7.592968\t6.683355\n8.692791\t9.389031\n7.589852\t6.005793\n10.550386\t11.736584\n8.578351\t7.227055\n7.526931\t6.875134\n8.577081\t9.877115\n9.272136\t11.050928\n10.300809\t10.653059\n8.642013\t9.006681\n9.720491\t10.265202\n9.029005\t9.646928\n8.736201\t7.975603\n8.672886\t9.070759\n8.370633\t8.412170\n9.483776\t9.183341\n6.790842\t7.594992\n9.842146\t10.156810\n9.563336\t7.962532\n8.724669\t9.870732\n9.012145\t9.171326\n9.116948\t9.791167\n6.219094\t7.988420\n9.468422\t8.359975\n8.825231\t8.475208\n9.572224\t9.696428\n9.609128\t8.488175\n9.428590\t10.468998\n8.293266\t8.617701\n9.423584\t10.355688\n9.240796\t9.517228\n10.915423\t13.026252\n10.854684\t11.130866\n9.226816\t9.391796\n9.580264\t10.359235\n7.289907\t6.898208\n9.338857\t10.374025\n9.523176\t11.332190\n10.162233\t10.357396\n8.873930\t9.207398\n8.607259\t7.794804\n8.852325\t8.215797\n8.077272\t6.501042\n8.169273\t8.269613\n6.806421\t7.544423\n8.793151\t9.691549\n11.640981\t11.365702\n9.544082\t11.576545\n9.009266\t9.605596\n9.726552\t9.426719\n9.495888\t10.626624\n8.683982\t9.337864\n8.322105\t8.631099\n8.887895\t8.644931\n8.662659\t11.373025\n9.263321\t7.536016\n7.802624\t7.171625\n8.773183\t8.561565\n8.730443\t10.197596\n8.942915\t7.758383\n8.057618\t8.774996\n8.112081\t8.202349\n10.378884\t12.103755\n9.248876\t8.637249\n9.739599\t9.708576\n8.126345\t8.278487\n8.894788\t7.966117\n9.683165\t9.019221\n10.886957\t12.053843\n9.668852\t10.902132\n7.486692\t6.471138\n8.794850\t9.173609\n8.835915\t8.296727\n9.443984\t11.375344\n8.696621\t6.434580\n9.645560\t9.233722\n9.623857\t7.915590\n10.840632\t12.620268\n7.298135\t7.356141\n9.639644\t8.902389\n9.849802\t7.682624\n10.609964\t10.259615\n9.768229\t11.382811\n7.646351\t7.571849\n10.230300\t9.470859\n8.224402\t8.496866\n6.879671\t8.393648\n7.976247\t8.667221\n9.183268\t8.694550\n11.471853\t12.786280\n10.428349\t10.615726\n8.090828\t5.902504\n9.738627\t8.485792\n8.139709\t8.396333\n9.508055\t8.990529\n8.857260\t8.497732\n8.902558\t7.014433\n9.660607\t11.040833\n8.772221\t10.512150\n11.020038\t9.354134\n7.918527\t7.742062\n7.630835\t7.756260\n11.043272\t11.041613\n9.299376\t8.674157\n9.795087\t8.431837\n9.415683\t8.312101\n7.942037\t6.942913\n9.724790\t11.766496\n10.222032\t11.550876\n8.894163\t8.306020\n8.394309\t8.070420\n9.012776\t6.880548\n9.661093\t10.138921\n9.896472\t9.762372\n9.135628\t8.759928\n8.762656\t10.306028\n8.602473\t8.861956\n10.085297\t10.464774\n10.644983\t10.945767\n9.034571\t8.391668\n8.602920\t8.501944\n8.224766\t7.402758\n8.755050\t9.431085\n9.669937\t8.641049\n10.693530\t10.287124\n9.462806\t7.611153\n9.287707\t10.082363\n10.941260\t10.783728\n9.263080\t7.913328\n10.167111\t10.225338\n8.783830\t9.465345\n8.958624\t8.662136\n9.841649\t9.926781\n7.205691\t6.790638\n8.629089\t9.135461\n7.469440\t8.450442\n8.179133\t7.790434\n8.083984\t7.875520\n9.271300\t8.135359\n8.652349\t8.254397\n7.983920\t6.609684\n7.836860\t9.785238\n7.418535\t7.011256\n8.458288\t10.095364\n9.387605\t9.726911\n8.663951\t8.206705\n10.146507\t11.698577\n8.937103\t10.990924\n11.218687\t11.141945\n8.363142\t9.106936\n7.877643\t7.122922\n9.620978\t9.905689\n9.509649\t10.773209\n6.748743\t6.705385\n9.300919\t8.085029\n9.332257\t9.818791\n7.898610\t8.366643\n9.841914\t9.480675\n6.920484\t8.959501\n8.544713\t9.563136\n8.162266\t6.715277\n8.659552\t9.282008\n10.673398\t13.174824\n9.024000\t10.379238\n8.183292\t6.647572\n10.544919\t10.649602\n7.201266\t6.529605\n9.557407\t11.096821\n8.304605\t6.940929\n9.742855\t9.920897\n10.024587\t9.645222\n10.002296\t9.998940\n8.965876\t8.665419\n7.823136\t6.949572\n8.125088\t7.654065\n6.569589\t6.046863\n10.195497\t8.689129\n11.730011\t10.374221\n8.739105\t7.457571\n9.820059\t10.278526\n9.547456\t10.398198\n8.375072\t8.416302\n8.889533\t8.308929\n8.861201\t9.290408\n12.677687\t12.788463\n9.100735\t8.620537\n7.728350\t6.328219\n7.955373\t8.355028\n8.733352\t8.645414\n10.257527\t11.191813\n9.246413\t9.497014\n9.745302\t9.642035\n7.785652\t8.147621\n7.431673\t8.566399\n8.654384\t8.466701\n8.475392\t6.744677\n9.968440\t10.765192\n10.163616\t10.806963\n10.238135\t10.036636\n9.902889\t10.746730\n9.523850\t8.749708\n9.214363\t9.149178\n9.266040\t10.841502\n8.494292\t7.770942\n10.821158\t10.410192\n8.645888\t7.970308\n9.885204\t10.098080\n9.084990\t10.886349\n9.277874\t8.871449\n8.135131\t7.137064\n7.917379\t9.080522\n9.685586\t8.822850\n8.558141\t7.848112\n9.502917\t10.061255\n6.409004\t5.164774\n10.149235\t10.579951\n7.847304\t8.411351\n8.846930\t6.819939\n8.675153\t9.411147\n9.476276\t9.061508\n11.099184\t10.644263\n8.792411\t10.379405\n8.400418\t7.072706\n8.555713\t7.923805\n8.024763\t8.426993\n8.642696\t10.453412\n7.906117\t7.920408\n8.793393\t9.722878\n8.280364\t7.669854\n9.387766\t9.706245\n9.626853\t10.762499\n10.163631\t10.919007\n9.375543\t11.513524\n9.309440\t8.575699\n10.055329\t10.297255\n8.706241\t9.097172\n10.032934\t11.951897\n10.812974\t11.311435\n10.352603\t10.819865\n8.276870\t9.055403\n8.397389\t7.944434\n9.371741\t10.395790\n10.825710\t10.144099\n9.158483\t11.385382\n10.658639\t11.389856\n8.091762\t6.631039\n10.734892\t10.054598\n11.535880\t11.604912\n9.799077\t11.371677\n8.478725\t9.078455\n9.399902\t8.947744\n7.305377\t8.144973\n7.613377\t6.668798\n10.681308\t10.830845\n9.973855\t10.004133\n9.369918\t7.855433\n8.838223\t7.429033\n9.521831\t10.623930\n9.724419\t10.447452\n8.890224\t9.275923\n9.932763\t11.589953\n10.839337\t9.051250\n8.497708\t7.521701\n8.440236\t8.705670\n9.063566\t9.755744\n8.449647\t8.929485\n8.554576\t8.063231\n10.348606\t10.550718\n5.985254\t5.186844\n9.931937\t10.175582\n9.854922\t9.201393\n9.114580\t9.134215\n10.334899\t8.543604\n"
  },
  {
    "path": "README.md",
    "content": "该分支主要存放的是个人的MachineLearning 以及DeepLearning代码以及数据\n\n后续将添加 Caffe model.\n\n更多机器学习深度学习博客请关注CSDN博客：[LiuLongpo](http://blog.csdn.net/llp1992)\n"
  },
  {
    "path": "bikMeans/README.md",
    "content": "博客链接：http://blog.csdn.net/llp1992/article/details/45096063\n\n更多机器学习深度学习博客请关注CSDN博客：[LiuLongpo](http://blog.csdn.net/llp1992)\n"
  },
  {
    "path": "bikMeans/bikMeans.m",
    "content": "function bikMeans\n%%\nclc\nclear\nclose all\n%%\nbiK = 4;\nbiDataSet = load('testSet.txt');\n[row,col] = size(biDataSet);\n% 存储质心矩阵\nbiCentSet = zeros(biK,col);\n% 初始化设定cluster数量为1\nnumCluster = 1;\n%第一列存储每个点被分配的质心，第二列存储点到质心的距离\nbiClusterAssume = zeros(row,2);\n%初始化质心\nbiCentSet(1,:) = mean(biDataSet);\nfor i = 1:row\n    biClusterAssume(i,1) = numCluster;\n    biClusterAssume(i,2) = distEclud(biDataSet(i,:),biCentSet(1,:));\nend\nwhile numCluster < biK\n    minSSE = 10000;\n    %寻找对哪个cluster进行划分最好，也就是寻找SSE最小的那个cluster\n    for j = 1:numCluster\n        curCluster = biDataSet(find(biClusterAssume(:,1) == j),:);\n        [spiltCentSet,spiltClusterAssume] = kMeans(curCluster,2);\n        spiltSSE = sum(spiltClusterAssume(:,2));\n        noSpiltSSE = sum(biClusterAssume(find(biClusterAssume(:,1)~=j),2));\n        curSSE = spiltSSE + noSpiltSSE;\n        fprintf('第%d个cluster被划分后的误差为：%f \\n' , [j, curSSE])\n        if (curSSE < minSSE)\n            minSSE = curSSE;\n            bestClusterToSpilt = j;\n            bestClusterAssume = spiltClusterAssume;\n            bestCentSet = spiltCentSet;\n        end\n    end\n\n     %更新cluster的数目  \n    numCluster = numCluster + 1;\n    % 必须先更新2的为新的类，再更新1的为原来的类，不然的话，当对第二个cluster进行划分的时候，就会被全部分为同一个类\n    bestClusterAssume(find(bestClusterAssume(:,1) == 2),1) = numCluster;\n    bestClusterAssume(find(bestClusterAssume(:,1) == 1),1) = bestClusterToSpilt;\n\n    \n    % 更新和添加质心坐标  第一行为更新质心，第二行为添加质心\n    biCentSet(bestClusterToSpilt,:) = bestCentSet(1,:);\n    biCentSet(numCluster,:) = bestCentSet(2,:);\n\n    % 更新被划分的cluster的每个点的质心分配以及误差\n    biClusterAssume(find(biClusterAssume(:,1) == bestClusterToSpilt),:) = bestClusterAssume;\nend\n\nfigure\n%scatter(dataSet(:,1),dataSet(:,2),5)\nfor i = 1:biK\n    pointCluster = find(biClusterAssume(:,1) == i);\n    scatter(biDataSet(pointCluster,1),biDataSet(pointCluster,2),5)\n    hold on\nend\n%hold on\nscatter(biCentSet(:,1),biCentSet(:,2),300,'+')\nhold off\nbiCentSet\nend\n\n% 计算欧式距离\nfunction dist = distEclud(vecA,vecB)\n    dist  = sum(power((vecA-vecB),2));\nend\n\n% K-means算法\nfunction [centSet,clusterAssment] = kMeans(dataSet,K)\n\n[row,col] = size(dataSet);\n% 存储质心矩阵\ncentSet = zeros(K,col);\n% 随机初始化质心\nfor i= 1:col\n    minV = min(dataSet(:,i));\n    if isempty(minV)\n        break;\n    end\n    rangV = max(dataSet(:,i)) - minV;\n    centSet(:,i) = bsxfun(@plus,minV,rangV*rand(K,1));\nend\n\n% 用于存储每个点被分配的cluster以及到质心的距离\nclusterAssment = zeros(row,2);\nclusterChange = true;\nwhile clusterChange\n    clusterChange = false;\n    % 计算每个点应该被分配的cluster\n    for i = 1:row\n        % 这部分可能可以优化\n        minDist = 10000;\n        minIndex = 0;\n        for j = 1:K\n            distCal = distEclud(dataSet(i,:) , centSet(j,:));\n            if (distCal < minDist)\n                minDist = distCal;\n                minIndex = j;\n            end\n        end\n        if minIndex ~= clusterAssment(i,1)            \n            clusterChange = true;\n        end\n        clusterAssment(i,1) = minIndex;\n        clusterAssment(i,2) = minDist;\n    end\n    \n    % 更新每个cluster 的质心\n    for j = 1:K\n        simpleCluster = find(clusterAssment(:,1) == j);\n        centSet(j,:) = mean(dataSet(simpleCluster',:));\n    end\nend\nend\n"
  },
  {
    "path": "bikMeans/testSet.txt",
    "content": "1.658985\t4.285136\n-3.453687\t3.424321\n4.838138\t-1.151539\n-5.379713\t-3.362104\n0.972564\t2.924086\n-3.567919\t1.531611\n0.450614\t-3.302219\n-3.487105\t-1.724432\n2.668759\t1.594842\n-3.156485\t3.191137\n3.165506\t-3.999838\n-2.786837\t-3.099354\n4.208187\t2.984927\n-2.123337\t2.943366\n0.704199\t-0.479481\n-0.392370\t-3.963704\n2.831667\t1.574018\n-0.790153\t3.343144\n2.943496\t-3.357075\n-3.195883\t-2.283926\n2.336445\t2.875106\n-1.786345\t2.554248\n2.190101\t-1.906020\n-3.403367\t-2.778288\n1.778124\t3.880832\n-1.688346\t2.230267\n2.592976\t-2.054368\n-4.007257\t-3.207066\n2.257734\t3.387564\n-2.679011\t0.785119\n0.939512\t-4.023563\n-3.674424\t-2.261084\n2.046259\t2.735279\n-3.189470\t1.780269\n4.372646\t-0.822248\n-2.579316\t-3.497576\n1.889034\t5.190400\n-0.798747\t2.185588\n2.836520\t-2.658556\n-3.837877\t-3.253815\n2.096701\t3.886007\n-2.709034\t2.923887\n3.367037\t-3.184789\n-2.121479\t-4.232586\n2.329546\t3.179764\n-3.284816\t3.273099\n3.091414\t-3.815232\n-3.762093\t-2.432191\n3.542056\t2.778832\n-1.736822\t4.241041\n2.127073\t-2.983680\n-4.323818\t-3.938116\n3.792121\t5.135768\n-4.786473\t3.358547\n2.624081\t-3.260715\n-4.009299\t-2.978115\n2.493525\t1.963710\n-2.513661\t2.642162\n1.864375\t-3.176309\n-3.171184\t-3.572452\n2.894220\t2.489128\n-2.562539\t2.884438\n3.491078\t-3.947487\n-2.565729\t-2.012114\n3.332948\t3.983102\n-1.616805\t3.573188\n2.280615\t-2.559444\n-2.651229\t-3.103198\n2.321395\t3.154987\n-1.685703\t2.939697\n3.031012\t-3.620252\n-4.599622\t-2.185829\n4.196223\t1.126677\n-2.133863\t3.093686\n4.668892\t-2.562705\n-2.793241\t-2.149706\n2.884105\t3.043438\n-2.967647\t2.848696\n4.479332\t-1.764772\n-4.905566\t-2.911070\n"
  },
  {
    "path": "kalmanFilter/KF.m",
    "content": "function [predData,dataX] = KF(dataZ)\n\n%%\n%\n%   Description : kalmanFiltering\n%   Author : Liulongpo\n%   Time：2015-4-29 16:42:34\n%\n%%\nZ = dataZ';\nlen = length(Z);\n%Z=(1:2:200); %观测值  汽车的位置  也就是我们要修改的量\nnoise=randn(1,len); %方差为1的高斯噪声\ndataX = zeros(2,len);\nZ=Z+noise;\nX=[Z(1) ; Z(2)-Z(1) ]; %初始状态  分别为 位置 和速度\nP=[1 0;0 1]; %状态协方差矩阵\nF=[1 1;0 1]; %状态转移矩阵\nQ=[0.0001,0;0 , 0.0001]; %状态转移协方差矩阵\nH=[1,0]; %观测矩阵\nR=1; %观测噪声协方差矩阵\n%figure;\n%hold on;\nfor i = 1:len\n%基于上一状态预测当前状态  \n% 2x1  2x1\nX_ = F*X;\n% 更新协方差  Q系统过程的协方差  这两个公式是对系统的预测\n%   2x1  2x1  1x2  2x2\nP_ = F*P*F'+Q;\n% 计算卡尔曼增益\nK = P_*H'/(H*P_*H'+R);\n% 得到当前状态的最优化估算值  增益乘以残差\nX = X_+K*(Z(i)-H*X_);\n%更新K状态的协方差\nP = (eye(2)-K*H)*P_;\ndataX(:,i) = [X(1);X(2)];\n%scatter(X(1), X(2),4); %画点，横轴表示位置，纵轴表示速度\nend\npredData = F*X;\nend\n"
  },
  {
    "path": "kalmanFilter/kalmanFiltering.m",
    "content": "function kalmanFiltering\n%%\nclc\nclose all\n\n%%\n%\n%   Description : kalmanFiltering\n%   Author : Liulongpo\n%   Time：2015-4-29 16:42:34\n%\n\n%%\nZ=(1:2:200); %观测值  汽车的位置  也就是我们要修改的量\nnoise=randn(1,100); %方差为1的高斯噪声\nZ=Z+noise;\nX=[0 ; 0 ]; %初始状态\nP=[1 0;0 1]; %状态协方差矩阵\nF=[1 1;0 1]; %状态转移矩阵\nQ=[0.0001,0;0 , 0.0001]; %状态转移协方差矩阵\nH=[1,0]; %观测矩阵\nR=1; %观测噪声协方差矩阵\nfigure;\nhold on;\nfor i = 1:100\n%基于上一状态预测当前状态  \nX_ = F*X;\n% 更新协方差  Q系统过程的协方差  这两个公式是对系统的预测\nP_ = F*P*F'+Q;\n% 计算卡尔曼增益\nK = P_*H'/(H*P_*H'+R);\n% 得到当前状态的最优化估算值  增益乘以残差\nX = X_+K*(Z(i)-H*X_);\n%更新K状态的协方差\nP = (eye(2)-K*H)*P_;\nscatter(X(1), X(2),4); %画点，横轴表示位置，纵轴表示速度\nend\n\nend\n"
  }
]