Search in sources :

Example 6 with IParameters

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.IParameters in project clusterMaker2 by RBVI.

the class ParameterTraining_SE method run.

public IParameters run(ConnectedComponent cc) {
    boolean terminateTraining = false;
    /*
		 * initialise positions of the cc - the same initial positions are used
		 * for all training rounds
		 */
    ILayoutInitialiser li = layouterEnum.createLayoutInitialiser();
    li.initLayoutInitialiser(cc);
    li.run();
    /* run initial generation */
    IParameters[] initialGeneration = createInitialParameterGeneration();
    runOneGeneration(initialGeneration, cc, 0);
    terminateTraining = terminateTraining(initialGeneration);
    /* add the best 10 random configs to the bestConfigs collection Vector */
    for (int i = 0; i < 10; i++) {
        // TODO
        this.bestConfigs.add(initialGeneration[i]);
    }
    // System.out.println("terminate training? "+terminateTraining);
    /* run all following generations */
    IParameters[] generation;
    for (int i = 1; i <= this.noOfGenerations; i++) {
        if (terminateTraining) {
            break;
        }
        generation = createParameterGeneration();
        runOneGeneration(generation, cc, i);
        terminateTraining = terminateTraining(generation);
        for (int j = 0; j < this.generationSize / 2; j++) {
            this.bestConfigs.add(generation[j]);
        }
    }
    /* convert best configurations vector to array */
    IParameters[] bestConfigsArray = new IParameters[bestConfigs.size()];
    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];
    bestConfigsArray[0].setScore(0.0);
    return bestConfigsArray[0];
}
Also used : IParameters(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.IParameters) ILayoutInitialiser(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.ILayoutInitialiser)

Example 7 with IParameters

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.IParameters in project clusterMaker2 by RBVI.

the class GeneralParameterTraining method runOneGeneration.

private void runOneGeneration(IParameters[][] parameters, ArrayList<File> connectedComponents, int gen) throws InvalidInputFileException, InvalidTypeException {
    TaskConfig.monitor.setStatusMessage("Start training generation: " + gen);
    int size = parameters.length;
    /* do clustering for each set of parameter configurations */
    for (int i = 0; i < size; i++) {
        /* copy the cc (ConnectedComponent) ArrayList - shares same resources! */
        ArrayList<ConnectedComponent> newConnectedComponents = new ArrayList<ConnectedComponent>(connectedComponents.size());
        // for (int j = 0; j < connectedComponents.size(); j++) {
        // ConnectedComponent cc = new CostMatrixReader(connectedComponents.get(j)).getConnectedComponent();
        // ConnectedComponent newCC = cc.copy();
        /* sets a new positions array for the copy */
        // newCC.setCCPositions(cc.copyCCPositions());
        // newConnectedComponents.add(newCC);
        // }
        /* start clustering */
        clusteringManager.setConnectedComponents(connectedComponents);
        clusteringManager.setLayouterParameters(parameters[i]);
        clusteringManager.runClustering();
        FORCEnDParameters fndparam = (FORCEnDParameters) parameters[i][0];
        fndparam.printParamters();
        newConnectedComponents.clear();
    }
// log.debug("Finished training generation: "+gen);
}
Also used : FORCEnDParameters(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.forcend.FORCEnDParameters) ConnectedComponent(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.ConnectedComponent) ArrayList(java.util.ArrayList)

Example 8 with IParameters

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.IParameters in project clusterMaker2 by RBVI.

the class ClusteringManager method initParametersAndCCs.

/**
 * Sets transitive connected components file if in input directory. Finds all cost matrix files
 * given and creates a new {@link ConnectedComponent} instance for each and adds them to
 * the list of ConnectedComponents.
 *
 * Also initialises the {@link IParameters} from the input configuration.
 * @throws InvalidInputFileException
 */
public void initParametersAndCCs() throws InvalidInputFileException {
    if (TaskConfig.mode == TaskConfig.CLUSTERING_MODE || TaskConfig.mode == TaskConfig.GENERAL_TRAINING_MODE) {
        // this.connectedComponents = new ArrayList<ConnectedComponent>();
        this.connectedComponents = new ArrayList<File>();
        TaskConfig.transitiveConnectedComponents = null;
        /* read the input file or directory */
        File cmFile = new File(this.cmPath);
        if (cmFile.isDirectory()) {
            log.finer("Input is a directory!");
            /* get all files in the directory */
            File[] files = cmFile.listFiles();
            /* check boolean whether cm files exist in directory */
            boolean noCostMatrices = true;
            boolean noTCCfile = true;
            for (int i = 0; i < files.length; i++) {
                String filePath = files[i].toString();
                /* find tcc file in directory */
                if (filePath.endsWith(".tcc") || filePath.endsWith(".rtcc")) {
                    noTCCfile = false;
                    TaskConfig.transitiveConnectedComponents = filePath;
                    log.info("Transitive connected components file: " + filePath);
                    InfoFile.appendToProjectDetails("Transitive connected component file: " + filePath);
                }
                /* find cm files*/
                if (files[i].toString().endsWith(".cm") || files[i].toString().endsWith(".rcm")) {
                    // cm files exist
                    noCostMatrices = false;
                    connectedComponents.add(files[i]);
                // create the connected component (cc) object and add to list
                // CostMatrixReader cmReader = new CostMatrixReader(files[i]);
                // ConnectedComponent cc = cmReader.getConnectedComponent();
                // connectedComponents.add(cc);
                }
            }
            if (noCostMatrices) {
                if (noTCCfile) {
                    throw new InvalidInputFileException("There are no cost matrix " + "files in the input directory and also no transitive connected components file, " + "or check whether the file extensions equal .cm, .rcm, or .tcc");
                }
            }
        } else {
            /* only one cost matrix file is given */
            log.finer("One cm file given");
            /* only one cost matrix as input - start clustering process */
            if (!cmFile.toString().endsWith(".tcc")) {
                // create the connected component (cc) object and add to list
                // CostMatrixReader cmReader = new CostMatrixReader(cmFile);
                // ConnectedComponent cc = cmReader.getConnectedComponent();
                // connectedComponents.add(cc);
                connectedComponents.add(cmFile);
            } else {
                if (cmFile.toString().endsWith(".tcc")) {
                    TaskConfig.transitiveConnectedComponents = cmFile.toString();
                    log.info("Only a transitive connected component file is given: " + cmFile.toString());
                    InfoFile.appendToProjectDetails("Only a transitive connected component file is given: " + cmFile.toString() + ". Therefore NO CLUSTERING IS PERFORMED, just the the " + "clusters from the TCC file are written into the clusters file.");
                } else {
                    throw new InvalidInputFileException("Either the input cost matrix is of " + "wrong file type. The file extension should be \".cm\" or \".rcm\"," + "or in the given TCC file is of the wrong type and should be \".tcc\".");
                }
            }
        }
    }
    /* initialise parameters from config */
    // LayoutFactory.EnumLayouterClass[] layouterEnumTypes = TaskConfig.layouterEnumTypes;
    layouterParameters = new IParameters[TaskConfig.layouterEnumTypes.length];
    for (int i = 0; i < TaskConfig.layouterEnumTypes.length; i++) {
        IParameters param = TaskConfig.layouterEnumTypes[i].createIParameters();
        param.readParametersFromConfig();
        layouterParameters[i] = param;
    }
    if (this.connectedComponents == null) {
    }
}
Also used : IParameters(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.IParameters) InfoFile(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.io.InfoFile) ClusterFile(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.io.ClusterFile) File(java.io.File)

Example 9 with IParameters

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.IParameters 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();
// }
}
Also used : IParameters(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.IParameters) IParameterTraining(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.parameter_training.IParameterTraining)

Example 10 with IParameters

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.IParameters 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;
}
Also used : IParameters(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.IParameters) ConnectedComponent(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.ConnectedComponent) ArrayList(java.util.ArrayList) CostMatrixReader(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.CostMatrixReader) Semaphore(java.util.concurrent.Semaphore) ClusterFile(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.io.ClusterFile)

Aggregations

IParameters (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.IParameters)12 ConnectedComponent (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.ConnectedComponent)5 ILayoutInitialiser (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.ILayoutInitialiser)5 IGeometricClusterer (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.geometric_clustering.IGeometricClusterer)3 ILayouter (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.ILayouter)3 FORCEnDParameters (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.forcend.FORCEnDParameters)3 IPostProcessing (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.postprocessing.IPostProcessing)3 ArrayList (java.util.ArrayList)3 CostMatrixReader (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.CostMatrixReader)2 FixedParameterClusterer (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.fixedparameterclustering.FixedParameterClusterer)2 GreedyClusterer (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.greedy.GreedyClusterer)2 PP_DivideAndRecluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.postprocessing.PP_DivideAndRecluster)2 PostProcessingFactory (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.postprocessing.PostProcessingFactory)2 ClusterFile (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.io.ClusterFile)2 InfoFile (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.io.InfoFile)2 File (java.io.File)2 IteratorThread (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.iterativeclustering.IteratorThread)1 IParameterTraining (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.parameter_training.IParameterTraining)1 ClusterTrainingTask (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.ClusterTrainingTask)1 Date (java.util.Date)1