Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. %% This is the code for the algorithm - simulator system
  2.  
  3. % Basic definitions %
  4. m = 10; % Number of Features
  5. n = 4; % Number of products (J)
  6.  
  7. k = 0.7; % Error parameter alpha'
  8. J = n; % Number of choices for a question
  9. kk = (J*k - 1)/(J-1); % Error paramter converted to weight parameter i.e. alpha
  10.  
  11. V = [];
  12. P = [];
  13. ACC = zeros(m,1);
  14. M = 2; % Number of uniform distributions which approximate the gaussian
  15. wm = [];
  16. wm(1) = 0.3;
  17. wm(2) = 0.4;
  18. wm(3) = 0.3;
  19.  
  20. Cm = []; % The coefficients for every uniform component
  21. Cm(1) = 0.05;
  22. Cm(2) = 0.10;
  23. Cm(3) = 0.15;
  24.  
  25. utrue = 10*rand(m,1); % Freeze the true partworth vector
  26.  
  27. PF = randi(10,m,n); % Generate the feature-product maxtrix
  28.  
  29. Q = 10; % Limit on number of questions
  30. xmax = zeros(m,Q);
  31.  
  32. %% Zero'th stage %%
  33.  
  34.  
  35.  
  36. for q=1:Q
  37.  
  38. % Get the product feature vector which has the maximum utility
  39. dummy = max_utility(utrue, PF,m,n);
  40. xmax(:,q) = dummy ;
  41.  
  42. % Generate the inequalities arising from deterministic utility
  43. % Format is (u')A <= b
  44.  
  45. for y=1:n
  46. A(:,y) = -(xmax(:,q) - PF(:,y)) ;
  47. b(y) = 0 ;
  48. end
  49.  
  50. % Generate the gaussian approxation inequalities
  51. % Append the same to the existing inequality matrix
  52.  
  53. % I think we can directly incorporate them as constraints in the
  54. % analytical center optimization problem
  55.  
  56. %% Generate all inequalities which define polytope %%
  57. % Store information up to the qth question to leverage the subsets %
  58.  
  59. % Generate subsets
  60.  
  61. Setq = [];
  62. Size = 0;
  63. Subset = {};
  64.  
  65. % Creating subsets
  66.  
  67. for i=1:q
  68. Setq(i)=i;
  69. Sq{i} = combntns(1:q,i);
  70. Size = Size + size(Sq{i},1);
  71. end
  72.  
  73. SS = [];
  74.  
  75. for i=1:q
  76. SS = Sq{i};
  77. for j=1:size(Sq{i},1)
  78. Subset = [Subset ; SS(j,:)];
  79. end
  80. end
  81.  
  82.  
  83. %% Analytical center and ellipsoids %%
  84.  
  85. for k=1:M
  86.  
  87. for i=1:Size
  88.  
  89. s = size(Subset{i},2);
  90. ws(i) = (kk^s)*((1-kk)^(q-s));
  91.  
  92. % Generating the respondent's matrix %
  93. % Get into familiar notation i.e A*x1 <= b %
  94. bb = b';
  95. AA = A';
  96. AA = ones(n,m) + AA;
  97.  
  98. % AA = ((-1)^m)*AA;
  99.  
  100.  
  101. lb = (utrue - ((Cm(k)*(1*(ones(m,1))))));
  102. ub = (utrue + ((Cm(k)*(1*(ones(m,1))))));
  103.  
  104. % Analytic center - My Code (V2) %
  105. cvx_begin
  106. variable x1(m);
  107. minimize -sum(log(eps + (AA*x1 - bb)));
  108. subject to
  109. sum(x1) <= 100;
  110. x1 >= ones(m,1);
  111. % for t=1:m;
  112. % lb(t) <= x1(t) <= ub(t) ;
  113. % end
  114.  
  115. % (ones(1,m))*x1 == 10;
  116.  
  117. cvx_end
  118.  
  119. x = x1;
  120.  
  121. % Ellipsoid - Using Hessian computation %
  122.  
  123. AC = (wm(k)*ws(i)).*(x) ;
  124.  
  125. % H = g1(AC, AA, bb) ;
  126.  
  127. syms x1 x2 x3 x4 x5 x6 x7 x8 x9 x10
  128. % syms x1 x2 x3
  129. Vv = [x1; x2; x3; x4; x5; x6; x7; x8; x9; x10];
  130. % V = [x1;x2;x3];
  131. f = -sum(log(AA*Vv-bb));
  132. % HH = jacobian(gradient(f));
  133. HH = hessian(f,Vv);
  134. H = (subs(HH, [x1; x2; x3; x4; x5; x6; x7; x8; x9; x10], AC ));
  135.  
  136.  
  137. Ht = inv(H);
  138. % Ht = H;
  139. U = sqrtm(Ht);
  140.  
  141. uhat = x1;
  142. [EV,D] = eig(H);
  143. EV1 = EV(:,n);
  144. VSM = EV1';
  145. V = [V;VSM];
  146.  
  147. P = [P; wm(k)*ws(i)];
  148.  
  149. ACC = ACC + AC ;
  150.  
  151. end
  152.  
  153.  
  154. end
  155.  
  156. %% Evaluating New Data Points %%
  157.  
  158. Pi = diag(P);
  159. ES = (V')*(Pi)*(V) ;
  160.  
  161. [EVect, EVal] = eig (ES) ;
  162.  
  163. % for i=1:J/2
  164. i=0;
  165. AX = EVect(:,n-i);
  166. b0 = [b; dot(AX,x1)];
  167. A0 = [AA; AX];
  168. XJ = linsolve(A0,b0);
  169.  
  170. JJ = horzcat(JJ, XJ);
  171.  
  172.  
  173. % Remind to update PF %
  174.  
  175. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement