算法系列:杂项


寻路算法
http://blog.jobbole.com/71044/

贝叶斯
http://mindhacks.cn/2008/09/21/the-magical-bayesian-method/

RSA
http://www.ruanyifeng.com/blog/2013/06/rsa_algorithm_part_one.html


http://blog.jobbole.com/61872/

Copyright © 1900-2016, NORYES, All Rights Reserved.

http://www.cnblogs.com/noryes/

欢迎转载,请保留此版权声明。

-----------------------------------------------------------------------------------------

旋转字符串

http://www.cnblogs.com/bakari/archive/2012/09/09/2677155.html


十大算法
http://code.csdn.net/news/2820149


http://blog.csdn.net/v_JULY_v/article/details/6096981


C++ Socket编程步骤
2016-03-19 23:29 52人阅读 评论(0) 收藏 举报
分类: cpp(6)
http://www.cnblogs.com/Sniper-quay/archive/2011/06/22/2086636.html

多线程
2016-03-19 23:57 50人阅读 评论(0) 收藏 举报
分类: cpp(6)
http://blog.csdn.net/hitwengqi/article/details/8015646

通俗易懂的机器学习入门指导
2016-03-23 22:31 60人阅读 评论(0) 收藏 举报
分类: machine learning(10)
http://blog.163.com/zhoulili1987619@126/blog/static/353082012015613104243192/


机器学习入门资源不完全汇总
2016-03-23 22:37 53人阅读 评论(0) 收藏 举报
分类: machine learning(10)
http://ml.memect.com/article/machine-learning-guide.html#%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5

Logistic Regression 模型简介
2016-03-23 23:14 42人阅读 评论(0) 收藏 举报
分类: machine learning(10)
http://tech.meituan.com/intro_to_logistic_regression.html


斯坦福机器学习公开课
2016-03-24 00:17 66人阅读 评论(0) 收藏 举报
分类: machine learning(10)
http://blog.csdn.net/abcjennifer/article/category/1173803/3




字符串反转
2016-03-24 00:55 37人阅读 评论(0) 收藏 举报
分类: algorithm(17)
http://www.cnblogs.com/bakari/archive/2012/09/09/2677155.html




聚类
2016-03-25 00:09 39人阅读 评论(0) 收藏 举报
分类: machine learning(10)
http://www.cnblogs.com/William_Fire/archive/2013/02/09/2909499.html




PAGERANK
2016-03-27 00:30 38人阅读 评论(0) 收藏 举报
分类: algorithm(17)
http://blog.jobbole.com/23286/



Fibonacci全面总结
2016-04-07 17:44 52人阅读 评论(0) 收藏 举报
分类: mathmatics(4)
版权声明:Copyright © 1990-2016, NORYES, All Rights Reserved.
目录(?)[+]
参考资料https://en.wikipedia.org/wiki/Fibonacci_number#CITEREFBeckGeoghegan2010



大数定理
2016-06-26 23:32 15人阅读 评论(0) 收藏 举报
分类: mathmatics(4)
作者:魏天闻
链接:https://www.zhihu.com/question/24538086/answer/31627340
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


