小编day*_*yup的帖子

我的例子表明SVD在数值上比QR分解更不稳定

我在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

3
推荐指数
1
解决办法
1045
查看次数

C++初始化向量

任何人都可以向我解释为什么我们可以这样初始化矢量?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.但是这两种方式没有关系.如何解释第一个.如果我们知道值,那么初始化向量的最佳方式(大多数人使用的)是什么.

c++ constructor stl initialization vector

2
推荐指数
1
解决办法
262
查看次数

const char*a [4]; 我可以更改[]值吗?

我认为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)

c++ const

2
推荐指数
1
解决办法
439
查看次数

mpi并行的快速图形分区

我是图表分区的新手,但我认为我问的问题应该已经有了一个很好的答案.我只想将一个巨大的网络(数十亿个节点)划分为几个子图.所以当使用MPI时,每个子图由不同的处理器处理.我目前正在使用图表的邻接列表表示.什么算法可以做到这一点?谢谢!

parallel-processing graph mpi adjacency-list database-partitioning

2
推荐指数
1
解决办法
201
查看次数

在 Linux 中即使“locate”返回其位置也找不到文件

我在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?谢谢

linux postgresql ubuntu postgis locate

1
推荐指数
1
解决办法
1398
查看次数

使用const char*,to_string()和c_str()的wierd输出

我在一个更大的程序中遇到了问题,我制作了另一个较小的程序来显示问题.我期待输出

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)

c++

1
推荐指数
1
解决办法
156
查看次数

1
推荐指数
1
解决办法
1137
查看次数

最小二乘法:正规方程与 svd

我尝试编写自己的线性回归代码,遵循正常方程beta = inv(X'X)X'Ylstsq然而,平方误差比中的函数大得多numpy.linalg。有人可以向我解释为什么 SVD 方法(lstsq 使用的)比正规方程更准确吗?谢谢

numpy linear-regression svd least-squares

1
推荐指数
1
解决办法
1482
查看次数

为什么BGL函数的参数用点而不是逗号分隔?

我在读某人的密码.这是来自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_mapdistance_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++ boost boost-graph

0
推荐指数
1
解决办法
186
查看次数