2014年4月26日星期六

Python basic

#size of array
len(array1)
array1.shape 
 
# transpose
array1.T
 
#assign value: 
chars = ['a', 'b', 'c']
 
#write to file
file = open("newfile.txt", "w")
file.write("\n".join(str(elem) for elem in array1)) #write array array1 to file
file.close() 
 
#read from file:
file = open('filename', 'r')
content = file.read()
content = file.readlines() 
 
#read lines with no '\n' 
lines = [line.strip() for line in open('filename')] 


#read data seperated with ' ' or '\n'
import numpy as np
data = np.genfromtxt("yourfile.dat",delimiter="\n")
 


Python模块学习 ---- random 随机数生成

分类: Python 11036人阅读 评论(4) 收藏 举报
目录(?)[+]
  Python中的random模块用于生成随机数。下面介绍一下random模块中最常用的几个函数。

random.random

random.random()用于生成一个0到1的随机符点数: 0 <= n < 1.0

random.uniform

random.uniform的函数原型为:random.uniform(a, b),用于生成一个指定范围内的随机符点数,两个参数其中一个是上限,一个是下限。如果a > b,则生成的随机数n: b <= n <= a。如果 a <b, 则 a <= n <= b。
[python] view plaincopy
  1. print random.uniform(10, 20)  
  2. print random.uniform(20, 10)  
  3. #---- 结果(不同机器上的结果不一样)  
  4. #18.7356606526  
  5. #12.5798298022  

random.randint

random.randint()的函数原型为:random.randint(a, b),用于生成一个指定范围内的整数。其中参数a是下限,参数b是上限,生成的随机数n: a <= n < b
[python] view plaincopy
  1. print random.randint(12, 20)  #生成的随机数n: 12 <= n < 20  
  2. print random.randint(20, 20)  #结果永远是20  
  3. #print random.randint(20, 10)  #该语句是错误的。下限必须小于上限。  

random.randrange

random.randrange的函数原型为:random.randrange([start], stop[, step]),从指定范围内,按指定基数递增的集合中 获取一个随机数。如:random.randrange(10, 100, 2),结果相当于从[10, 12, 14, 16, ... 96, 98]序列中获取一个随机数。random.randrange(10, 100, 2)在结果上与 random.choice(range(10, 100, 2) 等效。

random.choice

random.choice从序列中获取一个随机元素。其函数原型为:random.choice(sequence)。参数sequence表示一个有序类型。这里要说明 一下:sequence在python不是一种特定的类型,而是泛指一系列的类型。list, tuple, 字符串都属于sequence。有关sequence可以查看python手册数据模型这一章,也可以参考:http://www.17xie.com/read-37422.html 。下面是使用choice的一些例子:
[python] view plaincopy
  1. print random.choice("学习Python")   
  2. print random.choice(["JGood", "is", "a", "handsome", "boy"])  
  3. print random.choice(("Tuple", "List", "Dict"))  

random.shuffle

random.shuffle的函数原型为:random.shuffle(x[, random]),用于将一个列表中的元素打乱。如:
[python] view plaincopy
  1. p = ["Python", "is", "powerful", "simple", "and so on..."]  
  2. random.shuffle(p)  
  3. print p  
  4. #---- 结果(不同机器上的结果可能不一样。)  
  5. #['powerful', 'simple', 'is', 'Python', 'and so on...']  

random.sample

random.sample的函数原型为:random.sample(sequence, k),从指定序列中随机获取指定长度的片断。sample函数不会修改原有序列。
[python] view plaincopy
  1. list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]  
  2. slice = random.sample(list, 5)  #从list中随机获取5个元素,作为一个片断返回  
  3. print slice  
  4. print list #原有序列并没有改变。  
   上面这些方法是random模块中最常用的,在Python手册中,还介绍其他的方法。感兴趣的朋友可以通过查询Python手册了解更详细的信息。

OnEar-Kopfhörer

AKG K701

OnEar-Kopfhörer "Weiß" M o n s t e r Solo HD Beats by Dr. D r e Definition Onear-Kopfhörer


Rock music

Marshall Kopfhörer Major, black

2014年4月25日星期五

