楼主: Lisrelchen
18122 25

[休闲其它] 【独家发布】Bayesian Cognitive Modeling [推广有奖]

  • 0关注
  • 62粉丝

VIP

已卖:4194份资源

院士

67%

还不是VIP/贵宾

-

TA的文库  其他...

Bayesian NewOccidental

Spatial Data Analysis

东西方数据挖掘

威望
0
论坛币
50288 个
通用积分
83.6306
学术水平
253 点
热心指数
300 点
信用等级
208 点
经验
41518 点
帖子
3256
精华
14
在线时间
766 小时
注册时间
2006-5-4
最后登录
2022-11-6

楼主
Lisrelchen 发表于 2014-11-30 00:06:34 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

You can download


http://bayesmodels.com/
http://www.cambridge.org/us/academic/subjects/psychology/psychology-research-methods-and-statistics/bayesian-cognitive-modeling-practical-course
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Cognitive Bayesian Modeling model Bayes

已有 2 人评分经验 学术水平 热心指数 信用等级 收起 理由
swordsmen + 3 + 3 + 3 精彩帖子
kongqingbao280 + 10 精彩帖子

总评分: 经验 + 10  学术水平 + 3  热心指数 + 3  信用等级 + 3   查看全部评分

本帖被以下文库推荐

沙发
Lisrelchen 发表于 2014-11-30 00:07:32
  1. %% Inferring A Rate

  2. clear;

  3. sampler = 0; % Choose 0=WinBUGS, 1=JAGS

  4. %% Data
  5. k = 5;
  6. n = 10;

  7. %% Sampling
  8. % MCMC Parameters
  9. nchains = 2; % How Many Chains?
  10. nburnin = 0; % How Many Burn-in Samples?
  11. nsamples = 1e4;  %How Many Recorded Samples?
  12. nthin = 1; % How Often is a Sample Recorded?
  13. doparallel = 0; % Parallel Option

  14. % Assign Matlab Variables to the Observed Nodes
  15. datastruct = struct('k',k,'n',n);

  16. % Initialize Unobserved Variables
  17. for i=1:nchains
  18.     S.theta = rand; % An Intial Value for the Success Rate
  19.     init0(i) = S;
  20. end

  21. if ~sampler
  22.     % Use WinBUGS to Sample
  23.     tic
  24.     [samples, stats] = matbugs(datastruct, ...
  25.         fullfile(pwd, 'Rate_1.txt'), ...
  26.         'init', init0, ...
  27.         'nChains', nchains, ...
  28.         'view', 1, 'nburnin', nburnin, 'nsamples', nsamples, ...
  29.         'thin', nthin, 'DICstatus', 0, 'refreshrate',100, ...
  30.         'monitorParams', {'theta'}, ...
  31.         'Bugdir', 'C:/Program Files/WinBUGS14');
  32.     toc
  33. else
  34.     % Use JAGS to Sample
  35.     tic
  36.     fprintf( 'Running JAGS ...\n' );
  37.     [samples, stats] = matjags( ...
  38.         datastruct, ...
  39.         fullfile(pwd, 'Rate_1.txt'), ...
  40.         init0, ...
  41.         'doparallel' , doparallel, ...
  42.         'nchains', nchains,...
  43.         'nburnin', nburnin,...
  44.         'nsamples', nsamples, ...
  45.         'thin', nthin, ...
  46.         'monitorparams', {'theta'}, ...
  47.         'savejagsoutput' , 1 , ...
  48.         'verbosity' , 1 , ...
  49.         'cleanup' , 0 , ...
  50.         'workingdir' , 'tmpjags' );
  51.     toc
  52. end;

  53. %% Analysis
  54. figure(1);clf;hold on;
  55. eps = .01; binsc = eps/2:eps:1-eps/2; binse = 0:eps:1;
  56. count = histc(reshape(samples.theta,1,[]),binse);
  57. count = count(1:end-1);
  58. count = count/sum(count)/eps;
  59. ph = plot(binsc,count,'k-');
  60. set(gca,'box','on','fontsize',14);
  61. xlabel('Rate','fontsize',16);
  62. ylabel('Posterior Density','fontsize',16);
复制代码


