use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidInputFileException 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;
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidInputFileException in project clusterMaker2 by RBVI.
the class ClusteringManagerTask method run.
public void run() {
try {
TaskConfig.monitor.setStatusMessage("-----------------------------------");
TaskConfig.monitor.setStatusMessage("Running ... " + TaskConfig.NAME + " v" + TaskConfig.VERSION);
Date date = new Date(System.currentTimeMillis());
TaskConfig.monitor.setStatusMessage(date.toString());
TaskConfig.monitor.setStatusMessage("-----------------------------------");
if (TaskConfig.mode == TaskConfig.CLUSTERING_MODE) {
long time = System.currentTimeMillis();
this.clusterManager = new ClusteringManager(TaskConfig.cmPath);
try {
this.clusterManager.initParametersAndCCs();
this.clusterManager.runClustering();
// System.out.println(this.clusterManager.getConnectedComponents().size());
time = System.currentTimeMillis() - time;
TaskConfig.monitor.setStatusMessage("Time taken for complete clustering process: " + TaskUtility.convertTime(time));
} catch (InvalidInputFileException e) {
TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, e.getMessage());
// e.printStackTrace();
System.exit(-1);
} catch (InvalidTypeException e) {
TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, e.getMessage());
// e.printStackTrace();
System.exit(-1);
}
} else /* start general training */
if (TaskConfig.mode == TaskConfig.GENERAL_TRAINING_MODE) {
try {
long time = System.currentTimeMillis();
ClusteringManager clustermanage = new ClusteringManager(TaskConfig.cmPath);
GeneralParameterTraining generalParameterTraining = new GeneralParameterTraining(clustermanage);
IParameters[] layoutParams = generalParameterTraining.runGeneralTraining();
/* save newly found parameters to config file */
TaskConfig.saveConfigurationsToConfigFile(TaskConfig.outConfigPath);
/* print out information about training */
TaskConfig.monitor.setStatusMessage(TaskConfig.NL + "###### Best Parameter Configurations Found ######");
for (int i = 0; i < layoutParams.length; i++) {
TaskConfig.monitor.setStatusMessage(layoutParams[i].toString());
InfoFile.appendLnProjectResults(layoutParams[i].toString());
}
time = System.currentTimeMillis() - time;
TaskConfig.monitor.setStatusMessage("Time taken for complete general training: " + TaskUtility.convertTime(time));
} catch (InvalidInputFileException e) {
TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, e.getMessage());
// e.printStackTrace();
} catch (InvalidTypeException e) {
TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, e.getMessage());
// e.printStackTrace();
}
} else if (TaskConfig.mode == TaskConfig.COMPARISON_MODE || TaskConfig.mode == TaskConfig.HIERARICHAL_MODE) {
Thread t = new IteratorThread();
t.start();
} else /* no such mode */
{
TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, "ERROR: This mode does not exist: " + TaskConfig.mode);
}
/* create info file */
if (TaskConfig.info) {
InfoFile info = new InfoFile();
info.instantiateFile(TaskConfig.infoPath);
info.createAndCloseInfoFile();
/* clear information from StringBuffers in InfoFile */
InfoFile.clearData();
}
// /* ====== CLEAN UP AT END ====== */
} catch (Exception e) {
TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, "ERROR occured in run with the following message: " + e.getMessage());
// e.printStackTrace();
}
/* release permit in semaphore if necessary */
if (semaphore != null) {
semaphore.release();
}
/* reset the run button back to "RUN" and reset action command */
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidInputFileException in project clusterMaker2 by RBVI.
the class GeneralParameterTraining method runGeneralTraining.
/**
* Starts the general parameter training using a simple evolutionary method
* for the whole input directory (or just one file if
* this was given). Saves the best found parameters of each layout algorithm to the
* respective config classes. But does not create a config file.
*
* @return The best set of IParameters as an Array.
* @throws InvalidInputFileException If the input file/directory is somehow
* incorrect or cannot be read.
* @throws InvalidTypeException If an method type does not exist or hasn't
* been included properly.
*/
public IParameters[] runGeneralTraining() throws InvalidInputFileException, InvalidTypeException {
/* initialise connected components and parameters */
this.clusteringManager.initParametersAndCCs();
ArrayList<File> connectedComponents = clusteringManager.getConnectedComponents();
/*
* initialise positions of the cc with respect to the FIRST layouter - the same
* initial positions are used for all training rounds
*/
for (File cc : connectedComponents) {
ILayoutInitialiser li = TaskConfig.layouterEnumTypes[0].createLayoutInitialiser();
li.initLayoutInitialiser(new CostMatrixReader(cc).getConnectedComponent());
li.run();
}
boolean terminateTraining = false;
/* run initial generation */
IParameters[][] initialGeneration = createInitialParameterGeneration();
runOneGeneration(initialGeneration, connectedComponents, 0);
terminateTraining = terminateTraining(initialGeneration);
/* add the best 10 random configs to the bestConfigs collection Vector */
for (int i = 0; i < initialGeneration.length; i++) {
this.bestConfigs.add(initialGeneration[i]);
}
/* run all following generations */
IParameters[][] generation;
for (int i = 1; i <= this.noOfGenerations; i++) {
if (terminateTraining) {
break;
}
generation = createParameterGeneration();
runOneGeneration(generation, connectedComponents, i);
terminateTraining = terminateTraining(generation);
for (int j = 0; j < this.generationSize / 2; j++) {
this.bestConfigs.add(initialGeneration[j]);
}
}
/* convert best configurations vector to array */
IParameters[][] bestConfigsArray = new IParameters[bestConfigs.size()][TaskConfig.layouterEnumTypes.length];
for (int i = 0; i < bestConfigs.size(); i++) {
bestConfigsArray[i] = bestConfigs.get(i);
}
/*
* sort the IParameters array according to their score and return the
* best parameter set.
*/
Arrays.sort(bestConfigsArray, this.paramComparator);
this.bestPreviousIParameters = bestConfigsArray[0];
for (int i = 0; i < bestConfigsArray[0].length; i++) {
bestConfigsArray[0][i].saveParametersToConfig();
}
for (int i = 0; i < 30; i++) {
FORCEnDParameters ip = (FORCEnDParameters) bestConfigsArray[i][0];
ip.printParamters();
}
return bestConfigsArray[0];
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidInputFileException in project clusterMaker2 by RBVI.
the class Console method parseArgsAndInitProgram.
/**
* This method parses the input parameters from the console and starts the
* program with the correct parameters and in the correct mode. At this
* stage all input parameters are in this form: key value. Both key and
* value contain no spaces and if the value does, then it is bounded by
* apostrophes.
*
* @throws InvalidInputFileException
* @throws ArgsParseException
* @throws IOException
*/
private void parseArgsAndInitProgram() throws InvalidInputFileException, ArgsParseException, IOException {
boolean inputAndOutputGiven = findAndReadConfigIfGivenAndSetMode();
initGivenParameters();
if (TaskConfig.gui) {
/* start gui with previous set parameters */
} else if (inputAndOutputGiven && !TaskConfig.gui) {
ClusteringManagerTask manageTask = new ClusteringManagerTask();
// run without initialising new thread.
manageTask.run();
} else {
/* either input or output is missing */
throw new ArgsParseException("Either input file/directory (-i) or output file (-o) is missing!");
}
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.InvalidInputFileException in project clusterMaker2 by RBVI.
the class Console method findAndReadConfigIfGivenAndSetMode.
/**
* Looks through the input variables to see if a config file is defined. If
* so all parameters are read from this config file. If some do not exist, a
* warning is given, but the program continues. It may be the case that
* these parameters are unwanted or belong to an unused implementation. It
* also looks if a mode was given and sets this, otherwise the default is
* used.
*
* It also checks whether input AND output files/directories are given,
* which is compulsory when starting with the console and not with the gui.
*
* @return boolean value if an input and an output file (both) are given.
* @throws InvalidInputFileException
* If the given config class does not end in .conf.
*/
private boolean findAndReadConfigIfGivenAndSetMode() throws InvalidInputFileException, ArgsParseException {
boolean input = false;
boolean output = false;
String configPath = TaskConfig.DEFAULTCONFIG;
for (int i = 0; i < args.length; i++) {
/* check whether an input file is given */
if (args[i].trim().equals("-i")) {
input = true;
++i;
}
if (args[i].trim().equals("-o")) {
output = true;
++i;
}
/* check for mode parameter */
if (args[i].trim().equals("-mode")) {
String value = args[i + 1].trim();
try {
int md = Integer.parseInt(value);
if (md == TaskConfig.GENERAL_TRAINING_MODE) {
TaskConfig.mode = TaskConfig.GENERAL_TRAINING_MODE;
} else if (md == TaskConfig.CLUSTERING_MODE) {
TaskConfig.mode = TaskConfig.CLUSTERING_MODE;
} else if (md == TaskConfig.COMPARISON_MODE) {
TaskConfig.mode = TaskConfig.COMPARISON_MODE;
} else if (md == TaskConfig.HIERARICHAL_MODE) {
TaskConfig.mode = TaskConfig.HIERARICHAL_MODE;
} else {
throw new ArgsParseException("The given mode is incorrect - it does not exist! " + md);
}
} catch (Exception e) {
throw new ArgsParseException("The given mode is not an interger value: " + value);
}
++i;
}
/* check for config parameter */
if (args[i].trim().equals("-config")) {
String value = args[i + 1].trim();
if (value.endsWith(".conf")) {
TaskConfig.useConfigFile = true;
TaskConfig.inputConfigPath = value;
configPath = value;
} else {
throw new InvalidInputFileException("An invalid config file was entered. The file must end with '.conf'. Please try again! Given file=" + value);
}
++i;
}
/* check for if -cf parameter is set */
if (args[i].trim().equals("-cf")) {
TaskConfig.useConfigFile = Boolean.parseBoolean(args[i + 1].trim());
++i;
}
}
if (TaskConfig.useConfigFile) {
try {
FileInputStream s = new FileInputStream(configPath);
PropertyResourceBundle configrb = new PropertyResourceBundle(s);
// log.debug("Using config file " + configPath);
TaskConfig.initFromConfigFile(configrb);
FORCEnDLayoutConfig.initFromConfigFile(configrb);
GeometricClusteringConfig.initSLCFromConfigFile(configrb);
GeometricClusteringConfig.initKmeansFromConfigFile(configrb);
} catch (MissingResourceException ex) {
TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, "WARNING: Resources are missing in the given config file: " + TaskConfig.DEFAULTCONFIG + ", key=" + ex.getKey() + ". Either you have defined these parameters in the input, or the default values are used from the " + TaskConfig.DEFAULTCONFIG + ". Or these parameters do not interest you, because they belong to an unused implemtation.");
} catch (IOException ex) {
TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, "ERROR: Unable to read the given config file: " + configPath);
System.exit(-1);
} catch (InvalidTypeException ex) {
TaskConfig.monitor.showMessage(TaskMonitor.Level.ERROR, "ERROR: You have perhaps given an incorrect class name of an " + "implemtation. Please note that this is case sensitive.");
System.exit(-1);
}
}
if (input && output)
return true;
else
return false;
}
Aggregations