Révision 216
tmp/org.txm.statsengine.r.core/.settings/org.eclipse.jdt.core.prefs (revision 216) | ||
---|---|---|
1 |
eclipse.preferences.version=1 |
|
2 |
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
|
3 |
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 |
|
4 |
org.eclipse.jdt.core.compiler.compliance=1.6 |
|
5 |
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
|
6 |
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
|
7 |
org.eclipse.jdt.core.compiler.source=1.6 |
|
0 | 8 |
tmp/org.txm.statsengine.r.core/.classpath (revision 216) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<classpath> |
|
3 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> |
|
4 |
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> |
|
5 |
<classpathentry kind="src" path="src"/> |
|
6 |
<classpathentry exported="true" kind="lib" path="REngine.jar"/> |
|
7 |
<classpathentry exported="true" kind="lib" path="RserveEngine.jar"/> |
|
8 |
<classpathentry exported="true" kind="lib" path="colt-1.2.0.jar"/> |
|
9 |
<classpathentry kind="output" path="bin"/> |
|
10 |
</classpath> |
|
0 | 11 |
tmp/org.txm.statsengine.r.core/META-INF/MANIFEST.MF (revision 216) | ||
---|---|---|
1 |
Manifest-Version: 1.0 |
|
2 |
Bundle-ManifestVersion: 2 |
|
3 |
Bundle-Name: R Core |
|
4 |
Bundle-SymbolicName: org.txm.statsengine.r.core |
|
5 |
Bundle-Version: 1.0.0.qualifier |
|
6 |
Require-Bundle: org.eclipse.ui, |
|
7 |
org.eclipse.core.runtime, |
|
8 |
org.txm.utils;bundle-version="1.0.0" |
|
9 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 |
|
10 |
Bundle-ActivationPolicy: lazy |
|
11 |
Export-Package: cern.clhep, |
|
12 |
cern.colt, |
|
13 |
cern.colt.bitvector, |
|
14 |
cern.colt.buffer, |
|
15 |
cern.colt.function, |
|
16 |
cern.colt.list, |
|
17 |
cern.colt.list.adapter, |
|
18 |
cern.colt.map, |
|
19 |
cern.colt.matrix, |
|
20 |
cern.colt.matrix.bench, |
|
21 |
cern.colt.matrix.doublealgo, |
|
22 |
cern.colt.matrix.impl, |
|
23 |
cern.colt.matrix.linalg, |
|
24 |
cern.colt.matrix.objectalgo, |
|
25 |
cern.jet.math, |
|
26 |
cern.jet.random, |
|
27 |
cern.jet.random.engine, |
|
28 |
cern.jet.random.sampling, |
|
29 |
cern.jet.stat, |
|
30 |
cern.jet.stat.quantile, |
|
31 |
corejava, |
|
32 |
hep.aida, |
|
33 |
hep.aida.bin, |
|
34 |
hep.aida.ref, |
|
35 |
org.rosuda.REngine, |
|
36 |
org.rosuda.REngine.Rserve, |
|
37 |
org.rosuda.REngine.Rserve.protocol, |
|
38 |
org.txm.stat, |
|
39 |
org.txm.stat.data, |
|
40 |
org.txm.stat.engine.r, |
|
41 |
org.txm.stat.engine.r.data, |
|
42 |
org.txm.stat.engine.r.rcolt, |
|
43 |
org.txm.stat.utils |
|
44 |
Bundle-ClassPath: REngine.jar, |
|
45 |
RserveEngine.jar, |
|
46 |
., |
|
47 |
colt-1.2.0.jar |
|
0 | 48 |
tmp/org.txm.statsengine.r.core/.project (revision 216) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>org.txm.statsengine.r.core</name> |
|
4 |
<comment></comment> |
|
5 |
<projects> |
|
6 |
</projects> |
|
7 |
<buildSpec> |
|
8 |
<buildCommand> |
|
9 |
<name>org.eclipse.jdt.core.javabuilder</name> |
|
10 |
<arguments> |
|
11 |
</arguments> |
|
12 |
</buildCommand> |
|
13 |
<buildCommand> |
|
14 |
<name>org.eclipse.pde.ManifestBuilder</name> |
|
15 |
<arguments> |
|
16 |
</arguments> |
|
17 |
</buildCommand> |
|
18 |
<buildCommand> |
|
19 |
<name>org.eclipse.pde.SchemaBuilder</name> |
|
20 |
<arguments> |
|
21 |
</arguments> |
|
22 |
</buildCommand> |
|
23 |
</buildSpec> |
|
24 |
<natures> |
|
25 |
<nature>org.eclipse.pde.PluginNature</nature> |
|
26 |
<nature>org.eclipse.jdt.core.javanature</nature> |
|
27 |
</natures> |
|
28 |
</projectDescription> |
|
0 | 29 |
tmp/org.txm.statsengine.r.core/src/org/txm/stat/package.html (revision 216) | ||
---|---|---|
1 |
<html> |
|
2 |
<body> |
|
3 |
<p>Root package of all statistical and numeric computing functions of the toolbox.</p> |
|
4 |
</body> |
|
5 |
</html> |
|
0 | 6 |
tmp/org.txm.statsengine.r.core/src/org/txm/stat/utils/ArrayEquals.java (revision 216) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $ |
|
25 |
// $LastChangedRevision: 2386 $ |
|
26 |
// $LastChangedBy: mdecorde $ |
|
27 |
// |
|
28 |
package org.txm.stat.utils; |
|
29 |
|
|
30 |
import java.util.Arrays; |
|
31 |
|
|
32 |
// TODO: Auto-generated Javadoc |
|
33 |
/** |
|
34 |
* Utility methods for testing for equality of arrays. |
|
35 |
* |
|
36 |
* @author sloiseau |
|
37 |
* |
|
38 |
*/ |
|
39 |
public final class ArrayEquals { |
|
40 |
|
|
41 |
/** |
|
42 |
* Test for equality of both array. For consistency with Arrays.equals |
|
43 |
* contract, the two arrays are equals if both are <code>null</code>. |
|
44 |
* |
|
45 |
* @param array1 the array1 |
|
46 |
* @param array2 the array2 |
|
47 |
* @return <code>true</code> if (1) both arrays are <code>null</code> or if |
|
48 |
* (2) both arrays have the same length and contain pair of arrays |
|
49 |
* equals to each other according to |
|
50 |
* {@link Arrays#equals(int[], int[])}. |
|
51 |
*/ |
|
52 |
public static final boolean deepEquals(int[][] array1, int[][] array2) { |
|
53 |
if (array1 == null && array2 == null) |
|
54 |
return true; |
|
55 |
if (array1 == null || array2 == null) |
|
56 |
return false; |
|
57 |
if (array1.length != array2.length) |
|
58 |
return false; |
|
59 |
for (int i = 0; i < array2.length; i++) { |
|
60 |
if (!Arrays.equals(array1[i], array2[i])) |
|
61 |
return false; |
|
62 |
} |
|
63 |
return true; |
|
64 |
} |
|
65 |
|
|
66 |
} |
|
0 | 67 |
tmp/org.txm.statsengine.r.core/src/org/txm/stat/utils/VectorizeArray.java (revision 216) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $ |
|
25 |
// $LastChangedRevision: 2386 $ |
|
26 |
// $LastChangedBy: mdecorde $ |
|
27 |
// |
|
28 |
package org.txm.stat.utils; |
|
29 |
|
|
30 |
import org.txm.Messages; |
|
31 |
|
|
32 |
// TODO: Auto-generated Javadoc |
|
33 |
/** |
|
34 |
* Static methods for dealing vectorization of Arrays. |
|
35 |
* |
|
36 |
* @author sloiseau |
|
37 |
* |
|
38 |
*/ |
|
39 |
public final class VectorizeArray { |
|
40 |
|
|
41 |
/** |
|
42 |
* Convert a <code>double * double</code> array in a <code>double</code> |
|
43 |
* array. Each inner array of the argument is added one after the other into |
|
44 |
* the result array. |
|
45 |
* |
|
46 |
* <pre> |
|
47 |
* [ |
|
48 |
* [1, 2, 3], |
|
49 |
* [4, 5, 6] |
|
50 |
* ] |
|
51 |
* </pre> |
|
52 |
* |
|
53 |
* result in : |
|
54 |
* |
|
55 |
* <pre> |
|
56 |
* [1, 2, 3, 4, 5, 6] |
|
57 |
* </pre> |
|
58 |
* |
|
59 |
* that is, "row first". |
|
60 |
* |
|
61 |
* @param matrix a <code>double * double</code> array where all inner arrays |
|
62 |
* have the same length. |
|
63 |
* @return an array of <code>double</code> produced by vectorization of the |
|
64 |
* matrix. |
|
65 |
*/ |
|
66 |
public final static double[] vectorizeByInner(double[][] matrix) { |
|
67 |
if (matrix == null || matrix.length == 0) { |
|
68 |
throw new IllegalArgumentException(Messages.VectorizeArray_0); |
|
69 |
} |
|
70 |
int inner_length = matrix[0].length; |
|
71 |
if (inner_length < 1) { |
|
72 |
throw new IllegalArgumentException(Messages.VectorizeArray_1); |
|
73 |
} |
|
74 |
double[] vector = new double[matrix.length * matrix[0].length]; |
|
75 |
for (int i = 0; i < matrix.length; i++) { |
|
76 |
if (matrix[i] == null) { |
|
77 |
throw new IllegalArgumentException(Messages.VectorizeArray_10); |
|
78 |
} |
|
79 |
if (inner_length != matrix[i].length) { |
|
80 |
throw new IllegalArgumentException(Messages.VectorizeArray_3); |
|
81 |
} |
|
82 |
System.arraycopy(matrix[i], 0, vector, i * inner_length, |
|
83 |
inner_length); |
|
84 |
} |
|
85 |
return vector; |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* Convert a <code>int * int</code> array in a <code>double</code> array. |
|
90 |
* Each inner array of the argument is added one after the other into the |
|
91 |
* result array. |
|
92 |
* |
|
93 |
* <pre> |
|
94 |
* [ |
|
95 |
* [1, 2, 3], |
|
96 |
* [4, 5, 6] |
|
97 |
* ] |
|
98 |
* </pre> |
|
99 |
* |
|
100 |
* result in : |
|
101 |
* |
|
102 |
* <pre> |
|
103 |
* [1, 2, 3, 4, 5, 6] |
|
104 |
* </pre> |
|
105 |
* |
|
106 |
* that is, "row first". |
|
107 |
* |
|
108 |
* @param matrix a <code>int * int</code> array where all inner arrays have the |
|
109 |
* same length. |
|
110 |
* @return an array of <code>int</code> produced by vectorization of the |
|
111 |
* matrix. |
|
112 |
*/ |
|
113 |
public final static int[] vectorizeByInner(int[][] matrix) { |
|
114 |
if (matrix == null || matrix.length == 0) { |
|
115 |
throw new IllegalArgumentException(Messages.VectorizeArray_4); |
|
116 |
} |
|
117 |
int inner_length = matrix[0].length; |
|
118 |
if (inner_length < 1) { |
|
119 |
throw new IllegalArgumentException(Messages.VectorizeArray_5); |
|
120 |
} |
|
121 |
int[] vector = new int[matrix.length * matrix[0].length]; |
|
122 |
for (int i = 0; i < matrix.length; i++) { |
|
123 |
if (matrix[i] == null) { |
|
124 |
throw new IllegalArgumentException(Messages.VectorizeArray_10); |
|
125 |
} |
|
126 |
if (inner_length != matrix[i].length) { |
|
127 |
throw new IllegalArgumentException(Messages.VectorizeArray_7); |
|
128 |
} |
|
129 |
System.arraycopy(matrix[i], 0, vector, i * inner_length, |
|
130 |
inner_length); |
|
131 |
} |
|
132 |
return vector; |
|
133 |
} |
|
134 |
|
|
135 |
/** |
|
136 |
* Convert a <code>double * double</code> array in a <code>double</code> |
|
137 |
* array. The elements of the input array are assembled in the output array |
|
138 |
* so that elements of same index in the outer array are consecutive. So : |
|
139 |
* |
|
140 |
* <pre> |
|
141 |
* [ |
|
142 |
* [1, 2, 3], |
|
143 |
* [4, 5, 6] |
|
144 |
* ] |
|
145 |
* </pre> |
|
146 |
* |
|
147 |
* result in : |
|
148 |
* |
|
149 |
* <pre> |
|
150 |
* [1, 4, 2, 5, 3, 6] |
|
151 |
* </pre> |
|
152 |
* |
|
153 |
* that is, "column first". |
|
154 |
* |
|
155 |
* @param matrix a <code>double * double</code> array where all inner arrays |
|
156 |
* have the same length. |
|
157 |
* @return an array of <code>double</code> produced by vectorization of the |
|
158 |
* matrix. |
|
159 |
*/ |
|
160 |
public final static double[] vectorizeByOuter(double[][] matrix) { |
|
161 |
if (matrix == null || matrix.length == 0) { |
|
162 |
throw new IllegalArgumentException(Messages.VectorizeArray_8); |
|
163 |
} |
|
164 |
int inner_length = matrix[0].length; |
|
165 |
int outer_length = matrix.length; |
|
166 |
if (inner_length < 1) { |
|
167 |
throw new IllegalArgumentException(Messages.VectorizeArray_9); |
|
168 |
} |
|
169 |
double[] vector = new double[matrix.length * matrix[0].length]; |
|
170 |
for (int i = 0; i < matrix.length; i++) { |
|
171 |
if (matrix[i] == null) { |
|
172 |
throw new IllegalArgumentException(Messages.VectorizeArray_10); |
|
173 |
} |
|
174 |
if (inner_length != matrix[i].length) { |
|
175 |
throw new IllegalArgumentException(Messages.VectorizeArray_11); |
|
176 |
} |
|
177 |
for (int j = 0; j < matrix[i].length; j++) { |
|
178 |
vector[(j * outer_length) + i] = matrix[i][j]; |
|
179 |
} |
|
180 |
|
|
181 |
} |
|
182 |
return vector; |
|
183 |
} |
|
184 |
|
|
185 |
} |
|
0 | 186 |
tmp/org.txm.statsengine.r.core/src/org/txm/stat/utils/PrintArray.java (revision 216) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $ |
|
25 |
// $LastChangedRevision: 2386 $ |
|
26 |
// $LastChangedBy: mdecorde $ |
|
27 |
// |
|
28 |
package org.txm.stat.utils; |
|
29 |
|
|
30 |
import java.util.Arrays; |
|
31 |
|
|
32 |
// TODO: Auto-generated Javadoc |
|
33 |
/** |
|
34 |
* Various utilities method for printing arrays. |
|
35 |
* |
|
36 |
* @author sloiseau |
|
37 |
* |
|
38 |
*/ |
|
39 |
public final class PrintArray { |
|
40 |
|
|
41 |
/** |
|
42 |
* Double array. |
|
43 |
* |
|
44 |
* @param matrix the matrix |
|
45 |
* @return the string |
|
46 |
*/ |
|
47 |
public final static String doubleArray(double[][] matrix) { |
|
48 |
// DoubleMatrix2D m = new SparseDoubleMatrix2D(matrix); |
|
49 |
// return m.toString(); |
|
50 |
StringBuffer sb = new StringBuffer(); |
|
51 |
for (int i = 0; i < matrix.length; i++) { |
|
52 |
sb.append(Arrays.toString(matrix[i])); |
|
53 |
} |
|
54 |
return sb.toString(); |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* Int array. |
|
59 |
* |
|
60 |
* @param matrix the matrix |
|
61 |
* @return the string |
|
62 |
*/ |
|
63 |
public final static String intArray(int[][] matrix) { |
|
64 |
double[][] doublematrix = new double[matrix.length][matrix[0].length]; |
|
65 |
for (int i = 0; i < matrix.length; i++) { |
|
66 |
for (int j = 0; j < doublematrix[i].length; j++) { |
|
67 |
doublematrix[i][j] = matrix[i][j]; |
|
68 |
} |
|
69 |
} |
|
70 |
return doubleArray(doublematrix); |
|
71 |
} |
|
72 |
|
|
73 |
} |
|
0 | 74 |
tmp/org.txm.statsengine.r.core/src/org/txm/stat/utils/CheckArray.java (revision 216) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $ |
|
25 |
// $LastChangedRevision: 2386 $ |
|
26 |
// $LastChangedBy: mdecorde $ |
|
27 |
// |
|
28 |
package org.txm.stat.utils; |
|
29 |
|
|
30 |
// TODO: Auto-generated Javadoc |
|
31 |
/** |
|
32 |
* Various utility methods for checking consistency of matrix as java array of |
|
33 |
* arrays. |
|
34 |
* |
|
35 |
* @author sloiseau |
|
36 |
* |
|
37 |
*/ |
|
38 |
public final class CheckArray { |
|
39 |
|
|
40 |
/** |
|
41 |
* Check if an array is not null (or 0-length), does not include null inner |
|
42 |
* array (or 0 length), and if all inner arrays have the same length. |
|
43 |
* |
|
44 |
* @param array the array |
|
45 |
* @return <code>true</code> if the condition are satisfied, |
|
46 |
* <code>false</code> otherwise. |
|
47 |
*/ |
|
48 |
public final static boolean checkMatrixRepresentation(int[][] array) { |
|
49 |
// same code as in #checkMatrixRepresentation(double[][]) |
|
50 |
if (array == null) |
|
51 |
return false; |
|
52 |
int length = array.length; |
|
53 |
if (length < 1) |
|
54 |
return false; |
|
55 |
if (array[0] == null) |
|
56 |
return false; |
|
57 |
int firstElementLength = array[0].length; |
|
58 |
if (firstElementLength == 0) |
|
59 |
return false; |
|
60 |
for (int i = 0; i < array.length; i++) { |
|
61 |
if (array[i] == null) |
|
62 |
return false; |
|
63 |
if (array[i].length != firstElementLength) |
|
64 |
return false; |
|
65 |
} |
|
66 |
return true; |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* Check if an array is not null (or 0-length), does not include null inner |
|
71 |
* array (or 0 length), and if all inner arrays have the same length. |
|
72 |
* |
|
73 |
* @param array the array |
|
74 |
* @return <code>true</code> if the condition are satisfied, |
|
75 |
* <code>false</code> otherwise. |
|
76 |
*/ |
|
77 |
public final static boolean checkMatrixRepresentation(double[][] array) { |
|
78 |
// same code as in #checkMatrixRepresentation(int[][]) |
|
79 |
if (array == null) |
|
80 |
return false; |
|
81 |
int length = array.length; |
|
82 |
if (length < 1) |
|
83 |
return false; |
|
84 |
if (array[0] == null) |
|
85 |
return false; |
|
86 |
int firstElementLength = array[0].length; |
|
87 |
if (firstElementLength == 0) |
|
88 |
return false; |
|
89 |
for (int i = 0; i < array.length; i++) { |
|
90 |
if (array[i] == null) |
|
91 |
return false; |
|
92 |
if (array[i].length != firstElementLength) |
|
93 |
return false; |
|
94 |
} |
|
95 |
return true; |
|
96 |
} |
|
97 |
|
|
98 |
} |
|
0 | 99 |
tmp/org.txm.statsengine.r.core/src/org/txm/stat/utils/package.html (revision 216) | ||
---|---|---|
1 |
<html> |
|
2 |
<body> |
|
3 |
<p>Utility functions for dealing with array (vectorizing, indexing, checking consistency...).</p> |
|
4 |
</body> |
|
5 |
</html> |
|
0 | 6 |
tmp/org.txm.statsengine.r.core/src/org/txm/stat/utils/ArrayIndex.java (revision 216) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $ |
|
25 |
// $LastChangedRevision: 2386 $ |
|
26 |
// $LastChangedBy: mdecorde $ |
|
27 |
// |
|
28 |
package org.txm.stat.utils; |
|
29 |
|
|
30 |
import java.util.HashMap; |
|
31 |
import java.util.Map; |
|
32 |
|
|
33 |
import org.txm.Messages; |
|
34 |
|
|
35 |
// TODO: Auto-generated Javadoc |
|
36 |
/** |
|
37 |
* Utilities for managing index of vector. |
|
38 |
* |
|
39 |
* @author sloiseau |
|
40 |
* |
|
41 |
*/ |
|
42 |
public final class ArrayIndex { |
|
43 |
|
|
44 |
/** |
|
45 |
* Convert an array of zero-based index to an array of one-base index, that |
|
46 |
* is, add <code>1</code> to all elements. |
|
47 |
* |
|
48 |
* This method check every index (see exception thrown). |
|
49 |
* |
|
50 |
* @param zero_based the zero based index. |
|
51 |
* @param length the number of elements that can be indexed. |
|
52 |
* @return the one base index. |
|
53 |
*/ |
|
54 |
public static final int[] zeroToOneBasedIndex(int[] zero_based, int length) { |
|
55 |
if (zero_based == null || zero_based.length == 0) { |
|
56 |
throw new IllegalArgumentException(Messages.ArrayIndex_0); |
|
57 |
} |
|
58 |
int[] one_based = new int[zero_based.length]; |
|
59 |
for (int i = 0; i < zero_based.length; i++) { |
|
60 |
if (zero_based[i] < 0 || zero_based[i] >= length) { |
|
61 |
throw new IllegalArgumentException(Messages.ArrayIndex_1); |
|
62 |
} |
|
63 |
one_based[i] = zero_based[i] + 1; |
|
64 |
} |
|
65 |
return one_based; |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* Zero to one based index. |
|
70 |
* |
|
71 |
* @param zero_based the zero_based |
|
72 |
* @return the int |
|
73 |
*/ |
|
74 |
public static final int zeroToOneBasedIndex(int zero_based) { |
|
75 |
return zero_based + 1; |
|
76 |
} |
|
77 |
|
|
78 |
/** |
|
79 |
* Get the index (0-based) of the element of subvector into vector. Return |
|
80 |
* <code>-1</code> when no element in vector correspond to the element in |
|
81 |
* subvector. |
|
82 |
* |
|
83 |
* @param vector the vector |
|
84 |
* @param subvector the subvector |
|
85 |
* @return the index |
|
86 |
*/ |
|
87 |
public static int[] getIndex(String[] vector, String[] subvector) { |
|
88 |
int[] result = new int[subvector.length]; |
|
89 |
Map<String, Integer> index = new HashMap<String, Integer>(); |
|
90 |
for (int i = 0; i < subvector.length; i++) { |
|
91 |
index.put(subvector[i], i); |
|
92 |
result[i] = -1; |
|
93 |
} |
|
94 |
for (int i = 0; i < vector.length; i++) { |
|
95 |
if (index.containsKey(vector[i])) { |
|
96 |
result[index.get(vector[i])] = i; |
|
97 |
} |
|
98 |
} |
|
99 |
return result; |
|
100 |
} |
|
101 |
} |
|
0 | 102 |
tmp/org.txm.statsengine.r.core/src/org/txm/stat/ConnectToRserve.java (revision 216) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate:$ |
|
25 |
// $LastChangedRevision:$ |
|
26 |
// $LastChangedBy:$ |
|
27 |
// |
|
28 |
package org.txm.stat; |
|
29 |
import org.rosuda.REngine.REXP; |
|
30 |
import org.rosuda.REngine.RList; |
|
31 |
import org.rosuda.REngine.Rserve.RConnection; |
|
32 |
|
|
33 |
// TODO: Auto-generated Javadoc |
|
34 |
/** |
|
35 |
* The Class ConnectToRserve. |
|
36 |
*/ |
|
37 |
class ConnectToRserve { |
|
38 |
|
|
39 |
/** |
|
40 |
* The main method. |
|
41 |
* |
|
42 |
* @param args the arguments |
|
43 |
*/ |
|
44 |
public static void main(String args[]) { |
|
45 |
try { |
|
46 |
RConnection c = new RConnection(); |
|
47 |
String userhome = System.getProperty("user.home"); //$NON-NLS-1$ |
|
48 |
RList ret = c.eval("source('"+userhome+"/Bureau/R/Rdata')").asList(); //$NON-NLS-1$ //$NON-NLS-2$ |
|
49 |
|
|
50 |
System.out.println("source ret : "+ret.get(1)); //$NON-NLS-1$ |
|
51 |
System.out.println(ret); |
|
52 |
|
|
53 |
REXP ret2 = c.eval("print(lexicaltable)"); //$NON-NLS-1$ |
|
54 |
System.out.println("lexicaltable :"+ret2); //$NON-NLS-1$ |
|
55 |
} |
|
56 |
catch(Exception e) { |
|
57 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
58 |
} |
|
59 |
} |
|
60 |
} |
|
0 | 61 |
tmp/org.txm.statsengine.r.core/src/org/txm/stat/engine/r/data/ContingencyTableImpl.java (revision 216) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (Mon, 06 May 2013) $ |
|
25 |
// $LastChangedRevision: 2386 $ |
|
26 |
// $LastChangedBy: mdecorde $ |
|
27 |
// |
|
28 |
package org.txm.stat.engine.r.data; |
|
29 |
|
|
30 |
import org.rosuda.REngine.REXPMismatchException; |
|
31 |
import org.txm.stat.StatException; |
|
32 |
import org.txm.stat.data.ContingencyTable; |
|
33 |
import org.txm.stat.data.Vector; |
|
34 |
import org.txm.stat.engine.r.RWorkspaceException; |
|
35 |
import cern.colt.matrix.DoubleMatrix2D; |
|
36 |
|
|
37 |
// TODO: Auto-generated Javadoc |
|
38 |
/** |
|
39 |
* Implementation of the {@link ContingencyTable} interface, wrapping a R |
|
40 |
* matrix. |
|
41 |
* |
|
42 |
* @author sloiseau |
|
43 |
*/ |
|
44 |
public class ContingencyTableImpl extends MatrixImpl implements |
|
45 |
ContingencyTable { |
|
46 |
|
|
47 |
/** |
|
48 |
* Create a new contingency table after a {@link DoubleMatrix2D}. |
|
49 |
* |
|
50 |
* @param matrix the matrix |
|
51 |
* @throws RWorkspaceException the r workspace exception |
|
52 |
*/ |
|
53 |
public ContingencyTableImpl(DoubleMatrix2D matrix) |
|
54 |
throws RWorkspaceException { |
|
55 |
super(matrix); |
|
56 |
} |
|
57 |
|
|
58 |
/** |
|
59 |
* Create a new contingency table after a {@link DoubleMatrix2D}, with row |
|
60 |
* names and column names. |
|
61 |
* |
|
62 |
* @param matrix the matrix |
|
63 |
* @param rowNames row names. |
|
64 |
* @param columnNames the column names |
|
65 |
* @throws RWorkspaceException the r workspace exception |
|
66 |
*/ |
|
67 |
public ContingencyTableImpl(DoubleMatrix2D matrix, String[] rowNames, |
|
68 |
String[] columnNames) throws RWorkspaceException { |
|
69 |
super(matrix, rowNames, columnNames); |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* Instantiates a new contingency table impl. |
|
74 |
* |
|
75 |
* @param matrix the matrix |
|
76 |
* @param formNames the form names |
|
77 |
* @param partNames the part names |
|
78 |
* @throws RWorkspaceException the r workspace exception |
|
79 |
*/ |
|
80 |
public ContingencyTableImpl(int[][] matrix, String[] formNames, |
|
81 |
String[] partNames) throws RWorkspaceException { |
|
82 |
super(matrix, formNames, partNames); |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* See {@link MatrixImpl#Matrix(String, Header)}. |
|
87 |
* |
|
88 |
* @param symbol the name of the object |
|
89 |
* @throws RWorkspaceException the r workspace exception |
|
90 |
*/ |
|
91 |
public ContingencyTableImpl(String symbol) throws RWorkspaceException { |
|
92 |
super(symbol); |
|
93 |
} |
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
/* (non-Javadoc) |
|
98 |
* @see org.txm.stat.data.ContingencyTable#getColMargin() |
|
99 |
*/ |
|
100 |
public Vector getColMargin() throws RWorkspaceException { |
|
101 |
String colName = createSymbole(Vector.class); |
|
102 |
rw.voidEval(colName + "<- colSums(" + this.symbol + ");"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
103 |
return new VectorImpl(colName); |
|
104 |
} |
|
105 |
|
|
106 |
/* (non-Javadoc) |
|
107 |
* @see org.txm.stat.data.ContingencyTable#getRowMargin() |
|
108 |
*/ |
|
109 |
@Override |
|
110 |
public Vector getRowMarginsVector() throws StatException { |
|
111 |
String colName = createSymbole(Vector.class); |
|
112 |
rw.voidEval(colName + "<- rowSums(" + this.symbol + ");"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
113 |
return new VectorImpl(colName); |
|
114 |
} |
|
115 |
|
|
116 |
/* (non-Javadoc) |
|
117 |
* @see org.txm.stat.data.ContingencyTable#getRowMargin() |
|
118 |
*/ |
|
119 |
@Override |
|
120 |
public Vector getColMarginsVector() throws StatException { |
|
121 |
String rowName = createSymbole(Vector.class); |
|
122 |
try { |
|
123 |
rw.voidEval(rowName + "<- colSums(" + this.symbol + ");"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
124 |
return new VectorImpl(rowName); |
|
125 |
} catch (RWorkspaceException e) { |
|
126 |
throw new StatException(e); |
|
127 |
} |
|
128 |
|
|
129 |
} |
|
130 |
|
|
131 |
/* (non-Javadoc) |
|
132 |
* @see org.txm.stat.data.ContingencyTable#getTotal() |
|
133 |
*/ |
|
134 |
@Override |
|
135 |
public int getTotal() throws RWorkspaceException { |
|
136 |
int total; |
|
137 |
try { |
|
138 |
total = rw.eval("sum(" + this.symbol + ");").asInteger(); //$NON-NLS-1$ //$NON-NLS-2$ |
|
139 |
} catch (REXPMismatchException e) { |
|
140 |
throw new RWorkspaceException(e); |
|
141 |
} |
|
142 |
return total; |
|
143 |
} |
|
144 |
|
|
145 |
// /** |
|
146 |
// * Gets the col. |
|
147 |
// * |
|
148 |
// * @param index the index |
|
149 |
// * |
|
150 |
// * @return the col |
|
151 |
// */ |
|
152 |
// public DoubleMatrix1D getCol(int index) { |
|
153 |
// if (index < 0 || index >= matrix.columns()) { |
|
154 |
// throw new IllegalArgumentException("Column index (" + index + |
|
155 |
// ") too hight (max: " + matrix.columns() + ")"); |
|
156 |
// } |
|
157 |
// return matrix.viewColumn(index); |
|
158 |
// } |
|
159 |
// |
|
160 |
// /** |
|
161 |
// * Gets the sum. |
|
162 |
// * |
|
163 |
// * @return the sum |
|
164 |
// */ |
|
165 |
// public int getSum() { |
|
166 |
// if (sum == -1) { |
|
167 |
// sum = (int) this.matrix.zSum(); |
|
168 |
// } |
|
169 |
// return sum; |
|
170 |
// } |
|
171 |
// |
|
172 |
// |
|
173 |
// /** |
|
174 |
// * Row margin. |
|
175 |
// * |
|
176 |
// * @return the sum over the rows |
|
177 |
// */ |
|
178 |
// public DoubleMatrix1D getRowSum() { |
|
179 |
// if (rowSum==null){ |
|
180 |
// DoubleMatrix1D ones = DoubleFactory1D.dense.make(matrix.rows(),1); |
|
181 |
// rowSum = matrix.viewDice().zMult(ones, null); |
|
182 |
// } |
|
183 |
// return rowSum; |
|
184 |
// } |
|
185 |
// |
|
186 |
// |
|
187 |
// |
|
188 |
// /** |
|
189 |
// * Col margin. |
|
190 |
// * |
|
191 |
// * @return the sum over the columns |
|
192 |
// */ |
|
193 |
// public DoubleMatrix1D getColSum() { |
|
194 |
// if (colSum==null){ |
|
195 |
// DoubleMatrix1D ones = DoubleFactory1D.dense.make(matrix.columns(),1); |
|
196 |
// colSum = matrix.zMult(ones, null); |
|
197 |
// } |
|
198 |
// return colSum; |
|
199 |
// } |
|
200 |
|
|
201 |
/** |
|
202 |
* Apply a four paramters-function on the whole table. |
|
203 |
* |
|
204 |
* For each non zero value, the function will received four parameters: |
|
205 |
* <ul> |
|
206 |
* <li>The sum of the values in the matrix</li> |
|
207 |
* <li>The sum of the row of the given value</li> |
|
208 |
* <li>The sum of the column of the given value</li> |
|
209 |
* <li>The value</li> |
|
210 |
* </ul> |
|
211 |
* |
|
212 |
* @param fun |
|
213 |
* the fun |
|
214 |
* |
|
215 |
* @return the matrix |
|
216 |
*/ |
|
217 |
// public Matrix apply(final AbstractMatrixIntIntIntDoubleFunction fun) { |
|
218 |
// cacheColSum(); |
|
219 |
// cacheRowSum(); |
|
220 |
// cacheSum(); |
|
221 |
// return new Matrix( |
|
222 |
// matrix.copy().forEachNonZero( |
|
223 |
// new IntIntDoubleFunction() { |
|
224 |
// public double apply(int row, int col, double value) { |
|
225 |
// return fun.apply(sum, rowSum[row], colSum[col], value); |
|
226 |
// } |
|
227 |
// } |
|
228 |
// ) |
|
229 |
// ); |
|
230 |
// } |
|
231 |
|
|
232 |
/** |
|
233 |
* Apply a function on the given row. |
|
234 |
* |
|
235 |
* For each non zero value, the function will received four parameters: |
|
236 |
* <ul> |
|
237 |
* <li>The sum of the values in the matrix</li> |
|
238 |
* <li>The sum of the row of the given value</li> |
|
239 |
* <li>The sum of the column of the given value</li> |
|
240 |
* <li>The value</li> |
|
241 |
* </ul> |
|
242 |
* |
|
243 |
* @param fun |
|
244 |
* the fun |
|
245 |
* @param rowIndex |
|
246 |
* the row index |
|
247 |
* |
|
248 |
* @return the variable |
|
249 |
*/ |
|
250 |
// public NumericalVector applyOnRowWithMargin(final |
|
251 |
// AbstractMatrixIntIntIntDoubleFunction fun, int rowIndex) { |
|
252 |
// cacheColSum(); |
|
253 |
// cacheRowSum(); |
|
254 |
// cacheSum(); |
|
255 |
// IntArrayList indexList = new IntArrayList(); |
|
256 |
// DoubleArrayList valueList = new DoubleArrayList(); |
|
257 |
// matrix.viewRow(rowIndex).getNonZeros(indexList, valueList); |
|
258 |
// |
|
259 |
// DoubleArrayList result = new DoubleArrayList(indexList.size()); |
|
260 |
// |
|
261 |
// for (int i = 0; i < indexList.size(); i++) { |
|
262 |
// int column = indexList.getQuick(i); |
|
263 |
// double value = valueList.getQuick(i); |
|
264 |
// result.setQuick(i, fun.apply(sum, rowSum[rowIndex], colSum[column], |
|
265 |
// value)); |
|
266 |
// } |
|
267 |
// |
|
268 |
// return new NumericalVector(result); |
|
269 |
// } |
|
270 |
|
|
271 |
/** |
|
272 |
* Apply a function on the given column. |
|
273 |
* |
|
274 |
* For each non zero value, the function will received four parameters: |
|
275 |
* <ul> |
|
276 |
* <li>The sum of the values in the matrix</li> |
|
277 |
* <li>The sum of the row of the given value</li> |
|
278 |
* <li>The sum of the column of the given value</li> |
|
279 |
* <li>The value</li> |
|
280 |
* </ul> |
|
281 |
* |
|
282 |
* @param fun |
|
283 |
* the fun |
|
284 |
* @param columnIndex |
|
285 |
* the column index |
|
286 |
* |
|
287 |
* @return the variable |
|
288 |
*/ |
|
289 |
// public NumericalVector applyOnColumnWithMargin(final |
|
290 |
// AbstractMatrixIntIntIntDoubleFunction fun, int columnIndex) { |
|
291 |
// cacheColSum(); |
|
292 |
// cacheRowSum(); |
|
293 |
// cacheSum(); |
|
294 |
// IntArrayList indexList = new IntArrayList(); |
|
295 |
// DoubleArrayList valueList = new DoubleArrayList(); |
|
296 |
// matrix.viewColumn(columnIndex).getNonZeros(indexList, valueList); |
|
297 |
// |
|
298 |
// DoubleArrayList result = new DoubleArrayList(indexList.size()); |
|
299 |
// |
|
300 |
// for (int i = 0; i < indexList.size(); i++) { |
|
301 |
// int row = indexList.getQuick(i); |
|
302 |
// double value = valueList.getQuick(i); |
|
303 |
// result.setQuick(i, fun.apply(sum, rowSum[row], colSum[columnIndex], |
|
304 |
// value)); |
|
305 |
// } |
|
306 |
// return new NumericalVector(result); |
|
307 |
// } |
|
308 |
|
|
309 |
// /** |
|
310 |
// * For each non zero value in the matrix, get its row in the |
|
311 |
// * first list, its column in the second list, and its value |
|
312 |
// * in the third list. |
|
313 |
// * |
|
314 |
// * This is a strict delegation to {@link |
|
315 |
// DoubleMatrix2D#getNonZeros(IntArrayList, IntArrayList, DoubleArrayList)}. |
|
316 |
// * |
|
317 |
// * @param rowList |
|
318 |
// * @param columnList |
|
319 |
// * @param valueList |
|
320 |
// */ |
|
321 |
// public void getNonZeros(IntArrayList rowList, IntArrayList columnList, |
|
322 |
// DoubleArrayList valueList) { |
|
323 |
// matrix.getNonZeros(rowList, columnList, valueList); |
|
324 |
// } |
|
325 |
|
|
326 |
/** |
|
327 |
* For each non zero value in the matrix, get its row in the first list, its |
|
328 |
* column in the second list, its value in the third list, the total of the |
|
329 |
* column of the value in the fourth list, and the total of the row of the |
|
330 |
* value in the firth list. |
|
331 |
* |
|
332 |
* @param rowList |
|
333 |
* @param columnList |
|
334 |
* @param valueList |
|
335 |
* @param columnMargin |
|
336 |
* @param rowMargin |
|
337 |
*/ |
|
338 |
// public void getNonZerosWithMargin( |
|
339 |
// IntArrayList rowList, |
|
340 |
// IntArrayList columnList, |
|
341 |
// DoubleArrayList valueList, |
|
342 |
// IntArrayList columnMargin, |
|
343 |
// IntArrayList rowMargin |
|
344 |
// ) { |
|
345 |
// I'm not sure to understand what this function does, but I'm pretty sure |
|
346 |
// it's buggy |
|
347 |
// cacheColSum(); |
|
348 |
// cacheRowSum(); |
|
349 |
// matrix.getNonZeros(rowList, columnList, valueList); |
|
350 |
// columnMargin.setSize(rowList.size()); |
|
351 |
// rowMargin.setSize(rowList.size()); |
|
352 |
// for (int i = 0; i < rowList.size(); i++) { |
|
353 |
// columnMargin.setQuick(i, colSum[columnList.getQuick(i)]); |
|
354 |
// rowMargin.setQuick(i, rowSum[rowList.getQuick(i)]); |
|
355 |
// } |
|
356 |
// } |
|
357 |
} |
|
0 | 358 |
tmp/org.txm.statsengine.r.core/src/org/txm/stat/engine/r/data/QuantitativeDataStructureImpl.java (revision 216) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (Mon, 06 May 2013) $ |
|
25 |
// $LastChangedRevision: 2386 $ |
|
26 |
// $LastChangedBy: mdecorde $ |
|
27 |
// |
|
28 |
package org.txm.stat.engine.r.data; |
|
29 |
|
|
30 |
import org.rosuda.REngine.REXP; |
|
31 |
import org.txm.stat.data.QuantitativeDataStructure; |
|
32 |
import org.txm.stat.data.Vector; |
|
33 |
import org.txm.stat.engine.r.RWorkspace; |
|
34 |
import org.txm.stat.engine.r.RWorkspaceException; |
|
35 |
import org.txm.Messages; |
|
36 |
|
|
37 |
// TODO: Auto-generated Javadoc |
|
38 |
/** |
|
39 |
* The root of the hierarchy for all classes wrapping R data. |
|
40 |
* |
|
41 |
* @author Sylvain Loiseau <sloiseau@ens-lsh.fr> |
|
42 |
*/ |
|
43 |
public abstract class QuantitativeDataStructureImpl implements |
|
44 |
QuantitativeDataStructure { |
|
45 |
|
|
46 |
/** The counter. */ |
|
47 |
private static int counter = 1; |
|
48 |
|
|
49 |
/** |
|
50 |
* An immutable symbol for the name of this data structure in the R |
|
51 |
* workspace. |
|
52 |
*/ |
|
53 |
protected String symbol; |
|
54 |
|
|
55 |
/** The R workspace. */ |
|
56 |
protected final RWorkspace rw; |
|
57 |
|
|
58 |
/** |
|
59 |
* This constructor is called by every sub-classes for initializing final |
|
60 |
* fields header and symbol. |
|
61 |
* |
|
62 |
* @throws RWorkspaceException the r workspace exception |
|
63 |
*/ |
|
64 |
protected QuantitativeDataStructureImpl() throws RWorkspaceException { |
|
65 |
this.symbol = createSymbole(); |
|
66 |
this.rw = RWorkspace.getRWorkspaceInstance(); |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* This constructor is called by every sub-classes for initializing final |
|
71 |
* fields header and symbol. |
|
72 |
* |
|
73 |
* @param symbol the symbol |
|
74 |
* @throws RWorkspaceException the r workspace exception |
|
75 |
*/ |
|
76 |
protected QuantitativeDataStructureImpl(String symbol) |
|
77 |
throws RWorkspaceException { |
|
78 |
this.rw = RWorkspace.getRWorkspaceInstance(); |
|
79 |
/*if (!rw.containsVariable(symbol)) { |
|
80 |
throw new RObjectDoesNotExist( |
|
81 |
Messages.QuantitativeDataStructureImpl_0 + symbol |
|
82 |
+ Messages.QuantitativeDataStructureImpl_1); |
|
83 |
}*/ |
|
84 |
this.symbol = symbol; |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* Create an arbitrary symbol for naming this quantitative data structure |
|
89 |
* into the R workspace. |
|
90 |
* |
|
91 |
* @return a symbol. |
|
92 |
*/ |
|
93 |
protected final String createSymbole() { |
|
94 |
return createSymbole(getClass()); |
|
95 |
} |
|
96 |
|
|
97 |
/** |
|
98 |
* Create an arbitrary symbol for naming this quantitative data structure |
|
99 |
* into the R workspace given a class name. |
|
100 |
* |
|
101 |
* @param aClass the a class |
|
102 |
* @return the symbol. |
|
103 |
*/ |
|
104 |
public final static String createSymbole(Class<?> aClass) { |
|
105 |
int hash = counter++; |
|
106 |
// warning : always use the absolute value since the hashCode may |
|
107 |
// be a negative value; if turned into string, a negative value will |
|
108 |
// start with "-" |
|
109 |
// and produce an illegal R variable name. SL, 2009 05 22. |
|
110 |
String prefix = aClass.getSimpleName(); |
|
111 |
if (prefix.endsWith("Impl")) //$NON-NLS-1$ |
|
112 |
prefix = prefix.substring(0, prefix.length()-4); |
|
113 |
String s = prefix + String.valueOf(hash); |
|
114 |
return s; |
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* Remove the object from the R workspace. |
|
119 |
* |
|
120 |
* @throws RWorkspaceException the r workspace exception |
|
121 |
*/ |
|
122 |
protected void removeFromRWorkspace() throws RWorkspaceException { |
|
123 |
if (!rw.containsVariable(symbol)) { |
|
124 |
throw new RObjectDoesNotExist( |
|
125 |
Messages.QuantitativeDataStructureImpl_2); |
|
126 |
} |
|
127 |
rw.voidEval("rm(" + symbol + ")"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
128 |
} |
|
129 |
|
|
130 |
// @Override |
|
131 |
// /** |
|
132 |
// * Provide information about the header of this object and basic snapshot |
|
133 |
// of its content using the <code>str</code> R function. |
|
134 |
// */ |
|
135 |
// public String toString() { |
|
136 |
// StringBuffer sb = new StringBuffer(); |
|
137 |
// sb.append(header.toString()); |
|
138 |
// // String representation = ""; |
|
139 |
// // try { |
|
140 |
// // NO |
|
141 |
// // representation = rw.eval("str(" + symbol + ")").toString(); |
|
142 |
// // } catch (REXPMismatchException e) { |
|
143 |
// // representation = " [No representation available for this object.]"; |
|
144 |
// // } catch (RWorkspaceException e) { |
|
145 |
// // representation = " [No representation available for this object.]"; |
|
146 |
// // } |
|
147 |
// return sb.toString(); |
|
148 |
// } |
|
149 |
|
|
150 |
/** |
|
151 |
* Add the given key-value attribute pair to the wrapped R object. |
|
152 |
* |
|
153 |
* @param name the name |
|
154 |
* @param vals the vals |
|
155 |
* @throws RWorkspaceException the r workspace exception |
|
156 |
*/ |
|
157 |
protected void setAttribute(String name, String[] vals) |
|
158 |
throws RWorkspaceException { |
|
159 |
Vector attr = new VectorImpl(vals); |
|
160 |
|
|
161 |
StringBuffer exp = new StringBuffer(); |
|
162 |
exp.append("attr("); //$NON-NLS-1$ |
|
163 |
exp.append(symbol); |
|
164 |
exp.append(","); //$NON-NLS-1$ |
|
165 |
exp.append(name); |
|
166 |
exp.append(")"); //$NON-NLS-1$ |
|
167 |
exp.append("<-"); //$NON-NLS-1$ |
|
168 |
exp.append(attr.getSymbol()); |
|
169 |
exp.append(";"); //$NON-NLS-1$ |
|
170 |
|
|
171 |
rw.voidEval(exp.toString()); |
|
172 |
rw.voidEval("rm(" + attr.getSymbol() + ");"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
173 |
} |
|
174 |
|
|
175 |
/** |
|
176 |
* Get an attribute on a R object. |
|
177 |
* |
|
178 |
* @param name of the attribute |
|
179 |
* @return the attribute as a REXP object, since the attribute may be every |
|
180 |
* data type. |
|
181 |
* @throws RWorkspaceException the r workspace exception |
|
182 |
*/ |
|
183 |
protected REXP getAttribute(String name) throws RWorkspaceException { |
|
184 |
StringBuffer exp = new StringBuffer(); |
|
185 |
exp.append("attr("); //$NON-NLS-1$ |
|
186 |
exp.append(symbol); |
|
187 |
exp.append(","); //$NON-NLS-1$ |
|
188 |
exp.append(name); |
|
189 |
exp.append(")"); //$NON-NLS-1$ |
|
190 |
exp.append(";"); //$NON-NLS-1$ |
|
191 |
|
|
192 |
return rw.eval(exp.toString()); |
|
193 |
} |
|
194 |
|
|
195 |
/** |
|
196 |
* Gets the symbol, ie. the name of the data structure in R. |
|
197 |
* |
|
198 |
* @return the symbol |
|
199 |
*/ |
|
200 |
@Override |
|
201 |
public String getSymbol() { |
|
202 |
return symbol; |
|
203 |
} |
|
204 |
} |
|
0 | 205 |
tmp/org.txm.statsengine.r.core/src/org/txm/stat/engine/r/data/Factor.java (revision 216) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (Mon, 06 May 2013) $ |
|
25 |
// $LastChangedRevision: 2386 $ |
|
26 |
// $LastChangedBy: mdecorde $ |
|
27 |
// |
|
28 |
package org.txm.stat.engine.r.data; |
|
29 |
|
|
30 |
import org.txm.stat.engine.r.RWorkspaceException; |
|
31 |
import org.txm.Messages; |
|
32 |
|
|
33 |
// TODO: Auto-generated Javadoc |
|
34 |
/** |
|
35 |
* A wrapper on a R "factor". |
|
36 |
* |
|
37 |
* @author sloiseau |
|
38 |
* |
|
39 |
*/ |
|
40 |
public class Factor extends QuantitativeDataStructureImpl { |
|
41 |
|
|
42 |
/** |
|
43 |
* Create a factor. |
|
44 |
* |
|
45 |
* @param values the values of the factor. |
|
46 |
* @throws RWorkspaceException the r workspace exception |
|
47 |
*/ |
|
48 |
public Factor(String values) throws RWorkspaceException { |
|
49 |
throw new UnsupportedOperationException(Messages.Factor_0); |
|
50 |
} |
|
51 |
|
|
52 |
/** |
|
53 |
* The levels are the unordered set of dif ferent values present in the |
|
54 |
* factor. |
|
55 |
* |
|
56 |
* @return the levels |
|
57 |
*/ |
|
58 |
public String[] getLevels() { |
|
59 |
throw new UnsupportedOperationException(Messages.Factor_0); |
|
60 |
} |
|
61 |
} |
|
0 | 62 |
tmp/org.txm.statsengine.r.core/src/org/txm/stat/engine/r/data/package.html (revision 216) | ||
---|---|---|
1 |
<html> |
Formats disponibles : Unified diff