use of edu.ucsf.rbvi.clusterMaker2.internal.api.Matrix in project clusterMaker2 by RBVI.
the class FCMCluster method run.
/**
* The method run creates an instance of the RunFCM and creates the fuzzy clusters by applying the fuzzy c means algorithm.
* Also creates fuzzy groups and the Fuzzy Cluster Table
*
* @param Task Monitor
*/
public void run(TaskMonitor taskmonitor) {
this.monitor = taskmonitor;
monitor.setTitle("Performing FCM cluster");
if (network == null)
network = clusterManager.getNetwork();
// Make sure to update the context
context.setNetwork(network);
Long networkID = network.getSUID();
CyTable netAttributes = network.getDefaultNetworkTable();
CyTable nodeAttributes = network.getDefaultNodeTable();
CyTable edgeAttributes = network.getDefaultEdgeTable();
distanceMatrix = context.edgeAttributeHandler.getMatrix();
if (distanceMatrix == null) {
monitor.showMessage(TaskMonitor.Level.ERROR, "Can't get distance matrix: no attribute value?");
return;
}
createGroups = context.advancedAttributes.createGroups;
// Update our tunable results
clusterAttributeName = "CnC_Bicluster";
// distanceDataMatrix = new Matrix(network,0,0);
// distanceDataMatrix.buildDistanceMatrix(distanceMatrix);
distanceDataMatrix = distanceMatrix.copy();
if (context.estimateClusterNumber && context.cNumber < 0) {
// System.out.println("Estimated number of Clusters: "+ cEstimate);
context.cNumber = cEstimate();
}
int[] mostRelevantCluster = new int[network.getNodeList().size()];
FuzzyNodeCluster.fuzzyClusterCount = 0;
runFCM = new RunFCM(distanceMatrix, context.iterations, context.cNumber, context.fIndex, context.beta, context.membershipThreshold.getValue(), context.maxThreads, this.monitor);
runFCM.setDebug(debug);
if (canceled)
return;
monitor.showMessage(TaskMonitor.Level.INFO, "Clustering...");
List<FuzzyNodeCluster> clusters = runFCM.run(network, monitor, mostRelevantCluster);
// Canceled?
if (clusters == null)
return;
monitor.showMessage(TaskMonitor.Level.INFO, "Removing groups");
// Remove any leftover groups from previous runs
removeGroups(network, GROUP_ATTRIBUTE);
monitor.showMessage(TaskMonitor.Level.INFO, "Creating groups");
params = new ArrayList<String>();
context.edgeAttributeHandler.setParams(params);
List<List<CyNode>> nodeClusters = createFuzzyGroups(network, clusters, GROUP_ATTRIBUTE);
results = new AbstractClusterResults(network, clusters);
monitor.showMessage(TaskMonitor.Level.INFO, "Done. FCM results:\n" + results);
if (context.vizProperties.showUI) {
monitor.showMessage(TaskMonitor.Level.INFO, "Creating network");
insertTasksAfterCurrentTask(new NewNetworkView(network, clusterManager, true, context.vizProperties.restoreEdges, !selectedOnly));
} else {
monitor.showMessage(TaskMonitor.Level.INFO, "Done. FCM results:\n" + results);
}
createFuzzyTable(clusters);
}
use of edu.ucsf.rbvi.clusterMaker2.internal.api.Matrix in project clusterMaker2 by RBVI.
the class CyColtMatrix method getDistanceMatrix.
public CyMatrix getDistanceMatrix(DistanceMetric metric) {
CyColtMatrix dist = new CyColtMatrix(network, nRows, nRows);
if (rowNodes != null) {
dist.rowNodes = Arrays.copyOf(rowNodes, nRows);
dist.columnNodes = Arrays.copyOf(rowNodes, nRows);
}
Matrix cMatrix = super.getDistanceMatrix(metric);
return dist.copy(cMatrix);
}
use of edu.ucsf.rbvi.clusterMaker2.internal.api.Matrix in project clusterMaker2 by RBVI.
the class CyMatrixFactory method makeTypedMatrix.
private static CyMatrix makeTypedMatrix(CyNetwork network, int rows, int columns, boolean transpose, MatrixType type) {
int nrows = rows;
int ncolumns = columns;
if (transpose) {
nrows = columns;
ncolumns = rows;
}
CyMatrix matrix = null;
switch(type) {
case SIMPLE:
matrix = new CySimpleMatrix(network, nrows, ncolumns);
break;
// For now, we use Colt for both large and sparse matrices
case COLT:
case SPARSE:
matrix = new CyColtMatrix(network, nrows, ncolumns);
break;
case LARGE:
case OJALGO:
matrix = new CyOjAlgoMatrix(network, nrows, ncolumns);
break;
}
matrix.setTransposed(transpose);
return matrix;
}
use of edu.ucsf.rbvi.clusterMaker2.internal.api.Matrix in project clusterMaker2 by RBVI.
the class CyMatrixFactory method makeLargeMatrix.
/**
* Create a large, possibly sparse matrix populated with data from
* the indicated edge attribute
*
* @param network the network that will be the source of the data
* @param edgeAttribute the edge attribute to pull the data from
* @param selectedOnly only include selected edges
* @param converter the edge weight converter to use
* @param unDirected if true, the edges are undirected
* @param cutOff the minimum edge value to consider
* @return the resulting matrix
*/
public static CyMatrix makeLargeMatrix(CyNetwork network, String edgeAttribute, boolean selectedOnly, EdgeWeightConverter converter, boolean unDirected, double cutOff) {
List<CyNode> nodes;
List<CyEdge> edges;
double maxAttribute = Double.MIN_VALUE;
double minAttribute = Double.MAX_VALUE;
if (!selectedOnly) {
nodes = network.getNodeList();
edges = network.getEdgeList();
} else {
nodes = new ArrayList<CyNode>();
edges = new ArrayList<CyEdge>();
nodes.addAll(CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, true));
edges.addAll(ModelUtils.getConnectingEdges(network, nodes));
}
CyMatrix matrix = makeTypedMatrix(network, nodes.size(), nodes.size(), false, MatrixType.LARGE);
matrix.setRowNodes(nodes);
matrix.setColumnNodes(nodes);
Map<CyNode, Integer> nodeMap = new HashMap<CyNode, Integer>(nodes.size());
for (int row = 0; row < nodes.size(); row++) {
CyNode node = nodes.get(row);
nodeMap.put(node, row);
matrix.setRowLabel(row, ModelUtils.getNodeName(network, node));
matrix.setColumnLabel(row, ModelUtils.getNodeName(network, node));
}
matrix.setSymmetrical(unDirected);
CyTable edgeAttributes = network.getDefaultEdgeTable();
// First, we need the min and max values for our converter
if (edgeAttributes.getColumn(edgeAttribute) == null) {
minAttribute = 1.0;
maxAttribute = 1.0;
} else {
for (CyEdge edge : edges) {
if (network.getRow(edge).getRaw(edgeAttribute) == null)
continue;
double edgeWeight = ModelUtils.getNumericValue(network, edge, edgeAttribute);
if (edgeWeight < cutOff)
continue;
minAttribute = Math.min(minAttribute, edgeWeight);
maxAttribute = Math.max(maxAttribute, edgeWeight);
}
}
for (CyEdge edge : edges) {
double value;
if (minAttribute == 1.0 && maxAttribute == 1.0) {
value = 1.0;
} else {
Double val = ModelUtils.getNumericValue(network, edge, edgeAttribute);
if (val == null)
continue;
value = val.doubleValue();
}
double weight = converter.convert(value, minAttribute, maxAttribute);
if (weight < cutOff)
continue;
int sourceIndex = nodeMap.get(edge.getSource());
int targetIndex = nodeMap.get(edge.getTarget());
matrix.setValue(targetIndex, sourceIndex, weight);
// TODO: should we consider maybe doing this on the getValue side?
if (unDirected)
matrix.setValue(sourceIndex, targetIndex, weight);
}
// System.out.println("distance matrix: "+matrix.printMatrix());
return matrix;
}
use of edu.ucsf.rbvi.clusterMaker2.internal.api.Matrix in project clusterMaker2 by RBVI.
the class CyOjAlgoMatrix method getDistanceMatrix.
public CyMatrix getDistanceMatrix(DistanceMetric metric) {
CyOjAlgoMatrix dist = new CyOjAlgoMatrix(network, nRows, nRows);
if (rowNodes != null) {
dist.rowNodes = Arrays.copyOf(rowNodes, nRows);
dist.columnNodes = Arrays.copyOf(rowNodes, nRows);
}
Matrix cMatrix = super.getDistanceMatrix(metric);
return dist.copy(cMatrix);
}
Aggregations