楼主: Reader's
1714 5

Multi-Label Dimensionality Reduction [推广有奖]

  • 0关注
  • 0粉丝

已卖:1521份资源

博士生

59%

还不是VIP/贵宾

-

TA的文库  其他...

可解釋的機器學習

Operations Research(运筹学)

国际金融(Finance)

威望
0
论坛币
41198 个
通用积分
2.6173
学术水平
7 点
热心指数
5 点
信用等级
5 点
经验
2201 点
帖子
198
精华
1
在线时间
36 小时
注册时间
2015-6-1
最后登录
2024-3-3

楼主
Reader's 发表于 2016-1-18 01:36:57 |AI写论文
1论坛币

关键词:Dimensional dimension Reduction eduction label

本帖被以下文库推荐

沙发
Reader's 发表于 2016-1-18 01:37:38
  1. % CCA examples
  2. % This script demonstrates how to use the CCA function.
  3. %
  4. % Copyright(c) Liang Sun (sun.liang@asu.edu), Shuiwang Ji (shuiwang.ji@asu.edu), and Jieping Ye (jieping.ye@asu.edu), Arizona State Univerisity
  5. %

  6. clear all; clc;
  7. addpath('../Functions');


  8. % % We generate 200 samples, with dimensionality 10 and 100
  9. % d1 = 100;
  10. % d2 = 10;
  11. % n = 200;
  12. % X = rand(d1, n);
  13. % Y = rand(d2, n);

  14. % load the synthetic data
  15. % The dimensionality of X and Y are 1000 and 20, respectively.
  16. % and the sample size is 400.
  17. data_path = '../Data/Synthetic_1.mat';
  18. S = load(data_path);
  19. X = S.X;
  20. Y = S.Y;


  21. % ********** Examples of using CCA *********
  22. %=============================================================
  23. % Part 1. We show different usages of CCA when alg='eig'.
  24. opts = [];
  25. opts.alg = 'eig';
  26. opts.PrjX = 1;
  27. opts.PrjY = 1;
  28. opts.regX = 0.1;
  29. opts.regY = 1;
  30. [W_x, W_y, corr_list] = CCA(X, Y, opts);

  31. % We verify the correlation coefficient in the projected spaces
  32. X_p = W_x' * colCenter(X);
  33. Y_p = W_y' * colCenter(Y);
  34. c_list = zeros(size(W_x, 2), 1);
  35. if isfield(opts, 'regX')
  36.     regX = opts.regX;
  37. else
  38.     regX = 0;
  39. end
  40. if isfield(opts, 'regY')
  41.     regY = opts.regY;
  42. else
  43.     regY = 0;
  44. end
  45. for i = 1:size(X_p, 1)
  46.     x_p = X_p(i, :)';   
  47.     y_p = Y_p(i, :)';
  48.     % We consider regularization for both X and Y.
  49.     denom1 = x_p' * x_p + regX * W_x(:, i)' * W_x(:, i);
  50.     denom2 = y_p' * y_p + regY * W_y(:, i)' * W_y(:, i);
  51.     c = x_p' * y_p / sqrt(denom1) / sqrt(denom2);
  52.     c_list(i) = c;
  53. end

  54. if norm(c_list-corr_list)<1e-10
  55.     display('verfirication is successful for PrjX=1 and PrjY=1');
  56. else
  57.     display('verification failed for PrjX=1 and PrjY=1');
  58. end

  59. % only projection for X is computed
  60. opts = [];
  61. opts.alg = 'eig';
  62. opts.PrjX = 1;
  63. opts.PrjY = 0;
  64. opts.regX = 0.1;
  65. opts.regY = 1;
  66. [W_x1, W_y1, corr_list1] = CCA(X, Y, opts);
  67. % compute the difference between this setting and the last setting.
  68. d_W_x1 = norm(W_x - W_x1);
  69. d_c1 = norm(corr_list - corr_list1);
  70. if d_W_x1<1e-10 && d_c1<1e-10
  71.     display('equivalence is verified for (PrjX, PrjY) is (1,0) and (1,1)');
  72. else
  73.     display('equivalence is not verified for (PrjX, PrjY) is (1,0) and (1,1)');
  74. end

  75. % only projection for Y is computed
  76. opts = [];
  77. opts.alg = 'eig';
  78. opts.PrjX = 0;
  79. opts.PrjY = 1;
  80. opts.regX = 0.1;
  81. opts.regY = 1;
  82. [W_x2, W_y2, corr_list2] = CCA(X, Y, opts);
  83. % compute the difference between this setting and the last setting.
  84. % note that the sign may be different
  85. sign_change = sign(W_y2(1,:) ./ W_y(1,:));
  86. d_W_y2 = norm(W_y - W_y2 * diag(sign_change));
  87. d_c2 = norm(corr_list - corr_list2);
  88. if d_W_y2<1e-10 && d_c2<1e-10
  89.     display('equivalence is verfied for (PrjX, PrjY) is (0,1) and (1,1)');
  90. else
  91.     display('equivalence is not verfied for (PrjX, PrjY) is (0,1) and (1,1)');
  92. end

  93. %=============================================================
  94. % Part 2. Use ls and ls-lsqr implementation and verify the equivalence relationship in the un-regularized setting.
  95. % Compare ls and eig implementations
  96. % Generate the data

  97. opts = [];
  98. opts.alg = 'ls';
  99. opts.PrjX = 1;
  100. opts.PrjY = 0;
  101. W_x_ls = CCA(X, Y, opts);

  102. % Compute W_x_eig for the corresponding eig implementations.
  103. opts = [];
  104. opts.alg = 'eig';
  105. opts.PrjX = 1;
  106. opts.PrjY = 1;
  107. [W_x_eig_c1, W_y_eig_c1, corr_list_c1] = CCA(X, Y,opts);

  108. % compute the difference
  109. d_ls_eig_eq = norm(W_x_ls*W_x_ls' - W_x_eig_c1*W_x_eig_c1');
  110. if d_ls_eig_eq<1e-10
  111.     display('ls implementation is equivalent to eig implementation');
  112. else
  113.     display('ls implementation is not equivalent to eig implementation');
  114. end

  115. % test ls-lsqr implementation
  116. opts = [];
  117. opts.alg = 'ls-lsqr';
  118. opts.PrjX = 1;
  119. opts.PrjY = 0;
  120. opts.lsqr_tol = 1e-6;
  121. W_x_ls_lsqr = CCA(X, Y, opts);
  122. % compute the difference
  123. d_ls_lsqr_eq = norm(W_x_ls*W_x_ls' - W_x_ls_lsqr*W_x_ls_lsqr');
  124. if d_ls_lsqr_eq<1e-5
  125.     display('ls implementation is equivalent to ls-lsqr implementation');
  126. else
  127.     display('ls implementation is not equivalent to ls-lsqr implementation');
  128. end


  129. % test 2-norm regularized ls
  130. opts = [];
  131. opts.alg = 'ls';
  132. opts.PrjX = 1;
  133. opts.PrjY = 0;
  134. opts.reg_2norm = 1;
  135. W_x_ls_2reg = CCA(X, Y, opts);

  136. % display('check 1-norm regularization for ls implementation');
  137. % test 1-norm regularized ls
  138. opts = [];
  139. opts.alg = 'ls';
  140. opts.PrjX = 1;
  141. opts.PrjY = 0;
  142. opts.reg_1norm = 0.2;
  143. W_x_ls_1reg = CCA(X, Y, opts);

  144. % test 1-norm and 2-norm regularization together for ls
  145. opts = [];
  146. opts.alg = 'ls';
  147. opts.PrjX = 1;
  148. opts.PrjY = 0;
  149. opts.reg_1norm = 0.2;
  150. opts.reg_2norm = 1;
  151. W_x_ls_12reg = CCA(X, Y, opts);

  152. % test 2-norm regularization for ls-lsqr
  153. opts = [];
  154. opts.alg = 'ls-lsqr';
  155. opts.PrjX = 1;
  156. opts.PrjY = 0;
  157. opts.reg_2norm = 1;
  158. opts.lsqr_tol = 1e-6;
  159. W_x_ls_lsqr_2reg = CCA(X, Y, opts);


  160. % %=============================================================
  161. % Part 3. Use 2s and 2s-lsqr implementation
  162. % Comparison in the un-regularized setting.
  163. opts = [];
  164. opts.alg = '2s';
  165. opts.PrjX = 1;
  166. opts.PrjY = 0;
  167. W_x_2s = CCA(X, Y, opts);
  168. d_2s_eig_eq1 = norm(W_x_2s*W_x_2s' - W_x_eig_c1*W_x_eig_c1');
  169. if d_2s_eig_eq1<1e-10
  170.     display('2s implementation is equivalent to eig implementation in un-regularized setting');
  171. else
  172.     display('2s implementation is not equivalent to eig implementation in un-regularized setting');
  173. end


  174. % Compute projection for 2s-lsqr in the un-regularized setting.
  175. opts = [];
  176. opts.alg = '2s-lsqr';
  177. opts.PrjX = 1;
  178. opts.PrjY = 0;
  179. opts.lsqr_tol = 1e-6;
  180. W_x_2s_lsqr = CCA(X, Y, opts);
  181. % compute the difference
  182. d_2s_lsqr_eq = norm(W_x_2s*W_x_2s' - W_x_2s_lsqr*W_x_2s_lsqr');
  183. if d_2s_lsqr_eq<1e-5
  184.     display('2s implementation is equivalent to 2s-lsqr implementation (without regularization)');
  185. else
  186.     display('ls implementation is not equivalent to ls-lsqr implementation (without regularization)');
  187. end


  188. % Comparison in the regularization setting
  189. opts = [];
  190. opts.alg = '2s';
  191. opts.PrjX = 1;
  192. opts.PrjY = 0;
  193. opts.reg_2norm = 1;
  194. W_x_2s_reg = CCA(X, Y, opts);

  195. % Compute projection for eig implementation
  196. opts = [];
  197. opts.alg = 'eig';
  198. opts.PrjX = 1;
  199. opts.PrjY = 0;
  200. opts.regX = 1;
  201. [W_x_eig_c2, W_y_eig_c2, corr_list_c2] = CCA(X, Y, opts);
  202. d_2s_eig_eq2 = norm(W_x_2s_reg*W_x_2s_reg' - W_x_eig_c2*W_x_eig_c2');
  203. if d_2s_eig_eq2<1e-10
  204.     display('2s implementation is equivalent to eig implementation in regularization setting');
  205. else
  206.     display('2s implementation is not equivalent to eig implementation in regularization setting');
  207. end

  208. % Compute projection for 2s-lsqr with regularization
  209. opts = [];
  210. opts.alg = '2s-lsqr';
  211. opts.PrjX = 1;
  212. opts.PrjY = 0;
  213. opts.lsqr_tol = 1e-6;
  214. opts.reg_2norm = 1;
  215. W_x_2s_lsqr_reg = CCA(X, Y, opts);
  216. % compute the difference
  217. d_2s_lsqr_reg_eq = norm(W_x_2s_reg*W_x_2s_reg' - W_x_2s_lsqr_reg*W_x_2s_lsqr_reg');
  218. if d_2s_lsqr_reg_eq<1e-5
  219.     display('2s implementation is equivalent to 2s-lsqr implementation (with regularization)');
  220. else
  221.     display('ls implementation is not equivalent to ls-lsqr implementation (with regularization)');
  222. end