# include <iostream>
# include <memory>
# include <cstring>
using namespace std;
class MyString {
private:
char *m_data;
public:
MyString();
MyString(const char* ptr);
MyString(const MyString& rhs);
~MyString();
MyString& operator=(const MyString& rhs);
MyString operator+(const MyString& rhs);
char operator[](const unsigned int index);
bool operator==(const MyString& rhs);
friend ostream& operator<<(ostream& output, const MyString &rhs);
};
//默认的构造函数
MyString::MyString() {
m_data = new char[1];
*m_data = '';
}
//使用const char* 来初始化
MyString::MyString(const char* ptr) {
if (NULL == ptr) {
m_data = new char[1];
*m_data = '';
} else {
int len = strlen(ptr);
m_data = new char[len + 1];
strcpy(m_data, ptr);
}
}
//拷贝构造函数
MyString::MyString(const MyString& rhs) {
int len = strlen(rhs.m_data);
m_data = new char[len + 1];
strcpy(m_data, rhs.m_data);
}
bool MyString::operator ==(const MyString& rhs) {
int result = strcmp(m_data, rhs.m_data);
if (0 == result)
return true;
else
return false;
}
//赋值操作符
MyString& MyString::operator =(const MyString& rhs) {
if (this != &rhs) {
delete[] m_data;
m_data = new char[strlen(rhs.m_data) + 1];
strcpy(m_data, rhs.m_data);
}
return *this;
}
//重载运算符+
MyString MyString::operator+(const MyString &rhs) {
MyString newString;
if (!rhs.m_data)
newString = *this;
else if (!m_data)
newString = rhs;
else {
newString.m_data = new char[strlen(m_data) + strlen(rhs.m_data) + 1];
strcpy(newString.m_data, m_data);
strcat(newString.m_data, rhs.m_data);
}
return newString;
}
//重载下标运算符
char MyString::operator [](const unsigned int index) {
return m_data[index];
}
//析构函数
MyString::~MyString() {
delete[] m_data;
}
//重载<<
ostream& operator<<(ostream& output, const MyString &rhs) {
output << rhs.m_data;
return output;
}
int main() {
const char* p = "hello,world";
MyString s0 = "hello,world";
MyString s1(p);
MyString s2 = s1;
MyString s3;
s3 = s1;
MyString s4 = s3 + s1;
bool flag(s1 == s2);
cout << s0 << endl;
cout << s1 << endl;
cout << s2 << endl;
cout << s3 << endl;
cout << flag << endl;
char result = s3[1];
cout << result << endl;
cout << s4 << endl;
return 0;
}

欧拉角
2016-07-19 15:52 310人阅读 评论(0) 收藏 举报
分类: graphics/image(21)
版权声明:Copyright © 1990-2016, NORYES, All Rights Reserved.
目录(?)[+]
https://en.wikipedia.org/wiki/Euler_angles

四元数 001
2016-07-19 16:40 8人阅读 评论(0) 收藏 举报
分类: mathmatics(4)
目录(?)[+]

Understanding Quaternions


矩阵行存储、列存储、左乘、右乘
2016-07-21 11:24 27人阅读 评论(0) 收藏 举报
分类: graphics/image(21)
版权声明:Copyright © 1990-2016, NORYES, All Rights Reserved.
列矩阵(column major)和行矩阵(row major)是数学上的概念,和电脑无关。它只是一套约定(convention),按照矢量和矩阵的乘法运算时,矢量是列矢还是行矢命名。


这里只说4x4矩阵。齐次矢量可以看成是一个1x4的矩阵,就是行矢;或者4x1的矩阵,就是列矢。


列矩阵变换矢量时,用矩阵乘以列矢量(M * v),如下。其中1、2、3为三个轴向矢量。
| x1 x2 x3 xt | | x |
| y1 y2 y3 yt | * | y |
| z1 y2 y3 zt | | z |
| 0 0 0 1 | | w |


列矩阵之间乘法组合时,组合顺序为从右到左。例如依次做放缩S、旋转R、平移T,则组合为T * R * S。


行矩阵变换矢量时,用行矢量乘以矩阵(v * M),如下。其中1、2、3为三个轴向矢量。
| x1 y1 z1 0 |
| x y z w | * | x2 y2 z2 0 |
| x3 y3 z3 0 |
| xt yt zt 1 |


行矩阵之间乘法组合时,组合顺序为从左到右。例如依次做放缩S、旋转R、平移T,则组合为S * R * T。

