use of edu.ucsf.rbvi.clusterMaker2.internal.ui.ScatterPlotDialog in project clusterMaker2 by RBVI.
the class RunPCA method runOnNodeToAttributeMatrix.
// this method assumes that eigen values
// are sorted in increasing order
public void runOnNodeToAttributeMatrix() {
// System.out.println("runOnNodeToAttributeMatrix");
CyMatrix matrix = CyMatrixFactory.makeLargeMatrix(network, weightAttributes, context.selectedOnly, context.ignoreMissing, false, false);
// System.out.println("Computing principle components");
components = computePCs(matrix);
final Matrix loadingMatrix = calculateLoadingMatrix(matrix);
if (context.pcaResultPanel) {
CyServiceRegistrar registrar = manager.getService(CyServiceRegistrar.class);
CySwingApplication swingApplication = manager.getService(CySwingApplication.class);
ResultPanelPCA panel = new ResultPanelPCA(components, variance, network, networkView);
CytoPanel cytoPanel = swingApplication.getCytoPanel(CytoPanelName.EAST);
registrar.registerService(panel, CytoPanelComponent.class, new Properties());
if (cytoPanel.getState() == CytoPanelState.HIDE)
cytoPanel.setState(CytoPanelState.DOCK);
}
if (context.pcaPlot) {
if (components.length < 2) {
monitor.showMessage(TaskMonitor.Level.ERROR, "Only found " + components.length + " components. Need 2 for scatterplot. " + "Perhaps minimum variance is set too high?");
return;
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// System.out.println("Scatter plot dialog call");
ScatterPlotDialog dialog = new ScatterPlotDialog(manager, "PCA", monitor, components, loadingMatrix, variance);
}
});
}
}
use of edu.ucsf.rbvi.clusterMaker2.internal.ui.ScatterPlotDialog in project clusterMaker2 by RBVI.
the class RunPCoA method run.
public void run() {
long startTime = System.currentTimeMillis();
long time = startTime;
// System.out.println("Calculating values");
// double data[][]=matrix.toArray();
// System.out.println("Length "+ distanceMatrix.nRows());
//
distanceMatrix.updateMinMax();
double max = distanceMatrix.getMaxValue() * 10;
// the way the initial matrix is built. Set those to Double.MAX.
for (int row = 0; row < distanceMatrix.nRows(); row++) {
for (int col = 0; col < distanceMatrix.nColumns(); col++) {
double value = distanceMatrix.doubleValue(row, col);
if (value == 0.0 || Double.isNaN(value))
distanceMatrix.setValue(row, col, max);
}
}
Matrix mean = distanceMatrix.like(distanceMatrix.nColumns(), 1);
// TODO: center the matrix?
for (int j = 0; j < mean.nRows(); j++) {
mean.setValue(j, 0, CommonOps.columnMean(distanceMatrix, j));
}
for (int i = 0; i < distanceMatrix.nRows(); i++) {
for (int j = 0; j < distanceMatrix.nColumns(); j++) {
distanceMatrix.setValue(i, j, distanceMatrix.doubleValue(i, j) - mean.doubleValue(j, 0));
}
}
// System.out.println("Checking CyMatrix symmetrical "+distanceMatrix.isSymmetrical());
monitor.showMessage(TaskMonitor.Level.INFO, "Calculating Gower's Matrix");
// Get the Gower's Matrix
Matrix G = GowersMatrix.getGowersMatrix(distanceMatrix);
long delta = System.currentTimeMillis() - time;
time = System.currentTimeMillis();
monitor.showMessage(TaskMonitor.Level.INFO, "Constructed Gower's Matrix in " + delta + "ms");
monitor.showMessage(TaskMonitor.Level.INFO, "Doing Singlular Value Decomposition (SVD)");
// System.out.println("Got GowersMatrix in "+delta+"ms");
G.ops().svdInit();
Matrix V_t = CommonOps.transpose(G.ops().svdV());
// Get the singular values
Matrix S = G.ops().svdS();
double[] variances = getVariance(S);
V_t = reshape(V_t, 2, mean.nRows());
double[][] trafoed = new double[distanceMatrix.nRows()][2];
result = CyMatrixFactory.makeLargeMatrix(distanceMatrix.getNetwork(), distanceMatrix.nRows(), 2);
result.setRowNodes(distanceMatrix.getRowNodes());
result.setRowLabels(Arrays.asList(distanceMatrix.getRowLabels()));
result.setColumnLabel(0, "X");
result.setColumnLabel(1, "Y");
for (int i = 0; i < distanceMatrix.nRows(); i++) {
trafoed[i] = sampleToEigenSpace(V_t, distanceMatrix, mean, i);
for (int j = 0; j < trafoed[i].length; j++) {
result.setValue(i, j, trafoed[i][j] *= -1);
}
}
delta = System.currentTimeMillis() - time;
time = System.currentTimeMillis();
monitor.showMessage(TaskMonitor.Level.INFO, "Completed SVD Analysis in " + delta + "ms");
monitor.showMessage(TaskMonitor.Level.INFO, String.format("Variance explained by first three axes: %2.2f%%, %2.2f%%, and %2.2f%%", variances[0], variances[1], variances[2]));
if (context.pcoaPlot) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// System.out.println("Scatter plot dialog call");
ScatterPlotDialog dialog = new ScatterPlotDialog(manager, "PCoA", monitor, result);
}
});
}
}
use of edu.ucsf.rbvi.clusterMaker2.internal.ui.ScatterPlotDialog in project clusterMaker2 by RBVI.
the class RuntSNE method run.
public void run() {
context.cancelled = false;
context.setXin(matrix.toArray());
TSne tsne;
// System.out.println("Is Symmetrical "+matrix.isSymmetrical());
if (context.useBarnesHut) {
monitor.setTitle("Running t-Distributed Stochastic Neighbor (tSNE) using Barnes-Hut approximation");
tsne = new BHTSne();
} else {
monitor.setTitle("Running t-Distributed Stochastic Neighbor (tSNE)");
tsne = new FastTSne();
}
double[][] result = tsne.tsne(context, monitor);
if (result == null && context.cancelled) {
monitor.setStatusMessage("Cancelled by user");
return;
}
Y = matrix.copy();
Y.initialize(result.length, result[0].length, result);
if (context.showScatterPlot) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
ScatterPlotDialog dialog = new ScatterPlotDialog(manager, "tSNE", monitor, Y);
}
});
}
}
Aggregations