Commit 46bc574a authored by hvernier's avatar hvernier

Correction lignePanel

ajout alpha nuage de point
parent 694e5934
......@@ -90,6 +90,7 @@ import mustic.gui.dialog.arff.RawImageToArffDialog;
import mustic.gui.dialog.classifier.ConstraintsSelectionFrame;
import mustic.gui.dialog.consoleHandler.ConsoleFrame;
import mustic.gui.dialog.csv.CSVToDataDialog;
import mustic.gui.dialog.csv.DataToCSVDialog;
import mustic.gui.dialog.ogr.DataToOGRDialog;
import mustic.gui.dialog.ogr.OGRToDataDialog;
import mustic.gui.panels.Factory;
......@@ -756,6 +757,15 @@ public class MainFrame extends JFrame {
}
});
CSVMenu.add(menuItemLoadCSVToData);
menuItemLoadDataToCSV = new JMenuItem(Messages.getString("DataToCSV")); //$NON-NLS-1$
menuItemLoadDataToCSV.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
toolsMenuDatatoCSV();
}
});
CSVMenu.add(menuItemLoadDataToCSV);
OGRMenu = new JMenu(Messages.getString("MainFrame.323")); //$NON-NLS-1$
......@@ -1180,6 +1190,8 @@ public class MainFrame extends JFrame {
private Boolean actionLoadOGRToData;
private JMenuItem menuItemLoadCSVToData;
private Boolean actionLoadCSVToData;
private JMenuItem menuItemLoadDataToCSV;
private Boolean actionLoadDataToCSV;
private JMenuItem menuItemResultToCSV;
private Boolean actionResultToCSV;
private JMenuItem menuItemArffData;
......@@ -1278,6 +1290,7 @@ public class MainFrame extends JFrame {
this.actionLoadArff = true;
this.actionLoadArffToData = true;
this.actionLoadCSVToData = true;
this.actionLoadDataToCSV = true;
this.actionLoadOGRToData = true;
this.actionResultToCSV = true;
this.actionArffData = false;
......@@ -1381,6 +1394,7 @@ public class MainFrame extends JFrame {
menuItemOGRData.setEnabled(this.actionOGRData);
menuItemLoadArffToData.setEnabled(this.actionLoadArffToData);
menuItemLoadCSVToData.setEnabled(this.actionLoadCSVToData);
menuItemLoadDataToCSV.setEnabled(this.actionLoadDataToCSV);
menuItemLoadOGRToData.setEnabled(this.actionLoadOGRToData);
// menuItemResultToCSV.setEnabled(this.actionResultToCSV);
menuZoomIn.setEnabled(this.actionZoomIn);
......@@ -3704,6 +3718,11 @@ public class MainFrame extends JFrame {
dialog.toFront();
}
private void toolsMenuDatatoCSV(){
DataToCSVDialog dialog = new DataToCSVDialog();
this.desktop.add(dialog);
dialog.toFront();
}
private void toolsMenuClustering() throws Exception {
// MainFrame.getInstance().getDesktop().addFrame(ClassificationFrame.getInstance());
if (!ClassificationFrame.isCreated()) {
......
This diff is collapsed.
......@@ -247,8 +247,8 @@ public class ImageToArffDialog extends JInternalFrame {
+ "@ATTRIBUTE Pos_Y INTEGER\n"
+ attribBand
+ Messages.getString("ImageToArffDialog.38") //$NON-NLS-1$
+ Messages.getString("ImageToArffDialog.39") //$NON-NLS-1$
+ Messages.getString("ImageToArffDialog.40") //$NON-NLS-1$
//+ Messages.getString("ImageToArffDialog.39") //$NON-NLS-1$
//+ Messages.getString("ImageToArffDialog.40") //$NON-NLS-1$
+ Messages.getString("ImageToArffDialog.41")); //$NON-NLS-1$
for (int x = 0; x < image.getWidth(); x++) {
......@@ -256,7 +256,7 @@ public class ImageToArffDialog extends JInternalFrame {
writer.print(x + Messages.getString("ImageToArffDialog.42") + y); //$NON-NLS-1$
for (int b = 0; b < image.getNbBands(); b++) {
int classe = (int) (buffer[b][x][y] / div);
writer.print(Messages.getString("ImageToArffDialog.43") + date + b + df.format(classe)); //$NON-NLS-1$
writer.print(Messages.getString("ImageToArffDialog.43") + buffer[b][x][y]); //$NON-NLS-1$
}
writer.println();
}
......
package mustic.gui.dialog.csv;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import jcl.data.Data;
import mustic.gui.DataDesktopFrame;
import mustic.gui.MainFrame;
import mustic.gui.dialog.Messages;
import mustic.gui.dialog.arff.DataToArffDialog;
import mustic.utils.io.dataExchange.DataArffExchange;
import mustic.utils.io.dataExchange.DataCsvExchange;
public class DataToCSVDialog extends JInternalFrame {
private static final long serialVersionUID = 1L;
/** liste des images ouvertes */
private JComboBox<String> comboData = new JComboBox<String>();
/** chemin du fichier que l'on va créer */
private JTextField textSave = new JTextField();
private JTextField txtDate;
public DataToCSVDialog() {
super();
JPanel mainPanel = new JPanel(new BorderLayout());
JPanel panelData = new JPanel(new GridLayout(4, 2));
panelData.add(new JLabel(Messages.getString("DataToArffDialog.0"))); //$NON-NLS-1$
DataDesktopFrame[] desktopFrames = MainFrame.getInstance().getDesktop()
.getAllDataDesktopFrames();
int nbSession = desktopFrames.length;
for (int i = 0; i < nbSession; i++) {
String name = desktopFrames[i].getDataSession().getTitle();
this.comboData.addItem(name);
}
if (nbSession == 0) {
JOptionPane.showMessageDialog(this, Messages.getString("DataToArffDialog.24"), //$NON-NLS-1$
Messages.getString("DataToArffDialog.23"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
return;
}
this.comboData.setPreferredSize(new Dimension(100, 30));
panelData.add(comboData);
panelData.add(new JLabel(Messages.getString("DataToArffDialog.12"))); //$NON-NLS-1$
JPanel panelSave = new JPanel(new BorderLayout());
JButton buttonBrowse = new JButton(Messages.getString("DataToArffDialog.13")); //$NON-NLS-1$
buttonBrowse.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
DataDesktopFrame[] desktopFrames = MainFrame.getInstance()
.getDesktop().getAllDataDesktopFrames();
int nbSessions = desktopFrames.length;
if (nbSessions > 0) {
String name = desktopFrames[comboData.getSelectedIndex()]
.getDataSession().getData().getDataName();
String path = "~/" + name + ".csv"; //$NON-NLS-1$
File f = new File(path);
fileChooser.setSelectedFile(f);
}
int returnVal = fileChooser
.showSaveDialog(DataToCSVDialog.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
String path = fileChooser.getSelectedFile().getPath();
textSave.setText(path);
}
}
});
panelSave.add(this.textSave, BorderLayout.CENTER);
panelSave.add(buttonBrowse, BorderLayout.EAST);
panelData.add(panelSave);
txtDate = new JTextField();
DateFormat formatDate=new SimpleDateFormat("ddMMyy");
txtDate.setText(formatDate.format(new Date()));
panelData.add(new JLabel(Messages.getString("DataToArffDialog.15"))); //$NON-NLS-1$
panelData.add(txtDate);
// panelData.add(new JLabel(Messages.getString("DataToArffDialog.16"))); //$NON-NLS-1$
// JSpinner.NumberEditor spinnerEditor = new JSpinner.NumberEditor(
// this.spinner);
// this.spinner.setEditor(spinnerEditor);
// spinnerEditor.getModel().setMinimum(1);
// spinnerEditor.getModel().setMaximum(256);
// spinnerEditor.getModel().setStepSize(1);
// spinnerEditor.getModel().setValue(10);
// panelData.add(this.spinner);
JPanel panelOk = new JPanel();
JButton buttonOk = new JButton(Messages.getString("DataToArffDialog.17")); //$NON-NLS-1$
buttonOk.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
buttonOk_actionPerformed();
}
});
panelOk.add(buttonOk);
mainPanel.add(panelData, BorderLayout.NORTH);
mainPanel.add(panelOk, BorderLayout.SOUTH);
this.setContentPane(mainPanel);
this.setTitle(Messages.getString("DataToArffDialog.18")); //$NON-NLS-1$
this.setSize(350, 175);
this.setResizable(true);
this.setMaximizable(true);
this.setIconifiable(true);
this.setClosable(true);
this.setVisible(true);
this.requestFocus();
}
/**
* lance la création du fichier arff
*/
protected void buttonOk_actionPerformed() {
DataDesktopFrame[] desktopFrames = MainFrame.getInstance().getDesktop()
.getAllDataDesktopFrames();
int nbSessions = desktopFrames.length;
if (nbSessions == 0) {
JOptionPane.showMessageDialog(this,
Messages.getString("DataToArffDialog.19"), Messages.getString("DataToArffDialog.20"), //$NON-NLS-1$ //$NON-NLS-2$
JOptionPane.WARNING_MESSAGE);
this.dispose();
} else if (this.textSave.getText().equals("")) { //$NON-NLS-1$
JOptionPane.showMessageDialog(this, Messages.getString("DataToArffDialog.22"), //$NON-NLS-1$
Messages.getString("DataToArffDialog.23"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
} else {
Data data = desktopFrames[this.comboData.getSelectedIndex()]
.getDataSession().getData();
DataCsvExchange.dataToCSV(this.textSave.getText(), data,";",true);
JOptionPane.showMessageDialog(this,
Messages.getString("DataToArffDialog.44"), Messages.getString("DataToArffDialog.45"), //$NON-NLS-1$ //$NON-NLS-2$
JOptionPane.INFORMATION_MESSAGE);
this.dispose();
}
}
}
\ No newline at end of file
......@@ -88,6 +88,9 @@ public class CentroidsChart extends JPanel {
if (mSeq) {
switch (type) {
case 0: {
tabLigne = new double[((AttributeMultiDimSequence) _classification.getData().getOneDataObject().getAttribute(0)).sequence[0].length][0];
tabColorLigne = new Color[((AttributeMultiDimSequence) _classification.getData().getOneDataObject().getAttribute(0)).sequence[0].length][0];
this.indexBande1 = 0;
this.indexBande2 = 1;
this.chart = createXYChart(this.createXYDataset(this.type,
......@@ -307,6 +310,9 @@ public class CentroidsChart extends JPanel {
case 1:
// tmpSerie.add(j,tmpAttr.getSequence()[j][indexBande1]);
if(tmpAttr.getNbTuples()> seqMax) {
seqMax = tmpAttr.getNbTuples();
}
dataSet.addValue(tmpAttr.getSequence()[j][indexBande1],
i + "", (j + 1) + "");
break;
......
package mustic.models.gui.charts;
import weka.core.matrix.EigenvalueDecomposition;
import weka.core.matrix.Matrix;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.TreeMap;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import jcl.Classification;
import jcl.clustering.Cluster;
import jcl.clustering.ClusteringResult;
import jcl.data.DataObject;
import mustic.models.gui.panels.ClusterViewPanel;
import mustic.models.gui.panels.DataViewPanel;
import mustic.models.gui.widgets.ClarffxDialog;
import org.jfree.chart.*;
import org.jfree.chart.entity.CategoryItemEntity;
import org.jfree.chart.labels.*;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.category.BarRenderer3D;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.RefineryUtilities;
import org.jfree.ui.TextAnchor;
import org.jfree.util.ShapeUtilities;
public class GoodScatterPlotChart extends JPanel {
private static final long serialVersionUID = 1L;
/** Panel d'affichage du nuage de points */
private ChartPanel chartPanel = null;
/** Le resultat a afficher */
private ClusteringResult result = null;
public GoodScatterPlotChart(Classification classification) {
this.setBackground(Color.WHITE);
this.result = classification.getClusteringResult();
double [][] Dist = MatrixDist(classification);
double [][] coordinates = PCOA(Dist,2);
updateChart(coordinates);
setLayout(new BorderLayout());
add(this.chartPanel, BorderLayout.NORTH);
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int card=0,totalCard=0,longueur=0,x=0;
// setLayout(new BorderLayout());
/* Le dataset qui contient les cardinalitees */
for (int i = 0; i < result.getNbClusters(); i++)
if (result.getCluster(i).isVisible()) {
Cluster cluster = result.getCluster(i);
card = cluster.getCard();
totalCard = totalCard+card;
}
for (int i = 0; i < result.getNbClusters(); i++)
if (result.getCluster(i).isVisible()) {
Cluster cluster = result.getCluster(i);
card = cluster.getCard();
longueur = (int)(card * this.getWidth())/totalCard;
g.setColor(result.getCluster(i).getColor());
g.fillRect(x, this.getHeight()-this.getHeight()/40,longueur, this.getHeight()/40);
g.drawString(Integer.toString(card), x+longueur/3, this.getHeight()-this.getHeight()/35);
x= x+longueur;
}
}
public double[][] MatrixDist(Classification classif) {
ClusteringResult clusteringResult = classif.getClusteringResult();
List <DataObject> obj = classif.getData().getViewDataObjects();
List<DataObject> clusterCenter = clusteringResult.getClusterCenters();
double[][] matriceObj = new double [obj.size()][obj.size()];
double[][] matriceCenter = new double[classif.getNbClusters()][obj.size()];
for(int i =0 ; i<obj.size() ; i++){
for(int j =0 ; j< obj.size() ; j++){
matriceObj[i][j] = obj.get(i).distance(obj.get(j), classif.getData().getDistanceModel(),
classif.getData().getDistanceParameters()[0]);
if (matriceObj[i][j] <0) {
throw new IllegalArgumentException("The disimilarity matrix is not positif.");
}
if(i==j && matriceObj[i][j] != 0 ) {
throw new IllegalArgumentException("The matrix diagonal values are not zeros.");
}
}
}
for(int i =0 ; i<obj.size() ; i++){
for(int j =0 ; j< obj.size() ; j++){
if (i!=j && matriceObj[i][j] != matriceObj[j][i]) {
throw new IllegalArgumentException("The disimilarity matrix is not symetric.");
}
for(int k =0 ; k< obj.size() ; k++){
if(k!=i && k!=j) {
if(matriceObj[i][j]> matriceObj[i][k]+matriceObj[k][j]) {
throw new IllegalArgumentException("The disimilarity matrix does not recpect triangular inegality.");
}
}
}
}
}
for(int i =0 ; i<classif.getNbClusters() ; i++){
for(int j =0 ; j< obj.size() ; j++){
matriceCenter[i][j] = clusterCenter.get(i).distance(obj.get(j), classif.getData().getDistanceModel(),
classif.getData().getDistanceParameters()[0]);
}
}
return matriceObj;
}
public double[] max (double[] eigenvalues) {
double max = eigenvalues[0];
int posmax=0;
for(int i=1 ; i < eigenvalues.length ; i++) {
if (eigenvalues[i] > max ) {
max=eigenvalues[i];
posmax=i;
}
}
double[] sortie = new double[2];
sortie[0] = max;
sortie[1]=posmax;
return sortie;
}
public double maxNegatifs (double[] eigenvalues) {
double maxNeg ;
int i =0;
while(i<eigenvalues.length && eigenvalues[i]>=0) {
i=i+1;
}
maxNeg = eigenvalues[i];
if(maxNeg<0) {
for (i=0 ; i < eigenvalues.length ; i++) {
if (eigenvalues[i] < 0 && eigenvalues[i] > maxNeg ) {
maxNeg=eigenvalues[i];
}
}
}
return maxNeg;
}
public double[][] Bmatrice(double[][] B , int n){
double sumColumns=0 , sum=0, meanB=0;
double[] mean = new double[n];
for (int i = 0; i < n; i++) {
sumColumns=0;
for (int j = 0; j < n; j++) {
sumColumns = sumColumns + B[i][j];
}
mean[i] = sumColumns/n;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
sum = sum + B[i][j];
}
}
meanB = sum/Math.pow(n,2);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
B[i][j] = -0.5 * ( B[i][j] - mean[i] - mean[j] + meanB);
}
}
return B;
}
public double[][] PCOA(double[][] disimilarity , int p){
int m = disimilarity.length;
int n = disimilarity[0].length;
if (m != n) {
throw new IllegalArgumentException("The disimilarity matrix is not square.");
}
if (p < 1 || p > 3) {
throw new IllegalArgumentException("Invalid p = " + p);
}
double[][] B = new double[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
B[i][j] = Math.pow(disimilarity[i][j],2);
}
}
double[][] coordinates = new double[n][p];
Matrix A = new Matrix(Bmatrice(B,n));
double[] eigenvalues;
EigenvalueDecomposition e = A.eig();
eigenvalues = e.getRealEigenvalues();
int compteur = 0 ,i=0;
while( i<n && compteur<p) {
if(eigenvalues[i] > 0) {
compteur ++;
}
}
if(compteur == p) {
Matrix V = e.getV();
double[] Max ;
for( i=0 ; i<p ; i++) {
Max = max(eigenvalues);
eigenvalues[(int)Max[1]] = Integer.MIN_VALUE;
for(int j=0; j<n;j++) {
coordinates[j][i] = V.get(j, (int)Max[1]) * Math.sqrt(Max[0]);
}
}
}
else {
//Lingos correction
//rechercher le max des valeurs propres negatives c
double c=0;
c = maxNegatifs(eigenvalues);
for ( i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
B[i][j] = B[i][j]+ 2 * Math.abs(c);
}
}
Matrix C = new Matrix(Bmatrice(B,n));
e = C.eig();
eigenvalues = e.getRealEigenvalues();
compteur = 0 ;
i=0;
while( i<n && compteur<p) {
if(eigenvalues[i] > 0) {
compteur ++;
}
}
if(compteur == p) {
Matrix V = e.getV();
double[] Max ;
for( i=0 ; i<p ; i++) {
Max = max(eigenvalues);
eigenvalues[(int)Max[1]] = Integer.MIN_VALUE;
for(int j=0; j<n;j++) {
coordinates[j][i] = V.get(j, (int)Max[1]) * Math.sqrt(Max[0]);
}
}
}
else {
System.out.println(" ici ok ok aie");
throw new IllegalArgumentException("Correction Lingos inefficace");
}
}
return coordinates;
}
public void updateChart(double [][] coordinates) {
int j;
int clusterMap[] = this.result.getClusterMap();
XYSeriesCollection result = new XYSeriesCollection();
XYSeries[] series= new XYSeries[this.result.getNbClusters()];
for(int i=0;i<this.result.getNbClusters();i++) {
XYSeries serie = new XYSeries(this.result.getCluster(i).getName());
series[i] =serie;
}
for (int i = 0; i < coordinates.length;i++) {
double x = coordinates[i][0];
double