書評:Shocks, Crises, and False Alarms: How to Assess True Macroeconomic Risk

2025/4/20

Shocks, Crises, and False Alarms: How to Assess True Macroeconomic Risk Philipp Carlsson-Szlezak, Paul Swartz Shocks, Crises, and False Alarms: How to Assess True Macroeconomic Risk  本書はマクロ経済における近年見られたような、ショック、危機などのリスクを案内します。  マクロ経済のリスクを判断するとき、リスクが実際のショック ...

ReadMore

合衆国の新関税の税率と貿易収支

2025/4/17

2025年4月2日に合衆国の新しい関税の税率が公表されました。現在の貿易収支の状況と導入される関税の税率をまとめます。 合衆国の貿易収支 図1 合衆国の貿易収支2023年(単位:USD million)  図1は、左側が輸出国、右側が輸入国です。マウスポインタを領域の上に置くと、輸出入額(単位:100万USドル)を表示します。 データソースはJETROがまとめている貿易投資年報より参照。 新関税の税率と各国の対米貿易収支 図2 関税税率と対米貿易収支 対米貿易収支は、輸出額から輸入額を減算した値(単位:1 ...

ReadMore

強化学習による因果探索 gCastle因果探索アルゴリズムの検証(3)

2025/3/18

gCastleに実装された探索アルゴリズムの中で、強化学習を使ったアルゴリズムが高い性能を示しています。本稿ではこの探索のための強化学習アルゴリズムを解説します。 強化学習を使った探索  強化学習は一般的にポリシーを学習することを目的に用いられますが、彼らはこれをDAGの探索に使っています。  巡回セールスマンの問題と同様に、d次元のnシーケンスでベストスコアを導くことで、入力データからバイナリの隣接行列の生成を考えます。  隣接行列を出力するためにエンコーダ/デコーダ・モデルを作りますが、エンコーダ自己 ...

ReadMore

CastleBoardの使い方 gCastle因果探索アルゴリズムの検証(2)

2025/3/2

中国のAI技術動向の調査を兼ねて、gCastleに実装された因果探索アルゴリズムを検証しました。gCastleはGUIツールCastleBoardを含んでいますが、パッケージにツールのマニュアル類は添付されていません。そのため、本稿では実際にアルゴリズムを検証するためのCastleBoardの使い方について解説します。 CastleBoardの操作  GUIツールはいくつかの設定項目への入力でテストデータを生成できるため、テストプログラムを組むより簡単にアルゴリズムを検証できます。ツールの機能は主に二つの ...

ReadMore

マイニング・セクターのリスク許容度、関税の影響 (DoubleMLの推論)

2025/3/14

 2025年2月に合衆国の新政権の政策として、鉄鋼とアルミニウムに25%の関税が課されることが決定されました。一方で、ウクライナへのこれまでの支援の対価として、ウクライナの鉱物資源などの天然資源の権益取得が交渉されています。  この関税政策が、原料である鉄鉱石やボーキサイトなどの鉱物資源の採掘を行なっている企業に与える影響について分析します。  分析手段として機械学習を使った推論手法、DoubleML(Double Machine Learning)を用います。このDoubleMLという推論手法と同じ名称 ...

ReadMore

gCastle 因果探索アルゴリズムの検証

2025/2/28

gCastleは、因果探索アルゴリズムが実装された因果の構造を学習するツールチェインです。パッケージは、Webアプリを含んでおり、因果探索アルゴリズムがGUIベースの操作で検証できるようになっています。 gCastle 概要  Huawei社のリサーチラボから提供されています。因果探索アルゴリズムが実装されており、Webアプリを使用してアルゴリズムの動作が検証できます。  GCastleの名称は、Gradient-based Causal Structure Learning pipeline. の頭文字 ...

ReadMore

クレジット・カードの種別と利用額の最適化 YLearnによる因果推論(2)

2025/2/20

YLearn因果推論パッケージを使ったケース・スタディを使ってYLearnの機能を解説します。YLearnの因果推論パイプラインを使ったマーケティング上の分析の一つになります。クレジット・カードのグレードを更新した場合の効果の推論です。 機能と仕様  以下、簡単に機能をまとめ、最後にケーススタディを使って動作を確認します。ケース・スタディでは、Kaggleの実際のデータセットを使います。 DAG グラフと交絡因子  観測されていない変数はconfounding arcとして定義し、下の図1では(黒の点線) ...

ReadMore

YLearnによる因果推論(1) 概要とセットアップ

2025/2/20

 因果推論はAIシステムが、イベント間の真の因果関係をよりよく理解する助けになります。中国製のLLMが最近、話題(注1)になっていたので、データサイエンス分野で中国の因果推論に関する取り組みとツールについて評価します。  因果推論や因果探索のツールとして、Huaweiが提供しているgCastleと、因果探索・因果推論ツール、ylearnを使います。gCastleはPyTorchで実装された因果探索パッケージです。因果関係に関連した代表的なアルゴリズムが実装されて、検証ツールが提供されています。Huawei ...

ReadMore

Jupyter-notebookがAnaconda Navigatorから起動できない問題

2025/2/6

新しいAnaconda Navigatorをインストールしたところ、jupyter-notebook(7.3.2)がNavigatorから起動できない問題がありました。 Navigatorのエラーメッセージは、次のようになっています。 【The file /Users/xxx/anaconda3/bin/Jupyter_mac.command does not exist.】 jupyter_mac.command does not exist.  問題は、インストールまたはNavigatorが参照してい ...

ReadMore

Apple Silicon Mac 用 Anacondaバージョン更新・インストール

2025/2/5

Apple Silicon用に新しいバージョンのAnacondaがリリースされていたので、Navigatorの更新を兼ねてインストールします。 (Mac OSの更新(Sequoia15.3)によって、使用中のNavigatorが起動しなくなったため) Anaconda Navigatorのインストール  以下のAnacondaのサイトにアクセスします。最近のAIに対する、人と資本、計算リソースの流れを反映した画面に様変わりしています。 https://www.anaconda.com  【1】画面左上のP ...

ReadMore

システム

Apple Silicon M2 Mac の R環境設定 2

Rのインストール

Brewによるインストールを試しましたが、TCL/tkのバージョンの相違でコンパイルが止まりました。

後で、バイナリをインストールします。

brew install R
$ brew install R
==> Fetching dependencies for r: pkg-config, libpng, freetype, fontconfig, gettext, ninja, mpdecimal, ca-certificates, openssl@1.1, readline, sqlite, xz, python@3.11, meson, pcre2, glib, util-macros, xtrans, xorgproto, libxau, libxdmcp, libxcb, libx11, libxext, libxrender, lzo, pixman, cairo, gmp, isl, mpfr, libmpc, lz4, zstd, gcc, jpeg-turbo, openblas and tcl-tk
==> Fetching pkg-config
Warning: Building pkg-config from source:
  The bottle (and many others) needs to be installed into /opt/homebrew.

==> Downloading https://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar
######################################################################## 100.0%
==> Fetching libpng
==> Downloading https://ghcr.io/v2/homebrew/core/libpng/manifests/1.6.39-1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/libpng/blobs/sha256:27fb15928d0
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Fetching freetype
==> Downloading https://ghcr.io/v2/homebrew/core/freetype/manifests/2.13.0_1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/freetype/blobs/sha256:9dec5b349
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Fetching fontconfig
Warning: Building fontconfig from source as the bottle needs:
- HOMEBREW_CELLAR: /opt/homebrew/Cellar (yours is /Users/xxxxxxxx/homebrew/Cellar)
- HOMEBREW_PREFIX: /opt/homebrew (yours is /Users/xxxxxxxx/homebrew)
==> Downloading https://www.freedesktop.org/software/fontconfig/release/fontconf
######################################################################## 100.0%
==> Fetching gettext
Warning: Building gettext from source as the bottle needs:
- HOMEBREW_CELLAR: /opt/homebrew/Cellar (yours is /Users/xxxxxxxx/homebrew/Cellar)
- HOMEBREW_PREFIX: /opt/homebrew (yours is /Users/xxxxxxxx/homebrew)
==> Downloading https://ftp.gnu.org/gnu/gettext/gettext-0.21.1.tar.gz
curl: (6) Could not resolve host: ftp.gnu.org
Warning: Problem : timeout. Will retry in 1 seconds. 3 retries left.
curl: (6) Could not resolve host: ftp.gnu.org                                 
Warning: Problem : timeout. Will retry in 2 seconds. 2 retries left.
curl: (6) Could not resolve host: ftp.gnu.org                                 
Warning: Problem : timeout. Will retry in 4 seconds. 1 retries left.
curl: (6) Could not resolve host: ftp.gnu.org                                 

Trying a mirror...
==> Downloading https://ftpmirror.gnu.org/gettext/gettext-0.21.1.tar.gz
==> Downloading from https://gnu.askapache.com/gettext/gettext-0.21.1.tar.gz
######################################################################## 100.0%

..
..
              .

                      省略
              .
..
..
==> Fetching ninja
==> Fetching openblas
==> Downloading https://ghcr.io/v2/homebrew/core/openblas/manifests/0.3.21
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/openblas/blobs/sha256:5f2cdcefe
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Fetching tcl-tk
Warning: Building tcl-tk from source as the bottle needs:
- HOMEBREW_CELLAR: /opt/homebrew/Cellar (yours is /Users/xxxxxxxx/homebrew/Cellar)
- HOMEBREW_PREFIX: /opt/homebrew (yours is /Users/xxxxxxxx/homebrew)
==> Downloading https://github.com/andreas-kupries/critcl/archive/3.1.18.1.tar.g
==> Downloading from https://codeload.github.com/andreas-kupries/critcl/tar.gz/r
    # -#O=-#   #                                                              
==> Downloading https://downloads.sourceforge.net/project/tcllib/tcllib/1.21/tcl
==> Downloading from https://jaist.dl.sourceforge.net/project/tcllib/tcllib/1.21
######################################################################## 100.0%
==> Downloading https://core.tcl-lang.org/tcltls/uv/tcltls-1.7.22.tar.gz
######################################################################## 100.0%
==> Downloading https://downloads.sourceforge.net/project/tcl/Tcl/8.6.13/tk8.6.1
==> Downloading from https://jaist.dl.sourceforge.net/project/tcl/Tcl/8.6.13/tk8
######################################################################## 100.0%
==> Downloading https://downloads.sourceforge.net/project/incrtcl/%5Bincr%20Tcl_
==> Downloading from https://jaist.dl.sourceforge.net/project/incrtcl/%5Bincr%20
######################################################################## 100.0%
==> Downloading https://downloads.sourceforge.net/project/tcl/Tcl/8.6.13/tcl8.6.
==> Downloading from https://jaist.dl.sourceforge.net/project/tcl/Tcl/8.6.13/tcl
######################################################################## 100.0%
==> Fetching r
Warning: Building r from source as the bottle needs:
- HOMEBREW_CELLAR: /opt/homebrew/Cellar (yours is /Users/xxxxxxxx/homebrew/Cellar)
- HOMEBREW_PREFIX: /opt/homebrew (yours is /Users/xxxxxxxx/homebrew)
==> Downloading https://raw.githubusercontent.com/Homebrew/formula-patches/1b110
######################################################################## 100.0%
==> Downloading https://cran.r-project.org/src/base/R-4/R-4.2.3.tar.gz
######################################################################## 100.0%
Error: Your Command Line Tools are too outdated.
Update them from Software Update in System Settings.

If that doesn't show you any updates, run:
  sudo rm -rf /Library/Developer/CommandLineTools
  sudo xcode-select --install

Alternatively, manually download them from:
  https://developer.apple.com/download/all/.
You should download the Command Line Tools for Xcode 14.1.

エラーが発生したので、以下のコマンドを実行します。

sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install

インストール後に、再度 Rのインストールを実行します。

==> ./configure --prefix=/Users/xxxxxxxx/homebrew/Cellar/tcl-tk/8.6.13_1 
==> make
Last 15 lines from /Users/xxxxxxxx/Library/Logs/Homebrew/tcl-tk/16.make:
1 error generated.
make: *** [itkUtil.o] Error 1
make: *** [itkOption.o] Error 1
1 error generated.
1 error generated.
make: *** [itkStubInit.o] Error 1
In file included from ./generic/itkArchetype.c:36:
In file included from ./generic/itkInt.h:24:
In file included from ./generic/itk.h:86:
/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/include/tk.h:31:3: error: Tk 8.5 must be compiled with tcl.h from Tcl 8.5
#       error Tk 8.5 must be compiled with tcl.h from Tcl 8.5
        ^
make: *** [itkBase.o] Error 1
1 error generated.
make: *** [itkArchetype.o] Error 1

Do not report this issue to Homebrew/brew or Homebrew/homebrew-core!

このエラーはTcl 8.5と他のバージョンのTclが同居している場合に発生するようです。

コンパイラはXcodeのライブラリヘッダ参照しています。

makeするTcl/tkのソースが8.6なので、整合性が取れません。

SDK Xcodeのライブラリを参照しており、移動して確認してみるとフレームワークのバージョン8.5にリンクが貼られています。

cd /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/include/

lrwxr-xr-x  1 root  wheel  70  3 24 23:46 tk.h -> ../../System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/tk.h

参照するヘッダのリンク先を変更すれば良さそうですが、少し手間がかかりそうです。

CRANから Rバイナリパッケージをインストール

CRANを参照すると、ARM Mac用のビルド済みパッケージがありました。

問題解決です。

Brewでコンパイルせず、CRANからパッケージをダウンロードしてインストールします。

CRANのWebサイト へアクセスし "R-4.2.3-arm64.pkg" をダウンロードします。

https://cran.r-project.org

ダウンロードしたファイルをダブルクリックすると、インストーラが起動します。

GUIインターフェイスに従ってインストールすれば完了です。

コマンドプロンプトからRと入力。

起動できました。

バージョンを確認してみます。

R --version

R version 4.2.3 (2023-03-15) -- "Shortstop Beagle"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin20 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.

reposオプションでミラーサイトを指定します。

後は、必要なパッケージをインストールしてください。

options(repos="https://cran.ism.ac.jp/")
install.packages('必要なパッケージ')

パッケージをインストール中に以下の警告メッセージが出る場合があります。

 警告メッセージ: 
 doTryCatch(return(expr), name, parentenv, handler) で: 
   共有ライブラリ '/Library/Frameworks/R.framework/Resources/modules//R_X11.so' を読み込めません: 
  dlopen(/Library/Frameworks/R.framework/Resources/modules//R_X11.so, 0x0006): Library not loaded: /opt/X11/lib/libSM.6.dylib
  Referenced from: <A6A60F0C-DFA1-3218-B816-7CAADC1A4CD5> /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/modules/R_X11.so
  Reason: tried: '/opt/X11/lib/libSM.6.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/X11/lib/libSM.6.dylib' (no such file), '/opt/X11/lib/libSM.6.dylib' (no such file), '/Library/Frameworks/R.framework/Resources/lib/libSM.6.dylib' (no such file), '/Library/Java/JavaVirtualMachines/jdk-17.0.1+12/Contents/Home/lib/server/libSM.6.dylib' (no such file) 
> install.packages('Quandl')
 URL 'https://cran.ism.ac.jp/bin/macosx/big-sur-arm64/contrib/4.2/Quandl_2.11.0.tgz' を試しています 
Content type 'application/x-gzip' length 68298 bytes (66 KB)

 X11の共有ライブラリが読み込めないとのことです。

 X11をインストールします。

以下のWebサイトへ移動します。

https://www.xquartz.org

XQuartz -2.8.5.pkg をダウンロードします。
インストール後に再度,Quandlのパッケージをインストールします。

install.packages('Quandl')
 URL 'https://cran.ism.ac.jp/bin/macosx/big-sur-arm64/contrib/4.2/Quandl_2.11.0.tgz' を試しています 
Content type 'application/x-gzip' length 68298 bytes (66 KB)
==================================================
downloaded 66 KB


 ダウンロードされたパッケージは、以下にあります 
 	/var/folders/z3/y2vb_4653kjcytsygg5bkv7w0000gn/T//RtmpbdtPcd/downloaded_packages 

他の有用なファイナンス関連のパッケージもCRANからインストールしてください。

-システム
-,