藤椅
fjrong 在职认证  发表于 2014-11-30 00:09:24 来自手机
Lisrelchen 发表于 2014-11-30 00:06
You can download
  • the first two parts of the book
  • the associated code
  • 谢谢分享

    板凳
    Lisrelchen 发表于 2014-11-30 00:09:42
    1. %% Difference Between Two Rates

    2. clear;

    3. sampler = 0; % Choose 0=WinBUGS, 1=JAGS

    4. %% Data (Observed Variables)
    5. k1 = 0;
    6. n1 = 5;
    7. k2 = 5;
    8. n2 = 10;

    9. %% Sampling
    10. % MCMC Parameters
    11. nchains = 3; % How Many Chains?
    12. nburnin = 0; % How Many Burn-in Samples?
    13. nsamples = 5e4;  %How Many Recorded Samples?
    14. nthin = 1; % How Often is a Sample Recorded?
    15. doparallel = 0; % Parallel Option

    16. % Assign Matlab Variables to the Observed Nodes
    17. datastruct = struct('k1',k1,'n1',n1,'k2',k2,'n2',n2);

    18. %Initialize Unobserved Variables
    19. for i=1:nchains
    20.     S.theta1 = 0.5; % An Intial Value for the Success Rate
    21.     S.theta2 = 0.5; % An Intial Value for the Success Rate
    22.     init0(i) = S;
    23. end

    24. if ~sampler
    25.     % Use WinBUGS to Sample
    26. tic
    27. [samples, stats] = matbugs(datastruct, ...
    28.     fullfile(pwd, 'Rate_2.txt'), ...
    29.     'init', init0, ...
    30.     'nChains', nchains, ...
    31.     'view', 1, 'nburnin', nburnin, 'nsamples', nsamples, ...
    32.     'thin', nthin, 'DICstatus', 0, 'refreshrate',100, ...
    33.     'monitorParams', {'theta1','theta2','delta'}, ...
    34.     'Bugdir', 'C:/Program Files/WinBUGS14');
    35.     toc
    36. else
    37.     % Use JAGS to Sample
    38.     tic
    39.     fprintf( 'Running JAGS ...\n' );
    40.     [samples, stats] = matjags( ...
    41.         datastruct, ...
    42.         fullfile(pwd, 'Rate_2.txt'), ...
    43.         init0, ...
    44.         'doparallel' , doparallel, ...
    45.         'nchains', nchains,...
    46.         'nburnin', nburnin,...
    47.         'nsamples', nsamples, ...
    48.         'thin', nthin, ...
    49.         'monitorparams', {'theta1','theta2','delta'}, ...
    50.         'savejagsoutput' , 1 , ...
    51.         'verbosity' , 1 , ...
    52.         'cleanup' , 0 , ...
    53.         'workingdir' , 'tmpjags' );
    54.     toc
    55. end;

    56. %% Analysis
    57. % Plot Posterior
    58. figure(2);clf;hold on;
    59. eps = .025; binsc = -1+eps/2:eps:1-eps/2; binse = -1:eps:1;
    60. count = histc(reshape(samples.delta,1,[]),binse);
    61. count = count(1:end-1);
    62. count = count/sum(count)/eps;
    63. ph = plot(binsc,count,'k-');
    64. set(gca,'box','on','fontsize',14,'xtick',[-1:.2:1],'ytick',[1:ceil(max(get(gca,'ylim')))]);
    65. xlabel('Difference in Rates','fontsize',16);
    66. ylabel('Posterior Density','fontsize',16);

    67. % Summaries of Posterior
    68. % MEAN
    69. disp(sprintf('Mean is %1.2f',stats.mean.delta));
    70. % MODE
    71. [~,ind] = max(count);
    72. disp(sprintf('Mode is %1.2f',binsc(ind)));
    73. % MEDIAN
    74. disp(sprintf('Median is %1.2f',median(reshape(samples.delta,1,[]))));
    75. % CREDIBLE INTERVAL
    76. cred = 0.95;
    77. b1 = (1-cred)/2;b2=1-b1;
    78. val = sort(reshape(samples.delta,1,[]));
    79. disp(sprintf('%d percent credible interval is [%1.2f, %1.2f]',cred*100,val(round(b1*nsamples*nchains)),val(round(b2*nsamples*nchains))));
    复制代码


    报纸
    Lisrelchen 发表于 2014-11-30 00:12:52
    1. %% Inferring A Common Rate

    2. clear;

    3. sampler = 0; % Choose 0=WinBUGS, 1=JAGS

    4. %% Data
    5. k1 = 5;
    6. n1 = 10;
    7. k2 = 7;
    8. n2 = 10;

    9. %% Sampling
    10. % MCMC Parameters
    11. nchains = 2; % How Many Chains?
    12. nburnin = 0; % How Many Burn-in Samples?
    13. nsamples = 1e4;  %How Many Recorded Samples?
    14. nthin = 1; % How Often is a Sample Recorded?
    15. doparallel = 0; % Parallel Option

    16. % Assign Matlab Variables to the Observed Nodes
    17. datastruct = struct('k1',k1,'n1',n1,'k2',k2,'n2',n2);

    18. % Initialize Unobserved Variables
    19. for i=1:nchains
    20.     S.theta = 0.5; % An Intial Value for the Success Rate
    21.     init0(i) = S;
    22. end

    23. if ~sampler
    24.     % Use WinBUGS to Sample
    25. tic
    26. % Use WinBUGS to Sample
    27. [samples, stats] = matbugs(datastruct, ...
    28.     fullfile(pwd, 'Rate_3.txt'), ...
    29.     'init', init0, ...
    30.     'nChains', nchains, ...
    31.     'view', 1, 'nburnin', nburnin, 'nsamples', nsamples, ...
    32.     'thin', nthin, 'DICstatus', 0, 'refreshrate',100, ...
    33.     'monitorParams', {'theta'}, ...
    34.     'Bugdir', 'C:/Program Files/WinBUGS14');
    35.     toc
    36. else
    37.     % Use JAGS to Sample
    38.     tic
    39.     fprintf( 'Running JAGS ...\n' );
    40.     [samples, stats] = matjags( ...
    41.         datastruct, ...
    42.         fullfile(pwd, 'Rate_3.txt'), ...
    43.         init0, ...
    44.         'doparallel' , doparallel, ...
    45.         'nchains', nchains,...
    46.         'nburnin', nburnin,...
    47.         'nsamples', nsamples, ...
    48.         'thin', nthin, ...
    49.         'monitorparams', {'theta'}, ...
    50.         'savejagsoutput' , 1 , ...
    51.         'verbosity' , 1 , ...
    52.         'cleanup' , 0 , ...
    53.         'workingdir' , 'tmpjags' );
    54.     toc
    55. end;

    56. %% Analysis
    57. figure(3);clf;hold on;
    58. eps = .01; binsc = eps/2:eps:1-eps/2; binse = 0:eps:1;
    59. count = histc(reshape(samples.theta,1,[]),binse);
    60. count = count(1:end-1);
    61. count = count/sum(count)/eps;
    62. ph = plot(binsc,count,'k-');
    63. set(gca,'box','on','fontsize',14,'xtick',[0:.2:1],'ytick',[1:ceil(max(get(gca,'ylim')))]);
    64. xlabel('Rate','fontsize',16);
    65. ylabel('Posterior Density','fontsize',16);
    复制代码


    地板
    Lisrelchen 发表于 2014-11-30 00:14:41
    1. %% Prior and Posterior Predictive

    2. clear;

    3. sampler = 0; % Choose 0=WinBUGS, 1=JAGS

    4. %% Data
    5. dataset = 1;
    6. switch dataset
    7.     case 1, k = 1; n = 15; % Toy data
    8.     case 2, k = 24; n = 121; % Trouw nursing Home Data
    9. end;

    10. %% Sampling
    11. % MCMC Parameters
    12. nchains = 2; % How Many Chains?
    13. nburnin = 1e2; % How Many Burn-in Samples?
    14. nsamples = 1e4;  %How Many Recorded Samples?
    15. nthin = 1; % How Often is a Sample Recorded?
    16. doparallel = 0; % Parallel Option


    17. % Assign Matlab Variables to the Observed Nodes
    18. datastruct = struct('k',k,'n',n);

    19. % Initialize Unobserved Variables
    20. for i=1:nchains
    21.     S.theta = 0.5; % Intial Value
    22.     init0(i) = S;
    23. end

    24. if ~sampler
    25.     % Use WinBUGS to Sample
    26.     tic
    27.     [samples, stats] = matbugs(datastruct, ...
    28.         fullfile(pwd, 'Rate_4.txt'), ...
    29.         'init', init0, ...
    30.         'nChains', nchains, ...
    31.         'view', 1, 'nburnin', nburnin, 'nsamples', nsamples, ...
    32.         'thin', nthin, 'DICstatus', 0, 'refreshrate',100, ...
    33.         'monitorParams', {'theta','thetaprior','postpredk','priorpredk'}, ...
    34.         'Bugdir', 'C:/Program Files/WinBUGS14');
    35.     toc
    36. else
    37.     % Use JAGS to Sample
    38.     tic
    39.     fprintf( 'Running JAGS ...\n' );
    40.     [samples, stats] = matjags( ...
    41.         datastruct, ...
    42.         fullfile(pwd, 'Rate_4.txt'), ...
    43.         init0, ...
    44.         'doparallel' , doparallel, ...
    45.         'nchains', nchains,...
    46.         'nburnin', nburnin,...
    47.         'nsamples', nsamples, ...
    48.         'thin', nthin, ...
    49.         'monitorparams', {'theta','thetaprior','postpredk','priorpredk'}, ...
    50.         'savejagsoutput' , 1 , ...
    51.         'verbosity' , 1 , ...
    52.         'cleanup' , 0 , ...
    53.         'workingdir' , 'tmpjags' );
    54.     toc
    55. end;

    56. %% Analysis
    57. figure(4);clf;

    58. % Parameter Space
    59. subplot(211);hold on;
    60. eps=.015;binse=[0:eps:1];binsc=[eps/2:eps:1-eps/2];
    61. count=histc(reshape(samples.thetaprior,1,[]),binse);
    62. count=count(1:end-1);
    63. count=count/sum(count)/eps;
    64. ph=plot(binsc,count,'k--');
    65. count=histc(reshape(samples.theta,1,[]),binse);
    66. count=count(1:end-1);
    67. count=count/sum(count)/eps;
    68. ph=plot(binsc,count,'k-');
    69. set(gca,'xlim',[0 1],'box','on','fontsize',14,'xtick',[0:.2:1]);
    70. legend('Prior','Posterior');
    71. set(gca,'box','on','fontsize',14);
    72. xlabel('Rate','fontsize',16);
    73. ylabel('Density','fontsize',16);

    74. % Data Space
    75. subplot(212);hold on;
    76. kbins=[0:n];
    77. count1=histc(samples.priorpredk,kbins);
    78. count1=count1/sum(count1);
    79. count2=histc(samples.postpredk,kbins);
    80. count2=count2/sum(count2);
    81. switch dataset
    82.     case 1,
    83.         ph=bar(kbins,count1,.6);set(ph,'facecolor','none','linewidth',1.5,'linestyle','--')
    84.         ph=bar(kbins,count2,.8);set(ph,'facecolor','none')
    85.         set(gca,'xlim',[-1 n+1],'box','on','fontsize',14,'xtick',[0:n]);
    86.     otherwise,
    87.           ph=bar(kbins,count1,.6);set(ph,'facecolor','none','linewidth',0.5,'linestyle',':')
    88.         ph=bar(kbins,count2);set(ph,'facecolor','none');
    89.         set(gca,'xlim',[-1 n+1],'box','on','fontsize',14,'xtick',[0 n],'ticklength',[0 0]);
    90. end;
    91. [lh oh] = legend('Prior','Posterior');
    92. set(lh,'box','off');
    93. xlabel('Success Count','fontsize',16);
    94. ylabel('Mass','fontsize',16);
    复制代码


    7
    Lisrelchen 发表于 2014-11-30 00:22:23
    1. %% Prior and Posterior Predictive, Second Example

    2. clear;

    3. sampler = 0; % Choose 0=WinBUGS, 1=JAGS

    4. %% Data
    5. k1 = 0;
    6. n1 = 10;
    7. k2 = 10;
    8. n2 = 10;

    9. %% Sampling
    10. % MCMC Parameters
    11. nchains = 2; % How Many Chains?
    12. nburnin = 1e2; % How Many Burn-in Samples?
    13. nsamples = 1e4;  %How Many Recorded Samples?
    14. nthin = 1; % How Often is a Sample Recorded?
    15. doparallel = 0; % Parallel Option

    16. % Assign Matlab Variables to the Observed Nodes
    17. datastruct = struct('k1',k1,'k2',k2,'n1',n1,'n2',n2);

    18. % Initialize Unobserved Variables
    19. for i=1:nchains
    20.     S.theta = 0.5; % Intial Value
    21.     init0(i) = S;
    22. end

    23. if ~sampler
    24.     % Use WinBUGS to Sample
    25.     tic
    26.     [samples, stats] = matbugs(datastruct, ...
    27.         fullfile(pwd, 'Rate_5.txt'), ...
    28.         'init', init0, ...
    29.         'nChains', nchains, ...
    30.         'view', 1, 'nburnin', nburnin, 'nsamples', nsamples, ...
    31.         'thin', nthin, 'DICstatus', 0, 'refreshrate',100, ...
    32.         'monitorParams', {'theta','postpredk1','postpredk2'}, ...
    33.         'Bugdir', 'C:/Program Files/WinBUGS14');
    34.     toc
    35. else
    36.     % Use JAGS to Sample
    37.     tic
    38.     fprintf( 'Running JAGS ...\n' );
    39.     [samples, stats] = matjags( ...
    40.         datastruct, ...
    41.         fullfile(pwd, 'Rate_5.txt'), ...
    42.         init0, ...
    43.         'doparallel' , doparallel, ...
    44.         'nchains', nchains,...
    45.         'nburnin', nburnin,...
    46.         'nsamples', nsamples, ...
    47.         'thin', nthin, ...
    48.         'monitorparams', {'theta','postpredk1','postpredk2'}, ...
    49.         'savejagsoutput' , 1 , ...
    50.         'verbosity' , 1 , ...
    51.         'cleanup' , 0 , ...
    52.         'workingdir' , 'tmpjags' );
    53.     toc
    54. end;

    55. %% Analysis
    56. figure(5);clf;
    57. set(gcf,'units','norm','pos',[.2 .2 .6 .4],'paperpositionmode','auto');

    58. % Parameter Space
    59. subplot(121);hold on;
    60. axis square;
    61. eps=.015;bins=[0:eps:1];binsc=[eps/2:eps:1-eps/2];
    62. count=histc(reshape(samples.theta,1,[]),bins);
    63. count=count(1:end-1);
    64. count=count/sum(count)/eps;
    65. ph=plot(binsc,count,'k-');
    66. set(gca,'xlim',[0 1],'box','on','fontsize',14,'xtick',[0:.2:1],'ytick',[1:ceil(max(get(gca,'ylim')))]);
    67. set(gca,'box','on','fontsize',14);
    68. xlabel('Rate','fontsize',16);
    69. ylabel('Density','fontsize',16);

    70. % Data Space
    71. subplot(122);hold on;
    72. axis equal;
    73. axis([-1 n1+1 -1 n2+1]);
    74. sc=70;
    75. for i=0:n1
    76.     for j=0:n2
    77.         match=length(find(samples.postpredk1==i&samples.postpredk2==j))/nsamples/nchains;
    78.         if match>0
    79.             ph=plot(i,j,'ks');
    80.         set(ph,'markersize',sc*sqrt(match));
    81.         end;
    82.     end;
    83. end;
    84. ph=plot(k1,k2,'kx');
    85. set(ph,'markersize',16,'linewidth',4);
    86. set(gca,'box','on','fontsize',14,'xtick',[0:n1],'ytick',[0:n2]);
    87. xlabel('Success Count 1','fontsize',16);
    88. ylabel('Success Count 2','fontsize',16);
    复制代码


    8
    oliyiyi 发表于 2014-11-30 09:52:08
    谢谢分享

    9
    fjrong 在职认证  发表于 2014-11-30 09:52:18 来自手机
    Lisrelchen 发表于 2014-11-30 00:06
    You can download
  • the first two parts of the book
  • the associated code
  • 谢谢分享

    10
    meng山楂树 发表于 2014-12-1 07:16:12

    您需要登录后才可以回帖 登录 | 我要注册

    本版微信群
    jg-xs1
    拉您进交流群
    GMT+8, 2026-1-1 04:47