This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# objective function | |
obj_func <- function(x){ 100*(x[2]-x[1]^2)^2 + (1 - x[1])^2 } | |
# initial value | |
x1 <- c(-1.2, 1) | |
# nelder and mead method | |
Nelder_mead(x1, obj_func=obj_func) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### definition ##### | |
Nelder_mead <- function(x1, lambda=1, obj_func, alpha=1, gamma=2, rho=1/2, sigma=1/2){ | |
# dimmension | |
dim_x <- length(x1) | |
# generate n point using given x | |
# and summarize n+1 point (x1, ... , xn+1) | |
simplex_point <- cbind(x1, x1 + lambda*diag(dim_x)) | |
# initial criterion value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#========================== | |
# 日本地図描画関数を定義 | |
# JapanPlot3d | |
# 日本地図を描画する関数 | |
# 都道府県をローマ字で指定するとその県のみ描画する(複数指定可能) | |
# ローマ字の対応については以下を参照のこと | |
PreNames <- | |
c("Aichi","Ehime","Ibaraki","Okayama","Okinawa","Iwate","Gifu","Miyazaki", | |
"Miyagi","Kyoto","Kumamoto","Gunma","Hiroshima", "Kagawa","Kochi","Saga", | |
"Saitama","Mie","Yamagata","Yamaguchi","Yamanashi","Shiga","Kagoshima","Akita", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#========================== | |
# 日本地図描画関数を定義 | |
# JapanPlot これは2次元です | |
# 日本地図を描画する関数 | |
# 都道府県をローマ字で指定するとその県のみ描画する(複数指定可能) | |
# ローマ字の対応については以下を参照のこと | |
PreNames <- | |
c("Aichi","Ehime","Ibaraki","Okayama","Okinawa","Iwate","Gifu","Miyazaki", | |
"Miyagi","Kyoto","Kumamoto","Gunma","Hiroshima", "Kagawa","Kochi","Saga", | |
"Saitama","Mie","Yamagata","Yamaguchi","Yamanashi","Shiga","Kagoshima","Akita", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# package 読み込み | |
library(rgl) | |
library(maptools) | |
library(spsurvey) | |
# カレントディレクトリをshapeファイルがあるフォルダにあらかじめ移しておくこと | |
shape.world <- read.shape(filename='ne_10m_admin_1_states_provinces_scale_rank.shp') | |
jpn.num <- which(shape.world$sr_sov_a3=='JPN') | |
# shapeファイルに保存されている都道府県の表記, 兵庫だけちょっと変なので注意 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clear3d() | |
for(i in 1:n){ | |
tmp1 <- map.data[[i]] | |
tmp2 <- data.frame(tmp1,0) | |
if(i==1){ | |
plot3d(tmp2, type="l", xlim=jpn.xlim, ylim=jpn.ylim, zlim=c(0,100),xlab='', ylab='', zlab="") | |
} | |
lines3d(tmp2) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for(i in 1:n){ | |
tmp1 <- map.data[[i]] | |
if(i==1){ | |
plot(tmp1, type="l", xlim=jpn.xlim, ylim=jpn.ylim, xlab='', ylab='') | |
} | |
lines(tmp1) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# パッケージの読み込み | |
library(rgl) | |
library(maptools) | |
library(spsurvey) | |
# ダウンロードしたzipファイルを解答してできたフォルダがあるディレクトリに行きましょう。(下のコードはデスクトップに置いてある場合です) | |
setwd('~/Desktop/ne_10m_admin_1_states_provinces_scale_rank') | |
# shpファイルの読み込み | |
shape.world <- read.shape(filename='ne_10m_admin_1_states_provinces_scale_rank.shp') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x1 <- seq(0,1,0.0005) | |
x2 <- seq(1,100,1) | |
x <- c(x1, x2) | |
par(mfrow=c(1,1), family='HiraKakuProN-W3') | |
plot(0,0,type="n", ylim=c(-1,10), xlim=c(-8,10^2), xlab='', ylab='', main="対数関数の性質") | |
abline(h=c(0,8)) | |
abline(v=c(log(0.0005),0,1,log(100)), lty="dashed", lwd=0.5) | |
points(40, 8.5, pch="x") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jpn.xlim <- c(125, 150) | |
jpn.ylim <- c(25, 48) | |
jpn.zlim <- c(0,200) | |
clear3d() | |
for(i in 1:47){ | |
x <- all.list[[i]] | |
if(i==1){ | |
if(length(x)!=1){ | |
for(j in 1:length(x)){ | |
x2 <- x[[j]] |
NewerOlder