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
| /* ベイズ情報量基準 */ | |
| double bic(double logLike,int numSample,int numModel){ | |
| return -2*logLike+numModel*log(numSample); | |
| } | |
| /* 学習スコア */ | |
| double score(int numNode,int *edge,int numSample,double **likelies,int *variablePattern){ | |
| double like; | |
| int i,j,numModel,numParents; | |
| unsigned char parentPattern; |
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
| """ | |
| G検定による独立性の検定 | |
| """ | |
| import numpy as np | |
| from scipy.stats import chisqprob, chisquare | |
| def gtest(f_obs, f_exp=None, ddof=0): | |
| """ | |
| http://en.wikipedia.org/wiki/G-test | |
| The G test can test for goodness of fit to a distribution |
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
| # Refererce:http://ushi-goroshi.hatenablog.com/entry/2018/01/11/233317 | |
| # install.packages("bnlearn") | |
| # install.packages("BNSL") | |
| library(bnlearn) | |
| library(BNSL) | |
| set.seed(123) | |
| norm <- rnorm(4000) |
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
| import numpy as np | |
| n_sample = 1000 | |
| true_coef = np.array([2.0, 3.0]) | |
| u0 = np.array([0.0, 0.0]) | |
| A0 = 0.1 * np.eye(2) | |
| sample_X = np.random.normal(size=(n_sample, 2)) | |
| sample_y = np.dot(sample_X, true_coef.reshape(-1, 1)).reshape(-1,) + np.random.normal(size=n_sample) | |
| tmp1 = np.linalg.inv(np.dot(sample_X.T, sample_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
| """ | |
| String Kernel | |
| Reference: "5.構造化データに対するカーネル" 福水健次 | |
| http://www.ism.ac.jp/~fukumizu/ISM_lecture_2010/Kernel_5_structured.pdf | |
| """ | |
| import numpy as np | |
| def subSequenceJustLength(result, str, cur_str, length, depth=0): | |
| if depth == length: | |
| result.append(cur_str) |
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
| # -*- coding: utf-8 -*- | |
| """ | |
| Reference: | |
| トピックモデルによる統計的潜在意味解析 4章 | |
| """ | |
| from __future__ import print_function | |
| from scipy.special import digamma | |
| import numpy as np | |
| import time |
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
| # -*- coding: utf-8 -*- | |
| """ | |
| Reference: | |
| トピックモデルによる統計的潜在意味解析 4章 | |
| """ | |
| from __future__ import print_function | |
| from scipy.special import digamma | |
| import numpy as np | |
| import time |
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
| ''' | |
| Created on 2017/05/24 | |
| ''' | |
| from sklearn.grid_search import GridSearchCV | |
| import numpy as np | |
| from sklearn.cross_validation import KFold | |
| from sklearn.metrics import mean_squared_error |
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
| import pystan | |
| import numpy as np | |
| stan_code = """ | |
| data { | |
| int<lower=0> N; | |
| int<lower=0> K; | |
| matrix[N,K] x; | |
| vector[N] y; | |
| } |
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
| import pystan | |
| import numpy as np | |
| stan_code = """ | |
| data { | |
| int<lower=0> N; | |
| real<lower=0> x[N]; | |
| } | |
| parameters { | |
| real mu; |
NewerOlder