Revision 213

tmp/org.txm.r.core/.project (revision 213)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.txm.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.r.core/src/org/txm/stat/data/Vector.java (revision 213)
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.data;
29

  
30
import java.util.List;
31

  
32
import org.txm.stat.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.r.core/src/org/txm/stat/data/Matrix.java (revision 213)
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.data;
29

  
30
import org.txm.stat.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.r.core/src/org/txm/stat/data/ContingencyTable.java (revision 213)
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.data;
29

  
30
import org.txm.stat.StatException;
31
import org.txm.stat.engine.r.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.r.core/src/org/txm/stat/data/QuantitativeDataStructure.java (revision 213)
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.data;
29

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

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

  
46
}
0 47

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

  
tmp/org.txm.r.core/src/org/txm/stat/StatException.java (revision 213)
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;
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.r.core/src/org/txm/stat/package.html (revision 213)
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.r.core/src/org/txm/stat/utils/ArrayIndex.java (revision 213)
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.r.core/src/org/txm/stat/utils/ArrayEquals.java (revision 213)
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.r.core/src/org/txm/stat/utils/VectorizeArray.java (revision 213)
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.r.core/src/org/txm/stat/utils/PrintArray.java (revision 213)
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.r.core/src/org/txm/stat/utils/CheckArray.java (revision 213)
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.r.core/src/org/txm/stat/utils/package.html (revision 213)
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.r.core/src/org/txm/stat/ConnectToRserve.java (revision 213)
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.r.core/src/org/txm/stat/engine/r/data/MatrixImpl.java (revision 213)
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: 2015-05-22 09:06:15 +0200 (Fri, 22 May 2015) $
25
// $LastChangedRevision: 2973 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.stat.engine.r.data;
29

  
30
import java.io.BufferedReader;
31
import java.io.File;
32
import java.io.FileInputStream;
33
import java.io.InputStreamReader;
34
import java.util.ArrayList;
35
import java.util.Arrays;
36
import java.util.Collections;
37
import java.util.List;
38

  
39
import org.eclipse.core.runtime.Platform;
40
import org.rosuda.REngine.REXP;
41
import org.rosuda.REngine.REXPMismatchException;
42
import org.txm.stat.StatException;
43
import org.txm.stat.data.Matrix;
44
import org.txm.stat.data.Vector;
45
import org.txm.stat.engine.r.RException;
46
import org.txm.stat.engine.r.RWorkspace;
47
import org.txm.stat.engine.r.RWorkspaceException;
48
import org.txm.stat.utils.ArrayIndex;
49
import org.txm.utils.CharsetDetector;
50
import org.txm.utils.OSDetector;
51

  
52
import cern.colt.matrix.DoubleMatrix2D;
53

  
54
import org.txm.Messages;
55

  
56
// TODO: Auto-generated Javadoc
57
/**
58
 * Implementation of the {@link Matrix} interface, wrapping a R matrix.
59
 * 
60
 * define the methods to edit/delete elements in the matrix
61
 * 
62
 * @author sloiseau
63
 */
64
public class MatrixImpl extends QuantitativeDataStructureImpl
65
implements Matrix {
66

  
67

  
68
	public static int[][] asIntMatrix(REXP r) throws REXPMismatchException {
69

  
70
		int[] ct = r.asIntegers();
71
		if (ct == null) return null;
72
		REXP dim = r.getAttribute("dim"); //$NON-NLS-1$
73
		int[] ds = dim.asIntegers();
74
		if (ds == null || ds.length != 2)
75
			return null; // matrix must be 2-dimensional
76

  
77
		int m = ds[0], n = ds[1];
78
		int[][] rez = new int[m][n];
79

  
80
		// R stores matrices as matrix(c(1,2,3,4),2,2) = col1:(1,2), col2:(3,4)
81
		// we need to copy everything, since we create 2d array from 1d array
82
		int i = 0, k = 0;
83
		while (i < n) {
84
			int j = 0;
85
			while (j < m) {
86
				rez[j++][i] = ct[k++];
87
			}
88
			i++;
89
		}
90
		return rez;
91
	}
92

  
93
	//	/** The ncol. */
94
	//	protected int ncol;
95
	//	
96
	//	/** The nrow. */
97
	//	protected int nrow;
98

  
99

  
100
	/**
101
	 * Instantiates a new matrix impl.
102
	 *
103
	 * @param matrix the matrix
104
	 * @throws RWorkspaceException the r workspace exception
105
	 */
106
	public MatrixImpl(double[][] matrix) throws RWorkspaceException {
107
		super();
108
		rw.addMatrixToWorkspace(symbol, matrix);
109
		//		this.nrow = matrix.length;
110
		//		this.ncol = matrix[0].length;
111
		//this.rows = null;
112
		//this.cols = null;
113
	}
114

  
115
	/**
116
	 * Instantiates a new matrix impl.
117
	 *
118
	 * @param matrix the matrix
119
	 * @throws RWorkspaceException the r workspace exception
120
	 */
121
	public MatrixImpl(DoubleMatrix2D matrix) throws RWorkspaceException {
122
		super();
123
		rw.addMatrixToWorkspace(symbol, matrix);
124
		//		this.nrow = matrix.rows();
125
		//		this.ncol = matrix.columns();
126
		//this.rows = null;
127
		//this.cols = null;
128
	}
129

  
130
	/**
131
	 * Create a new matrix given a {@link DoubleMatrix2D}, with row and col
132
	 * names.
133
	 *
134
	 * @param matrix the matrix
135
	 * @param rowNames row names.
136
	 * @param columnNames the column names
137
	 * @throws RWorkspaceException the r workspace exception
138
	 */
139
	public MatrixImpl(DoubleMatrix2D matrix, String[] rowNames,
140
			String[] columnNames) throws RWorkspaceException {
141
		this(matrix);
142

  
143
		if (rowNames == null) {
144
			throw new IllegalArgumentException(Messages.MatrixImpl_4);
145
		}
146
		//		if (rowNames.length != nrow) {
147
		//			throw new IllegalArgumentException(Messages.MatrixImpl_5);
148
		//		}
149
		//this.rows = new VectorImpl(rowNames);
150
		rw.assignRowNamesToMatrix(symbol, new VectorImpl(rowNames).getSymbol());
151

  
152
		if (columnNames == null) {
153
			throw new IllegalArgumentException(Messages.MatrixImpl_6);
154
		}
155
		//		if (columnNames.length != ncol) {
156
		//			throw new IllegalArgumentException(Messages.MatrixImpl_7
157
		//					+ columnNames.length + ", " + ncol + ")."); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
158
		//		}
159
		//this.cols = new VectorImpl(columnNames);
160
		rw.assignColNamesToMatrix(symbol, new VectorImpl(columnNames).getSymbol());
161

  
162
	}
163

  
164
	/**
165
	 * Instantiates a new matrix impl.
166
	 *
167
	 * @param matrix the matrix
168
	 * @throws RWorkspaceException the r workspace exception
169
	 */
170
	public MatrixImpl(int[][] matrix) throws RWorkspaceException {
171
		super();
172
		rw.addMatrixToWorkspace(symbol, matrix);
173
		//		this.nrow = matrix.length;
174
		//		if (matrix.length > 0)
175
		//			this.ncol = matrix[0].length;
176
		//		else
177
		//			this.ncol = 0;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff