# Social Links. # Usage: `Key: permalink || icon` # Key is the link label showing to end users. # Value before `||` delimeter is the target permalink. # Value after `||` delimeter is the name of FontAwesome icon. If icon (with or without delimeter) is not specified, globe icon will be loaded. social: #GitHub: https://github.com/yourname || github E-Mail:mailto:yourname@gmail.com || envelope #Weibo: https://weibo.com/yourname || weibo #Google: https://plus.google.com/yourname || google #Twitter: https://twitter.com/yourname || twitter #FB Page: https://www.facebook.com/yourname || facebook #VK Group: https://vk.com/yourname || vk #StackOverflow: https://stackoverflow.com/yourname || stack-overflow #YouTube: https://youtube.com/yourname || youtube #Instagram: https://instagram.com/yourname || instagram #Skype: skype:yourname?call|chat || skype
valine: enable:true# When enable is set to be true, leancloud_visitors is recommended to be closed for the re-initialization problem within different leancloud adk version. appid:# your leancloud application appid appid:# your leancloud application appkey notify:false# mail notifier , https://github.com/xCss/Valine/wiki verify:false# Verification code placeholder: Just go go # comment box placeholder avatar: mm # gravatar style guest_info: nick,mail,link # custom comment header pageSize:10# pagination size visitor:true# leancloud-counter-security is not supported for now.
local_search: enable:true # if auto, trigger search by changing input # if manual, trigger search by pressing enter key or search button trigger: auto # show top n results per article, show all results by setting to -1 top_n_per_article:1 # unescape html strings to the readable one unescape:false
hexo new page "about" hexo new page "tags" hexo new page "categories"
-
-
之后source文件夹下就会出现三个这样的文件夹。
-
设置头像
打开thems/next/_config.yml,找到如下代码
-
1 2 3 4 5 6 7 8 9 10 11
avatar: # in theme directory(source/images): /images/avatar.gif # in site directory(source/uploads): /uploads/avatar.gif # You can also use other linking images. url:#/images/avatar.gif # If true, the avatar would be dispalyed in circle. rounded:false # The value of opacity should be choose from 0 to 1 to set the opacity of the avatar. opacity:1 # If true, the avatar would be rotated with the cursor. rotated:false
// 创建一个div元素 var div = document.createElement('div') var text = document.createTextNode('Hello Word') div.appendChild(text) // 最后还需要将节点加入到body中 document.body.appendChild(div)
echo "I am fine" 打印 I am fine echo "I am fine" > /root/test.txt 将 I am fine写入/root/test.txt中 echo "I am fine" >> /root/test.txt 将 I am fine追加到/root/test.txt末尾 grep "关键字" test.txt 在test.txt中查找含有关键字的行并打印 grep -v "关键字" test.txt 在test.txt中查找不含有关键字的行并打印 grep ^"关键字" test.txt 在test.txt中查找以关键字开头的行并打印 grep $"关键字" test.txt 在test.txt中查找以关键字结尾的行并打印
-
-
管道
1
ls -l | grep "关键字" > /root/test.txt 列出当前目录文件信息并交给grep过滤,最后写入/root/test.txt
下面我们来具体看一看当var b = Object.create(a)到底发生了什么,以下实在浏览器中的结果: 我们可以看到当var b = Object.create(a)实际上是把b的__proto__指向了a。当访问b.constructor时,实际上访问的是b.__proto__.__proto__.constructor。
-
五、实例与总结
1 2 3 4 5 6 7 8 9 10 11 12
functionPerson(name) { this.name = name } var person1 = new Person('sillywa')
将指定的 int 值分配给指定 int 型数组指定范围中的每个元素。同样的方法适用于所有的其他基本数据类型(Byte,short,Int等)。
-
1 2 3 4 5 6 7 8 9 10 11
int[] arrs = newint[5]; int a = 8; Arrays.fill(arrs,a); for (int item : arrs) { System.out.println(item); } // 8 // 8 // 8 // 8 // 8
-
-
3.public static boolean equals(long[] a, long[] a2)
-
如果两个指定的 long 型数组彼此相等,则返回 true。如果两个数组包含相同数量的元素,并且两个数组中的所有相应元素对都是相等的,则认为这两个数组是相等的。换句话说,如果两个数组以相同顺序包含相同的元素,则两个数组是相等的。同样的方法适用于所有的其他基本数据类型(Byte,short,Int等)。
int[] arrs = {1,2,3,4}; int a = 3; int b = 10; int index1 = Arrays.binarySearch(arrs, a); int index2 = Arrays.binarySearch(arrs, b); System.out.println(index1); System.out.println(index2);
// Person.java publicclassPerson{ int age = 10; String name = ""; voidsayAge(){ System.out.println("age:" + age); } }
-
-
一旦定义了一个类(在Java中你所做的全部工作就是定义类,产生那些类的对象,以及发送消息给这些对象),就可以在类中设置两种基本的元素:字段(有时也被称为数据成员)和方法(有时也被称为成员函数)。字段可以是任何类型的对象,可以通过其引用与其进行通信;也可以是基本类型的一种。如果字段是某个对象的引用,那么必须初始化该引用,以便使其与一个实际的对象(使用 new 来实现)相关联。
publicstaticvoidmain(String[] args){ // TODO Auto-generated method stub Son s = new Son("sillywa",23,"myfatyher"); System.out.println(s.getName()); System.out.println(s.getAge()); System.out.println(s.getFatherName()); }
}
-
-
*子类是不能继承父类的构造方法的,它只是隐式调用。如果父类的构造方法带有参数,则必须在子类的构造器中显式通过 super 关键字调用父类的构造方法并配有适当的参数。且必须在子类构造方法的第一行**
-
如果父类构造方法没有参数,则在子类的构造方法中不需要使用 super 关键字调用父类构造方法,系统会自动调用父类的无参构造方法。
publicstaticvoidmain(String[] args){ // TODO Auto-generated method stub Son s = new Son("sillywa",23,"myfatyher"); System.out.println(s.getName()); System.out.println(s.getAge()); System.out.println(s.getFatherName()); System.out.println(s.showDescription()); }
set fullName(newName: string) { if (newName && newName.length > fullNameMaxLength) { thrownewError("fullName has a max length of " + fullNameMaxLength); } this._fullName = newName; } }
let employee = new Employee(); employee.fullName = "Bob Smith"; if (employee.fullName) { console.log(employee.fullName); }}
首先随机选取 k 个对象,每个对象初始地代表了一个簇的平均值或中心,称为初始均值向量。对剩余的每个对象根据其与各个簇中心的距离,将它赋给最近的簇。然后重新计算每个簇的平均值得到新的均值向量。这个过程不断重复直到当前均值向量均保持不变。
-
算法描述:
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
从 D 中随机选择 k 个样本作为初始均值向量 repeat for j=1,2,…,m do 计算样本与各均值向量的距离 根据距离最近的均值向量确定样本的簇标记 将样本划入相应的簇 end for for i=1,2,…,k do 计算新的均值向量 if 两个均值向量不相同 then 更新均值向量 else 保持当前均值向量不变 end if end for until 当前均值向量均未更新
from matplotlib import pyplot as plt import random import math import copy classKmeans: __dataList = [] __k = 1 __kSample = [] __count = 0 def__init__(self,fileName,k): self.__dataList = self.__readData(fileName) self.__kSample = self.__getKSample(self.__dataList,k) self.__k = k
# 开始聚类 defstart(self): while(True): #计算每一个点与均值向量之间的距离,确定每一个点的类别 for index,item in enumerate(self.__dataList): self.__caculateType(self.__dataList[index],self.__kSample) # 保存均值向量的副本 copiedKSample = copy.deepcopy(self.__kSample) # 重新计算均值向量 self.__caculateKSampleByAverge(self.__kSample) # 如果两个均值向量相等,则循环停止 if copiedKSample == self.__kSample: break self.__count += 1 # 绘制散点图 defdrawPic(self): # 由于是二维坐标,因此只需x,y即可 x = [] y = [] c = [] for i in range(len(self.__dataList)): x.append(self.__dataList[i][0]) y.append(self.__dataList[i][1]) c.append(self.__dataList[i][2]) plt.title("dataset k=" + str(self.__k)) plt.scatter(x, y,c=c) plt.show() # 获取迭代次数 defgetCount(self): return self.__count
# 从文件中读取数据 def__readData(self,fileName): # 用存放数据的列表 dataList = [] try: fp = open(fileName,"r") fpList = fp.read().splitlines() # 将数据分割成二维列表 for item in fpList: dataList.append(item.split("\t")) # 将字符数据转化成浮点数 for i in range(len(dataList)): for j in range(len(dataList[i])): dataList[i][j] = float(dataList[i][j]) # 如果数据不包含类别信息 # for i in range(len(dataList)): # dataList[i].append(0) except IOError: print("error") #返回数据 return dataList # 获取初始k个点,也就是初始均值向量 def__getKSample(self,dataList, k): kSample = [] for i in range(k): #从所有数据集中随机选取k个数据 num = random.randint(0,len(dataList)-1) kSample.append(copy.deepcopy(dataList[num])) return kSample # 计算两个点之间的距离 def__getDistance(self,dataPoint1,dataPoint2): distance = 0 # 因为每一项数据的最后一位为类别,所以不参与计算距离 for i in range(len(dataPoint1)-1): distance = distance + pow(dataPoint1[i]-dataPoint2[i],2) distance = math.sqrt(distance) return distance # 根据每个样本距离均值向量的长短,计算每个样本所属的类别 def__caculateType(self,dataPoint,kSample): # 首先假设该样本距离第一个均值向量最近,即该样本属于第一类 minDistance = self.__getDistance(dataPoint,kSample[0]) # 记录该样本所属的类别 type = 0 # 计算该样本与每一个均值向量之间的距离 for index,item in enumerate(kSample): distance = self.__getDistance(dataPoint,item) # 如果该数据点距离该类别较小 if distance < minDistance: minDistance = distance # 更新最短距离 type = index # 更新样本点所属类别 # 修改数据点的类别 dataPoint[len(dataPoint)-1] = type
# 重新计算均值向量 def__caculateKSampleByAverge(self,kSample): # 对于每个均值向量,其下标为类别 for i in range(len(kSample)): typeI = [] # 遍历所有数据找到与其类别一致的数据点 for item in self.__dataList: if item[(len(item)-1)] == i: typeI.append(copy.deepcopy(item)) #求和 for j in range(1,len(typeI)): for k in range(len(typeI[j])): typeI[j][k] += typeI[j-1][k] # 求均值并更改每一类的聚类中心 for j in range(len(kSample[i])): kSample[i][j] = typeI[len(typeI)-1][j]/len(typeI)
a = Kmeans("f://machine_learning/shape_sets/D31.txt",3)
defgetKSample(dataList, k): kSample = [] # 首先随机选取一个数字为种子点 num = random.randint(0,len(dataList)-1) kSample.append(copy.deepcopy(dataList[num])) for i in range(k-1): # 用于保存距离的列表 D = [] # 用于存储概率的数组 P = [] # 对于每个点,我们都计算其和最近的一个“种子点”的距离D(x)^2并保存在一个数组里 for item1 in dataList: minDistance = getDistance(item1,kSample[0]) for item2 in kSample: distance = getDistance(item1,item2) if distance < minDistance: minDistance = distance
D.append(pow(minDistance,2)) # 循环结束之后得到储存距离的数组 sumD = 0 # 然后把距离加起来 for item in D: sumD = sumD + item # 计算每个样本被选为下一个聚类中心的概率 sumP = 0 for item in D: itemP = item/sumD sumP = sumP + itemP P.append(sumP) #随机产生0-1之间的数 rand = random.random() # 计算该数落在哪个区间 for index,item in enumerate(P): if rand < item: kSample.append(copy.deepcopy(dataList[index])) break return kSample
树(Tree)是由 n 个结点构成的有限集合。当 n=0 时,称为空树;对于任意一颗非空树,它具备以下特征:
-
-
树中有一个称为根的特殊节点,用 r 表示;
-
其余结点可分为 m 个互不相交的有限集 T1,T2,…,Tm,其中的每个集合本身又是一棵树,称为原来树的子树。
-
-
-
-
树的特点:
-
-
子树是不相交的;
-
除了根节点外,每个结点有且仅有一个父节点;
-
一颗 N 个结点的树有 N-1 条边。
-
-
树的一些基本术语:
-
1.结点的度(Degree):结点的子树个数 2.树的度:树的所有结点中最大的度数 3.叶结点(Leaf):度为 0 的结点 4.父节点(Parent):有子树的结点是其子树的根结点的父节点 5.子节点(Child):若 A 结点是 B 结点的父节点,则称 B 结点是 A 结点的子节点;子节点也称孩子结点 6.兄弟节点(Sibling):具有同一父节点的各节点彼此是兄弟节点 7.结点的层次(Level):规定根节点在 1 层,其它任一结点的层次是其父节点层数加1 7.树的深度(Depth):树中所有结点中的最大层次是这棵树的深度
如下给出了最大堆的插入操作算法。注意到如果新插入的 X 比原先堆中所有的元素都大,那么它将一直向上比较到根结点都不会停止。对于这种情况,我们可以加一个特殊判断,当 i 值取 1 时,直接跳出循环,但是这种程序不够优美。因此之前我们定义了一个“哨兵”,即事先知道堆中所有元素的取值范围,这样可以给 H->Data[0] 赋一个特殊的值 MAXDATA,这个值比堆中所有元素都要大,这样当 i 为 1 时 H->Data[i/2] < X 这个条件肯定不满足,跳出循环。
var bar = bind(foo, obj); var b = bar(3); // 2 3 console.log(b); // 5
-
-
ES5 中提供了 Function.prototype.bind 函数,它的用法如下:
-
1 2 3 4 5 6 7 8 9 10
unction foo(something) { console.log(this.a, something); returnthis.a + something; } var obj = { a: 2 }; var bar = foo.bind(obj); var b = bar(3); // 2 3 console.log(b); // 5
-
-
bind() 会返回一个硬编码的新函数,它会把你指定的参数设置为 this 的上下文并调用原始函数。
-
2.4 new绑定
在传统的面向对象的语言中,“构造函数”是类中的一些的特殊方法,使用 new 初始化类时会调用类中的构造函数。Javascript 中也有一个 new 操作符,但是 Javascript 中 new 的机制实际上和面向对象的语言完全不同。在 Javascript 中,构造函数只是一些使用 new 操作符时被调用的函数。它们并不属于某个类,也不会实例化一个类。
-
使用 new 来调用函数,或者说发生构造函数调用时,会自动执行下面的操作:
-
-
创建一个全新的对象。
-
这个对象会被执行 [[Prototype]] 连接。
-
这个新对象会被绑定到函数调用的 this。
-
如果函数没有返回其它对象,那么 new 表达式中的函数调用会自动返回这个新对象。
-
-
思考下面代码:
-
1 2 3 4 5
functionfoo(a) { this.a = a; } var bar = new foo(2); console.log(bar.a); // 2
-
-
使用 new 来调用 foo() 时,我们会构造一个新对象并把它绑定到 foo() 调用中的 this 上。 new 是最后一种可以影响函数调用时 this 绑定行为的方法,我们称之为 new 绑定。
-
3.判断 this
学习了上面四条规则,我们可以根据下面的顺序来判断 this 绑定的对象:
-
-
函数是否在 new 中调用(new 绑定)?如果是的话,this 绑定的是新创建的对象。
-
函数是否通过 call、apply 显示绑定或者硬绑定?如果是的话,this 绑定的是指定对象。
-
函数是否在某个上下文中调用(隐式绑定)?如果是的话,this 绑定的是那个上下文对象。
-
如果都不是,使用默认绑定。严格模式下绑定到 undefined,否则绑定到全局对象。
-
-
4.绑定例外
在某些场景下 this 的绑定行为会出乎意料,你认为应该应用其它绑定规则时,实际上应用的可能是默认绑定的规则。
-
4.1 被忽略的 this
如果把 null 或者 undefined 作为 this 的绑定对象传入 call、apply 或者 bind,这些值在调用时会被忽略,实际应用的是默认绑定的规则。
-
1 2 3 4 5
functionfoo() { console.log(this.a); } var a = 2; foo.call(null); //2
将堆一分为二,每一部分空间称为 semispace,然后采用复制的方式进行垃圾回收。在这两个 semispace 中,只有一个处于使用中,另一个处于闲置状态。处于使用中的空间称为 From 空间,处于闲置中的空间称为 To 空间。当我们在分配对象的时候,首先在 From 空间中进行分配。当进行垃圾回收的时候,检查 From 空间中的存活对象,将存活对象复制到 To 空间,而非存活对象的空间将会被释放。完成复制之后,From 空间变为 To 空间, To 空间变为 From 空间,即进行角色互换。
echo "I am fine" 打印 I am fine echo "I am fine" > /root/test.txt 将 I am fine写入/root/test.txt中 echo "I am fine" >> /root/test.txt 将 I am fine追加到/root/test.txt末尾 grep "关键字" test.txt 在test.txt中查找含有关键字的行并打印 grep -v "关键字" test.txt 在test.txt中查找不含有关键字的行并打印 grep ^"关键字" test.txt 在test.txt中查找以关键字开头的行并打印 grep $"关键字" test.txt 在test.txt中查找以关键字结尾的行并打印
-
-
管道
ls -l | grep "关键字" > /root/test.txt 列出当前目录文件信息并交给grep过滤,最后写入/root/test.txt
-]]>
-
- Linux
-
-
- Linux 命令
-
-
-
- Codestin Search App
- /2021/05/29/%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%961/
- 网站作为一种信息传递的媒介,在如今各类的 Web 项目中,图像资源的使用占比越来越大,因此我们应当注意图像资源的使用方式。如果网站中的图像资源未进行恰当的优化,当网站访问量较大时会产生很大的带宽挑战,同时也会造成大尺寸图像请求时间过长等问题。
-
将堆一分为二,每一部分空间称为 semispace,然后采用复制的方式进行垃圾回收。在这两个 semispace 中,只有一个处于使用中,另一个处于闲置状态。处于使用中的空间称为 From 空间,处于闲置中的空间称为 To 空间。当我们在分配对象的时候,首先在 From 空间中进行分配。当进行垃圾回收的时候,检查 From 空间中的存活对象,将存活对象复制到 To 空间,而非存活对象的空间将会被释放。完成复制之后,From 空间变为 To 空间, To 空间变为 From 空间,即进行角色互换。
var bar = bind(foo, obj); var b = bar(3); // 2 3 console.log(b); // 5
-
-
ES5 中提供了 Function.prototype.bind 函数,它的用法如下:
-
unction foo(something) { console.log(this.a, something); returnthis.a + something; } var obj = { a: 2 }; var bar = foo.bind(obj); var b = bar(3); // 2 3 console.log(b); // 5
-
-
bind() 会返回一个硬编码的新函数,它会把你指定的参数设置为 this 的上下文并调用原始函数。
-
2.4 new绑定
在传统的面向对象的语言中,“构造函数”是类中的一些的特殊方法,使用 new 初始化类时会调用类中的构造函数。Javascript 中也有一个 new 操作符,但是 Javascript 中 new 的机制实际上和面向对象的语言完全不同。在 Javascript 中,构造函数只是一些使用 new 操作符时被调用的函数。它们并不属于某个类,也不会实例化一个类。
-
使用 new 来调用函数,或者说发生构造函数调用时,会自动执行下面的操作:
-
-
创建一个全新的对象。
-
这个对象会被执行 [[Prototype]] 连接。
-
这个新对象会被绑定到函数调用的 this。
-
如果函数没有返回其它对象,那么 new 表达式中的函数调用会自动返回这个新对象。
-
-
思考下面代码:
-
functionfoo(a) { this.a = a; } var bar = new foo(2); console.log(bar.a); // 2
-
-
使用 new 来调用 foo() 时,我们会构造一个新对象并把它绑定到 foo() 调用中的 this 上。 new 是最后一种可以影响函数调用时 this 绑定行为的方法,我们称之为 new 绑定。
-
3.判断 this
学习了上面四条规则,我们可以根据下面的顺序来判断 this 绑定的对象:
-
-
函数是否在 new 中调用(new 绑定)?如果是的话,this 绑定的是新创建的对象。
-
函数是否通过 call、apply 显示绑定或者硬绑定?如果是的话,this 绑定的是指定对象。
-
函数是否在某个上下文中调用(隐式绑定)?如果是的话,this 绑定的是那个上下文对象。
-
如果都不是,使用默认绑定。严格模式下绑定到 undefined,否则绑定到全局对象。
-
-
4.绑定例外
在某些场景下 this 的绑定行为会出乎意料,你认为应该应用其它绑定规则时,实际上应用的可能是默认绑定的规则。
-
4.1 被忽略的 this
如果把 null 或者 undefined 作为 this 的绑定对象传入 call、apply 或者 bind,这些值在调用时会被忽略,实际应用的是默认绑定的规则。
-
functionfoo() { console.log(this.a); } var a = 2; foo.call(null); //2
如下给出了最大堆的插入操作算法。注意到如果新插入的 X 比原先堆中所有的元素都大,那么它将一直向上比较到根结点都不会停止。对于这种情况,我们可以加一个特殊判断,当 i 值取 1 时,直接跳出循环,但是这种程序不够优美。因此之前我们定义了一个“哨兵”,即事先知道堆中所有元素的取值范围,这样可以给 H->Data[0] 赋一个特殊的值 MAXDATA,这个值比堆中所有元素都要大,这样当 i 为 1 时 H->Data[i/2] < X 这个条件肯定不满足,跳出循环。
其余结点可分为 m 个互不相交的有限集 T1,T2,…,Tm,其中的每个集合本身又是一棵树,称为原来树的子树。
-
-
-
-
树的特点:
-
-
子树是不相交的;
-
除了根节点外,每个结点有且仅有一个父节点;
-
一颗 N 个结点的树有 N-1 条边。
-
-
树的一些基本术语:
-
1.结点的度(Degree):结点的子树个数 2.树的度:树的所有结点中最大的度数 3.叶结点(Leaf):度为 0 的结点 4.父节点(Parent):有子树的结点是其子树的根结点的父节点 5.子节点(Child):若 A 结点是 B 结点的父节点,则称 B 结点是 A 结点的子节点;子节点也称孩子结点 6.兄弟节点(Sibling):具有同一父节点的各节点彼此是兄弟节点 7.结点的层次(Level):规定根节点在 1 层,其它任一结点的层次是其父节点层数加1 7.树的深度(Depth):树中所有结点中的最大层次是这棵树的深度
首先随机选取 k 个对象,每个对象初始地代表了一个簇的平均值或中心,称为初始均值向量。对剩余的每个对象根据其与各个簇中心的距离,将它赋给最近的簇。然后重新计算每个簇的平均值得到新的均值向量。这个过程不断重复直到当前均值向量均保持不变。
-
算法描述:
-
从 D 中随机选择 k 个样本作为初始均值向量 repeat for j=1,2,…,m do 计算样本与各均值向量的距离 根据距离最近的均值向量确定样本的簇标记 将样本划入相应的簇 end for for i=1,2,…,k do 计算新的均值向量 if 两个均值向量不相同 then 更新均值向量 else 保持当前均值向量不变 end if end for until 当前均值向量均未更新
-
-
K-means 算法实现
from matplotlib import pyplot as plt import random import math import copy classKmeans: __dataList = [] __k = 1 __kSample = [] __count = 0 def__init__(self,fileName,k): self.__dataList = self.__readData(fileName) self.__kSample = self.__getKSample(self.__dataList,k) self.__k = k
# 开始聚类 defstart(self): while(True): #计算每一个点与均值向量之间的距离,确定每一个点的类别 for index,item in enumerate(self.__dataList): self.__caculateType(self.__dataList[index],self.__kSample) # 保存均值向量的副本 copiedKSample = copy.deepcopy(self.__kSample) # 重新计算均值向量 self.__caculateKSampleByAverge(self.__kSample) # 如果两个均值向量相等,则循环停止 if copiedKSample == self.__kSample: break self.__count += 1 # 绘制散点图 defdrawPic(self): # 由于是二维坐标,因此只需x,y即可 x = [] y = [] c = [] for i in range(len(self.__dataList)): x.append(self.__dataList[i][0]) y.append(self.__dataList[i][1]) c.append(self.__dataList[i][2]) plt.title("dataset k=" + str(self.__k)) plt.scatter(x, y,c=c) plt.show() # 获取迭代次数 defgetCount(self): return self.__count
# 从文件中读取数据 def__readData(self,fileName): # 用存放数据的列表 dataList = [] try: fp = open(fileName,"r") fpList = fp.read().splitlines() # 将数据分割成二维列表 for item in fpList: dataList.append(item.split("\t")) # 将字符数据转化成浮点数 for i in range(len(dataList)): for j in range(len(dataList[i])): dataList[i][j] = float(dataList[i][j]) # 如果数据不包含类别信息 # for i in range(len(dataList)): # dataList[i].append(0) except IOError: print("error") #返回数据 return dataList # 获取初始k个点,也就是初始均值向量 def__getKSample(self,dataList, k): kSample = [] for i in range(k): #从所有数据集中随机选取k个数据 num = random.randint(0,len(dataList)-1) kSample.append(copy.deepcopy(dataList[num])) return kSample # 计算两个点之间的距离 def__getDistance(self,dataPoint1,dataPoint2): distance = 0 # 因为每一项数据的最后一位为类别,所以不参与计算距离 for i in range(len(dataPoint1)-1): distance = distance + pow(dataPoint1[i]-dataPoint2[i],2) distance = math.sqrt(distance) return distance # 根据每个样本距离均值向量的长短,计算每个样本所属的类别 def__caculateType(self,dataPoint,kSample): # 首先假设该样本距离第一个均值向量最近,即该样本属于第一类 minDistance = self.__getDistance(dataPoint,kSample[0]) # 记录该样本所属的类别 type = 0 # 计算该样本与每一个均值向量之间的距离 for index,item in enumerate(kSample): distance = self.__getDistance(dataPoint,item) # 如果该数据点距离该类别较小 if distance < minDistance: minDistance = distance # 更新最短距离 type = index # 更新样本点所属类别 # 修改数据点的类别 dataPoint[len(dataPoint)-1] = type
# 重新计算均值向量 def__caculateKSampleByAverge(self,kSample): # 对于每个均值向量,其下标为类别 for i in range(len(kSample)): typeI = [] # 遍历所有数据找到与其类别一致的数据点 for item in self.__dataList: if item[(len(item)-1)] == i: typeI.append(copy.deepcopy(item)) #求和 for j in range(1,len(typeI)): for k in range(len(typeI[j])): typeI[j][k] += typeI[j-1][k] # 求均值并更改每一类的聚类中心 for j in range(len(kSample[i])): kSample[i][j] = typeI[len(typeI)-1][j]/len(typeI)
a = Kmeans("f://machine_learning/shape_sets/D31.txt",3)
defgetKSample(dataList, k): kSample = [] # 首先随机选取一个数字为种子点 num = random.randint(0,len(dataList)-1) kSample.append(copy.deepcopy(dataList[num])) for i in range(k-1): # 用于保存距离的列表 D = [] # 用于存储概率的数组 P = [] # 对于每个点,我们都计算其和最近的一个“种子点”的距离D(x)^2并保存在一个数组里 for item1 in dataList: minDistance = getDistance(item1,kSample[0]) for item2 in kSample: distance = getDistance(item1,item2) if distance < minDistance: minDistance = distance
D.append(pow(minDistance,2)) # 循环结束之后得到储存距离的数组 sumD = 0 # 然后把距离加起来 for item in D: sumD = sumD + item # 计算每个样本被选为下一个聚类中心的概率 sumP = 0 for item in D: itemP = item/sumD sumP = sumP + itemP P.append(sumP) #随机产生0-1之间的数 rand = random.random() # 计算该数落在哪个区间 for index,item in enumerate(P): if rand < item: kSample.append(copy.deepcopy(dataList[index])) break return kSample
set fullName(newName: string) { if (newName && newName.length > fullNameMaxLength) { thrownewError("fullName has a max length of " + fullNameMaxLength); } this._fullName = newName; } }
let employee = new Employee(); employee.fullName = "Bob Smith"; if (employee.fullName) { console.log(employee.fullName); }}
publicstaticvoidmain(String[] args){ // TODO Auto-generated method stub Son s = new Son("sillywa",23,"myfatyher"); System.out.println(s.getName()); System.out.println(s.getAge()); System.out.println(s.getFatherName()); }
}
-
-
*子类是不能继承父类的构造方法的,它只是隐式调用。如果父类的构造方法带有参数,则必须在子类的构造器中显式通过 super 关键字调用父类的构造方法并配有适当的参数。且必须在子类构造方法的第一行**
-
如果父类构造方法没有参数,则在子类的构造方法中不需要使用 super 关键字调用父类构造方法,系统会自动调用父类的无参构造方法。
publicstaticvoidmain(String[] args){ // TODO Auto-generated method stub Son s = new Son("sillywa",23,"myfatyher"); System.out.println(s.getName()); System.out.println(s.getAge()); System.out.println(s.getFatherName()); System.out.println(s.showDescription()); }
// Person.java publicclassPerson{ int age = 10; String name = ""; voidsayAge(){ System.out.println("age:" + age); } }
-
-
一旦定义了一个类(在Java中你所做的全部工作就是定义类,产生那些类的对象,以及发送消息给这些对象),就可以在类中设置两种基本的元素:字段(有时也被称为数据成员)和方法(有时也被称为成员函数)。字段可以是任何类型的对象,可以通过其引用与其进行通信;也可以是基本类型的一种。如果字段是某个对象的引用,那么必须初始化该引用,以便使其与一个实际的对象(使用 new 来实现)相关联。
将指定的 int 值分配给指定 int 型数组指定范围中的每个元素。同样的方法适用于所有的其他基本数据类型(Byte,short,Int等)。
-
int[] arrs = newint[5]; int a = 8; Arrays.fill(arrs,a); for (int item : arrs) { System.out.println(item); } // 8 // 8 // 8 // 8 // 8
-
-
3.public static boolean equals(long[] a, long[] a2)
-
如果两个指定的 long 型数组彼此相等,则返回 true。如果两个数组包含相同数量的元素,并且两个数组中的所有相应元素对都是相等的,则认为这两个数组是相等的。换句话说,如果两个数组以相同顺序包含相同的元素,则两个数组是相等的。同样的方法适用于所有的其他基本数据类型(Byte,short,Int等)。
int[] arrs = {1,2,3,4}; int a = 3; int b = 10; int index1 = Arrays.binarySearch(arrs, a); int index2 = Arrays.binarySearch(arrs, b); System.out.println(index1); System.out.println(index2);
// 创建一个div元素 var div = document.createElement('div') var text = document.createTextNode('Hello Word') div.appendChild(text) // 最后还需要将节点加入到body中 document.body.appendChild(div)
下面我们来具体看一看当var b = Object.create(a)到底发生了什么,以下实在浏览器中的结果: 我们可以看到当var b = Object.create(a)实际上是把b的__proto__指向了a。当访问b.constructor时,实际上访问的是b.__proto__.__proto__.constructor。
-
五、实例与总结
functionPerson(name) { this.name = name } var person1 = new Person('sillywa')
# Social Links. # Usage: `Key: permalink || icon` # Key is the link label showing to end users. # Value before `||` delimeter is the target permalink. # Value after `||` delimeter is the name of FontAwesome icon. If icon (with or without delimeter) is not specified, globe icon will be loaded. social: #GitHub: https://github.com/yourname || github E-Mail:mailto:yourname@gmail.com || envelope #Weibo: https://weibo.com/yourname || weibo #Google: https://plus.google.com/yourname || google #Twitter: https://twitter.com/yourname || twitter #FB Page: https://www.facebook.com/yourname || facebook #VK Group: https://vk.com/yourname || vk #StackOverflow: https://stackoverflow.com/yourname || stack-overflow #YouTube: https://youtube.com/yourname || youtube #Instagram: https://instagram.com/yourname || instagram #Skype: skype:yourname?call|chat || skype
valine: enable:true# When enable is set to be true, leancloud_visitors is recommended to be closed for the re-initialization problem within different leancloud adk version. appid:# your leancloud application appid appid:# your leancloud application appkey notify:false# mail notifier , https://github.com/xCss/Valine/wiki verify:false# Verification code placeholder: Just go go # comment box placeholder avatar: mm # gravatar style guest_info: nick,mail,link # custom comment header pageSize:10# pagination size visitor:true# leancloud-counter-security is not supported for now.
local_search: enable:true # if auto, trigger search by changing input # if manual, trigger search by pressing enter key or search button trigger: auto # show top n results per article, show all results by setting to -1 top_n_per_article:1 # unescape html strings to the readable one unescape:false
hexo new page "about" hexo new page "tags" hexo new page "categories"
-
-
之后source文件夹下就会出现三个这样的文件夹。
-
设置头像
打开thems/next/_config.yml,找到如下代码
-
avatar: # in theme directory(source/images): /images/avatar.gif # in site directory(source/uploads): /uploads/avatar.gif # You can also use other linking images. url:#/images/avatar.gif # If true, the avatar would be dispalyed in circle. rounded:false # The value of opacity should be choose from 0 to 1 to set the opacity of the avatar. opacity:1 # If true, the avatar would be rotated with the cursor. rotated:false