Revision 683

tmp/org.txm.ahc.core/.project (revision 683)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.txm.ahc.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.ahc.core/src/org/txm/ahc/core/messages/messages_ru.properties (revision 683)
1

  
2
RESULT_TYPE = Классификация
0 3

  
tmp/org.txm.ahc.core/src/org/txm/ahc/core/messages/messages_fr.properties (revision 683)
1

  
2
ERROR_EXPORT_TXT = Erreur durant l'export du résultat CAH : 
3

  
4
LOG_COMPUTE_CAH = Calcul de la CAH
5

  
6
RESULT_TYPE = Classification
0 7

  
tmp/org.txm.ahc.core/src/org/txm/ahc/core/messages/AHCCoreMessages.java (revision 683)
1
package org.txm.ahc.core.messages;
2

  
3
import org.txm.utils.messages.Utf8NLS;
4

  
5
public class AHCCoreMessages extends Utf8NLS {
6
	
7
	static {
8
		Utf8NLS.initializeMessages(AHCCoreMessages.class);
9
	}
10
	
11
	public static String RESULT_TYPE;
12
	
13
	public static String ERROR_EXPORT_TXT;
14
	public static String LOG_COMPUTE_CAH;
15
}
0 16

  
tmp/org.txm.ahc.core/src/org/txm/ahc/core/messages/messages.properties (revision 683)
1

  
2
ERROR_EXPORT_TXT = Error while exporting CAH result: 
3

  
4
LOG_COMPUTE_CAH = Computing CAH
5

  
6
RESULT_TYPE = Classification
0 7

  
tmp/org.txm.ahc.core/src/org/txm/ahc/core/functions/AHC.java (revision 683)
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.ahc.core.functions;
29

  
30
import java.io.File;
31
import java.util.Arrays;
32

  
33
import org.rosuda.REngine.REXP;
34
import org.txm.ca.core.functions.CA;
35
import org.txm.ahc.core.messages.AHCCoreMessages;
36
import org.txm.ahc.core.preferences.AHCPreferences;
37
import org.txm.chartsengine.core.results.ChartResult;
38
import org.txm.core.preferences.TXMPreferences;
39
import org.txm.core.results.Parameter;
40
import org.txm.core.results.TXMParameters;
41
import org.txm.lexicaltable.core.functions.LexicalTable;
42
import org.txm.statsengine.r.core.RWorkspace;
43
import org.txm.statsengine.r.core.exceptions.RWorkspaceException;
44
import org.txm.utils.logger.Log;
45

  
46
/**
47
 * Agglomerative Hierarchical Clustering.
48
 * 
49
 * @author mdecorde
50
 * @author sjacquot
51
 *
52
 */