复制代码

藤椅
Reader's 发表于 2016-1-18 01:38:14
  1. % In this script, we demonstrate how to use the HSL function.
  2. %
  3. % Copyright(c) Liang Sun (sun.liang@asu.edu), Shuiwang Ji (shuiwang.ji@asu.edu), and Jieping Ye (jieping.ye@asu.edu), Arizona State Univerisity
  4. %

  5. clear all; clc;
  6. addpath('../Functions');

  7. % Step 1. Load the Scene data set
  8. data_path = '../Data/Scene.mat';
  9. S = load(data_path);
  10. X_all  = S.D';
  11. Y_all = S.L';
  12. N = size(X_all, 2);

  13. % Randomly select 1000 samples for training
  14. random_N = randperm(N);
  15. tr_idx = random_N(1:1000)';
  16. X = X_all(:, tr_idx);
  17. Y = Y_all(:, tr_idx);

  18. % % use a random data set for testing
  19. % X = rand(10, 10);
  20. % Y = [1 0 0 1 0 1 1 0 1 0;
  21. %        0 1 1 0 1 0 0 0 0 1;
  22. %        1 0 1 1 0 0 0 1 0 1];

  23. % Note that in our implementation, each column correponds to a data point,
  24. % and each row corresponds to a feature.
  25. [d, n] = size(X);
  26. k = size(Y, 1);

  27. % Step 2. Perform HSL using different implemetations
  28. % Step 2.1 HSL by solving eigenvalue problem
  29. % Without regularization: solving the generalized eigenvalue problem
  30. opts = [];
  31. opts.Lap_type = 'clique';
  32. opts.alg = 'eig';
  33. W_eig_clique = HSL(X, Y, opts);

  34. opts = [];
  35. opts.Lap_type = 'star';
  36. opts.alg = 'eig';
  37. W_eig_star = HSL(X, Y, opts);

  38. opts = [];
  39. opts.Lap_type = 'zhou';
  40. opts.alg = 'eig';
  41. W_eig_zhou = HSL(X, Y, opts);

  42. % Solving Generalized Eigenvalue Problem with Regularization
  43. opts = [];
  44. opts.Lap_type = 'clique';
  45. opts.alg = 'eig';
  46. opts.reg_eig = 1;
  47. W_eig_reg = HSL(X, Y, opts);

  48. % Step 2.2 Solving Least Squares
  49. % without regularization
  50. opts = [];
  51. opts.Lap_type = 'clique';
  52. opts.alg = 'ls';
  53. W_ls = HSL(X, Y, opts);

  54. % Solving Least Squares with Regularization using SVD
  55. opts = [];
  56. opts.Lap_type = 'clique';
  57. opts.alg = 'ls';
  58. opts.reg_2norm = 1;
  59. opts.reg_1norm = 0.1;
  60. W_ls_reg = HSL(X, Y, opts);

  61. % Solving Least Square with Regularization using LSQR
  62. opts = [];
  63. opts.Lap_type = 'clique';
  64. opts.alg = 'ls-lsqr';
  65. opts.reg_2norm = 1;
  66. W_ls_lsqr_reg = HSL(X, Y, opts);

  67. % Step 2.3 Applying Two-Stage Approach with regularization
  68. opts = [];
  69. opts.Lap_type = 'clique';
  70. opts.alg = '2s';
  71. opts.reg_2norm = 1;
  72. W_2s_reg = HSL(X, Y, opts);

  73. % Applying Two-Stage Approach with Regularization using LSQR
  74. opts = [];
  75. opts.Lap_type = 'clique';
  76. opts.alg = '2s-lsqr';
  77. opts.reg_2norm = 1;
  78. W_2s_lsqr_reg = HSL(X, Y, opts);
复制代码

板凳
Reader's 发表于 2016-1-18 01:38:53
  1. % LDA_example.m
  2. % This script demonstrates how to use the LDA function.
  3. %
  4. % Copyright(c) Liang Sun (sun.liang@asu.edu), Shuiwang Ji (shuiwang.ji@asu.edu), and Jieping Ye (jieping.ye@asu.edu), Arizona State Univerisity
  5. %

  6. clear all; clc;
  7. addpath('../Functions');

  8. % Generate a random data set
  9. d = 15;
  10. k = 3;
  11. n = 10;
  12. X = rand(d, n);
  13. Y = rand_label(k, n);

  14. % Part 1.  No regularization
  15. % solve the generalized eigenvalue problem
  16. opts = [];
  17. opts.alg = 'eig';
  18. W_eig0 = LDA(X, Y, opts);

  19. % solve the least squares problem
  20. opts = [];
  21. opts.alg = 'ls';
  22. W_ls0 = LDA(X, Y, opts);

  23. % apply the two-stage approach
  24. opts = [];
  25. opts.alg = '2s';
  26. W_2s0 = LDA(X, Y, opts);

  27. % Verify the equivalence relationship in un-regularized setting
  28. d_eig_ls_0 = norm(W_eig0 * W_eig0' - W_ls0 * W_ls0');
  29. if d_eig_ls_0 < 1e-10
  30.     display('eig is equivalent to ls in un-regularized setting');
  31. else
  32.     display('eig is not equivalent to ls in un-regularized setting');
  33. end

  34. d_eig_2s_0 = norm(W_eig0 * W_eig0' - W_2s0 * W_2s0');
  35. if d_eig_2s_0 < 1e-10
  36.     display('eig is equivalent to 2s in un-regularized setting');
  37. else
  38.     display('eig is not equivalent to 2s in un-regularized setting');
  39. end

  40. % Part 2. Regularization is applied for eig and 2s
  41. % Verify the equivalence relationship in the regularized setting
  42. opts = [];
  43. opts.alg = 'eig';
  44. opts.reg_eig = 1;
  45. W_eig1 = LDA(X, Y, opts);


  46. opts = [];
  47. opts.alg = '2s';
  48. opts.reg_2norm = 1;
  49. W_2s1 = LDA(X, Y, opts);
  50. d_eig_2s_1 = norm(W_eig1(:,1:(k-1)) * W_eig1(:,1:(k-1))' - W_2s1 * W_2s1');
  51. if d_eig_2s_1 < 1e-10
  52.     display('eig is equivalent to 2s in regularized setting');
  53. else
  54.     display('eig is not equivalent to 2s in regularized setting');
  55. end
