Révision 252

tmp/org.txm.statsengine.r.core/.project (revision 252)
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/statsengine/core/data/ContingencyTable.java (revision 252)
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 252)
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 252)
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 252)
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 252)
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 252)
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 252)
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/core/utils/package.html (revision 252)
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 252)
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/utils/ArrayEquals.java (revision 252)
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 252)
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 252)
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 252)
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/r/core/RserveWatcher.java (revision 252)
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

  
30
import org.txm.Toolbox;
31
import org.txm.Watcher;
32

  
33
// TODO: Auto-generated Javadoc
34
/**
35
 * The Class RserveWatcher.
36
 */
37
//FIXME: not used ?
38
public class RserveWatcher extends Watcher	{
39

  
40
	
41
	/**
42
	 * Instantiates a new rserve watcher.
43
	 */
44
	public RserveWatcher()
45
	{
46
		this.processname = "RSERVE"; //$NON-NLS-1$
47
	}
48
	
49
	/* (non-Javadoc)
50
	 * @see org.txm.Watcher#check()
51
	 */
52
	@Override
53
	protected boolean check() {
54
		RWorkspace rw;
55
		try {
56
			rw = RWorkspace.getRWorkspaceInstance();
57
		} catch (RWorkspaceException e1) {
58
			System.out.println("Rserve watcher encounter an error: "+e1); //$NON-NLS-1$
59
			return false;
60
		}
61
		
62
		if (rw == null)
63
		{
64
			return false;
65
		}
66
		else
67
		{
68
			try {
69
				rw.eval("print(\"test\")"); //$NON-NLS-1$
70
			} catch (Exception e) {
71
				System.out.println("Rserve watcher encounter an error: "+e); //$NON-NLS-1$
72
				return false;
73
			}
74
		}
75
		return true;
76
	}
77

  
78
	/* (non-Javadoc)
79
	 * @see org.txm.Watcher#restart()
80
	 */
81
	@Override
82
	protected boolean restart() {
83
		return Toolbox.restartStatEngine(true);
84
	}
85
}
0 86

  
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/StartRserve.java (revision 252)
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-06-15 15:29:16 +0200 (Mon, 15 Jun 2015) $
25
// $LastChangedRevision: 2989 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.statsengine.r.core;
29

  
30
import java.io.File;
31

  
32
import org.rosuda.REngine.Rserve.RConnection;
33
import org.txm.statsengine.r.core.messages.RCoreMessages;
34
import org.txm.utils.OSDetector;
35
import org.txm.utils.StreamHog;
36
import org.txm.utils.logger.Log;
37

  
38
// TODO: Auto-generated Javadoc
39
/**
40
 * Helper class that consumes output of a process. In addition, it filter output
41
 * of the REG command on Windows to look for InstallPath registry entry which
42
 * specif ies the location of R.
43
 * 
44
 * @author RServe library
45
 */
46

  
47
/**
48
 * simple class that start Rserve locally if it's not running already - see
49
 * mainly <code>checkLocalRserve</code> method. It spits out quite some
50
 * debugging outout of the console, so feel free to modif y it for your
51
 * application if desired.
52
 * <p>
53
 * <i>Important:</i> All applications should shutdown every Rserve that they
54
 * started! Never leave Rserve running if you started it after your application
55
 * quits since it may pose a security risk. Inform the user if you started an
56
 * Rserve instance.
57
 */
