書評: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環境設定1

anacondaからARMネイティブなディストリビューションがリリースされていたのでインストールしました。

ところが、インストール後にナビゲーターを起動すると、R Studioがパッケージに含まれていません。

ARM MAC 版の Anacondaには Rの処理環境はバンドルされていません。

別途、Rの環境をインストールすることにします。

Home Brewのインストール

x86版のBrewがインストール済みであれば外してから、ARM版をインストールします。

# uninstall x86_64 homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"
# make sure you unalias "brew" if you aliased it with "arch"

# install arm64 homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
# install wget (to make sure stuff is working)
brew install wget

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
==> Checking for `sudo` access (which may request your password)...
Password:
==> This script will install:
/opt/homebrew/bin/brew
/opt/homebrew/share/doc/homebrew
/opt/homebrew/share/man/man1/brew.1
/opt/homebrew/share/zsh/site-functions/_brew
/opt/homebrew/etc/bash_completion.d/brew
/opt/homebrew
==> The following new directories will be created:
/opt/homebrew/Cellar
/opt/homebrew/Caskroom

Press RETURN/ENTER to continue or any other key to abort:
==> /usr/bin/sudo /bin/mkdir -p /opt/homebrew/Cellar /opt/homebrew/Caskroom
==> /usr/bin/sudo /bin/chmod ug=rwx /opt/homebrew/Cellar /opt/homebrew/Caskroom
==> /usr/bin/sudo /usr/sbin/chown xxxxxxxx /opt/homebrew/Cellar /opt/homebrew/Caskroom
==> /usr/bin/sudo /usr/bin/chgrp admin /opt/homebrew/Cellar /opt/homebrew/Caskroom
==> /usr/bin/sudo /usr/sbin/chown -R xxxxxxxx:admin /opt/homebrew
==> /usr/bin/sudo /bin/mkdir -p /Users/xxxxxxxx/Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Users/xxxxxxxx/Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown -R xxxxxxxx /Users/xxxxxxxx/Library/Caches/Homebrew
==> Downloading and installing Homebrew...
remote: Enumerating objects: 233534, done.
remote: Counting objects: 100% (119/119), done.
remote: Compressing objects: 100% (107/107), done.
remote: Total 233534 (delta 19), reused 80 (delta 12), pack-reused 233415
Receiving objects: 100% (233534/233534), 67.19 MiB | 255.00 KiB/s, done.
Resolving deltas: 100% (171421/171421), done.
From https://github.com/Homebrew/brew
 * [new branch]          master     -> origin/master
 * [new tag]             0.1        -> 0.1
 * [new tag]             0.2        -> 0.2
 * [new tag]             0.3        -> 0.3
 * [new tag]             0.4        -> 0.4
 * [new tag]             0.5        -> 0.5
 * [new tag]             0.6        -> 0.6
 * [new tag]             0.7        -> 0.7

  .
  .
 省略
  .
  .
  .

 * [new tag]             4.0.6      -> 4.0.6
 * [new tag]             4.0.7      -> 4.0.7
 * [new tag]             4.0.8      -> 4.0.8
 * [new tag]             4.0.9      -> 4.0.9