复制代码

报纸
Reader's 发表于 2016-1-18 01:39:59
  1. % % SSL_example.m
  2. % This script demonstrates how to use the SSL function..
  3. %
  4. % Copyright(c) Liang Sun (sun.liang@asu.edu), Shuiwang Ji (shuiwang.ji@asu.edu), and Jieping Ye (jieping.ye@asu.edu), Arizona State Univerisity
  5. %

  6. clear all; clc;
  7. addpath('../Functions');
  8. load ../Data/wine.mat
  9. dim_shared = 2;

  10. % Please uncomment the following lines if you want to test one of the text
  11. % data, it might take some time.
  12. % load science.mat
  13. % dim_shared = 15;

  14. % transpose the data in winexy.mat
  15. X_tr = X_tr';
  16. Y_tr = Y_tr';
  17. X_te = X_te';
  18. Y_te = Y_te';

  19. X_tr_backup = X_tr;
  20. X_te_backup = X_te;


  21. %% ML-LS
  22. method = 'ML-LS';
  23. [X_tr, X_te] = preprocess(X_tr_backup, X_te_backup, method);
  24. clear param;
  25. param.r =dim_shared;
  26. param.alpha = 10^-4;
  27. param.beta = 10^-5;
  28. model = SSL(X_tr, Y_tr, param);

  29. % tune the bias for F1
  30. model.bias = change_bias_for_F1(X_tr', Y_tr', model.W);
  31. perf = perf_evaluate_multi_label(X_te',Y_te',model.W, model.bias)
复制代码

地板
wwqqer 在职认证  发表于 2016-1-18 02:10:01
已有 1 人评分论坛币 收起 理由
Nicolle + 100 精彩帖子

总评分: 论坛币 + 100   查看全部评分

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-1 12:19