python list之append和extend的区别

1. 列表可包含任何数据类型的元素,单个列表中的元素无须全为同一类型。
2. append() 方法向列表的尾部添加一个新的元素。
3. 列表是以类的形式实现的。“创建”列表实际上是将一个类实例化。因此,列表有多种方法可以操作。extend() 方法只接受一个列表作为参数,并将该参数的每个元素都添加到原有的列表中。

extend的解释没看太明白,琢磨了一下

>>> myList = [1,2.0,'a']
>>> myList
[1, 2.0, 'a']
>>> myList.append('APP')
>>> myList
[1, 2.0, 'a', 'APP']
>>> myList.extend([123,'abc'])
>>> myList
[1, 2.0, 'a', 'APP', 123, 'abc']
>>> myList.append(1,2)
Traceback (most recent call last):
  File "<pyshell#69>", line 1, in <module>
    myList.append(1,2)
TypeError: append() takes exactly one argument (2 given)
>>> myList.extend([1],[2])
Traceback (most recent call last):
  File "<pyshell#70>", line 1, in <module>
    myList.extend([1],[2])
TypeError: extend() takes exactly one argument (2 given)
>>>

结果如下:
append和extend都仅只可以接收一个参数,
append 任意,甚至是tuple
extend 只能是一个列表,其实上面已经说清楚了,是自己没看明白。

------------------------------------------------------------------------
vstack 

np.vstack(([1,2,3],[4,5,6]))
array([[1, 2, 3],
       [4, 5, 6]])
>>> np.column_stack(([1,2,3],[4,5,6]))
array([[1, 4],
       [2, 5],
       [3, 6]])
>>> np.hstack(([1,2,3],[4,5,6]))
array([1, 2, 3, 4, 5, 6])
 

Illustration of PUF model

Script
#execution of python files
from PUFmodels import *
reload (PUFmodels); from PUFmodels import * 
test = XORArbPUF(10, 64, 'equal')
test.numXOR
test.calc_features(test.generate_challenge(4))
xorKnackertester(32, 2, 0.05, 0.01, 10, array([10000]), 'Test')

----------------------------------------------------------------------------
PUFmodels
# mathematic models of PUF
- linArbPUF
    ''' linArbPUF provides methods to simulate the behaviour of a standard
        Arbiter PUF (linear model)
       
        attributes:
        num_bits -- bit-length of the PUF
        delays -- runtime difference between the straight connections
            (first half) and crossed connection (second half) in every switch
        parameter -- parameter vector of the linear model (D. Lim)       
    '''
- XORArbPUF
    '''
       XOR of serveral independent PUFs
    '''

----------------------------------------------------------------------------
xorKnackertester
# attack of XOR-PUF
- xorKnackertester
  # just a interface to xorKnacker
- xorKnacker
model = prodLinearPredictor(bitzahl + 1, numxor)  # the prodLinearPredictor used for prediction
lesson = BasicTrainable(set, model, erf) # use this model for BasicTrainable

In class prodLinearPredictor(object): 
 self.indiv_linpredictor = [linearPredictor(dim, mean, stdev) for i in range(num_prod)]
self.indiv_linpredictor[predictor].shift_param([indiv_step]) # it actually uses shift_param of linearPredictor to change param step by step
So it comes to the basic function below:
##########################
    def shift_param(self, step):
        ''' change parameter by amount of step
       
        Keyword Arguments:
        step -- single element list of 1D array wth dimension as self.parameter
       
        Side Effects:
        changes the instance variable parameter
       
        Exeptions:
        DimensionError -- dimension of step and self.parameter do not match
        '''
        step = step[0]
        if step.shape != self.parameter.shape:
            raise DimensionError
        else: self.parameter += step
##########################
Execution test:
>xorKnackertester(32, 2, 0.05, 0.01, 10, array([10000]), 'Test')
10000
1 1.0001 0.5036
1 .) MCrate(train): 0.01 time since start: -0.337867975235
MCrate: (test) 0.0142 time since start: -0.344507932663

# self.iteration_count, total_grad, train_performance
# performanceTrain, start - time.time()
# performanceTest, start - time.time()
1 1.0001 0.4804
1 .) MCrate(train): 0.0089 time since start: -0.33918094635
MCrate: (test) 0.0124 time since start: -0.345828056335
1 1.0001 0.5077
1 .) MCrate(train): 0.0099 time since start: -0.284085035324
MCrate: (test) 0.0131 time since start: -0.290790081024
1 1.0001 0.4823
1 .) MCrate(train): 0.0098 time since start: -0.339424133301
MCrate: (test) 0.0088 time since start: -0.354150056839
1 1.0001 0.4978
1 .) MCrate(train): 0.0095 time since start: -0.31689786911
MCrate: (test) 0.0137 time since start: -0.323953866959
1 1.0001 0.5251
1 .) MCrate(train): 0.0094 time since start: -0.344790935516
MCrate: (test) 0.0092 time since start: -0.351211071014
1 1.0001 0.5008
1 .) MCrate(train): 0.01 time since start: -0.369421005249
MCrate: (test) 0.0129 time since start: -0.376559019089
1 1.0001 0.4864
1 .) MCrate(train): 0.0096 time since start: -0.235582113266
MCrate: (test) 0.012 time since start: -0.242256164551
1 1.0001 0.4934
1 .) MCrate(train): 0.0099 time since start: -0.406064033508
MCrate: (test) 0.0127 time since start: -0.412713050842
1 1.0001 0.5061
1 .) MCrate(train): 0.0088 time since start: -0.28179192543
MCrate: (test) 0.0122 time since start: -0.288369894028
finished
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

First line printed:
print self.iteration_count, total_grad, train_performance :

train_performance = self.mc_error.calc(lesson.trainset.targets,
                                               lesson.response()
                                               ) / lesson.trainset.targets.shape[0]
error = sum(1 - targets.squeeze() * sign(response.squeeze()) ) / 2
It is equivalent  to (1- (right-wrong) )/2.
shape: size of array
---------------------------------------------------------------------------- 
light

- xorKnackertester
- xorKnacker

----------------------------------------------------------------------------
predictor
# prediction using different models, including learning methods

Model:
- linearPredictor
- prodLinearPredictor
- FFNeuralNet
- SVMmodel



Transfer function
- Sigmoid
- Tanh


error estimation
- LRError
- MSError
- MCError
- MCC

Learning function
- RProp
- GradientDescent
- AnealingGradientDescent


Train:
- Trainable
- BasicTrainable
- Learner
- GradLearner
- CrossValidation
- Closures
- TrainData
- SubSampling



2014年4月24日星期四

Train SVM Classifiers Using a Custom Kernel

Ref: www.mathworks.nl/help/stats/support-vector-machines-svm.html#buax656-1a

Train SVM Classifiers Using a Custom Kernel

This example shows how to use a custom kernel function, such as the sigmoid kernel, to train SVM classifiers, and adjust custom kernel function parameters.
Generate a random set of points within the unit circle. Label points in the first and third quadrants as belonging to the positive class, and those in the second and fourth quadrants in the negative class.
产生两个类型的元素,一个在 1/3相限,一个在2/4相限
rng(1);  % For reproducibility
n = 100; % Number of points per quadrant

r1 = sqrt(rand(2*n,1));                     % Random radii
t1 = [pi/2*rand(n,1); (pi/2*rand(n,1)+pi)]; % Random angles for Q1 and Q3
X1 = [r1.*cos(t1) r1.*sin(t1)];             % Polar-to-Cartesian conversion

r2 = sqrt(rand(2*n,1));
t2 = [pi/2*rand(n,1)+pi/2; (pi/2*rand(n,1)-pi/2)]; % Random angles for Q2 and Q4
X2 = [r2.*cos(t2) r2.*sin(t2)];

X = [X1; X2];        % Predictors 
Y = ones(4*n,1);
Y(2*n + 1:end) = -1; % Labels
Plot the data.
figure;
gscatter(X(:,1),X(:,2),Y);
title('Scatter Diagram of Simulated Data')

