2 * PROJECT: NyARToolkit
\r
3 * --------------------------------------------------------------------------------
\r
4 * This work is based on the original ARToolKit developed by
\r
7 * HITLab, University of Washington, Seattle
\r
8 * http://www.hitl.washington.edu/artoolkit/
\r
10 * The NyARToolkit is Java edition ARToolKit class library.
\r
11 * Copyright (C)2008-2009 Ryo Iizuka
\r
13 * This program is free software: you can redistribute it and/or modify
\r
14 * it under the terms of the GNU General Public License as published by
\r
15 * the Free Software Foundation, either version 3 of the License, or
\r
16 * (at your option) any later version.
\r
18 * This program is distributed in the hope that it will be useful,
\r
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
21 * GNU General Public License for more details.
\r
23 * You should have received a copy of the GNU General Public License
\r
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
26 * For further information please contact.
\r
27 * http://nyatla.jp/nyatoolkit/
\r
28 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
\r
31 package jp.nyatla.nyartoolkit.core.pca2d;
\r
33 import jp.nyatla.nyartoolkit.NyARException;
\r
34 import jp.nyatla.nyartoolkit.core.NyARMat;
\r
35 import jp.nyatla.nyartoolkit.core.NyARVec;
\r
36 import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix22;
\r
38 * NyARMatrixを利用した主成分分析
\r
39 * ARToolKitと同じ処理をします。
\r
41 public class NyARPca2d_MatrixPCA implements INyARPca2d
\r
43 private final NyARMat __pca_input = new NyARMat(1, 2);
\r
44 private final NyARMat __pca_evec = new NyARMat(2, 2);
\r
45 private final NyARVec __pca_ev = new NyARVec(2);
\r
46 private final NyARVec __pca_mean = new NyARVec(2);
\r
48 public void pca(double[] i_v1,double[] i_v2,int i_number_of_point,NyARDoubleMatrix22 o_evec, double[] o_ev,double[] o_mean) throws NyARException
\r
50 final NyARMat input = this.__pca_input;// 次処理で初期化される。
\r
52 input.realloc(i_number_of_point, 2);
\r
53 final double[][] input_array=input.getArray();
\r
54 for(int i=0;i<i_number_of_point;i++){
\r
55 input_array[i][0]=i_v1[i];
\r
56 input_array[i][1]=i_v2[i];
\r
59 input.pca(this.__pca_evec, this.__pca_ev, this.__pca_mean);
\r
60 final double[] mean_array = this.__pca_mean.getArray();
\r
61 final double[][] evec_array = this.__pca_evec.getArray();
\r
62 final double[] ev_array=this.__pca_ev.getArray();
\r
63 o_evec.m00=evec_array[0][0];
\r
64 o_evec.m01=evec_array[0][1];
\r
65 o_evec.m10=evec_array[1][0];
\r
66 o_evec.m11=evec_array[1][1];
\r
67 o_ev[0]=ev_array[0];
\r
68 o_ev[1]=ev_array[1];
\r
69 o_mean[0]=mean_array[0];
\r
70 o_mean[1]=mean_array[1];
\r