列优先存储(column major storage)和行优先存储(row major storage)是计算机上的概念,指多维数组的元素在内存中的排列顺序。
对应到矩阵上,按内存地址顺序编号,则列优先存储的顺序为
| 1 5 9 13 |
| 2 6 10 14 |
| 3 7 11 15 |
| 4 8 12 16 |
行优先存储的顺序为
| 1 2 3 4 |
| 5 6 7 8 |
| 9 10 11 12 |
| 13 14 15 16 |


对于效率差异,其实并没有绝对区别,和处理器的指令设计有关,也和矩阵的主要使用方式有关。
在CPU上,一般是列矩阵用列优先存储,行矩阵用行优先存储,也就是矩阵major和存储major一致。一来比较简单清楚不容易犯错,二来可以直接在矩阵中访问三个轴矢量,三来在SSE优化时略有优势,可以使用4个mul-add指令完成矩阵乘矢量。但最新的SSE指令集也加入了dot指令,所以胜负难料。而在GPU上,由于矩阵是以矢量序列方式存储的,为了优化乘法速度,会颠倒存储顺序。不明白可以想想矩阵和矢量的乘法,可以拆解成4个矢量间点乘,点乘的操作数都在float4的矢量里就不用shuffle了。


决定选择哪种模式,更多的是历史原因。比如Maya、OpenInventor等虽然用的OpenGL,但使用的是行矩阵。OpenGL按着多数教科书习惯,用的列矩阵。而DirectX,沿袭了RenderMan等的习惯,用的行矩阵。


除此之外,也确实有个别采用了列矩阵但是行优先存储的……原因嘛,C的数组是行优先,在代码里写矩阵常量当然是行优先比较直观。大家可以找找那些图形库、图形引擎用了不一致的模式。

列矩阵列优先存储的内存数据,其实和行矩阵行优先存储的内存数据是一样的,都是
[ x1 y1 z1 0 x2 y2 z2 0 x3 y3 z3 0 xt yt zt 1 ]
这也是Maya、OpenInventor用行矩阵而不需要担心效率的原因,不需要转置,可以直接传给OpenGL。


另外,澄清一个经常混淆的概念:左乘(left multiplication, pre-multication)和右乘(right multiplication, post-multication)


这里的左右、pre/post,指的是矢量和矩阵相乘时,矢量的位置。对标量和矩阵相乘时,指标量的位置。


混淆的原因,是有个别组织、个人用其指代矩阵在乘法中的位置,导致正好相反的命名。比如Maya里的pre-multiplication和post-multiplication。


OpenGL 1.0 标准指定时,图形软件多使用左乘行矩阵行优先存储,包括OpenGL的前身IrisGL,而非软件领域则多用右乘列矩阵。(其实今天也是一样。)标准制定者希望消除这种差别,以便初学者不容易误解。但是,他们也不希望给已有的图形软件带来麻烦。于是,利用矩阵本身的行列和存储顺序两者独立这一特点,设计了一个trick的定义:右乘列矩阵列优先存储。这样存储的矩阵的内存数据布局和左乘行矩阵行优先存储一模一样,原有的数学库和使用方式不需要做任何更改。这样,两个目标就都实现了。


但是,事与愿违,这种设计在初学者中导致了更多的误解。很多初学者试图在给GL传矩阵时先转置,反而得不到正确的结果。而且C的数组是行优先存储,按书面排版写出的数组其实是列矩阵行优先存储。


PS:行矩阵、列矩阵(row major, column major)这两个词其实被用得比较乱,有时也被用来指行列优先存储顺序。左乘右乘更能体现这种矩阵本身的差别,当然除了Maya里这俩词是反着用的。


DX的行矩阵和GL的列矩阵的内存布局是一模一样的,所以通用数学库没有任何困难,直接用就行了。唯一例外的是投影矩阵,因为投影空间范围定义不同(还有一点额外表达形式的要求差异),所以需要两套实现。


某些偏执的人非要用行优先存储的列矩阵,认为这样才符合数学习惯,这就是自找麻烦了。

原文地址:https://www.cnblogs.com/noryes/p/5716675.html