HEAD is now at d80f7ac48 Merge pull request #15052 from MikeMcQuaid/formulary_service
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics data has been sent yet (nor will any be during this install run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations

==> Next steps:
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

次にwgetをインストールします

brew install wget

$ brew install wget
Running `brew update --auto-update`...
==> Auto-updated Homebrew!
Updated 2 taps (shivammathur/php and homebrew/core).
==> New Formulae
adr-viewer                               mailsy
agg                                      mariadb@10.10
aichat                                   mariadb@10.8
aicommits                                mariadb@10.9
aiven-client                             markdownlint-cli2
akku                                     marksman

  .
  .
  .
  省略
 .
  
lmfit                                    zf
luacheck                                 zlint
lucky-commit                             zls
m1ddc                                    zsh-autocomplete
macpine                                  zsh-autopair
==> Deleted Formulae
php@7.3 ✘

You have 52 outdated formulae installed.
You can upgrade them with brew upgrade
or list them with brew outdated.

Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
Please create a new installation in /opt/homebrew using one of the
"Alternative Installs" from:
  https://docs.brew.sh/Installation
You can migrate your previously installed formula list with:
  brew bundle dump

エラーになりました。

以前のバージョンとマイグレーションするため、以下のコマンドを試します。

brew bundle dump

$ brew bundle dump
==> Tapping homebrew/bundle
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-bundle'...
remote: Enumerating objects: 7042, done.
remote: Counting objects: 100% (843/843), done.
remote: Compressing objects: 100% (154/154), done.
Receiving objects: 100% (7042/7042), 1.65 MiB | 340.00 KiB/s, done.
remote: Total 7042 (delta 739), reused 744 (delta 689), pack-reused 6199
Resolving deltas: 100% (4117/4117), done.
Tapped 1 command (99 files, 2MB).

次にhomebrewを別な方法でインストールします。

git clone https://github.com/Homebrew/brew homebrew

$ git clone https://github.com/Homebrew/brew homebrew
Cloning into 'homebrew'...
remote: Enumerating objects: 233534, done.
remote: Counting objects: 100% (75/75), done.
remote: Compressing objects: 100% (63/63), done.
remote: Total 233534 (delta 19), reused 36 (delta 12), pack-reused 233459
Receiving objects: 100% (233534/233534), 67.19 MiB | 333.00 KiB/s, done.
Resolving deltas: 100% (171421/171421), done.

eval "$(homebrew/bin/brew shellenv)"
brew update --force --quiet

$ brew update --force --quiet
==> Homebrew has enabled anonymous aggregate formula and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics have been recorded yet (nor will be during this `brew` run).

==> Tapping homebrew/core
Cloning into '/Users/xxxxxxxxx/homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 1442857, done.
remote: Counting objects: 100% (364/364), done.
remote: Compressing objects: 100% (185/185), done.
remote: Total 1442857 (delta 225), reused 306 (delta 179), pack-reused 1442493
Receiving objects: 100% (1442857/1442857), 556.64 MiB | 1.67 MiB/s, done.
Resolving deltas: 100% (1007537/1007537), done.
Tapped 2 commands and 6597 formulae (6,950 files, 611.9MB).

chmod -R go-w "$(brew --prefix)/share/zsh"

ライブラリのインストール

ライブラリ関係をインストールします。

ダウンロードするファイルを一時保存しておくためのディレクトリを作成します。

その中にarm64用のライブラリをダウンロードします。

#install arm64 homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

#install wget

brew install wget

# place for r-libs
mkdir ~/Downloads/libs-arm64/
# go there
cd ~/Downloads/libs-arm64
# grab'em from https://mac.r-project.org/libs-arm64/
for dl in $(curl -sS "https://mac.r-project.org/libs-arm64/" \
  | xmllint --html --xpath '//td/a[contains(@href, 'tar.gz')]/@href' 2>/dev/null - \
  | sed -e 's/ href="//g' -e 's/"/\n/g'); do wget https://mac.r-project.org/libs-arm64/${dl} ; done

# prime sudo
sudo ls ~/Downloads/libs-arm64
# extract'em
for gz in $(ls ~/Downloads/libs-arm64/*gz); do  
  sudo tar fvxz ${gz} -C /
done
64-darwin20.dmg
mac.r-project.org (mac.r-project.org) をDNSに問いあわせています... 169.60.149.197
mac.r-project.org (mac.r-project.org)|169.60.149.197|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 73110774 (70M) [application/octet-stream]
`emacs-27.1-app-arm64-darwin20.dmg' に保存中

emacs-27.1-app-arm6 100%[===================>]  69.72M   378KB/s 時間 2m 26s   

2023-03-25 07:25:16 (488 KB/s) - `emacs-27.1-app-arm64-darwin20.dmg' へ保存完了 [73110774/73110774]

--2023-03-25 07:25:17--  https://mac.r-project.org/libs-arm64/tcltk-8.6.11-xft-darwin20.4-arm64.pkg
mac.r-project.org (mac.r-project.org) をDNSに問いあわせています... 169.60.149.197
mac.r-project.org (mac.r-project.org)|169.60.149.197|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 8393736 (8.0M) [application/octet-stream]
`tcltk-8.6.11-xft-darwin20.4-arm64.pkg' に保存中

tcltk-8.6.11-xft-da 100%[===================>]   8.00M  2.08MB/s 時間 3.9s     

2023-03-25 07:25:21 (2.08 MB/s) - `tcltk-8.6.11-xft-darwin20.4-arm64.pkg' へ保存完了 [8393736/8393736]

--2023-03-25 07:25:21--  https://mac.r-project.org/libs-arm64/texinfo-6.7-darwin20.4-arm64.pkg
mac.r-project.org (mac.r-project.org) をDNSに問いあわせています... 169.60.149.197
mac.r-project.org (mac.r-project.org)|169.60.149.197|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 1495341 (1.4M) [application/octet-stream]
`texinfo-6.7-darwin20.4-arm64.pkg' に保存中

texinfo-6.7-darwin2 100%[===================>]   1.43M   259KB/s 時間 5.5s     

2023-03-25 07:25:28 (265 KB/s) - `texinfo-6.7-darwin20.4-arm64.pkg' へ保存完了 [1495341/1495341]

ダウンロードしたファイルを展開します。

# prime sudo
sudo ls ~/Downloads/libs-arm64
# extract'em
for gz in $(ls ~/Downloads/libs-arm64/*gz); do  
  sudo tar fvxz ${gz} -C /
done

x opt/R/arm64/bin/lzmore
x opt/R/arm64/bin/lzfgrep
x opt/R/arm64/bin/xzmore
x opt/R/arm64/bin/xzgrep
x opt/R/arm64/bin/lzma
x opt/R/arm64/bin/lzegrep
x opt/R/arm64/bin/xzdiff
x opt/R/arm64/
x opt/R/arm64/bin/
x opt/R/arm64/include/
x opt/R/arm64/lib/
x opt/R/arm64/pkg/
x opt/R/arm64/pkg/zeromq-4.3.2-darwin.20-arm64.list
x opt/R/arm64/lib/pkgconfig/
x opt/R/arm64/lib/libzmq.la
x opt/R/arm64/lib/libzmq.a
x opt/R/arm64/lib/pkgconfig/libzmq.pc
x opt/R/arm64/include/zmq_utils.h
x opt/R/arm64/include/zmq.h
x opt/R/arm64/bin/curve_keygen

開発環境のインストール

# grab r-devel
wget https://mac.r-project.org/big-sur/R-devel/arm64/R-devel.tar.gz
$ wget https://mac.r-project.org/big-sur/R-devel/arm64/R-devel.tar.gz
--2023-03-25 07:27:52--  https://mac.r-project.org/big-sur/R-devel/arm64/R-devel.tar.gz
mac.r-project.org (mac.r-project.org) をDNSに問いあわせています... 169.60.149.197
mac.r-project.org (mac.r-project.org)|169.60.149.197|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 79330143 (76M) [application/octet-stream]
`R-devel.tar.gz' に保存中

R-devel.tar.gz      100%[===================>]  75.65M   861KB/s 時間 1m 44s   

2023-03-25 07:29:37 (744 KB/s) - `R-devel.tar.gz' へ保存完了 [79330143/79330143]

圧縮ファイルを展開してインストールします。

# extract it
sudo tar fvxz R*.tar.gz -C /

x Library/Frameworks/R.framework/Versions/4.4-arm64/PrivateHeaders/R_ext/stats_package.h
x Library/Frameworks/R.framework/Versions/4.4-arm64/PrivateHeaders/R_ext/Makefile.in
x Library/Frameworks/R.framework/Versions/4.4-arm64/PrivateHeaders/R_ext/Complex.h
x Library/Frameworks/R.framework/Versions/4.4-arm64/PrivateHeaders/R_ext/Lapack.h
x Library/Frameworks/R.framework/Versions/4.4-arm64/PrivateHeaders/R_ext/Random.h
x Library/Frameworks/R.framework/Versions/4.4-arm64/PrivateHeaders/R_ext/eventloop.h
x Library/Frameworks/R.framework/Versions/4.4-arm64/PrivateHeaders/vg/valgrind.h
x Library/Frameworks/R.framework/Versions/4.4-arm64/PrivateHeaders/vg/memcheck.h
brew install libxml2 ccache libgit2 unixodbc
For pkg-config to find libxml2 you may need to set:
  export PKG_CONFIG_PATH="/Users/xxxxxxxx/homebrew/opt/libxml2/lib/pkgconfig"
==> ccache
To install symlinks for compilers that will automatically use
ccache, prepend this directory to your PATH:
  /Users/xxxxxxxx/homebrew/opt/ccache/libexec

If this is an upgrade and you have previously added the symlinks to
your PATH, you may need to modify it to the path specified above so
it points to the current version.

NOTE: ccache can prevent some software from compiling.
ALSO NOTE: The brew command, by design, will never use ccache.

 パスをとうすために以下の一行を~/.zshrc に追加します。

export PATH=/opt/R/arm64/bin:$PATH

vi ~/.zshrc

また、コマンドプロンプトからも同じ処理実行します。

# and also run it at the command prompt
export PATH=/opt/R/arm64/bin:$PATH

変更を読み込みます。

source ~/.zshrc

続きの設定は以下のリンクへ

-システム
-,