Machine Learning实验6 理解核函数
来源:互联网 发布:bind 域名冲突 编辑:程序博客网 时间:2024/05/22 11:54
#include"stdio.h"#include <math.h>double function(double matrix[5][4],double theta[3],int sample_i){ double ret=0.0; for(int i=0;i<3;++i) { ret+=matrix[sample_i][i]*theta[i]; } return ret;}double theta[3]={1,1,1};int main(void){ double matrix[5][4]={ {1,1,1,1}, {1,1,4,2}, {1,1,9,3}, {1,1,16,4}, {1,1,25,5}, }; double alfa = 0.1; double c = 0; double d = 0.5; double loss = 0.0; for(int j = 0;j<15;++j) { double sum=function(matrix,theta,j); loss += pow((pow(sum+c,d)-matrix[j][3]),2); } printf("loss : %lf\n",loss); for(int i=0;i<200;++i) { for(int sample_i = 0; sample_i<5;sample_i++) { double result = function(matrix,theta,sample_i)+c; for(int j=0;j<3;++j) { theta[j] = theta[j] - alfa*(pow(result,d)-matrix[sample_i][3])*d*pow((result),d-1)*matrix[sample_i][j]; } } double loss = 0.0; for(int j = 0;j<5;++j) { double sum=function(matrix,theta,j); loss += pow((pow(sum+c,d)-matrix[j][3]),2); } printf("%d,loss now: %lf,%lf,%lf,%lf\n",i,loss,theta[0],theta[1],theta[2]); } return 0;}
上面这个是多项式核函数的实验,暂时不解释。未来整体写一个博客来解释。
通过本实验加强对向量点乘的理解。
以上实验受到Multivariate calculus课程的影响
网易公开课看到这个课程:http://v.163.com/special/opencourse/multivariable.html
MIT地址:http://ocw.mit.edu/courses/mathematics/18-02sc-multivariable-calculus-fall-2010/
from: http://blog.csdn.net/pennyliang/article/details/7164549
0 0
- Machine Learning实验6 理解核函数
- Machine Learning实验6 理解核函数
- [Machine learning]SVM实验续
- 【Machine Learning实验】牛顿迭代法
- 【Machine Learning实验5】SVM实验
- 【Machine Learning实验5】SVM实验
- 【Machine Learning实验3】SoftMax regression
- [Machine learning 实验4]linear programming
- machine learning实验7 矩阵求逆
- Machine Learning系列实验--感知机学习
- 【Machine Learning实验】梯度下降算法
- Machine Learning系列实验--SoftMax Regression
- Machine Learning系列实验--SoftMax Regression
- Machine Learning实验3】SoftMax regression
- [Machine learning 实验4]linear programming
- machine learning实验7 矩阵求逆
- Machine Learning系列实验--SoftMax Regression
- Machine Learning---6--Adaboost
- 【Machine Learning实验5】SVM实验
- Ant_的最完整build.xml解释
- [LeetCode]Missing Number
- java13天
- 60. Permutation Sequence
- Machine Learning实验6 理解核函数
- ECHI和OCHI
- Unity3D学习1——鼠标点击效果显示
- 双击文件夹新建一个窗口问题
- 来CSDN写博客的一些原因
- VS2012 的插件安装后,出现的ActivityLog.xml 日记错误的解决方案
- machine learning实验7 矩阵求逆
- ViewTreeObserver实现自动更新
- K-Means 聚类实例sample