Create the function mysigmoid.m, which accepts two matrices in the feature space as inputs, and transforms them into a Gram matrix using the sigmoid kernel.
%customized kernel,  U*V' = r1*r2 * cos(t2-t1), when t2=t1, U*V' = r1*r2
%use tanh, because we want even small r1*r2 will also create effective desicion boundary, which means G = 1 or -1
function G = mysigmoid(U,V)
% Sigmoid kernel function with slope gamma and intercept c
gamma = 1;
c = -1;
G = tanh(gamma*U*V' + c);
end 
 
Train an SVM classifier using the sigmoid kernel function. It is good practice to standardize the data.
SVMModel1 = fitcsvm(X,Y,'KernelFunction','mysigmoid','Standardize',true);
SVMModel is a ClassificationSVM classifier containing the estimated parameters.
Plot the data, and identify the support vectors and the decision boundary.
% Compute the scores over a grid
d = 0.02; % Step size of the grid
[x1Grid,x2Grid] = meshgrid(min(X(:,1)):d:max(X(:,1)),...
    min(X(:,2)):d:max(X(:,2)));
xGrid = [x1Grid(:),x2Grid(:)];        % The grid
[~,scores1] = predict(SVMModel1,xGrid); % The scores

figure;
h(1:2) = gscatter(X(:,1),X(:,2),Y);
hold on
h(3) = plot(X(SVMModel1.IsSupportVector,1),...
    X(SVMModel1.IsSupportVector,2),'ko','MarkerSize',10);
    % Support vectors
contour(x1Grid,x2Grid,reshape(scores1(:,2),size(x1Grid)),[0 0],'k');
    % Decision boundary
title('Scatter Diagram with the Decision Boundary')
legend({'-1','1','Support Vectors'},'Location','Best');
hold off

You can adjust the kernel parameters in an attempt to improve the shape of the decision boundary. This might also decrease the within-sample misclassification rate, but, you should first determine the out-of-sample misclassification rate.
Determine the out-of-sample misclassification rate by using 10-fold cross validation.
CVSVMModel1 = crossval(SVMModel1);
misclass1 = kfoldLoss(CVSVMModel1);
misclass1
misclass1 =

    0.1350
The out-of-sample misclassification rate is 13.5%.
Set gamma = 0.5; within mysigmoid.m. Then, train an SVM classifier using the adjusted sigmoid kernel. Plot the data and the decision region, and determine the out-of-sample misclassification rate.
SVMModel2 = fitcsvm(X,Y,'KernelFunction','mysigmoid','Standardize',true);
[~,scores2] = predict(SVMModel2,xGrid);

figure;
h(1:2) = gscatter(X(:,1),X(:,2),Y);
hold on
h(3) = plot(X(SVMModel2.IsSupportVector,1),...
    X(SVMModel2.IsSupportVector,2),'ko','MarkerSize',10);
title('Scatter Diagram with the Decision Boundary')
contour(x1Grid,x2Grid,reshape(scores2(:,2),size(x1Grid)),[0 0],'k');
legend({'-1','1','Support Vectors'},'Location','Best');
hold off

CVSVMModel2 = crossval(SVMModel2);
misclass2 = kfoldLoss(CVSVMModel2);
misclass2
misclass2 =

    0.0450

After the sigmoid slope adjustment, the new decision boundary seems to provide a better within-sample fit, and the cross-validation rate contracts by more than 66%.

SVM material


关于SVM的那点破事[faruto长期更新整理]


简易目录:


写在前面的碎碎念;
Libsvm下载;
SVM入门;
Libsvm安装与使用(待完善);
SVM相关文献资料;
SVM相关书籍推荐;
SVM[Libsvm]相关应用(待完善);
SVM相关杂帖(待完善);
写在最后的闲扯淡;
Faruto的联系方式(讨论MATLAB相关问题或者具体一些SVM相关问题或者再具体一些libsvm使用相关问题或者再再具体一些 … …);

===================无聊的分隔线=========================

写在前面的碎碎念 by faruto       

        还记得初次接触SVM是本科大三的时候参加北师本科科研基金在管理学院系统科学那边做一个有关脑电波EEG模式识别的项目,那时候对于“机器学习” 这个概念还是头一次染指,后来使用libsvm工具箱来做分类和回归,在用的过程中来学习SVM底层的统计学习理论,再后来自己完善提升libsvm的 matlab版本,在林智仁先生的libsvm-mat基础上自己编写了一些辅助函数(参数寻优什么的),后来不断完善,最终自己的libsvm-mat 版本是libsvm-mat-2.89-3[FarutoUltimate3.0],方便自己使用以及论坛的一些朋友使用。
        SVM的实现工具箱有很多,但我还是认为libsvm最好用(lssvm也不错的说),我认为把这一个SVM的实现工具箱研究的透彻就够了,反正我 是够用了,即如果现在需要SVM这个工具来进行分类或者回归我可以拿来libsvm-mat-2.89-3[FarutoUltimate3.0]就能熟 练使用以达到解决自己的问题的目的,而不用再重新学习掌握SVM这个工具。
        其实还有一些话要说,姑且先留着吧 … …

====================
MATLAB技术论坛电子期刊第九期(2011.06)[faruto帖子集锦]
http://www.matlabsky.com/thread-17223-1-1.html
====================
《Learn SVM Step by Step 》系列视频应用篇
Libsvm的下载、安装和使用
http://www.matlabsky.com/thread-18080-1-1.html

Libsvm参数实例详解
http://www.matlabsky.com/thread-18457-1-1.html

一个实例搞定libsvm分类
http://www.matlabsky.com/thread-18521-1-1.html

一个实例搞定libsvm回归
http://www.matlabsky.com/thread-18552-1-1.html
Libsvm下载

Libsvm-mat林智仁先生的原始版本下载

libsvm官方更新[2011.04.01]:libsvm-3.1
http://www.matlabsky.com/thread-14345-1-1.html

libsvm-mat-2.91-1.zip
http://www.matlabsky.com/thread-9328-1-1.html
【说明:最新的版本为libsvm-mat-3.0-1.zip大家可以在这里下载http://www.csie.ntu.edu.tw/~cjlin/libsvm/ 最新版本的改动是将SVM的model structure移动到了svm.h里面,对于常规用户没有影响基本和以前的都一样,只是方便一些高级用户自己进行底层代码的修改】

Libsvm-mat faruto版本下载

(更新libsvm-faruto版本归来)libsvm-3.1-[FarutoUltimate3.1Mcode]
http://www.matlabsky.com/thread-17936-1-1.html

libsvm-mat-2.89-3[FarutoUltimate3.0]
http://www.matlabsky.com/thread-9327-1-1.html

GUI版本下载【基于libsvm-mat-2.89-3[FarutoUltimate3.0]】
[原创]SVM_GUI_2.0[mcode][by_faruto]
http://www.matlabsky.com/thread-9333-1-1.html

SVM入门

我个人推荐您看这个系列帖子

SVM入门精品系列讲解目录
http://www.matlabsky.com/thread-10317-1-1.html
共有10个系列讲解,很适合SVM入门。

[整理]Libsvm官方FAQ翻译
http://www.matlabsky.com/thread-15225-1-1.html


Libsvm安装与使用(待完善);

libsvm-mat在MATLAB平台下的安装【by faruto】
http://www.matlabsky.com/thread-11925-1-1.html

如何使用libsvm进行分类【by faruto】
http://www.matlabsky.com/thread-12379-1-1.html

如何使用libsvm进行回归预测【by faruto】
http://www.matlabsky.com/thread-12390-1-1.html

利用libsvm-mat建立分类模型model参数解密【by faruto】
http://www.matlabsky.com/thread-12649-1-1.html

libsvm如何使用自定义核函数[有关-t 4 参数的使用例子]
http://www.matlabsky.com/thread-15296-1-1.html

【转】Matlab中使用libsvm进行分类预测时的标签问题再次说明
http://www.matlabsky.com/thread-12396-1-1.html

基于GridSearch的svm参数寻优
http://www.matlabsky.com/thread-12411-1-1.html

基于GA的svm参数寻优
http://www.matlabsky.com/thread-12412-1-1.html

基于PSO的svm参数寻优
http://www.matlabsky.com/thread-12414-1-1.html

线性可分模式的最优超平面的详细推导过程【支持向量机相关】
http://www.matlabsky.com/thread-12613-1-1.html


libsvm 参数说明【中英文双语版本】
http://www.matlabsky.com/thread-12380-1-1.html


这部分过一段还要完善,目前关于libsvm的安装与使用可以参看以下资源


另外一篇:MATLAB自带的svm实现函数与libsvm差别小议

1 MATLAB自带的svm实现函数仅有的模型是C-SVC(C-support vector classification); 而libsvm工具箱有C-SVC(C-support vector classification),nu-SVC(nu-support vector classification),one-class SVM(distribution estimation),epsilon-SVR(epsilon-support vector regression),nu-SVR(nu-support vector regression)等多种模型可供使用。
2 MATLAB自带的svm实现函数仅支持分类问题,不支持回归问题;而libsvm不仅支持分类问题,亦支持回归问题。
3 MATLAB自带的svm实现函数仅支持二分类问题,多分类问题需按照多分类的相应算法编程实现;而libsvm采用1v1算法支持多分类。
4 MATLAB自带的svm实现函数采用RBF核函数时无法调节核函数的参数gamma,貌似仅能用默认的;而libsvm可以进行该参数的调节。
5 libsvm中的二次规划问题的解决算法是SMO;而MATLAB自带的svm实现函数中二次规划问题的解法有三种可以选择:经典二次方法;SMO;最小二乘。(这个是我目前发现的MATLAB自带的svm实现函数唯一的优点~)

参看在优酷上的一个有关libsvm的视频(这个是我以前在国内某论坛制作过的一个视频被网友放到了优酷上)

http://v.youku.com/v_show/id_XMTIwOTIzNTQ4.html

SVM相关文献资料

[flash]
http://player.youku.com/player.php/sid/XMTIwOTIzNTQ4/v.swf
[/flash]


关于SVM的理论相关的,在下面提供了一些资源和paper, ppt,pdf,虽然这几个资源是有限的,但我敢说足够了.原因有两个:a.下面的几个文献本身质量就很高.b.这些文献主要的SVM的参考文献已经几乎全部列出了,你可以寻径查找.

田英杰_支持向量回归机及其应用研究
http://www.matlabsky.com/thread-12841-1-1.html

Sequential Minimal Optimization for SVM
http://www.matlabsky.com/thread-13059-1-1.html


资料截图: 1.jpg

资料打包下载:
游客,如果您要查看本帖隐藏内容请回复


SVM相关书籍推荐

关于SVM的相关书籍,我个人首推这本书《MATLAB 神经网络30个案例分析》,因为我是这本书的作者之一,这本书的12-15章是有关SVM的,很不错的一本书,欢迎您购买
MATLAB 神经网络30个案例分析(加印版).jpg
购买方式:
当当
http://product.dangdang.com/prod ... 07&ref=search-1-pub
china-pub
http://www.china-pub.com/50688
卓越
http://www.amazon.cn/mn/detailApp/ref=sr_1_1?_encoding=UTF8&s=books&qid=1287536439&asin=B003HGHB9W&sr=8-1

《MATLAB 神经网络30个案例分析》官方网站(可以额外购买书籍视频)
http://video.ourmatlab.com/
书籍视频销售客服QQ:1007911579


Matlab神经网络30个案例读者交流群
http://www.matlabsky.com/thread-14315-1-1.html


书籍目录
第1章 P神经网络的数据分类——语音特征信号分类1
第2章 BP神经网络的非线性系统建模——非线性函数拟合11
第3章 遗传算法优化BP神经网络——非线性函数拟合21
第4章 神经网络遗传算法函数极值寻优——非线性函数极值寻优36
第5章 基于BP_Adaboost的强分类器设计——公司财务预警建模45
第6章 PID神经元网络解耦控制算法——多变量系统控制54
第7章 RBF网络的回归——非线性函数回归的实现65
第8章 GRNN的数据预测——基于广义回归神经网络的货运量预测73
第9章 离散Hopfield神经网络的联想记忆——数字识别81
第10章 离散Hopfield神经网络的分类——高校科研能力评价90
第11章 连续Hopfield神经网络的优化——旅行商问题优化计算100
第12章 SVM的数据分类预测——意大利葡萄酒种类识别112
第13章 SVM的参数优化——如何更好的提升分类器的性能122
第14章 SVM的回归预测分析——上证指数开盘指数预测133
第15章 SVM的信息粒化时序回归预测——上证指数开盘指数变化趋势和变化空间预测141

第16章 自组织竞争网络在模式分类中的应用——患者癌症发病预测153
第17章 SOM神经网络的数据分类——柴油机故障诊断159
第18章 Elman神经网络的数据预测——电力负荷预测模型研究170
第19章 概率神经网络的分类预测——基于PNN的变压器故障诊断176
第20章 神经网络变量筛选——基于BP的神经网络变量筛选183
.第21章 LVQ神经网络的分类——乳腺肿瘤诊断188
第22章 LVQ神经网络的预测——人脸朝向识别198
第23章 小波神经网络的时间序列预测——短时交通流量预测208
第24章 模糊神经网络的预测算法——嘉陵江水质评价218
第25章 广义神经网络的聚类算法——网络入侵聚类229
第26章 粒子群优化算法的寻优算法——非线性函数极值寻优236
第27章 遗传算法优化计算——建模自变量降维243
第28章 基于灰色神经网络的预测算法研究——订单需求预测258
第29章 基于Kohonen网络的聚类算法——网络入侵聚类268
第30章 神经网络GUI的实现——基于GUI的神经网络拟合、模式识别、聚类277
========================================================
MATLAB神经网络30个案例分析 源代码+数据{SVM}[chapter12-15]
http://www.matlabsky.com/thread-11385-1-1.html
MATLAB神经网络30个案例分析 源代码+数据 大放送目录
http://www.matlabsky.com/thread-11479-1-1.html
========================================================

还有这本书也很不错~
《支持向量机--理论、算法与拓展》
作者: 邓乃扬    田英杰 
出版社:科学出版社
ISBN:9787030250315
上架时间:2009-8-12
出版日期:2009 年8月
开本:16开
页码:244
版次:1-1
1.jpg

China-pub上的购买链接:http://www.china-pub.com/47322


SVM[Libsvm]相关应用(待完善)

基于libsvm的手写字体识别
http://www.matlabsky.com/thread-11025-1-1.html
基于libsvm的图像分割
http://www.matlabsky.com/thread-11026-1-1.html
基于SVM的基因选择(SVM-RFE算法)[SVM Recursive Feature Elimination (SVM RFE)]
基因选择算法SVM-RFE
http://www.matlabsky.com/thread-11568-1-1.html

基于平均影响值MIV的SVM变量筛选方法
http://www.matlabsky.com/thread-11569-1-1.html

基于SVM的语音特征信号分类
http://www.matlabsky.com/thread-11821-1-1.html

如何可视化libsvm的分类结果以及分类曲线
http://www.matlabsky.com/thread-12358-1-1.html

【转】文本分类入门(番外篇)特征选择与特征权重计算的区别
http://www.matlabsky.com/thread-12574-1-1.html

一些计划中将要发的帖子:
下几个帖子计划 掰饽饽说馅 的给大家说说
如何使用libsvm进行分类
如何使用libsvm进行回归
如何优化libsvm的各种参数
使用libsvm进行分类和回归的通常的流程以及注意事项
【
这个最有技术含量了,因为总有朋友说用libsvm做分类或者回归效果不好,我说把数据给我试一 下,结果我做的效果一般都会比其要好,为啥捏?这里先简单说一点点:使用libsvm(SVM)不是简简单单的用svmtrain输入几个参数 -c -g 生成model后用svmpredict来分类或者回归,其实更重要的是前期的数据预处理和后期的参数选择(归一化范围的选取,降维算法的选取,以及最佳 参数选取的算法)这些才是关键,其实说白了如果这些您都搞得很透彻的话,选择其他分类器也能做好,即这些(前期的数据预处理和后期的参数选择)做好了,选 择神马分类器真的并不重要,在libsvm-mat-2.89-3[FarutoUltimate3.0]工 具箱中我把常见的数据预处理方法(归一化,降维pca)和参数选择算法(grid search 暴力搜索方法,启发式GA、PSO方法)都封装好了方便大家使用,同样是用这个加强工具箱,但对于同一个测试数据集合,我敢保证肯定会有人用的效果就没有 我的好,为啥捏?因为知其然不知其所以然!肯定是其仅仅是了解一些表象的使用,而对于底层到底是怎么回事没有搞清楚,这样在具体的参数调整上肯定是不行 的,这也回答之前的“为什么总有朋友说用libsvm做分类或者回归效果不好,我说把数据给我试一下,结果我做的效果一般都会比其要好”的原因。
】
如何可视化libsvm的分类结果【虚幻的浮云~】
如何处理unbalanced label(不平衡数据标签)问题【难点问题】



SVM相关杂帖(待完善)

交叉验证(Cross Validation)方法思想简介
http://www.matlabsky.com/thread-10567-1-1.html

SVM的多分类问题
http://www.matlabsky.com/thread-9471-1-1.html

MATLAB数据归一化汇总(最全面的归一化介绍)
http://www.matlabsky.com/thread-9268-1-1.html

LibSVM程序代码注释详解
http://www.matlabsky.com/thread-9462-1-1.html

PSO资源整合工具箱
http://www.matlabsky.com/thread-9330-1-1.html

Matlab Toolbox for Dimensionality Reduction [降维工具箱]
http://www.matlabsky.com/thread-9335-1-1.html

TSVM(Transductive SVM)
http://www.matlabsky.com/thread-14257-1-1.html

Matlab神经网络30个案例读者交流群
http://www.matlabsky.com/thread-14315-1-1.html


关于matlab中princomp的使用说明讲解小例子【by faruto】
http://www.matlabsky.com/thread-11751-1-1.html

主成份分析PCA源代码
http://www.matlabsky.com/thread-11750-1-1.html


SVM相关QQ讨论群整理
http://www.matlabsky.com/thread-11971-1-1.html

2014年4月23日星期三

SVM

More formally, a support vector machine constructs a hyperplane or set of hyperplanes in a high- or infinite-dimensional space, which can be used for classification, regression, or other tasks. Intuitively, a good separation is achieved by the hyperplane that has the largest distance to the nearest training data point of any class (so-called functional margin), since in general the larger the margin the lower the generalization error of the classifier.

Whereas the original problem may be stated in a finite dimensional space, it often happens that the sets to discriminate are not linearly separable in that space. For this reason, it was proposed that the original finite-dimensional space be mapped into a much higher-dimensional space, presumably making the separation easier in that space. To keep the computational load reasonable, the mappings used by SVM schemes are designed to ensure that dot products may be computed easily in terms of the variables in the original space, by defining them in terms of a kernel function K(x,y) selected to suit the problem.[2] The hyperplanes in the higher-dimensional space are defined as the set of points whose dot product with a vector in that space is constant. The vectors defining the hyperplanes can be chosen to be linear combinations with parameters \alpha_i of images of feature vectors that occur in the data base. With this choice of a hyperplane, the points x in the feature space that are mapped into the hyperplane are defined by the relation: \textstyle\sum_i \alpha_i K(x_i,x) = \mathrm{constant}. Note that if K(x,y) becomes small as y grows further away from x, each term in the sum measures the degree of closeness of the test point x to the corresponding data base point x_i. In this way, the sum of kernels above can be used to measure the relative nearness of each test point to the data points originating in one or the other of the sets to be discriminated. Note the fact that the set of points x mapped into any hyperplane can be quite convoluted as a result, allowing much more complex discrimination between sets which are not convex at all in the original space.


Linear separability

The problem of determining if a pair of sets is linearly separable and finding a separating hyperplane if they are arises in several areas. In statistics and machine learning, classifying certain types of data is a problem for which good algorithms exist that are based on this concept.

Three non-collinear points in two classes ('+' and '-') are always linearly separable in two dimensions. This is illustrated by the three examples in the following figure (the all '+' case is not shown, but is similar to the all '-' case):
VC1.svg VC2.svg VC3.svg
However, not all sets of four points, no three collinear, are linearly separable in two dimensions. The following example would need two straight lines and thus is not linearly separable:
VC4.svg