58
public class StartRserve {
59

  
60
	/** shortcut to <code>launchRserve(cmd, "--no-save --slave", "--no-save --slave", false)</code>. */
61
	public static Process Rserveprocess;
62

  
63
	/**
64
	 * Launch rserve.
65
	 *
66
	 * @param cmd the cmd
67
	 * @param options 
68
	 * @return true, if successful
69
	 */
70
	protected static boolean launchRserve(String cmd, int port, boolean debug, String rArgs, String rServeArgs) {
71
		if (new File(cmd).exists() && !new File(cmd).isDirectory()
72
				&& new File(cmd).canExecute())
73
			return launchRserve(cmd,
74
					"--no-save --slave --encoding utf8 "+rArgs, "--RS-encoding utf8 --no-save --slave --encoding utf8 "+rServeArgs, port, debug); //$NON-NLS-1$ //$NON-NLS-2$
75
		return false;
76
	}
77

  
78
	/**
79
	 * attempt to start Rserve. Note: parameters are <b>not</b> quoted, so avoid
80
	 * using any quotes in arguments
81
	 *
82
	 * @param cmd command necessary to start R
83
	 * @param rargs arguments are are to be passed to R
84
	 * @param rsrvargs arguments to be passed to Rserve
85
	 * @param debug the debug
86
	 * @return <code>true</code> if Rserve is running or was successfully
87
	 * started, <code>false</code> otherwise.
88
	 */
89
	protected static boolean launchRserve(String cmd, String rargs,
90
			String rsrvargs, int port, boolean debug) {
91
		//System.out.println("LAUNCH R SERVER "+cmd+" "+port+" "+debug);
92
		try {
93
			String[] cmdline = null;
94
			// FIXME: don't forget to remove this Window dedicated code if we manage to use http_proxy command line argument
95
			boolean isWindows = false;
96
			
97
			// Windows OS
98
			if (OSDetector.isFamilyWindows()) {
99
				isWindows = true; /* Windows startup */
100
				
101
				
102
				// TODO: old tests for setting proxy in R
103
				//Windows : set --internet2 option to manage proxy if any
104
				
105
//				// set Proxy configuration using Eclipse RCP stored values
106
//				String proxy_conf = "";
107
//				ProxyConf conf = new ProxyConf(RWorkspace.getRWorkspaceInstance());
108
//				if (conf.mustSetProxyConfiguration()) {
109
//					proxy_conf = "http_proxy="+conf.getHttpProxyUrl();
110
//					rsrvargs += " "+proxy_conf; // add the http_proxy parameter
111
//					Log.info("Run Rserve with proxy configuration: "+proxy_conf);
112
//				}
113
				
114
				cmdline = new String[] {
115
						cmd,
116
						rargs, 
117
						"-e", //$NON-NLS-1$
118
						"library(Rserve);Rserve(" //$NON-NLS-1$ 
119
						+ (debug ? "TRUE" : "FALSE")  //$NON-NLS-1$ //$NON-NLS-2$
120
						+ ",port=" + port + "" //$NON-NLS-1$ //$NON-NLS-2$
121
						+ ",args='" //$NON-NLS-1$
122
						+ rsrvargs + "')\" " //$NON-NLS-1$
123
				};	
124
			}
125
			// Mac, Linux
126
			else {
127
				cmdline = new String[] {
128
						"/bin/sh", //$NON-NLS-1$
129
						"-c", //$NON-NLS-1$
130
						"echo 'library(Rserve);Rserve(" //$NON-NLS-1$
131
						+ (debug ? "TRUE" : "FALSE") //$NON-NLS-1$ //$NON-NLS-2$
132
						+ ",port="+port+"" //$NON-NLS-1$ //$NON-NLS-2$
133
						+ ",args=\"" + rsrvargs //$NON-NLS-1$
134
						+ "\")'|" + cmd //$NON-NLS-1$ 
135
						+ " " + rargs }; //$NON-NLS-1$
136
			}
137

  
138
//			ProcessBuilder builder = new ProcessBuilder(cmdline);
139
//			Rserveprocess = builder.start();
140

  
141
			Runtime runtime = Runtime.getRuntime();
142
			Rserveprocess = runtime.exec(cmdline);
143
			
144
			//Log.info(Messages.StartRserve_0+Arrays.toString(cmdline));
145
			StreamHog errStream = new StreamHog(Rserveprocess.getErrorStream(), debug);
146
			StreamHog inStream = new StreamHog(Rserveprocess.getInputStream(), debug);
147
			RWorkspace.getRWorkspaceInstance().registerLogger(errStream, inStream);
148

  
149
			if (!debug && !isWindows)
150
				Rserveprocess.waitFor();
151
			// System.out.println("call terminated, let us try to connect ...");
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff