Révision 2683
| tmp/org.txm.ca.core/src/org/txm/ca/core/functions/CA.java (revision 2683) | ||
|---|---|---|
| 35 | 35 |
import java.util.List; |
| 36 | 36 |
|
| 37 | 37 |
import org.eclipse.osgi.util.NLS; |
| 38 |
import org.rosuda.REngine.REXPMismatchException; |
|
| 38 | 39 |
import org.txm.ca.core.messages.CACoreMessages; |
| 39 | 40 |
import org.txm.ca.core.preferences.CAPreferences; |
| 40 | 41 |
import org.txm.ca.core.statsengine.r.functions.FactoMineRCA; |
| ... | ... | |
| 175 | 176 |
protected boolean __compute(TXMProgressMonitor monitor) throws Exception {
|
| 176 | 177 |
|
| 177 | 178 |
try {
|
| 178 |
if (this.getLexicalTable().getNRows() == 0) {
|
|
| 179 |
if (this.getLexicalTable().getNRows() == 0 || this.getLexicalTable().getNColumns() == 0) {
|
|
| 179 | 180 |
Log.warning("** Empty Lexical table. Computing aborted.");
|
| 180 | 181 |
return false; |
| 181 | 182 |
} |
| ... | ... | |
| 188 | 189 |
this.rowtitles = null; |
| 189 | 190 |
this.rowtabledata = null; |
| 190 | 191 |
|
| 191 |
|
|
| 192 | 192 |
try {
|
| 193 | 193 |
if (this.getCA() != null) {
|
| 194 | 194 |
RWorkspace.getRWorkspaceInstance().removeVariableFromWorkspace(this.getCA().getSymbol()); |
| ... | ... | |
| 378 | 378 |
*/ |
| 379 | 379 |
public String[] getColNames() throws StatException {
|
| 380 | 380 |
if (colnames == null) {
|
| 381 |
colnames = getLexicalTable().getColNames().asStringsArray();
|
|
| 381 |
colnames = this.getCA().getColNames().asStringsArray();
|
|
| 382 | 382 |
} |
| 383 | 383 |
return colnames; |
| 384 | 384 |
} |
| ... | ... | |
| 426 | 426 |
* Gets the number of columns. |
| 427 | 427 |
* |
| 428 | 428 |
* @return the number of columns |
| 429 |
* @throws REXPMismatchException |
|
| 430 |
* @throws RWorkspaceException |
|
| 429 | 431 |
*/ |
| 430 |
public int getColumnsCount() {
|
|
| 432 |
public int getColumnsCount() throws RWorkspaceException, REXPMismatchException {
|
|
| 431 | 433 |
return this.r_ca.getColumnsCount(); |
| 432 | 434 |
} |
| 433 | 435 |
|
| ... | ... | |
| 554 | 556 |
* Gets the col all infos as Array of arrays. |
| 555 | 557 |
* |
| 556 | 558 |
* @return the col infos |
| 559 |
* @throws REXPMismatchException |
|
| 557 | 560 |
*/ |
| 558 |
public Object[] getColInfos() {
|
|
| 561 |
public Object[] getColInfos() throws REXPMismatchException {
|
|
| 559 | 562 |
|
| 560 | 563 |
if (coltabledata != null) {
|
| 561 | 564 |
return coltabledata.toArray(); |
| ... | ... | |
| 679 | 682 |
* Gets the number of rows. |
| 680 | 683 |
* |
| 681 | 684 |
* @return the number of rows |
| 685 |
* @throws REXPMismatchException |
|
| 686 |
* @throws RWorkspaceException |
|
| 682 | 687 |
*/ |
| 683 |
public int getRowsCount() {
|
|
| 688 |
public int getRowsCount() throws RWorkspaceException, REXPMismatchException {
|
|
| 684 | 689 |
return this.r_ca.getRowsCount(); |
| 685 | 690 |
} |
| 686 | 691 |
|
| ... | ... | |
| 812 | 817 |
* |
| 813 | 818 |
* @return the singular values |
| 814 | 819 |
* @throws StatException the stat exception |
| 820 |
* @throws REXPMismatchException |
|
| 815 | 821 |
*/ |
| 816 |
public double[] getSingularValues() throws StatException {
|
|
| 822 |
public double[] getSingularValues() throws StatException, REXPMismatchException {
|
|
| 817 | 823 |
return r_ca.getSingularValues(); |
| 818 | 824 |
} |
| 819 | 825 |
|
| ... | ... | |
| 821 | 827 |
* Get the singular values infos as List of Lists |
| 822 | 828 |
* |
| 823 | 829 |
* @return the singular values infos |
| 830 |
* @throws REXPMismatchException |
|
| 824 | 831 |
*/ |
| 825 |
public List<List<Object>> getSingularValuesInfos() {
|
|
| 832 |
public List<List<Object>> getSingularValuesInfos() throws REXPMismatchException {
|
|
| 826 | 833 |
List<List<Object>> svtabledata = new ArrayList<>(); |
| 827 | 834 |
|
| 828 | 835 |
double[] sv = null; |
| ... | ... | |
| 875 | 882 |
* |
| 876 | 883 |
* @return the valeurs propres |
| 877 | 884 |
* @throws StatException the stat exception |
| 885 |
* @throws REXPMismatchException |
|
| 878 | 886 |
*/ |
| 879 |
public double[] getValeursPropres() throws StatException {
|
|
| 887 |
public double[] getValeursPropres() throws StatException, REXPMismatchException {
|
|
| 880 | 888 |
return r_ca.getEigenvalues(); |
| 881 | 889 |
} |
| 882 | 890 |
|
| ... | ... | |
| 885 | 893 |
* |
| 886 | 894 |
* @return the valeurs propres sum |
| 887 | 895 |
* @throws StatException the stat exception |
| 896 |
* @throws REXPMismatchException |
|
| 888 | 897 |
*/ |
| 889 |
public double getValeursPropresSum() throws StatException {
|
|
| 898 |
public double getValeursPropresSum() throws StatException, REXPMismatchException {
|
|
| 890 | 899 |
double sum = 0; |
| 891 | 900 |
for (double d : getValeursPropres()) {
|
| 892 | 901 |
sum += d; |
| tmp/org.txm.ca.core/src/org/txm/ca/core/chartsengine/jfreechart/themes/highcharts/chartcreators/JFCCAChartCreator.java (revision 2683) | ||
|---|---|---|
| 15 | 15 |
import org.jfree.chart.plot.PlotOrientation; |
| 16 | 16 |
import org.jfree.chart.plot.XYPlot; |
| 17 | 17 |
import org.jfree.chart.ui.TextAnchor; |
| 18 |
import org.rosuda.REngine.REXPMismatchException; |
|
| 18 | 19 |
import org.txm.ca.core.chartsengine.base.CAChartCreator; |
| 19 | 20 |
import org.txm.ca.core.chartsengine.base.Utils; |
| 20 | 21 |
import org.txm.ca.core.chartsengine.jfreechart.datasets.CAXYDataset; |
| ... | ... | |
| 36 | 37 |
* |
| 37 | 38 |
*/ |
| 38 | 39 |
public class JFCCAChartCreator extends JFCChartCreator implements CAChartCreator {
|
| 39 |
|
|
| 40 |
|
|
| 40 | 41 |
@Override |
| 41 | 42 |
public JFreeChart createChart(ChartResult result) {
|
| 42 |
|
|
| 43 |
|
|
| 43 | 44 |
CA ca = (CA) result; |
| 44 |
JFreeChart chart = null;
|
|
| 45 |
|
|
| 45 |
JFreeChart chart = null; |
|
| 46 |
|
|
| 46 | 47 |
try {
|
| 47 |
//CAXYDataset dataset = new CAXYDataset(ca); |
|
| 48 |
|
|
| 49 |
chart = ChartFactory.createScatterPlot(Utils.createCAFactorialMapChartTitle(ca),
|
|
| 50 |
"", "", null, PlotOrientation.VERTICAL,
|
|
| 48 |
// CAXYDataset dataset = new CAXYDataset(ca);
|
|
| 49 |
|
|
| 50 |
chart = ChartFactory.createScatterPlot(Utils.createCAFactorialMapChartTitle(ca), |
|
| 51 |
"", "", null, PlotOrientation.VERTICAL, |
|
| 51 | 52 |
CAPreferences.getInstance().getBoolean(ChartsEnginePreferences.SHOW_LEGEND), false, false); |
| 52 |
|
|
| 53 |
|
|
| 53 | 54 |
// Custom renderer |
| 54 | 55 |
chart.getXYPlot().setRenderer(new CAItemSelectionRenderer(ca, chart)); |
| 55 | 56 |
} |
| 56 |
catch(Exception e) {
|
|
| 57 |
catch (Exception e) {
|
|
| 57 | 58 |
Log.severe("Can't create CA factorial map scatter plot" + e);
|
| 58 | 59 |
return null; |
| 59 | 60 |
} |
| 60 |
|
|
| 61 | 61 |
|
| 62 |
return chart; |
|
| 63 | 62 |
|
| 63 |
return chart; |
|
| 64 |
|
|
| 64 | 65 |
} |
| 65 |
|
|
| 66 |
|
|
| 66 | 67 |
@Override |
| 67 | 68 |
public void updateChart(ChartResult result) {
|
| 68 |
|
|
| 69 |
|
|
| 69 | 70 |
CA ca = (CA) result; |
| 70 | 71 |
|
| 71 |
JFreeChart chart = (JFreeChart)result.getChart(); |
|
| 72 |
|
|
| 72 |
JFreeChart chart = (JFreeChart) result.getChart();
|
|
| 73 |
|
|
| 73 | 74 |
// freeze rendering while computing |
| 74 | 75 |
chart.setNotify(false); |
| 75 |
|
|
| 76 |
|
|
| 76 | 77 |
try {
|
| 77 | 78 |
chart.getXYPlot().setDataset(new CAXYDataset(ca)); |
| 78 | 79 |
} |
| ... | ... | |
| 81 | 82 |
e.printStackTrace(); |
| 82 | 83 |
} |
| 83 | 84 |
|
| 84 |
CAItemSelectionRenderer renderer = (CAItemSelectionRenderer) chart.getXYPlot().getRenderer();
|
|
| 85 |
CAItemSelectionRenderer renderer = (CAItemSelectionRenderer) chart.getXYPlot().getRenderer(); |
|
| 85 | 86 |
|
| 86 | 87 |
renderer.setSeriesVisible(0, ca.isShowVariables()); |
| 87 | 88 |
renderer.setSeriesVisible(1, ca.isShowIndividuals()); |
| ... | ... | |
| 91 | 92 |
|
| 92 | 93 |
// Create the limits border |
| 93 | 94 |
this.createCAFactorialMapChartLimitsBorder(chart); |
| 94 |
|
|
| 95 |
|
|
| 95 | 96 |
this.updateChartCAFactorialMapSetDimensions(ca); |
| 96 | 97 |
|
| 97 |
//
|
|
| 98 |
// Draw the point shapes and the item labels
|
|
| 99 |
if(ca.isShowPointShapes()) {
|
|
| 100 |
|
|
| 101 |
renderer.setSeriesItemLabelPaint(0, renderer.getDefaultItemLabelPaint());
|
|
| 102 |
renderer.setSeriesItemLabelPaint(1, renderer.getDefaultItemLabelPaint());
|
|
| 103 |
|
|
| 104 |
// Labels position
|
|
| 105 |
ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER, TextAnchor.BOTTOM_CENTER, 0.0);
|
|
| 106 |
renderer.setDefaultPositiveItemLabelPosition(position);
|
|
| 107 |
renderer.setDefaultNegativeItemLabelPosition(position);
|
|
| 108 |
|
|
| 109 |
renderer.setItemLabelAnchorOffset(1);
|
|
| 110 |
|
|
| 111 |
}
|
|
| 112 |
// Draw only the item labels
|
|
| 113 |
else {
|
|
| 114 |
|
|
| 115 |
// Labels colors
|
|
| 116 |
Color rowsColor = (Color) renderer.getSeriesPaint(0);
|
|
| 117 |
rowsColor = new Color(rowsColor.getRed(), rowsColor.getGreen(), rowsColor.getBlue(), 235);
|
|
| 118 |
Color colsColor = (Color) renderer.getSeriesPaint(1);
|
|
| 119 |
colsColor = new Color(colsColor.getRed(), colsColor.getGreen(), colsColor.getBlue(), 235);
|
|
| 120 |
renderer.setSeriesItemLabelPaint(0, rowsColor);
|
|
| 121 |
renderer.setSeriesItemLabelPaint(1, colsColor);
|
|
| 122 |
|
|
| 123 |
// Labels position
|
|
| 124 |
ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 0.0);
|
|
| 125 |
renderer.setDefaultPositiveItemLabelPosition(position);
|
|
| 126 |
renderer.setDefaultNegativeItemLabelPosition(position);
|
|
| 127 |
|
|
| 128 |
renderer.setItemLabelAnchorOffset(0);
|
|
| 129 |
}
|
|
| 130 |
|
|
| 98 |
//
|
|
| 99 |
// Draw the point shapes and the item labels
|
|
| 100 |
if (ca.isShowPointShapes()) {
|
|
| 101 |
|
|
| 102 |
renderer.setSeriesItemLabelPaint(0, renderer.getDefaultItemLabelPaint());
|
|
| 103 |
renderer.setSeriesItemLabelPaint(1, renderer.getDefaultItemLabelPaint());
|
|
| 104 |
|
|
| 105 |
// Labels position
|
|
| 106 |
ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER, TextAnchor.BOTTOM_CENTER, 0.0);
|
|
| 107 |
renderer.setDefaultPositiveItemLabelPosition(position);
|
|
| 108 |
renderer.setDefaultNegativeItemLabelPosition(position);
|
|
| 109 |
|
|
| 110 |
renderer.setItemLabelAnchorOffset(1);
|
|
| 111 |
|
|
| 112 |
}
|
|
| 113 |
// Draw only the item labels
|
|
| 114 |
else {
|
|
| 115 |
|
|
| 116 |
// Labels colors
|
|
| 117 |
Color rowsColor = (Color) renderer.getSeriesPaint(0);
|
|
| 118 |
rowsColor = new Color(rowsColor.getRed(), rowsColor.getGreen(), rowsColor.getBlue(), 235);
|
|
| 119 |
Color colsColor = (Color) renderer.getSeriesPaint(1);
|
|
| 120 |
colsColor = new Color(colsColor.getRed(), colsColor.getGreen(), colsColor.getBlue(), 235);
|
|
| 121 |
renderer.setSeriesItemLabelPaint(0, rowsColor);
|
|
| 122 |
renderer.setSeriesItemLabelPaint(1, colsColor);
|
|
| 123 |
|
|
| 124 |
// Labels position
|
|
| 125 |
ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 0.0);
|
|
| 126 |
renderer.setDefaultPositiveItemLabelPosition(position);
|
|
| 127 |
renderer.setDefaultNegativeItemLabelPosition(position);
|
|
| 128 |
|
|
| 129 |
renderer.setItemLabelAnchorOffset(0);
|
|
| 130 |
}
|
|
| 131 |
|
|
| 131 | 132 |
super.updateChart(result); |
| 132 |
|
|
| 133 |
// FIXME
|
|
| 134 |
// this.getChartsEngine().squareOffGraph((JFreeChart) chart, 200, 200d);
|
|
| 135 |
|
|
| 133 |
|
|
| 134 |
// FIXME
|
|
| 135 |
// this.getChartsEngine().squareOffGraph((JFreeChart) chart, 200, 200d);
|
|
| 136 |
|
|
| 136 | 137 |
} |
| 137 |
|
|
| 138 |
|
|
| 139 | 138 |
|
| 139 |
|
|
| 140 |
|
|
| 140 | 141 |
/** |
| 141 | 142 |
* Add some borders to the limits of the specified XY plot. |
| 143 |
* |
|
| 142 | 144 |
* @param plot |
| 143 | 145 |
*/ |
| 144 |
public void createCAFactorialMapChartLimitsBorder(JFreeChart chart) {
|
|
| 145 |
|
|
| 146 |
public void createCAFactorialMapChartLimitsBorder(JFreeChart chart) {
|
|
| 147 |
|
|
| 146 | 148 |
XYPlot plot = chart.getXYPlot(); |
| 147 |
|
|
| 149 |
|
|
| 148 | 150 |
// Remove all existent annotations |
| 149 | 151 |
plot.clearAnnotations(); |
| 150 |
// for(int i = plot.getAnnotations().size() - 1; i >= 0; i--) {
|
|
| 151 |
// plot.removeAnnotation((XYAnnotation) plot.getAnnotations().get(i));
|
|
| 152 |
// }
|
|
| 153 |
|
|
| 154 |
|
|
| 155 |
// Gets the extreme coordinates values
|
|
| 152 |
// for(int i = plot.getAnnotations().size() - 1; i >= 0; i--) {
|
|
| 153 |
// plot.removeAnnotation((XYAnnotation) plot.getAnnotations().get(i));
|
|
| 154 |
// }
|
|
| 155 |
|
|
| 156 |
|
|
| 157 |
// Gets the extreme coordinates values
|
|
| 156 | 158 |
double minX = 0, maxX = 0, minY = 0, maxY = 0; |
| 157 |
|
|
| 159 |
|
|
| 158 | 160 |
// FIXME: new version |
| 159 |
// minX = plot.getDataRange(plot.getDomainAxis()).getLowerBound();
|
|
| 160 |
// maxX = plot.getDataRange(plot.getDomainAxis()).getUpperBound();
|
|
| 161 |
// |
|
| 162 |
// minY = plot.getDataRange(plot.getRangeAxis()).getLowerBound();
|
|
| 163 |
// maxY = plot.getDataRange(plot.getRangeAxis()).getUpperBound();
|
|
| 164 |
|
|
| 161 |
// minX = plot.getDataRange(plot.getDomainAxis()).getLowerBound();
|
|
| 162 |
// maxX = plot.getDataRange(plot.getDomainAxis()).getUpperBound();
|
|
| 163 |
//
|
|
| 164 |
// minY = plot.getDataRange(plot.getRangeAxis()).getLowerBound();
|
|
| 165 |
// maxY = plot.getDataRange(plot.getRangeAxis()).getUpperBound();
|
|
| 166 |
|
|
| 165 | 167 |
// FIXME: old version, to remove when new version will be validated |
| 166 | 168 |
// Rows |
| 167 |
if(plot.getRenderer().isSeriesVisible(0)) {
|
|
| 168 |
minX = ((CAXYDataset)plot.getDataset()).getMinX(0); |
|
| 169 |
if (plot.getRenderer().isSeriesVisible(0)) {
|
|
| 170 |
minX = ((CAXYDataset) plot.getDataset()).getMinX(0);
|
|
| 169 | 171 |
} |
| 170 | 172 |
// Cols |
| 171 |
if(plot.getRenderer().isSeriesVisible(1)) {
|
|
| 172 |
double tmpMinX = ((CAXYDataset)plot.getDataset()).getMinX(1); |
|
| 173 |
if(tmpMinX < minX) {
|
|
| 173 |
if (plot.getRenderer().isSeriesVisible(1)) {
|
|
| 174 |
double tmpMinX = ((CAXYDataset) plot.getDataset()).getMinX(1);
|
|
| 175 |
if (tmpMinX < minX) {
|
|
| 174 | 176 |
minX = tmpMinX; |
| 175 | 177 |
} |
| 176 | 178 |
} |
| 177 |
|
|
| 179 |
|
|
| 178 | 180 |
// Rows |
| 179 |
if(plot.getRenderer().isSeriesVisible(0)) {
|
|
| 180 |
maxX = ((CAXYDataset)plot.getDataset()).getMaxX(0); |
|
| 181 |
if (plot.getRenderer().isSeriesVisible(0)) {
|
|
| 182 |
maxX = ((CAXYDataset) plot.getDataset()).getMaxX(0);
|
|
| 181 | 183 |
} |
| 182 | 184 |
// Cols |
| 183 |
if(plot.getRenderer().isSeriesVisible(1)) {
|
|
| 184 |
double tmpMaxX = ((CAXYDataset)plot.getDataset()).getMaxX(1); |
|
| 185 |
if(tmpMaxX > maxX) {
|
|
| 185 |
if (plot.getRenderer().isSeriesVisible(1)) {
|
|
| 186 |
double tmpMaxX = ((CAXYDataset) plot.getDataset()).getMaxX(1);
|
|
| 187 |
if (tmpMaxX > maxX) {
|
|
| 186 | 188 |
maxX = tmpMaxX; |
| 187 | 189 |
} |
| 188 | 190 |
} |
| 189 |
|
|
| 191 |
|
|
| 190 | 192 |
// Rows |
| 191 |
if(plot.getRenderer().isSeriesVisible(0)) {
|
|
| 192 |
minY = ((CAXYDataset)plot.getDataset()).getMinY(0); |
|
| 193 |
if (plot.getRenderer().isSeriesVisible(0)) {
|
|
| 194 |
minY = ((CAXYDataset) plot.getDataset()).getMinY(0);
|
|
| 193 | 195 |
} |
| 194 | 196 |
// Cols |
| 195 |
if(plot.getRenderer().isSeriesVisible(1)) {
|
|
| 196 |
double tmpMinY = ((CAXYDataset)plot.getDataset()).getMinY(1); |
|
| 197 |
if(tmpMinY < minY) {
|
|
| 197 |
if (plot.getRenderer().isSeriesVisible(1)) {
|
|
| 198 |
double tmpMinY = ((CAXYDataset) plot.getDataset()).getMinY(1);
|
|
| 199 |
if (tmpMinY < minY) {
|
|
| 198 | 200 |
minY = tmpMinY; |
| 199 | 201 |
} |
| 200 | 202 |
} |
| 201 |
|
|
| 203 |
|
|
| 202 | 204 |
// Rows |
| 203 |
if(plot.getRenderer().isSeriesVisible(0)) {
|
|
| 204 |
maxY = ((CAXYDataset)plot.getDataset()).getMaxY(0); |
|
| 205 |
if (plot.getRenderer().isSeriesVisible(0)) {
|
|
| 206 |
maxY = ((CAXYDataset) plot.getDataset()).getMaxY(0);
|
|
| 205 | 207 |
} |
| 206 | 208 |
// Cols |
| 207 |
if(plot.getRenderer().isSeriesVisible(1)) {
|
|
| 208 |
double tmpMaxY = ((CAXYDataset)plot.getDataset()).getMaxY(1); |
|
| 209 |
if(tmpMaxY > maxY) {
|
|
| 209 |
if (plot.getRenderer().isSeriesVisible(1)) {
|
|
| 210 |
double tmpMaxY = ((CAXYDataset) plot.getDataset()).getMaxY(1);
|
|
| 211 |
if (tmpMaxY > maxY) {
|
|
| 210 | 212 |
maxY = tmpMaxY; |
| 211 | 213 |
} |
| 212 | 214 |
} |
| 213 |
|
|
| 215 |
|
|
| 214 | 216 |
// Add some margins to the border |
| 215 | 217 |
// FIXME : to compute according to the real series shape dimensions |
| 216 | 218 |
// The code below doesn't work |
| 217 |
// double shapeHalfWidth = chart.getXYPlot().getRenderer().getSeriesShape(0).getBounds2D().getWidth() / 2;
|
|
| 219 |
// double shapeHalfWidth = chart.getXYPlot().getRenderer().getSeriesShape(0).getBounds2D().getWidth() / 2;
|
|
| 218 | 220 |
double shapeHalfWidth = 0.02; |
| 219 | 221 |
minX -= shapeHalfWidth; |
| 220 | 222 |
maxX += shapeHalfWidth; |
| 221 | 223 |
minY -= shapeHalfWidth; |
| 222 | 224 |
maxY += shapeHalfWidth; |
| 223 |
|
|
| 224 |
|
|
| 225 |
|
|
| 226 |
|
|
| 225 | 227 |
// Create the border |
| 226 |
BasicStroke dashedStroke = new BasicStroke(0.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f, new float[] {2f}, 0f);
|
|
| 228 |
BasicStroke dashedStroke = new BasicStroke(0.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f, new float[] { 2f }, 0f);
|
|
| 227 | 229 |
XYLineAnnotation annotation; |
| 228 | 230 |
Color borderColor = Color.GRAY; |
| 229 |
|
|
| 231 |
|
|
| 230 | 232 |
// Left border |
| 231 | 233 |
annotation = new XYLineAnnotation(minX, minY, minX, maxY, dashedStroke, borderColor); |
| 232 |
plot.addAnnotation(annotation);
|
|
| 233 |
|
|
| 234 |
// Right border
|
|
| 234 |
plot.addAnnotation(annotation);
|
|
| 235 |
|
|
| 236 |
// Right border
|
|
| 235 | 237 |
annotation = new XYLineAnnotation(maxX, minY, maxX, maxY, dashedStroke, borderColor); |
| 236 |
plot.addAnnotation(annotation);
|
|
| 237 |
|
|
| 238 |
plot.addAnnotation(annotation);
|
|
| 239 |
|
|
| 238 | 240 |
// Bottom border |
| 239 | 241 |
annotation = new XYLineAnnotation(minX, minY, maxX, minY, dashedStroke, borderColor); |
| 240 |
plot.addAnnotation(annotation);
|
|
| 241 |
|
|
| 242 |
// Top border
|
|
| 242 |
plot.addAnnotation(annotation);
|
|
| 243 |
|
|
| 244 |
// Top border
|
|
| 243 | 245 |
annotation = new XYLineAnnotation(minX, maxY, maxX, maxY, dashedStroke, borderColor); |
| 244 |
plot.addAnnotation(annotation);
|
|
| 245 |
|
|
| 246 |
plot.addAnnotation(annotation);
|
|
| 247 |
|
|
| 246 | 248 |
} |
| 247 |
|
|
| 248 |
|
|
| 249 |
|
|
| 250 |
|
|
| 249 | 251 |
@Override |
| 250 | 252 |
public void updateChartCAFactorialMapHighlightPoints(Object chart, boolean rows, String[] labels) {
|
| 251 |
|
|
| 252 |
MultipleItemsSelector selector = (MultipleItemsSelector) ((CAItemSelectionRenderer)((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector(); |
|
| 253 |
|
|
| 253 |
|
|
| 254 |
MultipleItemsSelector selector = (MultipleItemsSelector) ((CAItemSelectionRenderer) ((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector();
|
|
| 255 |
|
|
| 254 | 256 |
// Rows |
| 255 | 257 |
int series = 0; |
| 256 | 258 |
// Columns |
| 257 |
if(!rows) {
|
|
| 259 |
if (!rows) {
|
|
| 258 | 260 |
series = 1; |
| 259 | 261 |
} |
| 260 | 262 |
selector.removeAllSelectedItems(series); |
| 261 |
int[] items = ((CAXYDataset)((JFreeChart) chart).getXYPlot().getDataset()).getLabelIndices(series, labels); |
|
| 262 |
|
|
| 263 |
for(int i = 0; i < items.length; i++) {
|
|
| 263 |
int[] items = ((CAXYDataset) ((JFreeChart) chart).getXYPlot().getDataset()).getLabelIndices(series, labels);
|
|
| 264 |
|
|
| 265 |
for (int i = 0; i < items.length; i++) {
|
|
| 264 | 266 |
selector.addSelectedItem(series, items[i]); |
| 265 | 267 |
} |
| 266 |
|
|
| 267 |
//((JFreeChart) chart).setNotify(true); |
|
| 268 |
|
|
| 269 |
// ((JFreeChart) chart).setNotify(true);
|
|
| 268 | 270 |
} |
| 269 |
|
|
| 270 |
|
|
| 271 |
|
|
| 272 |
|
|
| 271 | 273 |
@Override |
| 272 |
public void updateChartCAFactorialMapSetDimensions(CA ca) {
|
|
| 273 |
|
|
| 274 |
int dimension1 = ca.getFirstDimension(); |
|
| 275 |
int dimension2 = ca.getSecondDimension(); |
|
| 274 |
public void updateChartCAFactorialMapSetDimensions(CA ca) {
|
|
| 276 | 275 |
|
| 276 |
int dimension1 = ca.getFirstDimension(); |
|
| 277 |
int dimension2 = ca.getSecondDimension(); |
|
| 278 |
|
|
| 277 | 279 |
JFreeChart chart = (JFreeChart) ca.getChart(); |
| 278 | 280 |
|
| 279 |
// Modify data set
|
|
| 280 |
((CAXYDataset) ((JFreeChart) chart).getXYPlot().getDataset()).setAxis1(dimension1);
|
|
| 281 |
((CAXYDataset) ((JFreeChart) chart).getXYPlot().getDataset()).setAxis2(dimension2);
|
|
| 282 |
|
|
| 283 |
// Update axis labels
|
|
| 284 |
// FIXME : create a method in CA to directly get a singular value as percent ?
|
|
| 285 |
try {
|
|
| 286 |
double sinuglarValuesSum = ca.getValeursPropresSum();
|
|
| 287 |
DecimalFormat f = new DecimalFormat("###.00"); //$NON-NLS-1$
|
|
| 288 |
((JFreeChart) chart).getXYPlot().getDomainAxis().setLabel(NLS.bind(CACoreMessages.axisP0P1Percent, dimension1, f.format(100 * ca.getValeursPropres()[dimension1 - 1] / sinuglarValuesSum)));
|
|
| 289 |
((JFreeChart) chart).getXYPlot().getRangeAxis().setLabel(NLS.bind(CACoreMessages.axisP0P1Percent, dimension2, f.format(100 * ca.getValeursPropres()[dimension2 - 1] / sinuglarValuesSum)));
|
|
| 290 |
|
|
| 291 |
// Refresh data set
|
|
| 292 |
// FIXME : any way to fire a data set event rather than reassign the same data set?
|
|
| 293 |
((JFreeChart) chart).getXYPlot().setDataset(((JFreeChart) chart).getXYPlot().getDataset());
|
|
| 281 |
// Modify data set |
|
| 282 |
((CAXYDataset) chart.getXYPlot().getDataset()).setAxis1(dimension1);
|
|
| 283 |
((CAXYDataset) chart.getXYPlot().getDataset()).setAxis2(dimension2);
|
|
| 284 |
|
|
| 285 |
// Update axis labels |
|
| 286 |
// FIXME : create a method in CA to directly get a singular value as percent ? |
|
| 287 |
try {
|
|
| 288 |
double sinuglarValuesSum = ca.getValeursPropresSum(); |
|
| 289 |
DecimalFormat f = new DecimalFormat("###.00"); //$NON-NLS-1$
|
|
| 290 |
chart.getXYPlot().getDomainAxis().setLabel(NLS.bind(CACoreMessages.axisP0P1Percent, dimension1, f.format(100 * ca.getValeursPropres()[dimension1 - 1] / sinuglarValuesSum)));
|
|
| 291 |
chart.getXYPlot().getRangeAxis().setLabel(NLS.bind(CACoreMessages.axisP0P1Percent, dimension2, f.format(100 * ca.getValeursPropres()[dimension2 - 1] / sinuglarValuesSum)));
|
|
| 292 |
|
|
| 293 |
// Refresh data set |
|
| 294 |
// FIXME : any way to fire a data set event rather than reassign the same data set? |
|
| 295 |
chart.getXYPlot().setDataset(chart.getXYPlot().getDataset());
|
|
| 294 | 296 |
// the code below doesn't neither center the view nor update the axes ticks of the new chart, continue tests |
| 295 |
//((JFreeChart) chart).setNotify(true); |
|
| 296 |
|
|
| 297 |
|
|
| 297 |
// ((JFreeChart) chart).setNotify(true);
|
|
| 298 |
|
|
| 299 |
|
|
| 298 | 300 |
// Update the limits border |
| 299 |
this.createCAFactorialMapChartLimitsBorder((JFreeChart) chart);
|
|
| 300 |
|
|
| 301 |
this.createCAFactorialMapChartLimitsBorder(chart); |
|
| 302 |
|
|
| 301 | 303 |
} |
| 302 |
catch(StatException e) {
|
|
| 304 |
catch (StatException e) {
|
|
| 303 | 305 |
// TODO Auto-generated catch block |
| 304 | 306 |
e.printStackTrace(); |
| 305 | 307 |
} |
| 306 |
} |
|
| 307 |
|
|
| 308 |
|
|
| 308 |
catch (REXPMismatchException e) {
|
|
| 309 |
// TODO Auto-generated catch block |
|
| 310 |
e.printStackTrace(); |
|
| 311 |
} |
|
| 312 |
} |
|
| 309 | 313 |
|
| 314 |
|
|
| 315 |
|
|
| 310 | 316 |
@Override |
| 311 | 317 |
public ArrayList<String> getCAFactorialMapChartSelectedPoints(Object chart, int series) {
|
| 312 |
|
|
| 313 |
MultipleItemsSelector selector = (MultipleItemsSelector) ((CAItemSelectionRenderer)((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector(); |
|
| 314 |
ArrayList<String> pointLabels = new ArrayList<String>(selector.getSelectedItemsCount(series));
|
|
| 315 |
|
|
| 316 |
if(selector.getSelectedItemsCount(series) > 0) {
|
|
| 317 |
|
|
| 318 |
|
|
| 319 |
MultipleItemsSelector selector = (MultipleItemsSelector) ((CAItemSelectionRenderer) ((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector();
|
|
| 320 |
ArrayList<String> pointLabels = new ArrayList<>(selector.getSelectedItemsCount(series)); |
|
| 321 |
|
|
| 322 |
if (selector.getSelectedItemsCount(series) > 0) {
|
|
| 323 |
|
|
| 318 | 324 |
CAXYDataset dataset = (CAXYDataset) ((JFreeChart) chart).getXYPlot().getDataset(); |
| 319 | 325 |
int[] selectedItems = selector.getSelectedItems(series); |
| 320 |
|
|
| 321 |
for(int i = 0; i < selectedItems.length; i++) {
|
|
| 326 |
|
|
| 327 |
for (int i = 0; i < selectedItems.length; i++) {
|
|
| 322 | 328 |
pointLabels.add(dataset.getLabel(series, selectedItems[i])); |
| 323 | 329 |
} |
| 324 | 330 |
} |
| 325 | 331 |
return pointLabels; |
| 326 | 332 |
} |
| 327 | 333 |
|
| 328 |
|
|
| 329 |
|
|
| 330 |
|
|
| 334 |
|
|
| 335 |
|
|
| 336 |
|
|
| 331 | 337 |
@Override |
| 332 | 338 |
public void updateChartCAFactorialMapSetLabelItemsSelectionOrder(Object chart, String[] rowLabels, String[] colLabels) {
|
| 333 | 339 |
|
| 334 |
MultipleItemsSelector selector = (MultipleItemsSelector) ((CAItemSelectionRenderer)((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector(); |
|
| 335 |
selector.setCyclicItemsOrder(this.getItemsAndSeriesOrderedByLabels((CAXYDataset)((JFreeChart) chart).getXYPlot().getDataset(), rowLabels, colLabels));
|
|
| 340 |
MultipleItemsSelector selector = (MultipleItemsSelector) ((CAItemSelectionRenderer) ((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector();
|
|
| 341 |
selector.setCyclicItemsOrder(this.getItemsAndSeriesOrderedByLabels((CAXYDataset) ((JFreeChart) chart).getXYPlot().getDataset(), rowLabels, colLabels));
|
|
| 336 | 342 |
} |
| 337 |
|
|
| 338 | 343 |
|
| 344 |
|
|
| 339 | 345 |
/** |
| 340 | 346 |
* Gets a map where the values of the dataset are ordered according to the specified label arrays, keeping the order of these arrays and flatten but grouped by series. |
| 347 |
* |
|
| 341 | 348 |
* @param dataset |
| 342 | 349 |
* @return |
| 343 | 350 |
*/ |
| 344 |
public TreeMap<Object, ArrayList<Integer>> getItemsAndSeriesOrderedByLabels(CAXYDataset dataset, String[] rowLabels, String[] colLabels) {
|
|
| 351 |
public TreeMap<Object, ArrayList<Integer>> getItemsAndSeriesOrderedByLabels(CAXYDataset dataset, String[] rowLabels, String[] colLabels) {
|
|
| 345 | 352 |
|
| 346 |
TreeMap<Object, ArrayList<Integer>> orderedValues = new TreeMap<Object, ArrayList<Integer>>();
|
|
| 353 |
TreeMap<Object, ArrayList<Integer>> orderedValues = new TreeMap<>(); |
|
| 347 | 354 |
|
| 348 | 355 |
int[] rowIndices = dataset.getOrderedLabelIndices(0, rowLabels); |
| 349 | 356 |
int[] colIndices = dataset.getOrderedLabelIndices(1, colLabels); |
| 350 | 357 |
|
| 351 | 358 |
int i = 0; |
| 352 |
for(; i < rowIndices.length; i++) {
|
|
| 353 |
ArrayList<Integer> itemData = new ArrayList<Integer>(2);
|
|
| 359 |
for (; i < rowIndices.length; i++) {
|
|
| 360 |
ArrayList<Integer> itemData = new ArrayList<>(2); |
|
| 354 | 361 |
itemData.add(0); // series |
| 355 | 362 |
itemData.add(rowIndices[i]); // item |
| 356 | 363 |
orderedValues.put(i, itemData); |
| 357 | 364 |
} |
| 358 |
for(int j = 0; j < colIndices.length; j++) {
|
|
| 359 |
ArrayList<Integer> itemData = new ArrayList<Integer>(2);
|
|
| 365 |
for (int j = 0; j < colIndices.length; j++) {
|
|
| 366 |
ArrayList<Integer> itemData = new ArrayList<>(2); |
|
| 360 | 367 |
itemData.add(1); // series |
| 361 | 368 |
itemData.add(colIndices[j]); // item |
| 362 | 369 |
orderedValues.put(j + i, itemData); |
| 363 | 370 |
} |
| 364 |
|
|
| 371 |
|
|
| 365 | 372 |
return orderedValues; |
| 366 | 373 |
} |
| 367 | 374 |
|
| ... | ... | |
| 369 | 376 |
public Class getResultDataClass() {
|
| 370 | 377 |
return CA.class; |
| 371 | 378 |
} |
| 372 |
|
|
| 373 |
|
|
| 374 | 379 |
|
| 375 |
|
|
| 376 |
} |
|
| 380 |
|
|
| 381 |
|
|
| 382 |
|
|
| 383 |
} |
|
| tmp/org.txm.ca.core/src/org/txm/ca/core/chartsengine/jfreechart/themes/highcharts/chartcreators/JFCEigenvaluesChartCreator.java (revision 2683) | ||
|---|---|---|
| 5 | 5 |
import org.jfree.chart.axis.NumberAxis; |
| 6 | 6 |
import org.jfree.data.category.DefaultCategoryDataset; |
| 7 | 7 |
import org.jfree.data.general.DatasetUtils; |
| 8 |
import org.rosuda.REngine.REXPMismatchException; |
|
| 8 | 9 |
import org.txm.ca.core.chartsengine.jfreechart.themes.highcharts.renderers.CAEigenvaluesItemSelectionRenderer; |
| 9 | 10 |
import org.txm.ca.core.functions.CA; |
| 10 | 11 |
import org.txm.ca.core.functions.Eigenvalues; |
| ... | ... | |
| 22 | 23 |
* |
| 23 | 24 |
*/ |
| 24 | 25 |
public class JFCEigenvaluesChartCreator extends JFCChartCreator {
|
| 25 |
|
|
| 26 |
|
|
| 26 |
|
|
| 27 |
|
|
| 27 | 28 |
@Override |
| 28 | 29 |
public Object createChart(ChartResult result) {
|
| 29 | 30 |
|
| 30 |
CA ca = (CA) ((Eigenvalues) result).getCA();
|
|
| 31 |
CA ca = ((Eigenvalues) result).getCA(); |
|
| 31 | 32 |
JFreeChart chart = null; |
| 32 |
|
|
| 33 |
|
|
| 33 | 34 |
// Creates the empty dataset |
| 34 | 35 |
DefaultCategoryDataset dataset = new DefaultCategoryDataset(); |
| 35 | 36 |
// Create the chart |
| 36 | 37 |
chart = this.getChartsEngine().createCategoryBarChart(dataset, CACoreMessages.eigenvalues, CACoreMessages.axis, CACoreMessages.eigenvalue, false, false, false); |
| 37 |
|
|
| 38 |
|
|
| 38 | 39 |
// Custom renderer |
| 39 | 40 |
chart.getCategoryPlot().setRenderer(new CAEigenvaluesItemSelectionRenderer(ca)); |
| 40 |
|
|
| 41 |
|
|
| 41 | 42 |
return chart; |
| 42 | 43 |
} |
| 43 |
|
|
| 44 | 44 |
|
| 45 |
|
|
| 45 | 46 |
@Override |
| 46 | 47 |
public void updateChart(ChartResult result) {
|
| 47 |
|
|
| 48 |
CA ca = (CA) ((Eigenvalues) result).getCA();
|
|
| 48 |
|
|
| 49 |
CA ca = ((Eigenvalues) result).getCA(); |
|
| 49 | 50 |
JFreeChart chart = (JFreeChart) result.getChart(); |
| 50 | 51 |
|
| 51 | 52 |
// freeze rendering while computing |
| 52 | 53 |
chart.setNotify(false); |
| 53 |
|
|
| 54 |
|
|
| 54 | 55 |
// update the dataset |
| 55 | 56 |
try {
|
| 56 |
|
|
| 57 |
|
|
| 57 | 58 |
DefaultCategoryDataset dataset = (DefaultCategoryDataset) chart.getCategoryPlot().getDataset(); |
| 58 | 59 |
dataset.clear(); |
| 59 |
|
|
| 60 | 60 |
|
| 61 |
|
|
| 61 | 62 |
double[] singularValues = ca.getValeursPropres(); |
| 62 |
|
|
| 63 |
for(int i = 0; i < singularValues.length; i++) {
|
|
| 63 |
|
|
| 64 |
for (int i = 0; i < singularValues.length; i++) {
|
|
| 64 | 65 |
dataset.setValue(singularValues[i], CACoreMessages.eigenvalue, String.valueOf(i + 1)); |
| 65 | 66 |
} |
| 66 |
|
|
| 67 |
|
|
| 67 | 68 |
} |
| 68 |
catch(StatException e) {
|
|
| 69 |
catch (StatException e) {
|
|
| 69 | 70 |
Log.severe(NLS.bind(CACoreMessages.cantCreateBarChartOfTheCASingularValuesP0, e)); |
| 70 | 71 |
Log.printStackTrace(e); |
| 71 | 72 |
} |
| 72 |
|
|
| 73 |
// Custom range axis for ticks drawing options |
|
| 74 |
chart.getCategoryPlot().setRangeAxis(new ExtendedNumberAxis((NumberAxis) chart.getCategoryPlot().getRangeAxis(), false, true, 0, DatasetUtils.findMaximumRangeValue(chart.getCategoryPlot().getDataset()).doubleValue())); |
|
| 73 |
catch (REXPMismatchException e) {
|
|
| 74 |
// TODO Auto-generated catch block |
|
| 75 |
e.printStackTrace(); |
|
| 76 |
} |
|
| 75 | 77 |
|
| 78 |
// Custom range axis for ticks drawing options |
|
| 79 |
chart.getCategoryPlot().setRangeAxis(new ExtendedNumberAxis((NumberAxis) chart.getCategoryPlot().getRangeAxis(), false, true, 0, DatasetUtils.findMaximumRangeValue(chart.getCategoryPlot() |
|
| 80 |
.getDataset()).doubleValue())); |
|
| 81 |
|
|
| 76 | 82 |
super.updateChart(result); |
| 77 | 83 |
|
| 78 |
// force the hide of the domain axis lines
|
|
| 84 |
// force the hide of the domain axis lines |
|
| 79 | 85 |
chart.getCategoryPlot().setDomainGridlinesVisible(false); |
| 80 |
|
|
| 86 |
|
|
| 81 | 87 |
} |
| 82 | 88 |
|
| 83 | 89 |
|
| ... | ... | |
| 85 | 91 |
public Class getResultDataClass() {
|
| 86 | 92 |
return Eigenvalues.class; |
| 87 | 93 |
} |
| 88 |
|
|
| 89 |
|
|
| 90 | 94 |
|
| 91 |
|
|
| 92 |
} |
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
} |
|
| tmp/org.txm.ca.core/src/org/txm/ca/core/chartsengine/jfreechart/themes/highcharts/renderers/CAEigenvaluesItemSelectionRenderer.java (revision 2683) | ||
|---|---|---|
| 7 | 7 |
import org.jfree.chart.labels.CategoryToolTipGenerator; |
| 8 | 8 |
import org.jfree.data.category.CategoryDataset; |
| 9 | 9 |
import org.jfree.data.category.DefaultCategoryDataset; |
| 10 |
import org.rosuda.REngine.REXPMismatchException; |
|
| 10 | 11 |
import org.txm.ca.core.functions.CA; |
| 11 | 12 |
import org.txm.ca.core.messages.CACoreMessages; |
| 12 | 13 |
import org.txm.chartsengine.core.ChartsEngine; |
| ... | ... | |
| 18 | 19 |
|
| 19 | 20 |
/** |
| 20 | 21 |
* Renderer providing item selection system and drawing features for selected item and custom rendering for CA eigenvalues bar charts. |
| 22 |
* |
|
| 21 | 23 |
* @author sjacquot |
| 22 | 24 |
* |
| 23 | 25 |
*/ |
| 24 | 26 |
public class CAEigenvaluesItemSelectionRenderer extends ItemSelectionCategoryBarRenderer {
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 27 | 29 |
/** |
| 28 | 30 |
* Percent values number format. |
| 29 | 31 |
*/ |
| 30 | 32 |
protected DecimalFormat percentValuesNumberFormat; |
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 33 | 35 |
/** |
| 34 | 36 |
* Creates a renderer dedicated to CA charts. |
| 35 | 37 |
*/ |
| ... | ... | |
| 38 | 40 |
this.mouseOverItemSelector.setResult(ca); |
| 39 | 41 |
this.percentValuesNumberFormat = new DecimalFormat("#.00");
|
| 40 | 42 |
} |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 44 | 46 |
@Override |
| 45 |
public void initToolTipGenerator(final IRendererWithItemSelection renderer) {
|
|
| 47 |
public void initToolTipGenerator(final IRendererWithItemSelection renderer) {
|
|
| 46 | 48 |
this.setDefaultToolTipGenerator(new CategoryToolTipGenerator() {
|
| 47 |
|
|
| 49 |
|
|
| 48 | 50 |
@Override |
| 49 | 51 |
public String generateToolTip(CategoryDataset dataset, int row, int column) {
|
| 50 |
|
|
| 52 |
|
|
| 51 | 53 |
// Hexadecimal color |
| 52 | 54 |
Color color = (Color) getSeriesPaint(row); |
| 53 | 55 |
String hex = "#" + Integer.toHexString(color.getRGB()).substring(2); |
| 54 |
|
|
| 56 |
|
|
| 55 | 57 |
DefaultCategoryDataset catDataset = (DefaultCategoryDataset) dataset; |
| 56 | 58 |
Number value = catDataset.getValue(row, column); |
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 59 | 61 |
CA ca = (CA) getItemsSelector().getResult(); |
| 60 |
List<List<Object>> singularValuesData = ca.getSingularValuesInfos(); |
|
| 61 |
|
|
| 62 |
List<List<Object>> singularValuesData; |
|
| 63 |
try {
|
|
| 64 |
singularValuesData = ca.getSingularValuesInfos(); |
|
| 65 |
} |
|
| 66 |
catch (REXPMismatchException e) {
|
|
| 67 |
e.printStackTrace(); |
|
| 68 |
return e.getMessage(); |
|
| 69 |
} |
|
| 70 |
|
|
| 62 | 71 |
return CustomHTMLToolTip.getDefaultHTMLBody(renderer, hex) + "<p>#" + catDataset.getColumnKey(column) + "</p>" |
| 63 | 72 |
+ "<p><span style=\"color: " + hex + ";\">" + catDataset.getRowKey(row) + ChartsEngineCoreMessages.EMPTY |
| 64 |
+ " </span><b>" + valuesNumberFormat.format(value) + "</b></p>"
|
|
| 73 |
+ " </span><b>" + valuesNumberFormat.format(value) + "</b></p>" |
|
| 65 | 74 |
+ "<p><span style=\"color: " + hex + ";\">" + CACoreMessages.percent + ChartsEngineCoreMessages.EMPTY |
| 66 |
+ " </span><b>" + percentValuesNumberFormat.format(singularValuesData.get(column).get(2)) + "</b></p>"
|
|
| 75 |
+ " </span><b>" + percentValuesNumberFormat.format(singularValuesData.get(column).get(2)) + "</b></p>" |
|
| 67 | 76 |
+ "<p><span style=\"color: " + hex + ";\">" + CACoreMessages.charts_singularValues_tooltipSum + CACoreMessages.percent |
| 68 |
+ ChartsEngineCoreMessages.EMPTY
|
|
| 69 |
+ " </span><b>" + percentValuesNumberFormat.format(singularValuesData.get(column).get(3)) + "</b></p>"
|
|
| 77 |
+ ChartsEngineCoreMessages.EMPTY |
|
| 78 |
+ " </span><b>" + percentValuesNumberFormat.format(singularValuesData.get(column).get(3)) + "</b></p>" |
|
| 70 | 79 |
+ "</body><html>"; |
| 71 | 80 |
} |
| 72 | 81 |
}); |
| 73 | 82 |
} |
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
} |
|
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
} |
|
| tmp/org.txm.ca.core/src/org/txm/ca/core/statsengine/r/functions/FactoMineRCA.java (revision 2683) | ||
|---|---|---|
| 36 | 36 |
import org.txm.ca.core.messages.CACoreMessages; |
| 37 | 37 |
import org.txm.lexicaltable.core.statsengine.data.ILexicalTable; |
| 38 | 38 |
import org.txm.statsengine.core.StatException; |
| 39 |
import org.txm.statsengine.core.data.Vector; |
|
| 39 | 40 |
import org.txm.statsengine.r.core.RWorkspace; |
| 40 | 41 |
import org.txm.statsengine.r.core.data.QuantitativeDataStructureImpl; |
| 42 |
import org.txm.statsengine.r.core.data.VectorImpl; |
|
| 41 | 43 |
import org.txm.statsengine.r.core.exceptions.RWorkspaceException; |
| 42 | 44 |
|
| 43 |
// TODO: Auto-generated Javadoc |
|
| 44 | 45 |
/** |
| 45 |
* Access to the R implementation of the Correspondance Analysis.
|
|
| 46 |
* Access to the R implementation of the Correspondance Analysis of the FactoMineR library
|
|
| 46 | 47 |
* |
| 47 | 48 |
* @author mdecorde |
| 48 | 49 |
*/ |
| 49 | 50 |
public class FactoMineRCA implements ICA {
|
| 50 |
|
|
| 51 |
|
|
| 51 | 52 |
/** The singular values. */ |
| 52 | 53 |
private double[] eigenvalues = null; |
| 53 | 54 |
|
| 54 | 55 |
/** The singular values2. */ |
| 55 | 56 |
private double[] singularValues = null; |
| 56 |
|
|
| 57 |
|
|
| 57 | 58 |
/** The rowmass. */ |
| 58 | 59 |
private double[] rowmass = null; |
| 59 | 60 |
|
| ... | ... | |
| 71 | 72 |
|
| 72 | 73 |
/** The colinertia. */ |
| 73 | 74 |
private double[] colinertia = null; |
| 74 |
|
|
| 75 |
|
|
| 75 | 76 |
/** The rowcos2. */ |
| 76 | 77 |
private double[][] rowcos2 = null; |
| 77 | 78 |
|
| ... | ... | |
| 83 | 84 |
|
| 84 | 85 |
/** The colcontrib. */ |
| 85 | 86 |
private double[][] colcontrib = null; |
| 86 |
|
|
| 87 |
|
|
| 87 | 88 |
/** The rw. */ |
| 88 | 89 |
private final RWorkspace rw = RWorkspace.getRWorkspaceInstance(); |
| 89 | 90 |
|
| 90 | 91 |
/** The symbol. */ |
| 91 | 92 |
private final String symbol = QuantitativeDataStructureImpl.createSymbole(FactoMineRCA.class); |
| 92 |
|
|
| 93 |
|
|
| 93 | 94 |
/** The rowscoords. */ |
| 94 | 95 |
private double[][] rowscoords; |
| 95 |
|
|
| 96 |
|
|
| 96 | 97 |
/** The colscoords. */ |
| 97 | 98 |
private double[][] colscoords; |
| 98 |
|
|
| 99 |
private ILexicalTable table; |
|
| 100 | 99 |
|
| 100 |
private ILexicalTable table; |
|
| 101 |
|
|
| 101 | 102 |
/** |
| 102 | 103 |
* Create a correspondence analysis on the given table. The correspondence analysis is computed as soon as the object is created. |
| 103 | 104 |
* |
| ... | ... | |
| 105 | 106 |
* @throws StatException the stat exception |
| 106 | 107 |
*/ |
| 107 | 108 |
public FactoMineRCA(ILexicalTable table) throws StatException {
|
| 108 |
|
|
| 109 |
|
|
| 109 | 110 |
loadLibrary(); |
| 110 | 111 |
this.table = table; |
| 111 | 112 |
} |
| 112 | 113 |
|
| 114 |
@Override |
|
| 113 | 115 |
public void compute() throws StatException {
|
| 116 |
|
|
| 117 |
// reset cache |
|
| 118 |
rowscoords = null; |
|
| 119 |
colscoords = null; |
|
| 120 |
eigenvalues = null; |
|
| 121 |
singularValues = null; |
|
| 122 |
rowmass = null; |
|
| 123 |
rowdist = null; |
|
| 124 |
rowinertia = null; |
|
| 125 |
colmass = null; |
|
| 126 |
coldist = null; |
|
| 127 |
colinertia = null; |
|
| 128 |
rowcos2 = null; |
|
| 129 |
rowcontrib = null; |
|
| 130 |
colcos2 = null; |
|
| 131 |
colcontrib = null; |
|
| 132 |
|
|
| 114 | 133 |
if (!rw.containsVariable(table.getSymbol())) {
|
| 115 | 134 |
throw new StatException(CACoreMessages.error_lexicalTableNotFoundInWorkspace); |
| 116 | 135 |
} |
| 117 | 136 |
try {
|
| 118 |
//rw.callFunctionAndAffect("FactoMineR:CA", new String[] { table.getSymbol() }, symbol); //$NON-NLS-1$
|
|
| 119 |
rw.eval(symbol+" <- FactoMineR::CA("+table.getSymbol()+", graph=FALSE)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 120 |
} catch (RWorkspaceException e) {
|
|
| 137 |
// rw.callFunctionAndAffect("FactoMineR:CA", new String[] { table.getSymbol() }, symbol); //$NON-NLS-1$
|
|
| 138 |
// rw.eval(symbol+" <- FactoMineR::CA("+table.getSymbol()+", graph=FALSE)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 139 |
rw.eval(symbol + " <- FactoMineR::CA(" + table.getSymbol() + "[,colSums(" + table.getSymbol() + ") != 0], graph=FALSE)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 140 |
|
|
| 141 |
} |
|
| 142 |
catch (RWorkspaceException e) {
|
|
| 121 | 143 |
throw new StatException(NLS.bind(CACoreMessages.error_errorWhileComputingCAP0, e.getMessage()), e); |
| 122 | 144 |
} |
| 123 | 145 |
} |
| 124 |
|
|
| 125 |
/* (non-Javadoc) |
|
| 146 |
|
|
| 147 |
/* |
|
| 148 |
* (non-Javadoc) |
|
| 126 | 149 |
* @see org.txm.stat.engine.r.function.ICA#getColContrib() |
| 127 | 150 |
*/ |
| 128 | 151 |
@Override |
| ... | ... | |
| 132 | 155 |
REXP sv = rw.extractItemFromListByName(symbol, "col$contrib"); //$NON-NLS-1$ |
| 133 | 156 |
colcontrib = sv.asDoubleMatrix(); |
| 134 | 157 |
// Arrays.sort(rowdist); |
| 135 |
} catch (RWorkspaceException e) {
|
|
| 158 |
} |
|
| 159 |
catch (RWorkspaceException e) {
|
|
| 136 | 160 |
throw new StatException(NLS.bind(CACoreMessages.error_failedToGetContributionColumnP0, e.getMessage()), e); |
| 137 |
} catch (Exception e) {
|
|
| 138 |
// TODO Auto-generated catch block
|
|
| 161 |
} |
|
| 162 |
catch (Exception e) {
|
|
| 139 | 163 |
org.txm.utils.logger.Log.printStackTrace(e); |
| 140 | 164 |
} |
| 141 | 165 |
} |
| 142 | 166 |
return colcontrib; |
| 143 | 167 |
} |
| 144 |
|
|
| 145 |
/* (non-Javadoc) |
|
| 168 |
|
|
| 169 |
/* |
|
| 170 |
* (non-Javadoc) |
|
| 146 | 171 |
* @see org.txm.stat.engine.r.function.ICA#getColCos2() |
| 147 | 172 |
*/ |
| 148 | 173 |
@Override |
| ... | ... | |
| 152 | 177 |
REXP sv = rw.extractItemFromListByName(symbol, "col$cos2"); //$NON-NLS-1$ |
| 153 | 178 |
colcos2 = sv.asDoubleMatrix(); |
| 154 | 179 |
// Arrays.sort(rowdist); |
| 155 |
} catch (RWorkspaceException e) {
|
|
| 180 |
} |
|
| 181 |
catch (RWorkspaceException e) {
|
|
| 156 | 182 |
throw new StatException(NLS.bind(CACoreMessages.error_failedToGetCos2ColumnP0, e.getMessage()), e); |
| 157 |
} catch (Exception e) {
|
|
| 158 |
// TODO Auto-generated catch block
|
|
| 183 |
} |
|
| 184 |
catch (Exception e) {
|
|
| 159 | 185 |
org.txm.utils.logger.Log.printStackTrace(e); |
| 160 | 186 |
} |
| 161 | 187 |
} |
| 162 | 188 |
return colcos2; |
| 163 | 189 |
} |
| 164 |
|
|
| 190 |
|
|
| 165 | 191 |
/** |
| 166 | 192 |
* Get the rows mass. |
| 167 | 193 |
* |
| ... | ... | |
| 170 | 196 |
*/ |
| 171 | 197 |
@Override |
| 172 | 198 |
public double[] getColDist() throws StatException {
|
| 173 |
if (coldist == null) |
|
| 174 |
{
|
|
| 199 |
if (coldist == null) {
|
|
| 175 | 200 |
double[][] colcoords = getColsCoords(); |
| 176 | 201 |
coldist = new double[colcoords.length]; |
| 177 |
for (int i = 0; i < colcoords.length; i++) |
|
| 178 |
for (int c = 0; c < colcoords[i].length; c++) |
|
| 202 |
for (int i = 0; i < colcoords.length; i++) {
|
|
| 203 |
for (int c = 0; c < colcoords[i].length; c++) {
|
|
| 179 | 204 |
coldist[i] += Math.pow(colcoords[i][c], 2); |
| 205 |
} |
|
| 206 |
} |
|
| 180 | 207 |
} |
| 181 | 208 |
return coldist; |
| 182 | 209 |
} |
| 183 |
|
|
| 184 |
/* (non-Javadoc) |
|
| 210 |
|
|
| 211 |
/* |
|
| 212 |
* (non-Javadoc) |
|
| 185 | 213 |
* @see org.txm.stat.engine.r.function.ICA#getColsCoords() |
| 186 | 214 |
*/ |
| 187 | 215 |
@Override |
| ... | ... | |
| 190 | 218 |
try {
|
| 191 | 219 |
REXP exp = rw.extractItemFromListByName(symbol, "col$coord"); //$NON-NLS-1$ |
| 192 | 220 |
colscoords = exp.asDoubleMatrix(); |
| 193 |
|
|
| 194 |
//System.out.println("Avant:");
|
|
| 195 |
// for (int i = 0; i < colscoords.length; i++) |
|
| 196 |
// {
|
|
| 197 |
// for (int c = 0; c < colscoords[i].length; c++) |
|
| 198 |
// {
|
|
| 199 |
// System.out.println(" "+colscoords[i][c]);
|
|
| 200 |
// } |
|
| 201 |
// System.out.println(); |
|
| 202 |
// } |
|
| 203 | 221 |
|
| 222 |
// System.out.println("Avant:");
|
|
| 223 |
// for (int i = 0; i < colscoords.length; i++) |
|
| 224 |
// {
|
|
| 225 |
// for (int c = 0; c < colscoords[i].length; c++) |
|
| 226 |
// {
|
|
| 227 |
// System.out.println(" "+colscoords[i][c]);
|
|
| 228 |
// } |
|
| 229 |
// System.out.println(); |
|
| 230 |
// } |
|
| 231 |
|
|
| 204 | 232 |
// multiply coords by sv |
| 205 |
// this.getSingularValues();
|
|
| 206 |
// for (int i = 0; i < colscoords.length; i++)
|
|
| 207 |
// for (int c = 0; c < colscoords[i].length; c++)
|
|
| 208 |
// colscoords[i][c] = colscoords[i][c] * singularValues[c];
|
|
| 209 |
//
|
|
| 210 |
// System.out.println("Apres:");
|
|
| 211 |
// for (int i = 0; i < colscoords.length; i++)
|
|
| 212 |
// {
|
|
| 213 |
// for (int c = 0; c < colscoords[i].length; c++)
|
|
| 214 |
// {
|
|
| 215 |
// System.out.println(" "+colscoords[i][c]);
|
|
| 216 |
// }
|
|
| 217 |
// System.out.println();
|
|
| 218 |
// }
|
|
| 219 |
|
|
| 220 |
} catch (Exception e) {
|
|
| 221 |
// TODO Auto-generated catch block
|
|
| 233 |
// this.getSingularValues();
|
|
| 234 |
// for (int i = 0; i < colscoords.length; i++)
|
|
| 235 |
// for (int c = 0; c < colscoords[i].length; c++)
|
|
| 236 |
// colscoords[i][c] = colscoords[i][c] * singularValues[c];
|
|
| 237 |
//
|
|
| 238 |
// System.out.println("Apres:");
|
|
| 239 |
// for (int i = 0; i < colscoords.length; i++)
|
|
| 240 |
// {
|
|
| 241 |
// for (int c = 0; c < colscoords[i].length; c++)
|
|
| 242 |
// {
|
|
| 243 |
// System.out.println(" "+colscoords[i][c]);
|
|
| 244 |
// }
|
|
| 245 |
// System.out.println();
|
|
| 246 |
// }
|
|
| 247 |
|
|
| 248 |
} |
|
| 249 |
catch (Exception e) {
|
|
| 222 | 250 |
org.txm.utils.logger.Log.printStackTrace(e); |
| 223 | 251 |
} |
| 224 | 252 |
} |
| 225 | 253 |
return colscoords; |
| 226 | 254 |
} |
| 227 |
|
|
| 255 |
|
|
| 228 | 256 |
/** |
| 229 | 257 |
* Get the rows mass. |
| 230 | 258 |
* |
| ... | ... | |
| 238 | 266 |
REXP sv = rw.extractItemFromListByName(symbol, "col$contrib"); //$NON-NLS-1$ |
| 239 | 267 |
colinertia = RWorkspace.toDouble(sv); |
| 240 | 268 |
// Arrays.sort(colinertia); |
| 241 |
} catch (RWorkspaceException e) {
|
|
| 269 |
} |
|
| 270 |
catch (RWorkspaceException e) {
|
|
| 242 | 271 |
throw new StatException(CACoreMessages.bind(CACoreMessages.error_unableToExtractSingularValuesP0, e.getMessage()), e); |
| 243 | 272 |
} |
| 244 | 273 |
} |
| 245 | 274 |
return colinertia; |
| 246 | 275 |
} |
| 247 |
|
|
| 276 |
|
|
| 248 | 277 |
/** |
| 249 | 278 |
* Get the rows mass. |
| 250 | 279 |
* |
| ... | ... | |
| 258 | 287 |
REXP sv = rw.extractItemFromListByName(symbol, "call$marge.col"); //$NON-NLS-1$ |
| 259 | 288 |
colmass = RWorkspace.toDouble(sv); |
| 260 | 289 |
// Arrays.sort(colmass); |
| 261 |
} catch (RWorkspaceException e) {
|
|
| 290 |
} |
|
| 291 |
catch (RWorkspaceException e) {
|
|
| 262 | 292 |
throw new StatException(CACoreMessages.bind(CACoreMessages.error_unableToExtractSingularValuesP0, e.getMessage()), e); |
| 263 | 293 |
} |
| 264 | 294 |
} |
| 265 | 295 |
return colmass; |
| 266 | 296 |
} |
| 267 |
|
|
| 268 |
/* (non-Javadoc) |
|
| 297 |
|
|
| 298 |
/* |
|
| 299 |
* (non-Javadoc) |
|
| 269 | 300 |
* @see org.txm.stat.engine.r.function.ICA#getRowContrib() |
| 270 | 301 |
*/ |
| 271 | 302 |
@Override |
| 272 | 303 |
public double[][] getRowContrib() throws StatException {
|
| 273 |
//System.out.println("FACTO: getRowContrib");
|
|
| 304 |
// System.out.println("FACTO: getRowContrib");
|
|
| 274 | 305 |
if (rowcontrib == null) {
|
| 275 | 306 |
try {
|
| 276 | 307 |
REXP sv = rw.extractItemFromListByName(symbol, "row$contrib"); //$NON-NLS-1$ |
| 277 | 308 |
rowcontrib = sv.asDoubleMatrix(); |
| 278 |
for (int i = 0 ; i < rowcontrib.length ; i++)
|
|
| 279 |
for (int j = 0 ; j < rowcontrib[i].length ; j++)
|
|
| 280 |
rowcontrib[i][j] = rowcontrib[i][j] / 100.0;
|
|
| 309 |
for (int i = 0; i < rowcontrib.length; i++)
|
|
| 310 |
for (int j = 0; j < rowcontrib[i].length; j++)
|
|
| 311 |
rowcontrib[i][j] = rowcontrib[i][j] / 100.0; |
|
| 281 | 312 |
// Arrays.sort(rowdist); |
| 282 |
} catch (RWorkspaceException e) {
|
|
| 313 |
} |
|
| 314 |
catch (RWorkspaceException e) {
|
|
| 283 | 315 |
throw new StatException(NLS.bind(CACoreMessages.error_failedToGetConstributionRowP0, e.getMessage()), e); |
| 284 |
} catch (Exception e) {
|
|
| 285 |
// TODO Auto-generated catch block
|
|
| 316 |
} |
|
| 317 |
catch (Exception e) {
|
|
| 286 | 318 |
org.txm.utils.logger.Log.printStackTrace(e); |
| 287 | 319 |
} |
| 288 | 320 |
} |
| 289 | 321 |
return rowcontrib; |
| 290 | 322 |
} |
| 291 |
|
|
| 292 |
/* (non-Javadoc) |
|
| 323 |
|
|
| 324 |
/* |
|
| 325 |
* (non-Javadoc) |
|
| 293 | 326 |
* @see org.txm.stat.engine.r.function.ICA#getRowCos2() |
| 294 | 327 |
*/ |
| 295 | 328 |
@Override |
| ... | ... | |
| 299 | 332 |
REXP sv = rw.extractItemFromListByName(symbol, "row$cos2"); //$NON-NLS-1$ |
| 300 | 333 |
rowcos2 = sv.asDoubleMatrix(); |
| 301 | 334 |
// Arrays.sort(rowdist); |
| 302 |
} catch (RWorkspaceException e) {
|
|
| 335 |
} |
|
| 336 |
catch (RWorkspaceException e) {
|
|
| 303 | 337 |
throw new StatException(NLS.bind(CACoreMessages.error_failedToGetCos2RowP0, e.getMessage()), e); |
| 304 |
} catch (Exception e) {
|
|
| 305 |
// TODO Auto-generated catch block
|
|
| 338 |
} |
|
| 339 |
catch (Exception e) {
|
|
| 306 | 340 |
org.txm.utils.logger.Log.printStackTrace(e); |
| 307 | 341 |
} |
| 308 | 342 |
} |
| 309 | 343 |
return rowcos2; |
| 310 | 344 |
} |
| 311 |
|
|
| 345 |
|
|
| 312 | 346 |
/** |
| 313 | 347 |
* Get the rows mass. |
| 314 | 348 |
* |
| ... | ... | |
| 317 | 351 |
*/ |
| 318 | 352 |
@Override |
| 319 | 353 |
public double[] getRowDist() throws StatException {
|
| 320 |
if (rowdist == null) |
|
| 321 |
{
|
|
| 354 |
if (rowdist == null) {
|
|
| 322 | 355 |
double[][] rowcoords = getRowsCoords(); |
| 323 | 356 |
rowdist = new double[rowcoords.length]; |
| 324 |
for (int i = 0; i < rowcoords.length; i++) |
|
| 325 |
for (int c = 0; c < rowcoords[i].length; c++) |
|
| 357 |
for (int i = 0; i < rowcoords.length; i++) {
|
|
| 358 |
for (int c = 0; c < rowcoords[i].length; c++) {
|
|
| 326 | 359 |
rowdist[i] += Math.pow(rowcoords[i][c], 2); |
| 360 |
} |
|
| 361 |
} |
|
| 327 | 362 |
} |
| 328 | 363 |
return rowdist; |
| 329 | 364 |
} |
| 330 |
|
|
| 331 |
/* (non-Javadoc) |
|
| 365 |
|
|
| 366 |
/* |
|
| 367 |
* (non-Javadoc) |
|
| 332 | 368 |
* @see org.txm.stat.engine.r.function.ICA#getRowsCoords() |
| 333 | 369 |
*/ |
| 334 | 370 |
@Override |
| ... | ... | |
| 338 | 374 |
REXP sv = rw.extractItemFromListByName(symbol, "row$coord"); //$NON-NLS-1$ |
| 339 | 375 |
rowscoords = sv.asDoubleMatrix(); |
| 340 | 376 |
|
| 341 |
// this.getSingularValues();
|
|
| 342 |
// //System.out.println("Apres:");
|
|
| 343 |
// for (int i = 0; i < rowscoords.length; i++)
|
|
| 344 |
// {
|
|
| 345 |
// for (int c = 0; c < rowscoords[i].length; c++)
|
|
| 346 |
// {
|
|
| 347 |
// rowscoords[i][c] = rowscoords[i][c] * singularValues[c];
|
|
| 348 |
// // System.out.println(" "+rowscoords[i][c]);
|
|
| 349 |
// }
|
|
| 350 |
// //System.out.println();
|
|
| 351 |
// }
|
|
| 352 |
|
|
| 353 |
} catch (Exception e) {
|
|
| 354 |
// TODO Auto-generated catch block
|
|
| 377 |
// this.getSingularValues();
|
|
| 378 |
// //System.out.println("Apres:");
|
|
| 379 |
// for (int i = 0; i < rowscoords.length; i++)
|
|
| 380 |
// {
|
|
| 381 |
// for (int c = 0; c < rowscoords[i].length; c++)
|
|
| 382 |
// {
|
|
| 383 |
// rowscoords[i][c] = rowscoords[i][c] * singularValues[c];
|
|
| 384 |
// // System.out.println(" "+rowscoords[i][c]);
|
|
| 385 |
// }
|
|
| 386 |
// //System.out.println();
|
|
| 387 |
// }
|
|
| 388 |
|
|
| 389 |
} |
|
| 390 |
catch (Exception e) {
|
|
| 355 | 391 |
org.txm.utils.logger.Log.printStackTrace(e); |
| 356 | 392 |
} |
| 357 | 393 |
} |
| 358 | 394 |
return rowscoords; |
| 359 | 395 |
} |
| 360 |
|
|
| 396 |
|
|
| 361 | 397 |
/** |
| 362 | 398 |
* Get the rows mass. |
| 363 | 399 |
* |
| ... | ... | |
| 371 | 407 |
REXP sv = rw.extractItemFromListByName(symbol, "row$contrib"); //$NON-NLS-1$ |
| 372 | 408 |
rowinertia = RWorkspace.toDouble(sv); |
| 373 | 409 |
// Arrays.sort(rowinertia); |
| 374 |
} catch (RWorkspaceException e) {
|
|
| 410 |
} |
|
| 411 |
catch (RWorkspaceException e) {
|
|
| 375 | 412 |
throw new StatException(CACoreMessages.bind(CACoreMessages.error_unableToExtractSingularValuesP0, e.getMessage()), e); |
| 376 | 413 |
} |
| 377 | 414 |
} |
| 378 | 415 |
return rowinertia; |
| 379 | 416 |
} |
| 380 |
|
|
| 417 |
|
|
| 381 | 418 |
/** |
| 382 | 419 |
* Get the rows mass. |
| 383 | 420 |
* |
| ... | ... | |
| 391 | 428 |
REXP sv = rw.extractItemFromListByName(symbol, "call$marge.row"); //$NON-NLS-1$ |
| 392 | 429 |
rowmass = RWorkspace.toDouble(sv); |
| 393 | 430 |
// Arrays.sort(rowmass); |
| 394 |
} catch (RWorkspaceException e) {
|
|
| 431 |
} |
|
| 432 |
catch (RWorkspaceException e) {
|
|
| 395 | 433 |
throw new StatException(CACoreMessages.bind(CACoreMessages.error_unableToExtractSingularValuesP0, e.getMessage()), e); |
| 396 | 434 |
} |
| 397 | 435 |
} |
| 398 | 436 |
return rowmass; |
| 399 | 437 |
} |
| 400 |
|
|
| 438 |
|
|
| 401 | 439 |
/** |
| 402 | 440 |
* Get the singular values. |
| 403 | 441 |
* |
| 404 | 442 |
* @return the singular values |
| 405 | 443 |
* @throws StatException the stat exception |
| 444 |
* @throws REXPMismatchException |
|
| 406 | 445 |
*/ |
| 407 | 446 |
@Override |
| 408 |
public double[] getSingularValues() throws StatException {
|
|
| 447 |
public double[] getSingularValues() throws StatException, REXPMismatchException {
|
|
| 409 | 448 |
if (singularValues == null) {
|
| 410 | 449 |
getEigenvalues(); |
| 411 | 450 |
singularValues = new double[eigenvalues.length]; |
| 412 |
for(int i = 0 ; i < eigenvalues.length ; i++)
|
|
| 451 |
for (int i = 0; i < eigenvalues.length; i++) {
|
|
| 413 | 452 |
singularValues[i] = Math.pow(eigenvalues[i], 0.5); |
| 453 |
} |
|
| 414 | 454 |
} |
| 415 | 455 |
return singularValues; |
| 416 | 456 |
} |
| 417 |
|
|
| 418 |
/* (non-Javadoc) |
|
| 457 |
|
|
| 458 |
/* |
|
| 459 |
* (non-Javadoc) |
|
| 419 | 460 |
* @see org.txm.stat.engine.r.function.ICA#getSymbol() |
| 420 | 461 |
*/ |
| 421 | 462 |
@Override |
| 422 | 463 |
public String getSymbol() {
|
| 423 | 464 |
return symbol; |
| 424 | 465 |
} |
| 425 |
|
|
| 466 |
|
|
| 426 | 467 |
/** |
| 427 | 468 |
* Gets the valeurs propres. |
| 428 | 469 |
* |
| 429 | 470 |
* @return the singular values pow 2 |
| 471 |
* @throws RWorkspaceException |
|
| 430 | 472 |
* @throws StatException the stat exception |
| 473 |
* @throws REXPMismatchException |
|
| 431 | 474 |
*/ |
| 432 | 475 |
@Override |
| 433 |
public double[] getEigenvalues() throws StatException {
|
|
| 476 |
public double[] getEigenvalues() throws RWorkspaceException, REXPMismatchException {
|
|
| 434 | 477 |
if (eigenvalues == null) {
|
| 435 |
try {
|
|
| 436 |
REXP sv = rw.eval(symbol+"$eig$eigenvalue"); //$NON-NLS-1$ |
|
| 437 |
eigenvalues = RWorkspace.toDouble(sv); |
|
| 438 |
// remove last singular value |
|
| 439 |
if (eigenvalues.length == table.getNColumns()) |
|
| 440 |
eigenvalues = Arrays.copyOfRange(eigenvalues, 0, eigenvalues.length -1); |
|
| 441 |
// Arrays.sort(singularValues); |
|
| 442 |
} catch (RWorkspaceException e) {
|
|
| 443 |
throw new StatException(CACoreMessages.bind(CACoreMessages.error_unableToExtractSingularValuesP0, e.getMessage()), e); |
|
| 478 |
// try {
|
|
| 479 |
REXP sv = rw.eval(symbol + "$eig$eigenvalue"); //$NON-NLS-1$ |
|
| 480 |
eigenvalues = RWorkspace.toDouble(sv); |
|
| 481 |
// remove last singular value |
|
| 482 |
if (eigenvalues.length == this.getColumnsCount()) {
|
|
| 483 |
eigenvalues = Arrays.copyOfRange(eigenvalues, 0, eigenvalues.length - 1); |
|
| 444 | 484 |
} |
| 485 |
// Arrays.sort(singularValues); |
|
| 486 |
// } |
|
| 487 |
// catch (Exception|StatException e) {
|
|
| 488 |
// throw new StatException(CACoreMessages.bind(CACoreMessages.error_unableToExtractSingularValuesP0, e.getMessage()), e); |
|
| 489 |
// } |
|
| 445 | 490 |
} |
| 446 | 491 |
return eigenvalues; |
| 447 | 492 |
|
| ... | ... | |
| 455 | 500 |
*/ |
| 456 | 501 |
@Override |
| 457 | 502 |
public String getEigenvaluesRSymbol() throws StatException {
|
| 458 |
return symbol+"$eig$eigenvalue";
|
|
| 503 |
return symbol + "$eig$eigenvalue";
|
|
| 459 | 504 |
} |
| 460 |
|
|
| 461 |
/* (non-Javadoc) |
|
| 505 |
|
|
| 506 |
/* |
|
| 507 |
* (non-Javadoc) |
|
| 462 | 508 |
* @see org.txm.stat.engine.r.function.ICA#loadLibrary() |
| 463 | 509 |
*/ |
| 464 | 510 |
@Override |
| 465 |
public boolean loadLibrary(){
|
|
| 511 |
public boolean loadLibrary() {
|
|
| 466 | 512 |
try {
|
| 467 | 513 |
rw.voidEval("library(FactoMineR)"); //$NON-NLS-1$
|
| 468 |
} catch (RWorkspaceException e) {
|
|
| 514 |
} |
|
| 515 |
catch (RWorkspaceException e) {
|
|
| 469 | 516 |
System.out.println(NLS.bind(CACoreMessages.error_canNotLoadCALibraryP0, e)); |
| 470 | 517 |
return false; |
| 471 | 518 |
} |
| 472 | 519 |
return true; |
| 473 | 520 |
} |
| 474 |
|
|
| 521 |
|
|
| 475 | 522 |
/** |
| 476 | 523 |
* Draw in the given file a plot of the factorial map. |
| 477 | 524 |
* |
| ... | ... | |
| 485 | 532 |
public boolean toTxt(File file, String encoding, String colseparator, String txtseparator) {
|
| 486 | 533 |
try {
|
| 487 | 534 |
RWorkspace rw = RWorkspace.getRWorkspaceInstance(); |
| 488 |
rw.eval("sink(file=\"" + file.getAbsolutePath().replace("\\", "\\\\")+"\")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
|
| 489 |
rw.eval("print("+symbol+")"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 535 |
rw.eval("sink(file=\"" + file.getAbsolutePath().replace("\\", "\\\\") + "\")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
|
| 536 |
rw.eval("print(" + symbol + ")"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 490 | 537 |
|
| 491 |
rw.eval("print("+symbol+"$eig)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 538 |
rw.eval("print(" + symbol + "$eig)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 492 | 539 |
|
| 493 |
rw.eval("print("+symbol+"$col)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 540 |
rw.eval("print(" + symbol + "$col)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 494 | 541 |
|
| 495 |
rw.eval("print("+symbol+"$col$coord)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 542 |
rw.eval("print(" + symbol + "$col$coord)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 496 | 543 |
|
| 497 |
rw.eval("print("+symbol+"$col$cos2)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 544 |
rw.eval("print(" + symbol + "$col$cos2)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 498 | 545 |
|
| 499 |
rw.eval("print("+symbol+"$col$contrib)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 546 |
rw.eval("print(" + symbol + "$col$contrib)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 500 | 547 |
|
| 501 |
rw.eval("print("+symbol+"$row)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 548 |
rw.eval("print(" + symbol + "$row)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 502 | 549 |
|
| 503 |
rw.eval("print("+symbol+"$row$coord)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 550 |
rw.eval("print(" + symbol + "$row$coord)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 504 | 551 |
|
| 505 |
rw.eval("print("+symbol+"$row$cos2)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 552 |
rw.eval("print(" + symbol + "$row$cos2)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 506 | 553 |
|
| 507 |
rw.eval("print("+symbol+"$row$contrib)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 508 |
// rw.eval("print("+symbol+"$call)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 509 |
// rw.eval("print("+symbol+"$call$marge.col)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 510 |
// rw.eval("print("+symbol+"$call$marge.row)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 554 |
rw.eval("print(" + symbol + "$row$contrib)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 555 |
// rw.eval("print("+symbol+"$call)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 556 |
// rw.eval("print("+symbol+"$call$marge.col)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 557 |
// rw.eval("print("+symbol+"$call$marge.row)"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 511 | 558 |
rw.eval("sink()"); //$NON-NLS-1$
|
| 512 |
} catch (StatException e) {
|
|
| 559 |
} |
|
| 560 |
catch (StatException e) {
|
|
| 513 | 561 |
org.txm.utils.logger.Log.printStackTrace(e); |
| 514 | 562 |
return false; |
| 515 | 563 |
} |
| 516 | 564 |
return true; |
| 517 | 565 |
} |
| 518 | 566 |
|
| 567 |
@Override |
|
| 568 |
public int getRowsCount() throws RWorkspaceException, REXPMismatchException {
|
|
| 569 |
return rw.eval("length(" + this.symbol + "$call$marge.row)").asInteger();
|
|
| 570 |
} |
|
| 519 | 571 |
|
| 520 | 572 |
@Override |
| 521 |
public int getRowsCount() {
|
|
| 522 |
return this.table.getRowsCount();
|
|
| 573 |
public int getColumnsCount() throws RWorkspaceException, REXPMismatchException {
|
|
| 574 |
return rw.eval("length(" + this.symbol + "$call$marge.col)").asInteger();
|
|
| 523 | 575 |
} |
| 524 |
|
|
| 576 |
|
|
| 525 | 577 |
@Override |
Formats disponibles : Unified diff