Révision 255

tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/core/utils/ArrayEquals.java (revision 255)
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.statsengine.core.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/statsengine/core/utils/VectorizeArray.java (revision 255)
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.statsengine.core.utils;
29

  
30
import org.txm.core.messages.TXMCoreMessages;
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(TXMCoreMessages.VectorizeArray_0);
69
		}
70
		int inner_length = matrix[0].length;
71
		if (inner_length < 1) {
72
			throw new IllegalArgumentException(TXMCoreMessages.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(TXMCoreMessages.VectorizeArray_10);
78
			}
79
			if (inner_length != matrix[i].length) {
80
				throw new IllegalArgumentException(TXMCoreMessages.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(TXMCoreMessages.VectorizeArray_4);
116
		}
117
		int inner_length = matrix[0].length;
118
		if (inner_length < 1) {
119
			throw new IllegalArgumentException(TXMCoreMessages.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(TXMCoreMessages.VectorizeArray_10);
125
			}
126
			if (inner_length != matrix[i].length) {
127
				throw new IllegalArgumentException(TXMCoreMessages.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(TXMCoreMessages.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(TXMCoreMessages.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(TXMCoreMessages.VectorizeArray_10);
173
			}
174
			if (inner_length != matrix[i].length) {
175
				throw new IllegalArgumentException(TXMCoreMessages.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/statsengine/core/utils/PrintArray.java (revision 255)
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.statsengine.core.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/statsengine/core/utils/CheckArray.java (revision 255)
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.statsengine.core.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/statsengine/core/utils/package.html (revision 255)
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/statsengine/core/utils/ArrayIndex.java (revision 255)
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.statsengine.core.utils;
29

  
30
import java.util.HashMap;
31
import java.util.Map;
32

  
33
import org.txm.core.messages.TXMCoreMessages;
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(TXMCoreMessages.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(TXMCoreMessages.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/statsengine/core/data/ContingencyTable.java (revision 255)
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.statsengine.core.data;
29

  
30
import org.txm.statsengine.core.StatException;
31
import org.txm.statsengine.r.core.RWorkspaceException;
32

  
33
// TODO: Auto-generated Javadoc
34
/**
35
 * The Interface ContingencyTable.
36
 * 
37
 * @author sloiseau
38
 */
39
public interface ContingencyTable extends Matrix {
40

  
41
	/**
42
	 * Gets the row margin.
43
	 * 
44
	 * @return the row margin
45
	 * 
46
	 * @throws RWorkspaceException
47
	 *             the r workspace exception
48
	 */
49
	public Vector getRowMarginsVector() throws StatException;
50

  
51
	/**
52
	 * Gets the col margin.
53
	 * 
54
	 * @return the col margin
55
	 * 
56
	 * @throws RWorkspaceException
57
	 *             the r workspace exception
58
	 */
59
	public Vector getColMarginsVector() throws StatException;
60
	
61
	/**
62
	 * Gets the col margin.
63
	 * 
64
	 * @return the col margin
65
	 * 
66
	 * @throws RWorkspaceException
67
	 *             the r workspace exception
68
	 */
69
	public int[] getColMargins() throws Exception;
70
	
71
	/**
72
	 * Gets the col margin.
73
	 * 
74
	 * @return the col margin
75
	 * 
76
	 * @throws RWorkspaceException
77
	 *             the r workspace exception
78
	 */
79
	public int[] getRowMargins() throws Exception;
80

  
81
	/**
82
	 * Gets the total.
83
	 * 
84
	 * @return the total
85
	 * 
86
	 * @throws RWorkspaceException
87
	 *             the r workspace exception
88
	 */
89
	public int getTotal() throws RWorkspaceException;
90

  
91
}
0 92

  
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/core/data/QuantitativeDataStructure.java (revision 255)
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.statsengine.core.data;
29

  
30
import org.txm.core.results.ITXMResult;
31

  
32
// TODO: Auto-generated Javadoc
33
/**
34
 * The root of all other data structures.
35
 * 
36
 * @author sloiseau
37
 */
38
public interface QuantitativeDataStructure extends ITXMResult {
39

  
40
	/**
41
	 * The symbol is a the name of the data structure in a wrapped statistical
42
	 * engine.
43
	 * 
44
	 * @return the symbol of this data structure.
45
	 */
46
	public String getSymbol();
47

  
48
}
0 49

  
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/core/data/package.html (revision 255)
1
<html>
2
<body>
3
<p>Definition of quantitative data structures for representing corpus.</p>
4
</body>
5
</html>
0 6

  
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/core/data/Vector.java (revision 255)
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.statsengine.core.data;
29

  
30
import java.util.List;
31

  
32
import org.txm.statsengine.core.StatException;
33

  
34
// TODO: Auto-generated Javadoc
35
/**
36
 * The interface Vector.
37
 * 
38
 * @author sloiseau
39
 */
40
public interface Vector extends QuantitativeDataStructure {
41

  
42
	/**
43
	 * Get the sub-vector given index.
44
	 * 
45
	 * @param index
46
	 *            0-based index.
47
	 * 
48
	 * @return a new vector, copy to the selected values (modif ication to the
49
	 *         vector returned does not modif y the vector).
50
	 * 
51
	 * @throws StatException
52
	 *             if anything goes wrong.
53
	 */
54
	public Vector get(int[] index) throws StatException;
55

  
56
	/**
57
	 * Convert the vector to a java array of <code>int</code>, if possible.
58
	 * 
59
	 * @return a java array of <code>int</code>.
60
	 * 
61
	 * @throws StatException
62
	 *             if anything goes wrong, ni particular if this Vector cannot
63
	 *             be converted into <code>int</code>.
64
	 */
65
	public int[] asIntArray() throws StatException;
66

  
67
	/**
68
	 * Convert the vector to a java array of <code>double</code>, if possible.
69
	 * 
70
	 * @return a java array of <code>double</code>.
71
	 * 
72
	 * @throws StatException
73
	 *             if anything goes wrong, ni particular if this Vector cannot
74
	 *             be converted into <code>double</code>.
75
	 */
76
	public double[] asDoubleArray() throws StatException;
77

  
78
	/**
79
	 * Convert the vector to a java array of <code>String</code>, if possible.
80
	 * 
81
	 * @return a java array of <code>String</code>.
82
	 * 
83
	 * @throws StatException
84
	 *             if anything goes wrong, ni particular if this Vector cannot
85
	 *             be converted into <code>String</code>.
86
	 */
87
	public String[] asStringsArray() throws StatException;
88

  
89
	/**
90
	 * Get the length of the vector.
91
	 * 
92
	 * @return the length.
93
	 * 
94
	 * @throws StatException
95
	 *             if anything goes wrong.
96
	 */
97
	public int getLength() throws StatException;
98

  
99
	/**
100
	 * Removes the.
101
	 *
102
	 * @param col the col
103
	 * @return true, if successful
104
	 */
105
	public boolean remove(int col);
106

  
107
	/**
108
	 * Sets the string.
109
	 *
110
	 * @param i the i
111
	 * @param value the value
112
	 */
113
	public void setString(int i, String value);
114

  
115
	/**
116
	 * Sets the int.
117
	 *
118
	 * @param i the i
119
	 * @param value the value
120
	 */
121
	public void setInt(int i, int value);
122

  
123
	/**
124
	 * Sets the double.
125
	 *
126
	 * @param i the i
127
	 * @param value the value
128
	 */
129
	public void setDouble(int i, double value);
130

  
131
	/**
132
	 * Sort.
133
	 *
134
	 * @param reverse the reverse
135
	 */
136
	public void sort(Boolean reverse);
137

  
138
	/**
139
	 * Sets the order.
140
	 *
141
	 * @param neworder the neworder
142
	 * @param reverse the reverse
143
	 */
144
	public void setOrder(List<Integer> neworder, Boolean reverse);
145

  
146
	/**
147
	 * Cut.
148
	 *
149
	 * @param nlines the nlines
150
	 */
151
	public void cut(int nlines);
152

  
153
	// public String get(int i);
154

  
155
}
0 156

  
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/core/data/Matrix.java (revision 255)
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.statsengine.core.data;
29

  
30
import org.txm.statsengine.core.StatException;
31

  
32
// TODO: Auto-generated Javadoc
33
/**
34
 * The Interface Matrix, root of all other matrix-like structure.
35
 * 
36
 * @author sloiseau
37
 */
38
public interface Matrix extends QuantitativeDataStructure {
39

  
40
	/**
41
	 * Get the value at the specif ied cell.
42
	 *
43
	 * @param row 0-based row index
44
	 * @param col 0-based column index
45
	 * @return the value as a <code>double</code>
46
	 * @throws StatException the stat exception
47
	 */
48
	public double get(int row, int col) throws StatException;
49

  
50
	/**
51
	 * The number of rows in the contingency table.
52
	 * 
53
	 * @return the number of raw
54
	 */
55
	public abstract int getNRows();
56

  
57
	/**
58
	 * Exchange 2 columns in the lexical table
59
	 * @param c1 1..N+1
60
	 * @param c2 1..N+1
61
	 */
62
	public abstract void exchangeColumns(int c1, int c2);
63
	
64
	/**
65
	 * The number of columns in the contingency table.
66
	 * 
67
	 * @return the number of columns
68
	 */
69
	public abstract int getNColumns();
70

  
71
	/**
72
	 * Get the row names or null if no row names.
73
	 * 
74
	 * Row names are available if the
75
	 *
76
	 * @return the row names
77
	 * {@link #Matrix(DoubleMatrix2D, String[], String[], Header)} constructor
78
	 * has been used for this object.
79
	 */
80
	public abstract Vector getRowNames();
81

  
82
	/**
83
	 * Get the col names or null if no col names.
84
	 * 
85
	 * Col names are available if the
86
	 *
87
	 * @return the col names
88
	 * {@link #Matrix(DoubleMatrix2D, String[], String[], Header)} constructor
89
	 * has been used for this object.
90
	 */
91
	public abstract Vector getColNames();
92

  
93
	/**
94
	 * Gets a row vector as a Vector object.
95
	 *
96
	 * @param index 0-based row index.
97
	 * @return the row
98
	 * @throws StatException the stat exception
99
	 */
100
	public abstract Vector getRow(int index) throws StatException;
101

  
102
	/**
103
	 * Gets a column vector as a Vector object.
104
	 *
105
	 * @param index 0-based index column index.
106
	 * @return the row
107
	 * @throws StatException the stat exception
108
	 */
109
	public abstract Vector getCol(int index) throws StatException;
110

  
111
	/**
112
	 * Gets a column vector as a Vector object.
113
	 *
114
	 * @param column the column name
115
	 * @return the column vector
116
	 * @throws StatException the stat exception
117
	 */
118
	public abstract Vector getCol(String column) throws StatException;
119

  
120
	/**
121
	 * Gets a row vector as a Vector object.
122
	 *
123
	 * @param row the row name
124
	 * @return the row vector
125
	 * @throws StatException the stat exception
126
	 */
127
	public abstract Vector getRow(String row) throws StatException;
128

  
129
}
0 130

  
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/core/StatException.java (revision 255)
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.statsengine.core;
29

  
30
// TODO: Auto-generated Javadoc
31
/**
32
 * General exception in statistical computing, the super class of all exceptions
33
 * related to statistical computing.
34
 * 
35
 * @author sloiseau
36
 * 
37
 */
38
public class StatException extends Exception {
39
	
40
	/** The Constant serialVersionUID. */
41
	private static final long serialVersionUID = 7220819361950262761L;
42

  
43
	/**
44
	 * Instantiates a new stat exception.
45
	 */
46
	public StatException() {
47
		super();
48
		// TODO Auto-generated constructor stub
49
	}
50

  
51
	/**
52
	 * Instantiates a new stat exception.
53
	 *
54
	 * @param message the message
55
	 * @param cause the cause
56
	 */
57
	public StatException(String message, Throwable cause) {
58
		super(message, cause);
59
		// TODO Auto-generated constructor stub
60
	}
61

  
62
	/**
63
	 * Instantiates a new stat exception.
64
	 *
65
	 * @param message the message
66
	 */
67
	public StatException(String message) {
68
		super(message);
69
		// TODO Auto-generated constructor stub
70
	}
71

  
72
	/**
73
	 * Instantiates a new stat exception.
74
	 *
75
	 * @param cause the cause
76
	 */
77
	public StatException(Throwable cause) {
78
		super(cause);
79
		// TODO Auto-generated constructor stub
80
	}
81

  
82
}
0 83

  
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/core/package.html (revision 255)
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/statsengine/r/core/preferences/RPreferences.java (revision 255)
1
package org.txm.statsengine.r.core.preferences;
2

  
3

  
4
import org.eclipse.core.runtime.preferences.DefaultScope;
5
import org.osgi.framework.FrameworkUtil;
6
import org.osgi.service.prefs.Preferences;
7
import org.txm.utils.preferences.TXMPreferences;
8

  
9
/**
10
 * Default preferences initializer.
11
 * 
12
 * @author mdecorde
13
 * @author sjacquot
14
 *
15
 */
16
public class RPreferences extends TXMPreferences {
17

  
18

  
19
	// auto populate the preference node qualifier from the current bundle id
20
	public static final String PREFERENCES_NODE = FrameworkUtil.getBundle(RPreferences.class).getSymbolicName();
21

  
22
	
23
	public static final String PREFERENCES_PREFIX = "r_"; //$NON-NLS-1$
24
	
25
	/** The Constant R_REMOTE. */
26
	public static final String IS_MANDATORY = PREFERENCES_PREFIX + "is_mandatory"; //$NON-NLS-1$
27

  
28
	/** The Constant R_PATH_TO_EXECUTABLE. */
29
	public static final String PATH_TO_EXECUTABLE = PREFERENCES_PREFIX + "path_to_executable"; //$NON-NLS-1$
30

  
31
	/** The Constant R_REMOTE. */
32
	public static final String REMOTE = PREFERENCES_PREFIX + "remote"; //$NON-NLS-1$
33
	public static final String DEBUG = PREFERENCES_PREFIX + "debug"; //$NON-NLS-1$
34

  
35
	/** The Constant R_SERVER_ADDRESS. */
36
	public static final String SERVER_ADDRESS = PREFERENCES_PREFIX + "server_address"; //$NON-NLS-1$
37

  
38
	/** The Constant R_PORT. */
39
	public static final String PORT = PREFERENCES_PREFIX + "port"; //$NON-NLS-1$
40

  
41
	/** The Constant R_USER. */
42
	public static final String USER = PREFERENCES_PREFIX + "user"; //$NON-NLS-1$
43

  
44
	/** The Constant R_PASSWORD. */
45
	public static final String PASSWORD = PREFERENCES_PREFIX + "password"; //$NON-NLS-1$
46

  
47
	/** The Constant R_PACKAGES_PATH. */
48
	public static final String PACKAGES_PATH = PREFERENCES_PREFIX + "packages_path"; //$NON-NLS-1$
49

  
50
	public static final String RARGS = PREFERENCES_PREFIX + "rargs"; //$NON-NLS-1$
51
	public static final String RSERVEARGS = PREFERENCES_PREFIX + "rserveargs"; //$NON-NLS-1$
52

  
53
	/** The Constant R_DISABLE. */
54
	public static final String DISABLE = PREFERENCES_PREFIX + "disable"; //$NON-NLS-1$
55

  
56
	/** The Constant R_FILE_TRANSFERT. */
57
	public static final String FILE_TRANSFERT = PREFERENCES_PREFIX + "file_transfert"; //$NON-NLS-1$
58
	public static final String SVG_DEVICE = PREFERENCES_PREFIX + "svg_device"; //$NON-NLS-1$
59

  
60

  
61
	
62

  
63
	/**
64
	 * 
65
	 */
66
	public RPreferences() {
67
		// TODO Auto-generated constructor stub
68
	}
69

  
70
	@Override
71
	public void initializeDefaultPreferences() {
72
		Preferences preferences = DefaultScope.INSTANCE.getNode(PREFERENCES_NODE);
73
		
74
		preferences.putBoolean(IS_MANDATORY, false);
75
		preferences.put(PATH_TO_EXECUTABLE, "");
76
		preferences.put(SERVER_ADDRESS, "127.0.0.1");
77
		preferences.putBoolean(REMOTE, false);
78
		preferences.putBoolean(DISABLE, false);
79
		preferences.putBoolean(DEBUG, false);
80
		preferences.put(PORT, "6311");
81
		preferences.put(USER, "");
82
		preferences.put(PASSWORD, "");
83
		preferences.put(RARGS, "");
84
		preferences.put(RSERVEARGS, "");
85
		preferences.putBoolean(FILE_TRANSFERT, false);
86
		preferences.put(SVG_DEVICE, "svg");
87
		
88
	}
89
	
90
}
0 91

  
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/ConnectToRserve.java (revision 255)
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.statsengine.r.core;
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
// not used? class of test?
38
class ConnectToRserve {
39
	
40
	/**
41
	 * The main method.
42
	 *
43
	 * @param args the arguments
44
	 */
45
	public static void main(String args[]) {
46
		try {
47
			RConnection c = new RConnection();
48
			String userhome = System.getProperty("user.home"); //$NON-NLS-1$
49
			RList ret = c.eval("source('"+userhome+"/Bureau/R/Rdata')").asList(); //$NON-NLS-1$ //$NON-NLS-2$
50
			
51
			System.out.println("source ret : "+ret.get(1)); //$NON-NLS-1$
52
			System.out.println(ret);
53
			
54
			REXP ret2 = c.eval("print(lexicaltable)"); //$NON-NLS-1$
55
			System.out.println("lexicaltable :"+ret2); //$NON-NLS-1$
56
		}
57
		catch(Exception e) {
58
			org.txm.utils.logger.Log.printStackTrace(e);
59
		}
60
	}
61
}
0 62

  
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/rcolt/RColt.java (revision 255)
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.statsengine.r.core.rcolt;
29

  
30
import cern.colt.function.IntIntDoubleFunction;
31
import cern.colt.matrix.DoubleMatrix2D;
32

  
33
// TODO: Auto-generated Javadoc
34
/**
35
 * Method for transformation of colt matrix into various array.
36
 * 
37
 * @author sloiseau
38
 * 
39
 */
40
public final class RColt {
41

  
42
	/**
43
	 * Double matrix2 d2 int int array.
44
	 *
45
	 * @param matrix the matrix
46
	 * @return the int[][]
47
	 */
48
	public final static int[][] doubleMatrix2D2IntIntArray(DoubleMatrix2D matrix) {
49
		int rows = matrix.rows();
50
		int columns = matrix.columns();
51
		int[][] values = new int[rows][columns];
52
		for (int row = rows; --row >= 0;) {
53
			int[] currentRow = values[row];
54
			for (int column = columns; --column >= 0;) {
55
				currentRow[column] = (int) matrix.getQuick(row, column);
56
			}
57
		}
58
		return values;
59
		// final IntIntDoubleFunction fun = new CreateIntIntArray(matrix.rows(),
60
		// matrix.columns());
61
		// matrix.forEachNonZero(fun);
62
		// return ((CreateIntIntArray)fun).getIntIntArray();
63
	}
64

  
65
	/**
66
	 * Double matrix2 d2 double double array.
67
	 *
68
	 * @param matrix the matrix
69
	 * @return the double[][]
70
	 */
71
	public final static double[][] doubleMatrix2D2DoubleDoubleArray(
72
			DoubleMatrix2D matrix) {
73
		matrix.trimToSize();
74
		return matrix.toArray();
75
	}
76

  
77
	/*
78
	 * public final static int[][] intMatrix2D2IntIntArray (IntMatrix2D matrix)
79
	 * { matrix.trimToSize(); return matrix.toArray(); }
80
	 */
81

  
82
	/**
83
	 * Transform a Colt {@link DoubleMatrix2D} into an array of <code>int</code>
84
	 * .
85
	 * 
86
	 * The value of the matrix are stored by column (the values of the first
87
	 * column, then the values of the second column, etc.)
88
	 *
89
	 * @param matrix the matrix
90
	 * @return an array of <code>int</code>
91
	 * @todo use {@link DoubleMatrix2D#trimToSize()} and
92
	 * {@link DoubleMatrix2D#toArray()}
93
	 */
94
	public final static int[] doubleMatrix2D2IntArray(DoubleMatrix2D matrix) {
95
		final IntIntDoubleFunction fun = new CreateIntArray(matrix.rows(),
96
				matrix.columns());
97
		matrix.forEachNonZero(fun);
98
		return ((CreateIntArray) fun).getIntArray();
99
	}
100

  
101
	// public final static REXP DoubleMatrix2D2REXP(DoubleMatrix2D matrix,
102
	// Rengine engine, String varName) {
103
	// final IntIntDoubleFunction fun = new CreateIntIntArray(matrix.rows(),
104
	// matrix.columns());
105
	// matrix.forEachNonZero(fun);
106
	// int[][] m = ((CreateIntIntArray)fun).getIntIntArray();
107
	// engine.assign(varName, m);
108
	// return ((CreateIntIntArray)fun).getIntIntArray();
109
	// }
110

  
111
	/**
112
	 * The Class CreateIntIntArray.
113
	 */
114
	static class CreateIntIntArray implements IntIntDoubleFunction {
115

  
116
		/** The array. */
117
		private final int[][] array;
118

  
119
		/**
120
		 * Instantiates a new creates the int int array.
121
		 *
122
		 * @param rows the rows
123
		 * @param columns the columns
124
		 */
125
		public CreateIntIntArray(int rows, int columns) {
126
			array = new int[rows][columns];
127
			for (int i = 0; i < array.length; i++) {
128
				for (int j = 0; j < array[i].length; j++) {
129
					array[i][j] = 0;
130
				}
131
			}
132
		}
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff