use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.io.ClusterFile in project clusterMaker2 by RBVI.
the class ClusteringManager method runClusteringForOneConnectedComponent.
/**
* Runs clustering for one {@link ConnectedComponent} and sets the total score to
* the parameters if in the general training mode.
* @param cc The connected component object.
* @param clusterFile The clusters file (null if in general training mode)
* @param semaphore The Semaphore to give to the clustering task to keep track of it.
* @param time
* @throws InvalidInputFileException
*/
public void runClusteringForOneConnectedComponent(ConnectedComponent cc, ClusterFile clusterFile, Semaphore semaphore, Semaphore maxThreadSemaphore, long time) throws InvalidInputFileException {
/* check whether layouterParameters has been initialised */
if (this.layouterParameters == null) {
if (TaskConfig.mode == TaskConfig.CLUSTERING_MODE || TaskConfig.mode == TaskConfig.GENERAL_TRAINING_MODE)
log.warning("Incorrect use of the ClusteringManager, the layouter parameters list" + "hadn't been initialised. Called method to initialise this and the connected components from " + "the config");
this.initParametersAndCCs();
}
// if(TaskConfig.mode == TaskConfig.CLUSTERING_MODE){
if (TaskConfig.doLayoutParameterTraining && !TaskConfig.greedy) {
for (int i = 0; i < this.layouterParameters.length; i++) {
/* start parameter training for the cc */
IParameterTraining paramTrain = TaskConfig.parameterTrainingEnum.createParameterTrainer();
paramTrain.initialise(TaskConfig.layouterEnumTypes[i], TaskConfig.noOfParameterConfigurationsPerGeneration, TaskConfig.noOfGenerations);
paramTrain.setMaxThreadSemaphoreAndThreadsList(maxThreadSemaphore, this.allThreads);
IParameters bestparam = paramTrain.run(cc);
log.fine("PARAMETER TRAINING RESULT\n: " + cc.getCcPath() + "\n" + bestparam.toString());
this.layouterParameters[i] = bestparam;
}
}
// }
/* run clustering with the previously determined parameters */
ClusteringTask clusterTask = new ClusteringTask(cc, this.layouterParameters, TaskConfig.layouterEnumTypes, clusterFile);
clusterTask.setTime(time);
// if(!TaskConfig.doLayoutParameterTraining&&TaskConfig.useThreads){
// clusterTask.setSemaphore(semaphore);
// Thread t = new Thread(clusterTask);
// clusterTask.setMaxThreadSemaphore(maxThreadSemaphore, allThreads, t);
// t.start();
// }else{
clusterTask.run();
// }
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.io.ClusterFile in project clusterMaker2 by RBVI.
the class ClusteringManager method runClustering.
/**
* Runs the clustering with the given configurations in the config class: {@link TaskConfig}.
* Clusters each {@link ConnectedComponent} separately and waits until all are done.
* Differes between the modes clustering and general training. Creates a Config file if
* the training mode is used.
* @throws InvalidInputFileException If the file/directory given produces an error.
* @throws InvalidTypeException An incorrect method implementation was given, or some
* other error occured with this.
*/
public void runClustering() throws InvalidInputFileException, InvalidTypeException {
/* initialise ClusterFile if in clustering mode */
ClusterFile clusterFile = null;
if (TaskConfig.mode == TaskConfig.CLUSTERING_MODE) {
log.fine("Running clustering in clustering mode!");
clusterFile = new ClusterFile();
clusterFile.instantiateFile(TaskConfig.clustersPath);
clusterFile.printPreProcessingClusters(TaskConfig.transitiveConnectedComponents);
/* check whether connectedComponents has been initialised */
if (this.connectedComponents == null) {
if (TaskConfig.transitiveConnectedComponents == null) {
log.warning("Incorrect use of the ClusteringManager, the connected components list" + "hadn't been initialised. Called method to initialise this and the parameters from " + "the config. Or only a TCC file was given and no connected components.");
this.initParametersAndCCs();
} else {
log.info("No cost matrices were given, just a transitive connected components file, which" + "is converted to a clusters file. NO CLUSTERING IS PERFORMED!");
InfoFile.appendToProjectDetails("No cost matrices were given, just a transitive connected components file, which" + "is converted to a clusters file. NO CLUSTERING IS PERFORMED!");
}
}
}
if (this.connectedComponents != null) {
/* go through cc list and start training for each and control thread use */
ArrayList<Semaphore> allSemaphores = new ArrayList<Semaphore>();
Semaphore maxThreadSemaphore = new Semaphore(TaskConfig.maxNoThreads, true);
for (int i = 0; i < this.connectedComponents.size(); i++) {
Semaphore semaphore = new Semaphore(1);
allSemaphores.add(semaphore);
long time = System.currentTimeMillis();
CostMatrixReader cmReader = new CostMatrixReader(this.connectedComponents.get(i));
ConnectedComponent cc = cmReader.getConnectedComponent();
runClusteringForOneConnectedComponent(cc, clusterFile, semaphore, maxThreadSemaphore, time);
}
/* wait for all clustering tasks to finish */
for (Semaphore s : allSemaphores) {
try {
s.acquire();
} catch (InterruptedException e) {
log.severe(e.getMessage());
e.printStackTrace();
}
}
}
if (clusterFile != null)
clusterFile.closeFile();
/* END OF CLUSTERING */
log.info("Clustering scores sum: " + totalScoreSum);
if (TaskConfig.mode == TaskConfig.CLUSTERING_MODE) {
InfoFile.appendLnProjectResults("Total sum of clustering scores for given input: " + TaskUtility.round(totalScoreSum, 2));
}
/* set score to IParameters objects for general training mode */
if (TaskConfig.mode == TaskConfig.GENERAL_TRAINING_MODE) {
log.fine("Setting parameters score for training mode!");
for (IParameters parameter : this.layouterParameters) {
parameter.setScore(totalScoreSum);
}
}
totalScoreSum = 0;
}
Aggregations