53
public class AHC extends ChartResult	{
54

  
55
	/**
56
	 * The R name prefix.
57
	 */
58
	protected static String prefixR = "FactoMineRAHC"; //$NON-NLS-1$
59

  
60
	/**
61
	 * Counter used in name suffix.
62
	 */
63
	protected static int ahcCounter = 1;
64
	
65

  
66
	/** The symbol. */
67
	String symbol = null;
68

  
69
	/** The CA symbol target. */
70
	String target;
71

  
72
	
73
	/**
74
	 * The coordinates of the clusters.
75
	 */
76
	protected double[][] clusterCoords = null;
77

  
78
	/**
79
	 * The numbers of the clusters.
80
	 */
81
	protected int[] clusterNumbers = null;
82

  
83
	/**
84
	 * The names of the cluster rows.
85
	 */
86
	protected String[] clusterRowNames = null;
87

  
88
	/**
89
	 * The ordered names of the cluster rows.
90
	 */
91
	protected String[] clusterOrderedRowNames = null;
92

  
93
	/**
94
	 * The cluster tree heights.
95
	 */
96
	protected double[] clusterHeights = null;
97

  
98
	/**
99
	 * The cluster tree merges.
100
	 */
101
	protected double[][] clusterMerges = null;
102

  
103
	/**
104
	 * The inertia gains.
105
	 */
106
	protected double[] inertiaGains = null;
107

  
108
	protected CA ca;
109
	protected LexicalTable table;
110

  
111
	
112
	
113
	
114
	
115
	
116
	/**
117
	 * The metric (euclidean, manhattan).
118
	 */
119
	@Parameter(key=AHCPreferences.METRIC)
120
	protected String metric;
121

  
122
	/**
123
	 * The method (METHODS <- c("average", "single", "complete", "ward", "weighted", "flexible")).
124
	 */
125
	@Parameter(key=AHCPreferences.METHOD)
126
	protected String method;
127

  
128
	/**
129
	 * The number of clusters.
130
	 */
131
	@Parameter(key=AHCPreferences.N_CLUSTERS)
132
	protected int numberOfClusters;
133

  
134
	/**
135
	 * To compute the columns or the rows.
136
	 */
137
	@Parameter(key=AHCPreferences.COLUMNS_COMPUTING)
138
	protected boolean columnsComputing;
139
	
140
	/**
141
	 * To display in 2D or 3D.
142
	 */
143
	@Parameter(key=AHCPreferences.RENDERING_2D)
144
	protected boolean rendering2D;
145
	
146
	
147
	
148
	/**
149
	 * Instantiates a new AHC.
150
	 *
151
	 * @param ca the ca
152
	 * @param col the col
153
	 * @param method the method
154
	 * @param metric the metric
155
	 * @param numberOfClusters the n cluster
156
	 * @param display2D the display mode
157
	 */
158
	public AHC(CA ca)	{
159
		super(ca);
160
		this.ca = ca;
161
	}
162

  
163
	@Override
164
	protected boolean _compute()	{
165

  
166
		
167
		Log.info("Computing CAH...");
168
		try {
169
			this.table = this.ca.getLexicalTable();
170
			this.target = this.ca.getSymbol();
171

  
172
			// reset the number of clusters to default
173
			if(this.hasParameterChanged(AHCPreferences.COLUMNS_COMPUTING))	{
174
				this.numberOfClusters = TXMPreferences.getInt(AHCPreferences.N_CLUSTERS, AHCPreferences.PREFERENCES_NODE);
175
			}
176

  
177
			
178
			String colOrLine = "columns"; //$NON-NLS-1$
179
			if (!this.columnsComputing)
180
				colOrLine ="rows"; //$NON-NLS-1$
181

  
182
			if (this.symbol == null)	{
183
				this.symbol = prefixR + (ahcCounter++);
184
			}
185

  
186
			RWorkspace rw = RWorkspace.getRWorkspaceInstance();
187
			rw.eval("library(FactoMineR)"); //$NON-NLS-1$
188
			rw.eval(this.symbol +" <- HCPC(" + this.target + //$NON-NLS-1$
189
					", cluster.CA=\"" + colOrLine + "\"" + //$NON-NLS-1$ //$NON-NLS-2$
190
					", nb.clust=" + this.numberOfClusters + //$NON-NLS-1$
191
					", metric=\"" + this.metric + "\"" + //$NON-NLS-1$ //$NON-NLS-2$
192
					", method=\"" + this.method + "\"" + //$NON-NLS-1$ //$NON-NLS-2$
193
					", graph=FALSE)"); //$NON-NLS-1$
194
			
195
		} catch(Exception e) {
196
			Log.printStackTrace(e);
197
			return false;
198
		}
199

  
200
		// Reset the cached data
201
		this.resetCache();
202
		this.dirty = false;
203
		return true;
204
	}
205
	
206
	
207
	
208
	public void setParameters(Boolean columns, String metric, Integer nCluster, String method) {
209
		if (columns != null) this.columnsComputing = columns;
210
		if (metric != null) this.metric = metric;
211
		if (nCluster != null) this.numberOfClusters = nCluster;
212
		if (method != null) this.method = method;
213
		dirty = true;
214
	}
215

  
216

  
217
	@Override
218
	public boolean loadParameters() {
219
		// nothing to do
220
		return true;
221
	}
222

  
223
	@Override
224
	public boolean saveParameters() {
225
		// nothing to do
226
		return true;
227
	}
228

  
229
	
230
	
231
	@Override
232
	public boolean canCompute() {
233
		return this.ca != null 
234
				&& Arrays.binarySearch(AHC.getMethods(), this.method) >= 0 
235
				&& Arrays.binarySearch(AHC.getMetrics(), this.metric) >= 0
236
				&& this.numberOfClusters >= 2;
237
	}
238

  
239
	@Override
240
	public boolean setParameters(TXMParameters parameters) {
241
		// TODO Auto-generated method stub
242
		System.err.println("AHC.setParameters(): not yet implemented.");
243
		return true;
244
	}
245

  
246
	/**
247
	 * Resets the cached data so the next getter calls will request the values from R.
248
	 */
249
	public void resetCache() {
250
		this.clusterCoords = null;
251
		this.clusterNumbers = null;
252
		this.clusterRowNames = null;
253
		this.clusterOrderedRowNames = null;
254
		this.clusterHeights = null;
255
		this.clusterMerges = null;
256
	}
257

  
258
	/**
259
	 * Gets the symbol.
260
	 *
261
	 * @return the symbol
262
	 */
263
	public String getSymbol() {
264
		return symbol;
265
	}
266

  
267
	/**
268
	 * Gets the methods.
269
	 *
270
	 * @return the methods
271
	 */
272
	public static String[] getMethods() {
273
		String[] methods = {"average", "single", "complete", "ward", "weighted", "flexible"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
274
		return methods;
275
	}
276

  
277
	/**
278
	 * Gets the metrics.
279
	 *
280
	 * @return the metrics
281
	 */
282
	public static String[] getMetrics() {
283
		String[] metrics = {"euclidean", "manhattan"}; //$NON-NLS-1$ //$NON-NLS-2$
284
		return metrics;
285
	}
286

  
287
	/**
288
	 *
289
	 * @param outfile
290
	 * @param encoding
291
	 * @return
292
	 */
293
	//FIXME: extract to future exporter extension
294
	@Deprecated
295
	public boolean toTxt(File outfile, String encoding)	{
296
		boolean ret = true;
297
		acquireSemaphore();
298
		RWorkspace rw;
299
		try {
300
			rw = RWorkspace.getRWorkspaceInstance();
301
			rw.eval("sink(file=\"" + outfile.getAbsolutePath().replace("\\", "\\\\")+"\")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
302
			rw.eval("print("+symbol+"$call)"); //$NON-NLS-1$ //$NON-NLS-2$
303
			rw.eval("sink()"); //$NON-NLS-1$
304
		} catch (RWorkspaceException e) {
305
			// TODO Auto-generated catch block
306
			System.out.println(AHCCoreMessages.ERROR_EXPORT_TXT + e);
307
			org.txm.utils.logger.Log.printStackTrace(e);
308
			ret = false;
309
		} finally {
310
			releaseSemaphore();
311
		}
312
		return true;
313
	}
314

  
315
	//FIXME: extract to future exporter extension
316
	@Deprecated
317
	public boolean toTxt(File outfile, String encoding, String colsep, String txtsep) {
318
		return toTxt(outfile, encoding);
319
	}
320

  
321
	/**
322
	 * Gets the default method.
323
	 *
324
	 * @return the default method
325
	 */
326
	public static String getDefaultMethod() {
327
		return "ward"; //$NON-NLS-1$
328
	}
329

  
330
	/**
331
	 * Gets the default metric.
332
	 *
333
	 * @return the default metric
334
	 */
335
	public static String getDefaultMetric() {
336
		return "euclidean"; //$NON-NLS-1$
337
	}
338

  
339
	@Override
340
	public void clean() {
341
		// TODO Auto-generated method stub
342

  
343
	}
344

  
345
	/**
346
	 * Gets the clusters coordinates.
347
	 * @return the clusters coordinates
348
	 */
349
	public double[][] getClusterCoords() {
350
		if (this.clusterCoords == null) {
351
			try {
352

  
353
				// FIXME: check this code for the CAH 3D chart implementation
354
				RWorkspace rw = RWorkspace.getRWorkspaceInstance();
355
				for(int i = 0; i < 2; i++) { // 2 dimensions
356
					REXP sv = rw.extractItemFromListByName(symbol, "data.clust[,"+ (i + 1)+ "]"); //$NON-NLS-1$
357
					double[] coords = RWorkspace.toDouble(sv);
358
					for(int j = 0; j < coords.length; j++) {
359
						if(this.clusterCoords  == null)	{
360
							this.clusterCoords = new double[coords.length][2];
361
						}
362
						this.clusterCoords[j][i] = coords[j];
363
					}
364
				}
365
			}
366
			catch (Exception e) {
367
				// TODO Auto-generated catch block
368
				org.txm.utils.logger.Log.printStackTrace(e);
369
			}
370
		}
371
		return this.clusterCoords;
372
	}
373

  
374

  
375
	/**
376
	 * Gets the clusters numbers.
377
	 * @return
378
	 */
379
	public int[] getClusterNumbers() {
380
		if (this.clusterNumbers == null) {
381
			try {
382
				RWorkspace rw = RWorkspace.getRWorkspaceInstance();
383
				// FIXME: not sorted version
384
				REXP sv = rw.extractItemFromListByName(symbol, "data$clust"); //$NON-NLS-1$
385
				// FIXME: sorted version
386
				//REXP sv = rw.extractItemFromListByName(symbol, "data$clust[c(" + symbol + "$call$t$tree$order)]"); //$NON-NLS-1$
387
				this.clusterNumbers = sv.asIntegers();
388
			}
389
			catch (Exception e) {
390
				// TODO Auto-generated catch block
391
				org.txm.utils.logger.Log.printStackTrace(e);
392
			}
393
		}
394
		return this.clusterNumbers;
395
	}
396

  
397
	/**
398
	 * Gets the cluster row names.
399
	 * @return
400
	 */
401
	public String[] getClusterRowNames() {
402
		if (this.clusterRowNames == null) {
403
			try {
404
				RWorkspace rw = RWorkspace.getRWorkspaceInstance();
405

  
406
				// FIXME: old method, Save the row names in the R data frame
407
				//				rw.safeEval(symbol + "$rownames <- rownames(" + symbol + "$data)");
408
				//				REXP sv = rw.extractItemFromListByName(symbol, "rownames"); //$NON-NLS-1$
409

  
410

  
411
				REXP sv = rw.extractItemFromListByName(symbol, "call$t$tree$labels"); //$NON-NLS-1$
412

  
413

  
414
				this.clusterRowNames = sv.asStrings();
415

  
416
			}
417
			catch (Exception e) {
418
				// TODO Auto-generated catch block
419
				org.txm.utils.logger.Log.printStackTrace(e);
420
			}
421
		}
422
		return this.clusterRowNames;
423
	}
424

  
425

  
426

  
427
	/**
428
	 * Gets the cluster orderer row names.
429
	 * @return
430
	 */
431
	public String[] getClusterOrderedRowNames() {
432
		if (this.clusterOrderedRowNames == null) {
433
			try {
434
				RWorkspace rw = RWorkspace.getRWorkspaceInstance();
435
				REXP sv = rw.extractItemFromListByName(symbol, "call$t$tree$labels[c(" + symbol + "$call$t$tree$order)]"); //$NON-NLS-1$
436
				this.clusterOrderedRowNames = sv.asStrings();
437
			}
438
			catch (Exception e) {
439
				// TODO Auto-generated catch block
440
				org.txm.utils.logger.Log.printStackTrace(e);
441
			}
442
		}
443
		return this.clusterOrderedRowNames;
444
	}
445

  
446

  
447
	/**
448
	 * Gets the cluster tree heights.
449
	 * @return
450
	 */
451
	public double[] getClusterTreeHeights() {
452
		if (this.clusterHeights == null) {
453
			try {
454
				RWorkspace rw = RWorkspace.getRWorkspaceInstance();
455
				REXP sv = rw.extractItemFromListByName(symbol, "call$t$tree$height"); //$NON-NLS-1$
456
				this.clusterHeights = sv.asDoubles();
457
			}
458
			catch (Exception e) {
459
				// TODO Auto-generated catch block
460
				org.txm.utils.logger.Log.printStackTrace(e);
461
			}
462
		}
463
		return this.clusterHeights;
464
	}
465

  
466

  
467
	/**
468
	 * Gets the inertia gains.
469
	 * @return
470
	 */
471
	// FIXME: for test purpose, this method is not used for the chart computing
472
	public double[] getInertiaGains() {
473
		if (this.inertiaGains == null) {
474
			try {
475
				RWorkspace rw = RWorkspace.getRWorkspaceInstance();
476
				REXP sv = rw.extractItemFromListByName(symbol, "call$t$inert.gain"); //$NON-NLS-1$
477
				// FIXME: tests
478
				//			REXP sv = rw.extractItemFromListByName(symbol, "call$t$within"); //$NON-NLS-1$
479

  
480
				this.inertiaGains = sv.asDoubles();
481
			}
482
			catch (Exception e) {
483
				// TODO Auto-generated catch block
484
				org.txm.utils.logger.Log.printStackTrace(e);
485
			}
486
		}
487
		return this.inertiaGains;
488
	}
489

  
490

  
491
	/**
492
	 * Gets the cluster tree merges.
493
	 * @return
494
	 */
495
	public double[][] getClusterTreeMerges() {
496
		if (this.clusterMerges == null) {
497
			try {
498
				RWorkspace rw = RWorkspace.getRWorkspaceInstance();
499
				REXP sv = rw.extractItemFromListByName(symbol, "call$t$tree$merge"); //$NON-NLS-1$
500
				this.clusterMerges = sv.asDoubleMatrix();
501
			}
502
			catch (Exception e) {
503
				// TODO Auto-generated catch block
504
				org.txm.utils.logger.Log.printStackTrace(e);
505
			}
506
		}
507
		return this.clusterMerges;
508
	}
509

  
510

  
511

  
512

  
513

  
514

  
515
	/**
516
	 * Sets the metric to use for computing.
517
	 * @param metric the metric to set
518
	 */
519
	public void setMetric(String metric) {
520
		this.metric = metric;
521
	}
522

  
523
	/**
524
	 * Sets the method to use for computing
525
	 * @param method the method to set
526
	 */
527
	public void setMethod(String method) {
528
		this.method = method;
529
	}
530

  
531
	/**
532
	 * Sets the computing to columns or rows and rest the number of clusters to default value.
533
	 * @param columnsComputing the columns to set
534
	 */
535
	public void setColumnsComputing(boolean columnsComputing) {
536
		this.columnsComputing = columnsComputing;
537
	}
538

  
539
	/**
540
	 * Sets the number of clusters to use for computing
541
	 * @param nClusters the nCluster to set
542
	 */
543
	public void setNumberOfClusters(int nClusters) {
544
		numberOfClusters = nClusters;
545
	}
546

  
547
	/**
548
	 * Checks if the computing mode is set as columns. If not, the computing mode is set as rows.
549
	 * @return  
550
	 */
551
	public boolean isColumnsComputing() {
552
		return columnsComputing;
553
	}
554

  
555
	/**
556
	 * Gets the maximum clusters available according to the current computing mode (columns or rows) and according to current source (<code>CA</code> or <code>LexicalTable</code>).
557
	 * The maximum numbers of available clusters is for now limited to 16 by this method due of a limitation of FactoMineR plot.HCPC().
558
	 * @return the maximum clusters available according to the current computing mode
559
	 */
560
	public int getMaxClustersCount()	{
561

  
562
		int maxClustersCount = -1;
563

  
564
		try {
565
			RWorkspace rw = RWorkspace.getRWorkspaceInstance();
566
			REXP sv = rw.eval("min(length(" + symbol + "$data$clust) - 1, 16)"); //$NON-NLS-1$ //$NON-NLS-2$
567
			maxClustersCount = sv.asInteger();
568
		} catch(Exception e) {
569
			System.out.println("Error: "+e.getLocalizedMessage());
570
			Log.printStackTrace(e);
571
		}
572

  
573
		// FIXME: FactoMineR plot.HCPC doesn't manage more than 16 clusters when tree.barplot=TRUE, therefore we can't plot a SVG with more than that, see ticket #836 then use the code below in ChartsEngine to compute
574
		// the real maximum available clusters count
575
		//		// CA
576
		//		if(this.source instanceof CA)	{
577
		//			if(this.columns == true)	{
578
		//				maxClustersCount = ((CA)this.source).getColumnsCount() - 1;
579
		//			}
580
		//			else	{
581
		//				maxClustersCount = ((CA)this.source).getRowsCount() - 1;
582
		//			}
583
		//		}
584
		//		// Lexical table
585
		//		else if(this.source instanceof LexicalTable)	{
586
		//			if(this.columns == true)	{
587
		//				maxClustersCount = ((LexicalTable)this.source).getColumnsCount() - 1;
588
		//			}
589
		//			else	{
590
		//				maxClustersCount = ((LexicalTable)this.source).getRowsCount() - 1;
591
		//			}
592
		//		}
593

  
594
		return maxClustersCount;
595
	}
596

  
597

  
598

  
599
	@Override
600
	public String[] getExportTXTExtensions() {
601
		return new String[]{"*.txt"};
602
	}
603

  
604

  
605
	/**
606
	 * Returns the number of clusters.
607
	 * @return the number of clusters
608
	 */
609
	public int getNumberOfClusters() {
610
		return numberOfClusters;
611
	}
612

  
613
	public CA getCA() {
614
		return ca;
615
	}
616

  
617
	public LexicalTable getLexicalTable() {
618
		return table;
619
	}
620

  
621

  
622
	@Override
623
	public String getName() {
624
		return getParent().getName();
625
	}
626

  
627

  
628
	@Override
629
	public String getSimpleName() {
630
		StringBuffer buffer = new StringBuffer();
631
		buffer.append(this.columnsComputing ? "cols" : "rows"); //$NON-NLS-1$
632
		buffer.append(this.method);
633
		buffer.append(this.metric);
634
		buffer.append(this.numberOfClusters);
635
		return this.getName();
636
	}
637

  
638
	@Override
639
	public String getDetails() {
640
		return this.getName();
641
	}
642

  
643
	/**
644
	 * Gets the 2D rendering state.
645
	 * If false, the rendering will be done in 3D.
646
	 * @return the rendering2D
647
	 */
648
	public boolean isRendering2D() {
649
		return rendering2D;
650
	}
651

  
652
	/**
653
	 * Sets the 2D rendering state.
654
	 * If set to false, the rendering will be done in 3D.
655
	 * @param rendering2d the rendering2D to set
656
	 */
657
	public void setRendering2D(boolean rendering2d) {
658
		rendering2D = rendering2d;
659
	}
660

  
661

  
662

  
663
}
0 664

  
tmp/org.txm.ahc.core/src/org/txm/ahc/core/functions/package.html (revision 683)
1
<html>
2
<body>
3
<p>Classifcation using FactoMineR's CAH.</p>
4
</body>
5
</html>
0 6

  
tmp/org.txm.ahc.core/src/org/txm/ahc/core/chartsengine/jfreechart/JFCAHCChartCreator.java (revision 683)
1
package org.txm.ahc.core.chartsengine.jfreechart;
2

  
3
import org.jfree.chart.JFreeChart;
4
import org.txm.ahc.core.functions.AHC;
5
import org.txm.chartsengine.core.results.ChartResult;
6
import org.txm.chartsengine.jfreechart.core.JFCChartCreator;
7

  
8
/**
9
 * JFC CAH chart creator.
10
 * 
11
 * @author mdecorde
12
 * @author sjacquot
13
 * 
14
 * 
15
 */
16
public class JFCAHCChartCreator extends JFCChartCreator {
17

  
18

  
19
	@Override
20
	public JFreeChart createChart(ChartResult result) {
21

  
22
		System.err.println("JFCAHCChartCreator.createChart(): not yet implemented.");
23
		
24
		final AHC cah = (AHC) result;
25
		
26
		
27
		return null;
28
		
29
	}
30

  
31
	
32
	@Override
33
	// FIXME: to not load the chart creator, to remove when implemented 
34
	public Class getChartsEngineClass() {
35
		return null;
36
	}
37

  
38
	
39

  
40
	@Override
41
	public Class getResultDataClass() {
42
		return AHC.class;
43
	}
44

  
45

  
46

  
47

  
48
	
49
	// FIXME: old version with bar plot renderer
50
//	@Override
51
//	public JFreeChart createCAH2dChart(CAH cah) {
52
//
53
//
54
//		JFreeChart chart = null;
55
//
56
//		// Creating the data set from the result
57
//		DefaultCategoryDataset dataset = new DefaultCategoryDataset();
58
//		String category = "cluster ";
59
//
60
//
61
//
62
//		int[] clusterNumbers = cah.getClusterNumbers();
63
//		String[] rowNames = cah.getClusterRowNames();
64
//		String[] orderedRowNames = cah.getClusterOrderedRowNames();
65
//		double[] clusterHeights = cah.getClusterTreeHeights();
66
//		double[][] clusterMerges = cah.getClusterTreeMerges();
67
//		double[][] clusterCoords = cah.getClusterCoords();
68
//
69
//		double[] yValuesByOrderedRowNames = new double[rowNames.length];
70
//		double[] clusterNumbersValuesByOrderedRowNames = new double[rowNames.length];
71
//
72
//
73
//
74
//		// FIXME: Sort the cluster numbers in reverse order
75
////			Arrays.sort(clusterNumbers);
76
////			ArrayUtils.reverse(clusterNumbers);
77
////			System.out.println(Arrays.toString(clusterNumbers));
78
//
79
//
80
//		// FIXME: tests row names
81
//		//System.err.println("JFCChartsEngine.createCAH2dChart(): cluster row names: \t\t" + Arrays.toString(rowNames));
82
//
83
//		// FIXME: tests ordered row names
84
//		//System.err.println("JFCChartsEngine.createCAH2dChart(): cluster ordered row names: \t" + Arrays.toString(orderedRowNames));
85
//
86
//		// FIXME: tests, ordered cluster numbers
87
//		//System.err.println("JFCChartsEngine.createCAH2dChart(): cluster numbers: \t\t" + Arrays.toString(clusterNumbers));
88
//
89
//		// FIXME: tests, cluster tree merges
90
//		//System.err.println("JFCChartsEngine.createCAH2dChart(): cluster tree merges: \t\t" + Arrays.toString(clusterMerges));
91
//
92
//		// FIXME: tests, heights
93
////		System.err.println("JFCChartsEngine.createCAH2dChart(): cluster heights: \t\t" + Arrays.toString(clusterHeights));
94
//
95
//
96
//		// FIXME: tests
97
//		System.err.println("JFCChartsEngine.createCAH2dChart(): tests: \t\t" + Arrays.toString(cah.getInertiaGains()));
98
//
99
//
100
//
101
//		System.out.println("JFCChartsEngine.createCAH2dChart() cluster heights count: " + clusterHeights.length);
102
//		for(int i = 0; i < clusterHeights.length; i++) {
103
//			System.out.println("JFCChartsEngine.createCAH2dChart() cluster height: " + new DecimalFormat("0.00000000000000000").format(clusterHeights[i]));
104
//		}
105
//
106
////
107
////		String[] clusterUnorderedRowNames = cah.getClusterRowNames();
108
////		for(int i = 0; i < clusterUnorderedRowNames.length; i++) {
109
////			System.out.println("JFCChartsEngine.createCAH2dChart() unordered row names " + i + " : " + clusterUnorderedRowNames[i]);
110
////		}
111
//
112
//		// Parse the merge pairs
113
//		// A negative number in the FactoMineR tree merge table means a singleton
114
//		for (int i = 0 ; i < clusterMerges.length ; i++) {
115
//
116
//			// FIXME: debug
117
//			//for (int j = 0 ; j < clusterMerges.length ; j++) {
118
//				System.err.println("JFCChartsEngine.createCAH2dChart(): cluster tree merges: \t\t" + Arrays.toString(clusterMerges[i]));
119
//				System.err.println("JFCChartsEngine.createCAH2dChart(): row names: \t\t" + rowNames[(int) Math.abs(clusterMerges[i][0]) - 1] + " | " + rowNames[(int) Math.abs(clusterMerges[i][1]) - 1]);
120
//
121
//
122
//			//}
123
//
124
//			// Leaves pair
125
//			if(clusterMerges[i][0] < 0)	{
126
//
127
//				//System.err.print("JFCChartsEngine.createCAH2dChart(): merging: " + rowNames[(int) Math.abs(clusterMerge[i][0]) - 1]);
128
//
129
//				// Put the height in the ordered by names values table
130
//				for(int j = 0; j < orderedRowNames.length; j++) {
131
//					if(orderedRowNames[j].equals(rowNames[(int) Math.abs(clusterMerges[i][0]) - 1]))	{
132
//						yValuesByOrderedRowNames[j] = clusterHeights[i];
133
//						//clusterNumbersValuesByOrderedRowNames[j] = clusterNumbers[(int) Math.abs(clusterMerge[i][0]) - 1];
134
//					}
135
//				}
136
//
137
//			}
138
//			// Non-singleton
139
////				else	{
140
////					//System.err.print("JFCChartsEngine.createCAH2dChart(): merging aggregation: " +  clusterMerge[i][0]);
141
////				}
142
//
143
//			// Leaves pair
144
//			if(clusterMerges[i][1] < 0)	{
145
//				//System.err.print(" with: " + rowNames[(int) Math.abs(clusterMerge[i][1]) - 1]);
146
//
147
//				// Put the height in the ordered by names values table
148
//				for(int j = 0; j < orderedRowNames.length; j++) {
149
//					if(orderedRowNames[j].equals(rowNames[(int) Math.abs(clusterMerges[i][1]) - 1]))	{
150
//						yValuesByOrderedRowNames[j] = clusterHeights[i];
151
//						//clusterNumbersValuesByOrderedRowNames[j] = clusterNumbers[(int) Math.abs(clusterMerge[i][1]) - 1];
152
//					}
153
//
154
//				}
155
//
156
//			}
157
//			// Non-singleton
158
////				else	{
159
////					//System.err.print(" with aggregation: " + clusterMerge[i][1]);
160
////				}
161
//
162
//			//System.err.println(" and height: " + clusterHeights[i] + " as aggregation: " + (i + 1));
163
//
164
//		}
165
//
166
//
167
//		//
168
////		for (int i = 0 ; i <  cah.getClusterTreeMerges().length; i++) {
169
////			System.err.println("JFCChartsEngine.createCAH2dChart() merges : ");
170
////			for(int j = 0; j < cah.getClusterTreeMerges()[i].length; j++) {
171
////				System.err.print(" : " + cah.getClusterTreeMerges()[i][j]);
172
////			}
173
////		}
174
//
175
//
176
//
177
////		ArrayList<Double> middlePoints = cah.getClusterTreeMiddlePoints();
178
////
179
////		for (int i = 0 ; i <  middlePoints.size(); i++) {
180
////			System.err.println("JFCChartsEngine.createCAH2dChart() middle points X: " + middlePoints.get(i));
181
////		}
182
//
183
//
184
//
185
////		for (int i = 0 ; i < cah.getClusterCoords().length ; i++) {
186
////			for(int j = 0; j < cah.getClusterCoords()[i].length; j++) {
187
////				//System.err.println("JFCChartsEngine.createCAH2dChart(): " + cah.getClusterCoords()[i][j]);
188
////				dataset.setValue(cah.getClusterCoords()[i][j], category + clusterNumbers[i], rownames[i]);
189
////			}
190
////		}
191
//
192
//
193
//
194
//		// Create chart title
195
//		String title = "title";
196
//		String xAxisLabel = "Column";
197
//		if(!cah.isColumnsComputing())	{
198
//			xAxisLabel = "Row";
199
//		}
200
//
201
//
202
//
203
//		// Create the data set
204
//		// FIXME: bar plot test
205
////		for(int i = 0; i < yValuesByOrderedRowNames.length; i++) {
206
////			//dataset.setValue(yValuesByOrderedRowNames[i], category + clusterNumbers[clusterNumbers.length - 1 - i], orderedRowNames[i]);
207
////
208
////
209
////			dataset.setValue(yValuesByOrderedRowNames[i], category + clusterNumbers[yValuesByOrderedRowNames.length - 1 - i], orderedRowNames[i]);
210
////			//dataset.setValue(yValuesByOrderedRowNames[i], category + clusterNumbers[i], orderedRowNames[i]);
211
////
212
////			//dataset.setValue(yValuesByOrderedRowNames[i], category + clusterNumbersValuesByOrderedRowNames[i], orderedRowNames[i]);
213
////		}
214
////
215
////		// Create the chart
216
////        chart = this.createCategoryBarChart(dataset, title, xAxisLabel, "Height", false, false, false);
217
////        ((IItemSelectionRenderer) chart.getCategoryPlot().getRenderer()).setChartType(ChartsEngine.CHART_TYPE_CAH_2D);
218
////
219
////        // Draw tree
220
////        for(int j = 0; j < chart.getCategoryPlot().getDataset().getColumnCount() - 1; j++) {
221
////			//System.err.println("JFCChartsEngine.createCAH2dChart(): " + chart.getCategoryPlot().getDataset().getColumnKey(j));
222
////
223
////
224
////        	// Non-singleton pairs lines
225
////			if(yValuesByOrderedRowNames[j] == yValuesByOrderedRowNames[j + 1])	{
226
////				chart.getCategoryPlot().addAnnotation(new CategoryLineAnnotation(chart.getCategoryPlot().getDataset().getColumnKey(j), yValuesByOrderedRowNames[j],
227
////						chart.getCategoryPlot().getDataset().getColumnKey(j + 1), yValuesByOrderedRowNames[j + 1], Color.red, new BasicStroke(2.0f)));
228
////			}
229
////
230
////
231
////			//chart.getCategoryPlot().addAnnotation(new Cate
232
////
233
////
234
////
235
////		}
236
//
237
//
238
//
239
//		// Create the data set
240
//		// FIXME: step chart test
241
////		for(int i = 0; i < yValuesByOrderedRowNames.length - 1; i++) {
242
////			if(yValuesByOrderedRowNames[i] == yValuesByOrderedRowNames[i + 1])	{
243
////				dataset.setValue(yValuesByOrderedRowNames[i], category + clusterNumbers[yValuesByOrderedRowNames.length - 1 - i], orderedRowNames[i]);
244
////			}
245
////		}
246
//////		dataset.addValue(0, "test", "truc 1");
247
//////		dataset.addValue(0.5, "test", "truc 1");
248
//////		dataset.addValue(0.9, "test", "truc 1");
249
////		// Create the chart
250
////        chart = this.createCategoryStepChart(dataset, title, xAxisLabel, "Height", false, false);
251
////        ((IItemSelectionRenderer) chart.getCategoryPlot().getRenderer()).setChartType(ChartsEngine.CHART_TYPE_CAH_2D);
252
//
253
//
254
//		// Create the data set
255
//		// FIXME: XY category bar chart test
256
//		XYSeriesCollection dataset2 = new XYSeriesCollection();
257
//
258
//		// Last tree level (leaves level)
259
//		XYSeries series = new XYSeries("leaves");
260
//		for(int i = 0; i < yValuesByOrderedRowNames.length - 1; i++) {
261
//			series.add(i, 0);
262
//			series.add(i, yValuesByOrderedRowNames[i]);
263
//			if(yValuesByOrderedRowNames[i] == yValuesByOrderedRowNames[i + 1])	{
264
//				series.add(i + 1, yValuesByOrderedRowNames[i]);
265
//				series.add(i + 1, 0);
266
//			}
267
//			else	{
268
//				series.add(i + 1, null);
269
//			}
270
//		}
271
//		dataset2.addSeries(series);
272
//
273
//
274
//		// Link singletons to non singleton
275
//		series = new XYSeries("singleton to non singleton links");
276
//		for(int i = clusterHeights.length; i >= 0; i--) {
277
//
278
//			// Skip non singletons case
279
//			if(i > 3 && yValuesByOrderedRowNames[i] == yValuesByOrderedRowNames[i - 1] && yValuesByOrderedRowNames[i - 2] == yValuesByOrderedRowNames[i - 3])	{
280
//				continue;
281
//			}
282
//
283
//			// Link singletons to non singleton
284
//			if(i > 1 && yValuesByOrderedRowNames[i] == yValuesByOrderedRowNames[i - 1] && yValuesByOrderedRowNames[i - 1] != yValuesByOrderedRowNames[i - 2]) {
285
//				series.add(i - 0.5, yValuesByOrderedRowNames[i - 2]);
286
//				series.add(i - 0.5, yValuesByOrderedRowNames[i]);
287
//				series.add(i - 0.5, null);
288
//				series.add(i - 2, yValuesByOrderedRowNames[i - 2]);
289
//			}
290
//		}
291
//		dataset2.addSeries(series);
292
//
293
//		// Link singletons to newly created pairs
294
//		series = new XYSeries("singleton to newly created pairs");
295
//		for(int i = clusterHeights.length; i >= 0; i--) {
296
//
297
//			// Skip non singletons case
298
//			if(i > 0 && yValuesByOrderedRowNames[i] == yValuesByOrderedRowNames[i - 1])	{
299
//				series.add(i, null);
300
//				continue;
301
//			}
302
//
303
//			// Link singletons to newly created pairs
304
//			if(i < clusterHeights.length - 1 && yValuesByOrderedRowNames[i] != yValuesByOrderedRowNames[i + 1]
305
//					&& yValuesByOrderedRowNames[i + 1] != yValuesByOrderedRowNames[i + 2]
306
//
307
////						&& i > 1 &&
308
//
309
//							) {
310
//
311
//				series.add(i, null);
312
//
313
//				series.add(i, yValuesByOrderedRowNames[i]);
314
//
315
//				series.add(i + 1.75, yValuesByOrderedRowNames[i]);
316
//				series.add(i + 1.75, yValuesByOrderedRowNames[i + 1]);
317
//
318
//
319
//				//series.add(i - 2, yValuesByOrderedRowNames[i - 2]);
320
//			}
321
//		}
322
//		dataset2.addSeries(series);
323
//
324
//
325
//
326
//		// Link singletons; test 2
327
////		series = new XYSeries("singleton links");
328
////		for(int i = 0; i <  clusterHeights.length - 2; i++) {
329
////			if(i > 0 && i < clusterHeights.length - 2 && yValuesByOrderedRowNames[i] != yValuesByOrderedRowNames[i + 1] && yValuesByOrderedRowNames[i] != yValuesByOrderedRowNames[i - 1]) {
330
////				series.add(i, yValuesByOrderedRowNames[i]);
331
////				series.add(i + 1.5, yValuesByOrderedRowNames[i]);
332
////				series.add(i + 1.5, yValuesByOrderedRowNames[i + 1]);
333
////				series.add(i + 1.5, null);
334
////			}
335
////		}
336
////		dataset2.addSeries(series);
337
//
338
//
339
////		// Other clusters
340
////		ArrayList<Double> otherClusters = new ArrayList<Double>();
341
////		//series = new XYSeries("other clusters");
342
////		for(int i = 0; i < clusterHeights.length; i++) {
343
////			// If not a leaf
344
////			boolean done = false;
345
////			for(int j = 0; j < clusterNumbersValuesByOrderedRowNames.length; j++) {
346
////				if(clusterHeights[i] == yValuesByOrderedRowNames[j])	{
347
////					done = true;
348
////					break;
349
////				}
350
////			}
351
////			if(done)	{
352
////				continue;
353
////			}
354
////			System.err.println("JFCChartsEngine.createCAH2dChart() other clusters: " + new DecimalFormat("0.0000000000000000").format(clusterHeights[i]));
355
////		}
356
////		//dataset2.addSeries(series);
357
//
358
//
359
//
360
////		dataset.addValue(0, "test", "truc 1");
361
////		dataset.addValue(0.5, "test", "truc 1");
362
////		dataset.addValue(0.9, "test", "truc 1");
363
//		// Create the chart
364
//        //chart = this.createXYBarChart(dataset2, title, xAxisLabel, "Height", false, false);
365
//        chart = ChartFactory.createXYLineChart(
366
//        		title,      // chart title
367
//        		xAxisLabel,                      // x axis label
368
//                "height",                      // y axis label
369
//                dataset2,                  // data
370
//                PlotOrientation.VERTICAL,
371
//                true,                     // include legend
372
//                true,                     // tooltips
373
//                false                     // urls
374
//            );
375
//
376
//
377
//
378
//
379
//        chart.getXYPlot().setRenderer(this.theme.createXYLineAndShapeRenderer(true, false));
380
//        ((IItemSelectionRenderer) chart.getXYPlot().getRenderer()).setChartType(ChartsEngine.CHART_TYPE_CAH_2D);
381
//
382
//
383
//        //chart.getXYPlot().addAnnotation(new XYLineAnnotation(0.5,  yValuesByOrderedRowNames[0], 0.5,  yValuesByOrderedRowNames[0] + 0.002));
384
//
385
//
386
//
387
//
388
//
389
//
390
//
391
//
392
//        //System.err.println("JFCChartsEngine.createCAH2dChart() " + chart.getCategoryPlot().getCategories().get(0));
393
//        //chart.getCategoryPlot().addAnnotation(new CategoryLineAnnotation("1970-12-31", .0002, "1965-12-31", .00005, Color.red, new BasicStroke(2.0f)));
394
//
395
//        // Custom range axis for ticks drawing options
396
//        //chart.getCategoryPlot().setRangeAxis(new ExtendedNumberAxis((NumberAxis) chart.getCategoryPlot().getRangeAxis(), false, true, 0, DatasetUtilities.findMaximumRangeValue(chart.getCategoryPlot().getDataset()).doubleValue()));
397
//
398
//
399
//
400
//		// Apply theme to the chart
401
//		this.theme.apply(chart);
402
//
403
//
404
//
405
//		// FIXME: test algo R
406
//		int dimens = 2;
407
//		int ax1 = 0;
408
//		int ax2 = 1;
409
//		double x1, y1, x2, y2, w1, w2;
410
//
411
//		double h1, h2; // FIXME: when using 3 dimensions
412
//
413
//
414
//		double[][] aa = new double[clusterMerges.length][4];
415
//		for(int i = 0; i < clusterMerges.length; i++) {
416
//			for(int j = 0; j < 4; j++) {
417
//				aa[i][j] = 0;
418
//			}
419
//		}
420
//
421
//
422
//		   //aa=matrix(ncol=4, nrow=nrow(merge))
423
//
424
//
425
//
426
//
427
//		// Decrement/increment the cluster merge value because the R algorithm uses 1 as first table index
428
//
429
//		for(int i = 0; i < clusterMerges.length; i++) {
430
//			if(clusterMerges[i][0] < 0)	{
431
//				clusterMerges[i][0]++;
432
//			}
433
//			else	{
434
//				clusterMerges[i][0]--;
435
//			}
436
//
437
//			if(clusterMerges[i][1] < 0)	{
438
//				clusterMerges[i][1]++;
439
//			}
440
//			else	{
441
//				clusterMerges[i][1]--;
442
//			}
443
//		}
444
//
445
//
446
//		for(int i = 0; i < clusterMerges.length; i++) {
447
//
448
////		    for(i in 1:nrow(merge)){
449
//			     // if(merge[i,1]<0){
450
//			// Singleton
451
//			if(clusterMerges[i][0] < 0)	{
452
//
453
//
454
//			        x1 = clusterCoords[(int) -clusterMerges[i][0]][ax1];
455
//			        y1 = clusterCoords[(int) -clusterMerges[i][0]][ax2];
456
//
457
//
458
//			        h1 = 0;
459
//			        w1 = 1;
460
//			      }
461
//			      else{
462
//			        x1 = aa[(int) clusterMerges[i][0]][0];
463
//			        y1 = aa[(int) clusterMerges[i][0]][1];
464
//			        w1 = aa[(int) clusterMerges[i][0]][3];
465
//			        h1 = aa[(int) clusterMerges[i][0]][2];
466
//			      }
467
//			// Singleton
468
//			if(clusterMerges[i][1] < 0)	{
469
//			      //if(merge[i,2]<0){
470
//			        x2 = clusterCoords[-(int) clusterMerges[i][1]][ax1];
471
//			        y2 = clusterCoords[-(int) clusterMerges[i][1]][ax2];
472
//			        h2 = 0;
473
//			        w2 = 1;
474
//			      }
475
//			      else{
476
//			        x2 = aa[(int) clusterMerges[i][1]][0];
477
//			        y2 = aa[(int) clusterMerges[i][1]][1];
478
//			        w2 = aa[(int) clusterMerges[i][1]][3];
479
//			        h2 = aa[(int) clusterMerges[i][1]][2];
480
//			      }
481
//			      aa[i][0] = (w1 * x1 + w2 * x2) / (w1 + w2);
482
//			      aa[i][1] = (w1 * y1 + w2 * y2) / (w1 + w2);
483
//
484
//			      //if(i<=nrow(merge)-t.level+1)
485
//			      if(i <= clusterMerges.length)	{
486
//			    	  clusterHeights[i] = 0;
487
//			      }
488
//
489
//			      aa[i][2] = clusterHeights[i];
490
//			      aa[i][3] = w1 + w2;
491
//
492
////			      if(i>(nrow(merge)-t.level+1)){
493
////			      if(i > clusterMerges[i][1]){ // FIXME: this test is strange
494
////			        if(dimens==3) s$points3d(rbind(c(x1,y1,h1),c(x1,y1,height[i]), c(x2,y2,height[i]),c(x2,y2,h2)), lty=1, type="o", pch="")
495
//			        if(dimens == 2)	{
496
//			        //	lines(c(x1,x2), c(y1,y2), lwd=(height[i]/max(height))*3)
497
//
498
//			        	//chart.getXYPlot().addAnnotation(new XYLineAnnotation(x1, y1, x2, y2));
499
//			        	// tests with steps lines
500
//			        	x1 *= 10;
501
//			        	x2 *= 10;
502
//			        	y1 /= 100;
503
//			        	y2 /= 100;
504
//
505
//			        	chart.getXYPlot().addAnnotation(new XYLineAnnotation(x1, y1, x1, y2));
506
//			        	chart.getXYPlot().addAnnotation(new XYLineAnnotation(x1, y2, x2, y2));
507
//			        	chart.getXYPlot().addAnnotation(new XYLineAnnotation(x2, y2, x2, y1));
508
//
509
//
510
//			        	// FIXME: labels tests
511
//			        	chart.getXYPlot().addAnnotation(new XYTextAnnotation(rowNames[(int) Math.abs(clusterMerges[i][0])], x1, y1));
512
//			        	chart.getXYPlot().addAnnotation(new XYTextAnnotation(rowNames[(int) Math.abs(clusterMerges[i][1])], x2, y1));
513
//
514
//
515
//
516
////			        	chart.getXYPlot().addAnnotation(new XYLineAnnotation(y2, x1, y1, x1));
517
//
518
//
519
//			        	//chart.getXYPlot().addAnnotation(new XYLineAnnotation(x2, y2, x2, y2));
520
//
521
//
522
//			        	System.err.println("JFCChartsEngine.createCAH2dChart(): draw line " + x1 + ", " + y1 + " | " + x2 + "," + y2);
523
//			        }
524
////			      }
525
//		//	    }
526
//
527
//
528
//		}
529
//
530
//
531
//		// FIXME: test symbol axis
532
//		//chart.getXYPlot().setDomainAxis(new SymbolAxis("test symbol axis", new String[]{"A", "b", "c"}));
533
//
534
//		// FIXME: for cluster boxes we may use XYBoxAnnotation()
535
//
536
//
537
//		//chart.getXYPlot().addAnnotation(new XYLineAnnotation(x1, y1, x2, y2));
538
//
539
//
540
//        return chart;
541
//
542
//	}
543

  
544
	// FIXME: new version with category step renderer
545
//	@Override
546
//	public JFreeChart createCAH2dChart(CAH cah) {
547
//
548
//
549
//			JFreeChart chart = null;
550
//
551
//			// Creating the data set from the result
552
//			DefaultCategoryDataset dataset = new DefaultCategoryDataset();
553
//			String category = "cluster ";
554
//
555
//
556
//
557
//			int[] clusterNumbers = cah.getClusterNumbers();
558
//			String[] rowNames = cah.getClusterRowNames();
559
//			String[] orderedRowNames = cah.getClusterOrderedRowNames();
560
//			double[] clusterHeights = cah.getClusterTreeHeights();
561
//			double[][] clusterMerge = cah.getClusterTreeMerges();
562
//
563
//
564
//			double[] yValuesByOrderedRowNames = new double[rowNames.length];
565
//			double[] clusterNumbersValuesByOrderedRowNames = new double[rowNames.length];
566
//
567
//
568
//
569
//			// FIXME: Sort the cluster numbers in reverse order
570
////			Arrays.sort(clusterNumbers);
571
////			ArrayUtils.reverse(clusterNumbers);
572
////			System.out.println(Arrays.toString(clusterNumbers));
573
//
574
//
575
//			// FIXME: tests row names
576
//			//System.err.println("JFCChartsEngine.createCAH2dChart(): cluster row names: \t\t" + Arrays.toString(rowNames));
577
//
578
//			// FIXME: tests ordered row names
579
//			//System.err.println("JFCChartsEngine.createCAH2dChart(): cluster ordered row names: \t" + Arrays.toString(orderedRowNames));
580
//
581
//			// FIXME: tests, ordered cluster numbers
582
//			//System.err.println("JFCChartsEngine.createCAH2dChart(): cluster number: \t\t" + Arrays.toString(clusterNumbers));
583
//
584
//
585
//
586
//			for (int i = 0 ; i < clusterMerge.length ; i++) {
587
//
588
//				// Singleton
589
//				if(clusterMerge[i][0] < 0)	{
590
//
591
//					//System.err.print("JFCChartsEngine.createCAH2dChart(): merging: " + rowNames[(int) Math.abs(clusterMerge[i][0]) - 1]);
592
//
593
//					// Put the height in the ordered by names values table
594
//					for(int j = 0; j < orderedRowNames.length; j++) {
595
//						if(orderedRowNames[j].equals(rowNames[(int) Math.abs(clusterMerge[i][0]) - 1]))	{
596
//							yValuesByOrderedRowNames[j] = clusterHeights[i];
597
//							//clusterNumbersValuesByOrderedRowNames[j] = clusterNumbers[(int) Math.abs(clusterMerge[i][0]) - 1];
598
//						}
599
//					}
600
//
601
//				}
602
//				// Non-singleton
603
//				else	{
604
//					//System.err.print("JFCChartsEngine.createCAH2dChart(): merging aggregation: " +  clusterMerge[i][0]);
605
//				}
606
//
607
//				// Singleton
608
//				if(clusterMerge[i][1] < 0)	{
609
//					//System.err.print(" with: " + rowNames[(int) Math.abs(clusterMerge[i][1]) - 1]);
610
//
611
//					// Put the height in the ordered by names values table
612
//					for(int j = 0; j < orderedRowNames.length; j++) {
613
//						if(orderedRowNames[j].equals(rowNames[(int) Math.abs(clusterMerge[i][1]) - 1]))	{
614
//							yValuesByOrderedRowNames[j] = clusterHeights[i];
615
//							//clusterNumbersValuesByOrderedRowNames[j] = clusterNumbers[(int) Math.abs(clusterMerge[i][1]) - 1];
616
//						}
617
//
618
//					}
619
//
620
//				}
621
//				// Non-singleton
622
//				else	{
623
//					//System.err.print(" with aggregation: " + clusterMerge[i][1]);
624
//				}
625
//
626
//				//System.err.println(" and height: " + clusterHeights[i] + " as aggregation: " + (i + 1));
627
//
628
//			}
629
//
630
//
631
//			// Create the data set
632
//
633
//			for(int i = 0; i < yValuesByOrderedRowNames.length; i++) {
634
//				//dataset.setValue(yValuesByOrderedRowNames[i], category + clusterNumbers[clusterNumbers.length - 1 - i], orderedRowNames[i]);
635
//
636
//				dataset.setValue(yValuesByOrderedRowNames[i], category + clusterNumbers[yValuesByOrderedRowNames.length - 1 - i], orderedRowNames[i]);
637
//				//dataset.setValue(yValuesByOrderedRowNames[i], category, orderedRowNames[i]);
638
//
639
//				//dataset.setValue(yValuesByOrderedRowNames[i], category + clusterNumbersValuesByOrderedRowNames[i], orderedRowNames[i]);
640
//			}
641
//
642
////
643
////			for (int i = 0 ; i <  cah.getClusterTreeMerges().length; i++) {
644
////				System.err.println("JFCChartsEngine.createCAH2dChart() merges : ");
645
////				for(int j = 0; j < cah.getClusterTreeMerges()[i].length; j++) {
646
////					System.err.print(" : " + cah.getClusterTreeMerges()[i][j]);
647
////				}
648
////			}
649
//
650
//
651
//
652
////			ArrayList<Double> middlePoints = cah.getClusterTreeMiddlePoints();
653
////
654
////			for (int i = 0 ; i <  middlePoints.size(); i++) {
655
////				System.err.println("JFCChartsEngine.createCAH2dChart() middle points X: " + middlePoints.get(i));
656
////			}
657
//
658
//
659
//
660
////			for (int i = 0 ; i < cah.getClusterCoords().length ; i++) {
661
////				for(int j = 0; j < cah.getClusterCoords()[i].length; j++) {
662
////					//System.err.println("JFCChartsEngine.createCAH2dChart(): " + cah.getClusterCoords()[i][j]);
663
////					dataset.setValue(cah.getClusterCoords()[i][j], category + clusterNumbers[i], rownames[i]);
664
////				}
665
////			}
666
//
667
//
668
//
669
//			// Create chart title
670
//			String title = "title";
671
//			String xAxisLabel = "Column";
672
//			if(!cah.isColumnsComputing())	{
673
//				xAxisLabel = "Row";
674
//			}
675
//
676
//
677
//			// Create the chart
678
//	        chart = this.createCategoryStepChart(dataset, title, xAxisLabel, "Height", false, false);
679
//
680
//
681
//	        ((IItemSelectionRenderer) chart.getCategoryPlot().getRenderer()).setChartType(ChartsEngine.CHART_TYPE_CAH_2D);
682
//
683
//
684
//	        // Draw tree
685
//	        chart.getCategoryPlot().addAnnotation(new CategoryLineAnnotation(chart.getCategoryPlot().getDataset().getColumnKey(0), 5.0,
686
//	        		chart.getCategoryPlot().getDataset().getColumnKey(1), 8.0, Color.red, new BasicStroke(2.0f)));
687
//
688
//	        // Custom range axis for ticks drawing options: cut the range to minimum and maximum values
689
//	        chart.getCategoryPlot().setRangeAxis(new ExtendedNumberAxis((NumberAxis) chart.getCategoryPlot().getRangeAxis(), false, true, 0, DatasetUtilities.findMaximumRangeValue(chart.getCategoryPlot().getDataset()).doubleValue()));
690
//
691
//
692
//		return chart;
693
//
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff