対称行列の大きい方の固有ベクトルを求める問題は次のようにも書ける given M: (n,n)対称行列, to be found X: (n,k)行列 argmax <X, M X> subject to <X, X> = 1, where <A, B> := tr (A^T, B) subject to ...の部分がスティーフェル多様体の定義になっている 特に、k=1の場合は(n-1)次元単位球面になる 身近にある多様体の例になっていると思う 0252デフォルトの名無しさん2019/02/02(土) 19:02:21.25ID:QulgKzxC 間違え subject to X^T X = (k,k)単位行列 0253デフォルトの名無しさん2019/02/22(金) 22:52:15.13ID:+pFzFvdM ``` {Rcpp} #include <Rcpp.h> // 「rcpp 参照渡し」で検索すると出てくる話題 // [[Rcpp::plugins(cpp14)]] // [[Rcpp::export]] SEXP unsafe_negate (SEXP out) { // コピーなしを確実にするために面倒だがSEXP switch (TYPEOF (out)) { // 思いつく残りのキーワード: Rtools on Windows, case REALSXP: { // knitr::all_rcpp_labels, RCPP_MODULE, Rcpp/dispatch.h. Rcpp::NumericVector a (out); // RCPP_MODULE = boost::python std::transform (a.begin (), a.end (), a.begin (), std::negate <double> ()); return out; // https://wiki.python.org/moin/boost.python/HowTo } break; default: { // R 3.5以上で動くかわからない throw std::runtime_error ("unsupported type"); } break; // https://purrple.cat/blog/2018/10/14/altrep-and-cpp/ } // デビアン系だけかもしれないけど、Rstudioの環境下ではC++が超お手軽 } // [[Rcpp::export]] Rcpp::NumericVector safe_negate (Rcpp::NumericVector inn) { Rcpp::NumericVector out = Rcpp::no_init (inn.size ()); std::transform (inn.begin (), inn.end (), out.begin (), std::negate <double> ()); return out; } ``` 0254デフォルトの名無しさん2019/02/22(金) 22:55:11.29ID:+pFzFvdM 残りを貼り忘れた
``` {r} a = 1.0; b = safe_negate (a); cat (a, '->', b); # 1 -> - 1 a = 1.0; b = unsafe_negate (a); cat (a, '->', b); # - 1 -> - 1 ``` 0255デフォルトの名無しさん2019/02/24(日) 02:20:59.21ID:46dkn3Pk 統計使ってオプションの自動売買したいんですけど これ使えばできるようになりますかね? 0256デフォルトの名無しさん2019/02/24(日) 13:00:49.75ID:EIdikGBL もう30年近く前からいっぱい使われてるよ。 それより統計知識と業務知識が先にないとあかんよ。 0257デフォルトの名無しさん2019/03/16(土) 22:01:31.43ID:NxubCN5z 最近ハマったRの文法 ``` {r} tryCatch ({ f = function (x) { x + 1; } + 1; cat (f (1)); }, error = function (ex) { cat (ex); }); ``` 落とし穴というより他のプログラミング言語からの固定観念に縛られていた jsと対比してみる <pre id = 'dump'></pre> ``` {js} $ (window).on ('load', function () { try { const f = function (x) { x + 1; } + 1; $ ('#dump').html (f (1)); } catch (ex) { $ ('#dump').html (ex); } }); ``` 0258デフォルトの名無しさん2019/03/21(木) 11:09:31.67ID:FMbOnfHj 仕事で急遽Rを勉強している者です。 rvestを用いたスクレイピングについて解る方 いらっしゃいましたらご教授願います。
@下記ページを参考に rvest html_sessionで「次へ」のリンクを辿ってURLを抜き出し http://estrellita.hatenablog.com/entry/2015/11/11/084310 AそのURLをリストに追加して Bread_html をかけようとしてるんですが Cno applicable method for 'xml_find_all' applied to an object of class "list" とエラーが出てしまいます。
無知で申し訳ないのですが、原因と解決法わかりますでしょうか? 0259デフォルトの名無しさん2019/03/21(木) 23:21:26.63ID:2X9Nl1zM わかる人が来るまでのつなぎ - 30年以内に来ればラッキーだと思うけど * ['rvest::html' is deprecated, but rvest::read_html doesn't exist. Issue #191 tidyverse/rvest GitHub](https://github.com/tidyverse/rvest/issues/191) * [rvest package | R Documentation](https://www.rdocumentation.org/packages/rvest/versions/0.3.2) ``` {r} with (list (`%>%` = purrr::`%>%`, size = length, null = NULL), { home = 'https://stackoverflow.com'; depth = 0; done = list (); todo = list ('/questions/28863775/scraping-linked-html-webpages-by-looping-the-rvestfollow-link-function'); while (0 < size (todo) & depth < 2) { depth = depth + 1; done = c (done, todo); todo = purrr::reduce (.init = null, .x = todo, .f = function (out, path) { url = paste0 (home, path); text = xml2::read_html (url); nodes = rvest::html_nodes (text, css = '.related a.question-hyperlink'); purrr::reduce (.init = out, .x = nodes, function (out, node) { path = rvest::html_attr (node, 'href'); if (path %in% done) { cat ('what a small world:', path, '\n'); out; } else { cat ('i am going to stalk:', rvest::html_text (node), '\n'); c (out, path); } }); }); } }); ``` 0260デフォルトの名無しさん2019/03/21(木) 23:54:04.09ID:ZeSQsBE1 no applicable method for 'xml_find_all' applied to an object of class "list"
あちこちの変数をデバッグすれば? まず、エラーの場所を特定するべき!
スクレイピングには、Ruby, Nokogiri, Selenium WebDriver が良い 0261デフォルトの名無しさん2019/03/22(金) 12:52:49.39ID:s6oj+Xdm なんで、こういうツールってDOMでのスクレイピングじゃないの? 覚えるの面倒なんだ。 0262デフォルトの名無しさん2019/03/22(金) 22:45:06.06ID:+8Wqz6u2 バグ修正 if (path %in% done | path %in% out) { cat ('what a small world:', path, '\n'); out; } else { cat ('i am going to stalk:', rvest::html_text (node), '\n'); c (out, path); } 0263デフォルトの名無しさん2019/03/24(日) 22:07:13.75ID:EjBOavUP 楽しいライブラリ