我在Math Stackexchange中问过这个问题,但似乎没有得到足够的关注,所以我在这里问它.https://math.stackexchange.com/questions/1729946/why-do-we-say-svd-can-handle-singular-matrx-when-doing-least-square-comparison?noredirect=1#comment3530971_1729946
我从一些教程中了解到,当解决最小二乘问题时,SVD应该比QR分解更稳定,并且它能够处理奇异矩阵.但是我在matlab中编写的以下示例似乎支持相反的结论.我对SVD没有深刻的理解,所以如果您可以在Math StackExchange的旧帖子中查看我的问题并向我解释,我会非常感激.
我使用具有大条件数(e + 13)的矩阵.结果显示SVD得到比QR(e-27)大得多的误差(0.8)
% we do a linear regression between Y and X
data= [
47.667483331 -122.1070832;
47.667483331001 -122.1070832
];
X = data(:,1);
Y = data(:,2);
X_1 = [ones(length(X),1),X];
%%
%SVD method
[U,D,V] = svd(X_1,'econ');
beta_svd = V*diag(1./diag(D))*U'*Y;
%% QR method(here one can also use "\" operator, which will get the same result as I tested. I just wrote down backward substitution to educate myself)
[Q,R] = qr(X_1)
%now do backward substitution
[nr nc] = …Run Code Online (Sandbox Code Playgroud) matlab svd least-squares qr-decomposition matrix-decomposition
任何人都可以向我解释为什么我们可以这样初始化矢量?int a[]={1,2,3,4,5}; std::vector<int> vec(a,a+sizeof(a)/sizeof(int));我也知道这种方式std::vector<int> vec(5,0);意味着vec有五个元素,它们都被初始化为0.但是这两种方式没有关系.如何解释第一个.如果我们知道值,那么初始化向量的最佳方式(大多数人使用的)是什么.
我认为const char*a [4]意味着[]的元素是const,所以我不能在初始化后改变它.但是,以下代码向我显示它们可以更改.我很困惑......这里的const是什么?
#incldue<iostream>
#include<string>
using namespace std;
int main()
{
int order=1;
for(int i=1; i<10;++i,++order){
const char* a[2];
int b = 10;
// a[0] = to_string(order).c_str();
a[0] = "hello world";
a[1] = to_string(b).c_str();
cout << a[0] << endl;
cout << a[1] << endl;
cout << "**************" << endl;
a[0] = "hello" ;
cout << a[0] << endl;
}
}
Run Code Online (Sandbox Code Playgroud) 我是图表分区的新手,但我认为我问的问题应该已经有了一个很好的答案.我只想将一个巨大的网络(数十亿个节点)划分为几个子图.所以当使用MPI时,每个子图由不同的处理器处理.我目前正在使用图表的邻接列表表示.什么算法可以做到这一点?谢谢!
parallel-processing graph mpi adjacency-list database-partitioning
我在ubuntu 14.04上安装了postgis-9.3,它应该有一个名为“shp2pgsql”的功能。当我“定位”它的位置时,它返回结果,但实际上它不在那里。
yang@ubuntu:~$ locate shp2pgsql-gui
/home/yang/shp2pgsql-gui (1).1
/usr/bin/shp2pgsql-gui
/usr/share/man/man1/shp2pgsql-gui.1.gz
yang@ubuntu:~$ /usr/bin/sh
sha1pass sha384sum showconsolefont shred
sha1sum sha512sum showfont shuf
sha224sum shasum showkey
sha256sum shotwell showrgb
yang@ubuntu:~$ /usr/bin/shp2pgsql-gui
-su: /usr/bin/shp2pgsql-gui: No such file or directory
Run Code Online (Sandbox Code Playgroud)
在哪里可以找到 shp2pgsql?谢谢
我在一个更大的程序中遇到了问题,我制作了另一个较小的程序来显示问题.我期待输出
1 10
10 10
***************
2 10
10 10
****************
3 10
10 10
*****************
Run Code Online (Sandbox Code Playgroud)
...
但结果却不同.我在哪里弄错了?是因为它是const char*类型吗?我真的很困惑.
谢谢.
#include<iostream>
#include<string>
using namespace std;
int main()
{
int order=1;
for(int i=1; i<10;++i,++order){
const char* a[2];
int b = 10;
a[0] = to_string(order).c_str();
a[1] = to_string(b).c_str();
cout << a[0] << endl;
cout << a[1] << endl;
cout << "**************" << endl;
}
}
Run Code Online (Sandbox Code Playgroud)
OUTPUT:
10
10
**************
10
10
**************
10
10
**************
10
10
**************
10
10
**************
10 …Run Code Online (Sandbox Code Playgroud) 我可以用什么样的工具来显示R树的边界框,节点,叶子,就像本页所示的那样?谢谢
我尝试编写自己的线性回归代码,遵循正常方程beta = inv(X'X)X'Y。lstsq然而,平方误差比中的函数大得多numpy.linalg。有人可以向我解释为什么 SVD 方法(lstsq 使用的)比正规方程更准确吗?谢谢
我在读某人的密码.这是来自boost图库的函数.这是原始的函数定义.
void dijkstra_shortest_paths
(const Graph& g,
typename graph_traits<Graph>::vertex_descriptor s,
PredecessorMap predecessor, DistanceMap distance, WeightMap weight,
VertexIndexMap index_map,
CompareFunction compare, CombineFunction combine, DistInf inf, DistZero zero,
DijkstraVisitor vis, ColorMap color = default)
Run Code Online (Sandbox Code Playgroud)
这是我从某人那里挑选出的一段代码.它有效,但我只是不明白他为什么在中间使用点predecessor_map weight_map而distance_map不是逗号?他传入函数的参数是多少?
dijkstra_shortest_paths(graph, source_vertex,
predecessor_map(&predecessors[0])
.weight_map(get(&Edge::cost, graph))
.distance_map(&distances[0]));
Run Code Online (Sandbox Code Playgroud) c++ ×4
svd ×2
boost ×1
boost-graph ×1
bounding-box ×1
const ×1
constructor ×1
geospatial ×1
graph ×1
linux ×1
locate ×1
matlab ×1
mpi ×1
numpy ×1
postgis ×1
postgresql ×1
r-tree ×1
stl ×1
tree ×1
ubuntu ×1
vector ×1