List of usage examples for org.apache.commons.configuration2.builder FileBasedConfigurationBuilder FileBasedConfigurationBuilder
public FileBasedConfigurationBuilder(final Class<? extends T> resCls)
From source file:imp.lstm.main.Driver.java
public static void main(String[] args) throws FileNotFoundException, IOException, ConfigurationException, InvalidParametersException { FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>( PropertiesConfiguration.class).configure( new Parameters().properties().setFileName(args[0]).setThrowExceptionOnMissing(true) .setListDelimiterHandler(new DefaultListDelimiterHandler(';')) .setIncludesAllowed(false)); Configuration config = builder.getConfiguration(); String inputSongPath = config.getString("input_song"); String outputFolderPath = config.getString("output_folder"); String autoEncoderParamsPath = config.getString("auto_encoder_params"); String nameGeneratorParamsPath = config.getString("name_generator_params"); String queueFolderPath = config.getString("queue_folder"); String referenceQueuePath = config.getString("reference_queue", "nil"); String inputCorpusFolder = config.getString("input_corpus_folder"); boolean shouldWriteQueue = config.getBoolean("should_write_generated_queue"); boolean frankensteinTest = config.getBoolean("queue_tests_frankenstein"); boolean interpolateTest = config.getBoolean("queue_tests_interpolation"); boolean iterateOverCorpus = config.getBoolean("iterate_over_corpus", false); boolean shouldGenerateSongTitle = config.getBoolean("generate_song_title"); boolean shouldGenerateSong = config.getBoolean("generate_leadsheet"); LogTimer.initStartTime(); //start our logging timer to keep track of our execution time LogTimer.log("Creating name generator..."); //here is just silly code for generating name based on an LSTM lol $wag LSTM lstm = new LSTM(); FullyConnectedLayer fullLayer = new FullyConnectedLayer(Operations.None); Loadable titleNetLoader = new Loadable() { @Override// www.ja v a 2s. c o m public boolean load(INDArray array, String path) { String car = pathCar(path); String cdr = pathCdr(path); switch (car) { case "full": return fullLayer.load(array, cdr); case "lstm": return lstm.load(array, cdr); default: return false; } } }; LogTimer.log("Packing name generator from files..."); (new NetworkConnectomeLoader()).load(nameGeneratorParamsPath, titleNetLoader); String characterString = " !\"'[],-.01245679:?ABCDEFGHIJKLMNOPQRSTUVWYZabcdefghijklmnopqrstuvwxyz"; //Initialization LogTimer.log("Creating autoencoder..."); int inputSize = 34; int outputSize = EncodingParameters.noteEncoder.getNoteLength(); int featureVectorSize = 100; ProductCompressingAutoencoder autoencoder = new ProductCompressingAutoencoder(24, 48, 84 + 1, false); //create our network int numInterpolationDivisions = 5; //"pack" the network from weights and biases file directory LogTimer.log("Packing autoencoder from files"); (new NetworkConnectomeLoader()).load(autoEncoderParamsPath, autoencoder); File[] songFiles; if (iterateOverCorpus) { songFiles = new File(inputCorpusFolder).listFiles(); } else { songFiles = new File[] { new File(inputSongPath) }; } for (File inputFile : songFiles) { (new NetworkConnectomeLoader()).refresh(autoEncoderParamsPath, autoencoder, "initialstate"); String songTitle; if (shouldGenerateSong) { Random rand = new Random(); AVector charOut = Vector.createLength(characterString.length()); GroupedSoftMaxSampler sampler = new GroupedSoftMaxSampler( new Group[] { new Group(0, characterString.length(), true) }); songTitle = ""; for (int i = 0; i < 50; i++) { charOut = fullLayer.forward(lstm.step(charOut)); charOut = sampler.filter(charOut); int charIndex = 0; for (; charIndex < charOut.length(); charIndex++) { if (charOut.get(charIndex) == 1.0) { break; } } songTitle += characterString.substring(charIndex, charIndex + 1); } songTitle = songTitle.trim(); LogTimer.log("Generated song name: " + songTitle); } else { songTitle = "The Song We Never Name"; } LogTimer.log("Reading file..."); LeadSheetDataSequence inputSequence = LeadSheetIO.readLeadSheet(inputFile); //read our leadsheet to get a data vessel as retrieved in rbm-provisor LeadSheetDataSequence outputSequence = inputSequence.copy(); outputSequence.clearMelody(); if (interpolateTest) { LeadSheetDataSequence additionalOutput = outputSequence.copy(); for (int i = 0; i < numInterpolationDivisions; i++) { outputSequence.concat(additionalOutput.copy()); } } LeadSheetDataSequence decoderInputSequence = outputSequence.copy(); LogTimer.startLog("Encoding data..."); //TradingTimer.initStart(); //start our trading timer to keep track our our generation versus realtime play while (inputSequence.hasNext()) { //iterate through time steps in input data //TradingTimer.waitForNextTimedInput(); autoencoder.encodeStep(inputSequence.retrieve()); //feed the resultant input vector into the network if (advanceDecoding) { //if we are using advance decoding (we start decoding as soon as we can) if (autoencoder.canDecode()) { //if queue has enough data to decode from outputSequence.pushStep(null, null, autoencoder.decodeStep(decoderInputSequence.retrieve())); //take sampled data for a timestep from autoencoder //TradingTimer.logTimestep(); //log our time to TradingTimer so we can know how far ahead of realtime we are } } } LogTimer.endLog(); if (shouldWriteQueue) { String queueFilePath = queueFolderPath + java.io.File.separator + inputFile.getName().replace(".ls", ".q"); FragmentedNeuralQueue currQueue = autoencoder.getQueue(); currQueue.writeToFile(queueFilePath); LogTimer.log("Wrote queue " + inputFile.getName().replace(".ls", ".q") + " to file..."); } if (shouldGenerateSong) { if (interpolateTest) { FragmentedNeuralQueue refQueue = new FragmentedNeuralQueue(); refQueue.initFromFile(referenceQueuePath); FragmentedNeuralQueue currQueue = autoencoder.getQueue(); //currQueue.writeToFile(queueFilePath); autoencoder.setQueue(currQueue.copy()); while (autoencoder.hasDataStepsLeft()) { //we are done encoding all time steps, so just finish decoding!{ outputSequence.pushStep(null, null, autoencoder.decodeStep(decoderInputSequence.retrieve())); //take sampled data for a timestep from autoencoder //TradingTimer.logTimestep(); //log our time to TradingTimer so we can know how far ahead of realtime we are } for (int i = 1; i <= numInterpolationDivisions; i++) { System.out.println("Starting interpolation " + ((1.0 / numInterpolationDivisions) * (i))); (new NetworkConnectomeLoader()).refresh(autoEncoderParamsPath, autoencoder, "initialstate"); FragmentedNeuralQueue currCopy = currQueue.copy(); currCopy.basicInterpolate(refQueue, (1.0 / numInterpolationDivisions) * (i)); autoencoder.setQueue(currCopy); int timeStep = 0; while (autoencoder.hasDataStepsLeft()) { //we are done encoding all time steps, so just finish decoding!{ System.out.println("interpolation " + i + " step " + ++timeStep); outputSequence.pushStep(null, null, autoencoder.decodeStep(decoderInputSequence.retrieve())); //take sampled data for a timestep from autoencoder //TradingTimer.logTimestep(); //log our time to TradingTimer so we can know how far ahead of realtime we are } } } if (frankensteinTest) { LogTimer.startLog("Loading queues"); File queueFolder = new File(queueFolderPath); int numComponents = config.getInt("frankenstein_num_components", 5); int numCombinations = config.getInt("frankenstein_num_combinations", 6); double interpolationMagnitude = config.getDouble("frankenstein_magnitude", 2.0); if (queueFolder.isDirectory()) { File[] queueFiles = queueFolder.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.contains(".q"); } }); List<File> fileList = new ArrayList<>(); for (File file : queueFiles) { fileList.add(file); } Collections.shuffle(fileList); int numSelectedFiles = (numComponents > queueFiles.length) ? queueFiles.length : numComponents; for (int i = 0; i < queueFiles.length - numSelectedFiles; i++) { fileList.remove(fileList.size() - 1); } List<FragmentedNeuralQueue> queuePopulation = new ArrayList<>(fileList.size()); songTitle += " - a mix of "; for (File file : fileList) { FragmentedNeuralQueue newQueue = new FragmentedNeuralQueue(); newQueue.initFromFile(file.getPath()); queuePopulation.add(newQueue); songTitle += file.getName().replaceAll(".ls", "") + ", "; } LogTimer.endLog(); LeadSheetDataSequence additionalOutput = outputSequence.copy(); for (int i = 1; i < numCombinations; i++) { outputSequence.concat(additionalOutput.copy()); } decoderInputSequence = outputSequence.copy(); FragmentedNeuralQueue origQueue = autoencoder.getQueue(); for (int i = 0; i < numCombinations; i++) { LogTimer.startLog("Performing queue interpolation..."); AVector combinationStrengths = Vector.createLength(queuePopulation.size()); Random vectorRand = new Random(i); for (int j = 0; j < combinationStrengths.length(); j++) { combinationStrengths.set(j, vectorRand.nextDouble()); } combinationStrengths.divide(combinationStrengths.elementSum()); FragmentedNeuralQueue currQueue = origQueue.copy(); for (int k = 0; k < combinationStrengths.length(); k++) { currQueue.basicInterpolate(queuePopulation.get(k), combinationStrengths.get(k) * interpolationMagnitude); } LogTimer.endLog(); autoencoder.setQueue(currQueue); LogTimer.startLog("Refreshing autoencoder state..."); (new NetworkConnectomeLoader()).refresh(autoEncoderParamsPath, autoencoder, "initialstate"); LogTimer.endLog(); LogTimer.startLog("Decoding segment..."); while (autoencoder.hasDataStepsLeft()) { //we are done encoding all time steps, so just finish decoding!{ outputSequence.pushStep(null, null, autoencoder.decodeStep(decoderInputSequence.retrieve())); //take sampled data for a timestep from autoencoder //TradingTimer.logTimestep(); //log our time to TradingTimer so we can know how far ahead of realtime we are } LogTimer.endLog(); } } } while (autoencoder.hasDataStepsLeft()) { //we are done encoding all time steps, so just finish decoding!{ outputSequence.pushStep(null, null, autoencoder.decodeStep(decoderInputSequence.retrieve())); //take sampled data for a timestep from autoencoder //TradingTimer.logTimestep(); //log our time to TradingTimer so we can know how far ahead of realtime we are } LogTimer.log("Writing file..."); String outputFilename = outputFolderPath + java.io.File.separator + inputFile.getName().replace(".ls", "_Output"); //we'll write our generated file with the same name plus "_Output" LeadSheetIO.writeLeadSheet(outputSequence, outputFilename, songTitle); System.out.println(outputFilename); } else { autoencoder.setQueue(new FragmentedNeuralQueue()); } } LogTimer.log("Process finished"); //Done! }
From source file:Executable.LinkImputeR.java
/** * Main function//w w w . j av a 2s . c om * @param args Command line arguments * @throws Exception If an uncaught error occurs */ public static void main(String[] args) throws Exception { try { Options options = new Options(); OptionGroup all = new OptionGroup(); all.addOption(Option.builder("c").build()); all.addOption(Option.builder("s").build()); all.addOption(Option.builder("v").build()); all.addOption(Option.builder("h").build()); options.addOptionGroup(all); CommandLineParser parser = new DefaultParser(); CommandLine commands = parser.parse(options, args); String[] fileNames = commands.getArgs(); XMLConfiguration c; boolean done = false; if (commands.hasOption("c")) { if (fileNames.length == 2) { c = convert(new File(fileNames[0])); writeXML(c, new File(fileNames[1])); } else { System.out.println("An input and output file must be provided"); System.out.println(); help(); } done = true; } if (commands.hasOption("s")) { if (fileNames.length == 1) { c = convert(new File(fileNames[0])); accuracy(c); } else { System.out.println("An input file must be provided"); System.out.println(); help(); } done = true; } if (commands.hasOption("v")) { System.out.println("LinkImputeR version 1.1.3"); done = true; } if (commands.hasOption("h")) { help(); done = true; } if (!done) { if (fileNames.length == 3) { File xml = new File(fileNames[0]); FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>( XMLConfiguration.class).configure(new Parameters().xml().setFile(xml)); XMLConfiguration config = builder.getConfiguration(); switch (config.getString("mode")) { case "accuracy": accuracy(config); break; case "impute": if (args.length == 3) { impute(config, args[1], new File(args[2])); } else { impute(config, null, null); } break; } } else { System.out.println("An input file, case name and output file must be provided (in that order)"); System.out.println(); help(); } } } catch (UnrecognizedOptionException ex) { System.err.println("Unrecognised command line option (" + ex.getOption() + ")"); System.err.println(); help(); } catch (AlreadySelectedException ex) { System.err.println("Only one option can be selected at a time"); System.err.println(); help(); } catch (VCFException ex) { System.err.println("====="); System.err.println("ERROR"); System.err.println("====="); System.err.println("There's a problem with the VCF file"); System.err.println(ex.getMessage()); System.err.println(); System.err.println("Technical details follow:"); throw ex; } catch (INIException ex) { System.err.println("====="); System.err.println("ERROR"); System.err.println("====="); System.err.println("There's a problem with the ini file"); System.err.println(ex.getMessage()); System.err.println(); System.err.println("Technical details follow:"); throw ex; } catch (OutputException ex) { System.err.println("====="); System.err.println("ERROR"); System.err.println("====="); System.err.println("There's a problem writing an output file"); System.err.println(ex.getMessage()); System.err.println(); System.err.println("Technical details follow:"); throw ex; } catch (AlgorithmException ex) { System.err.println("====="); System.err.println("ERROR"); System.err.println("====="); System.err.println("There's a problem with the algorithms"); System.err.println(ex.getMessage()); System.err.println(); System.err.println("Technical details follow:"); throw ex; } catch (ProgrammerException ex) { System.err.println("====="); System.err.println("ERROR"); System.err.println("====="); System.err.println("Well this is embarrassing. This shouldn't have happened. " + "Please contact the maintainer if you can not solve the error" + "from the technical details."); System.err.println(); System.err.println("Technical details follow:"); throw ex; } catch (Exception ex) { System.err.println("====="); System.err.println("ERROR"); System.err.println("====="); System.err.println("Well this is embarrassing. This was not expected to have happened. " + "Please contact the maintainer if you can not solve the error" + "from the technical details."); System.err.println(); System.err.println("Note: The maintainer would be interested in knowing " + "about any XML related messages so he can write nicer error " + "messages for these problems."); System.err.println(); System.err.println("Technical details follow:"); throw ex; } }
From source file:main.Driver.java
/** * The path to a properties file which will supply parameter values for the tests should be passed in as argument 0 to main. * The test that will be run is determined by the value of 'test_type' in the properties file, and each of the tests have their own properties: * 'encode+decode' - Encode and decode the given leadsheet with the autoencoder, writing the result to a leadsheet file. * Params: /* w w w . j av a2 s .c o m*/ * * autoencoder_connectome={the path to the connectome which the autoencoder will be loaded with} * * name_generator_connectome={the path to the connectome which the name generator will be loaded with} * * input_leadsheet={the path to the leadsheet file which will be encoded and decoded} * * output_folder={the path to the output folder which the result leadsheet file will be written in} * * 'encode+write_queue' - Encode the given leadsheet with the autoencoder, then write the encoded feature queue to a queue file. * Params: * * autoencoder_connectome={the path to the connectome which the autoencoder will be loaded with} * * input_leadsheet={the path to the leadsheet file which will be encoded} * * queue_folder={the path to the output folder which the result queue file will be written in} * * 'encode+write_queue+decode' - Encode the given leadsheet with the autoencoder, write the encoded feature queue to a queue file, and then write the result leadsheet to a leadsheet file. * * autoencoder_connectome={the path to the connectome which the autoencoder will be loaded with} * * name_generator_connectome={the path to the connectome which the name generator will be loaded with} * * input_leadsheet={the path to the leadsheet file which will be encoded and decoded} * * queue_folder={the path to the output folder which the result queue file will be written in} * * output_folder={the path to the output folder which the result leadsheet file will be written in} * 'create_feature_property_vector' - Given a corpus folder of leadsheets, construct a vector consisting of property analysis values for each feature in the corpus data * * input_corpus_folder={the path to the corpus folder containing all leadsheets to analyze} * * feature_size={the size (in time steps) of each feature} * * feature_properties_path={the path to write the generated vector file to (the file will be a csv file containing all the values in left-to-right order} * * feature_property={the type of feature property to analyze - current options are 'rest', 'sustain', articulate' (these return ratios of time steps with the given property to the total time steps in the feature). * 'compile_feature_queue_matrix' - Given a corpus folder of feature queues, construct a matrix of all feature vectors and write it as a csv file * * queue_folder={the path to the folder containing all queue files to compile} * * feature_matrix_path={the path to write the result csv file to} * 'generate_from_feature_queue_matrix' - Given a matrix of feature vectors, load the autoencoder with a queue of those features and decode from it, writing the result leadsheet to a file * * autoencoder_connectome={the path to the connectome which the autoencoder will be loaded with} * * reference_leadsheet={the path to the leadsheet we will take the chord sequence from (and loop it to match the length of the feature queue)} * * feature_queue_matrix_path={the path to the feature queue matrix file we will decode from} * * output_file_path={the path to the file we will write our result leadsheet to} * * (optional) song_title={the song title to write in the leadsheet file - by default this is "Generation from Feature Matrix {path of the feature matrix}"} * * feature_size={the size (in time steps) of features} * 'population_trade' - Given a leadsheet file, split it into sections of a specified size, and between sections, generate a response that plays off of a population of previously encoded feature queues * * autoencoder_connectome={the path to the connectome which the autoencoder will be loaded with} * * input_leadsheet={the path to the leadsheet file which will be encoded and traded with} * * output_folder={the path to the output folder which the result leadsheet file will be written in} * * trading_part_size={the size (in time steps) of each trading part. The input leadsheet will be split into sections of this size, and trading responses will be generated in between.} * * interpolation_variance={a random value between zero and this will be added to the interpolation_min at each trading section to calculate the interpolation of the recently encoded queue towards the queue population before decoding the trading response} * * interpolation_min={the minimum ratio of interpolation at each trading section} * * herding_strength={the maximum strength of the herding operation at each section (all queues in the population are interpolated a random amount towards the most recent queue)} * * mutation_strength={the maximum strength of mutation at each section (each element of the feature vectors of all queues in the population are mutated at a random strength} * * crossover_strength{the maximum strength of crossover at each section (there is a chance for every queue that the queue will swap a random feature of itself with the corresponding feature of another random queue)} * 'interpolation' - Given a leadsheet file and a reference queue file, encode the leadsheet file with the autoencoder, and generate from the encoded queue for a number of divisions of a full interpolation towards the target queue * * autoencoder_connectome={the path to the connectome which the autoencoder will be loaded with} * * input_leadsheet={the path to the leadsheet file which will be encoded and interpolated} * * target_queue={the path to the queue to interpolate towards at each interpolation value}; * * output_folder={the path to the output folder which the result leadsheet file will be written in} * * num_interpolation_divisions={the number of divisions of the interpolation strength from 0.0 to 1.0 (the length of the result leadsheet will be equal to the length of the original times 1 + number of divisions, as the first section of the result leadsheet is for interpolation 0.0)} * 'frankenstein' - Given a primary queue, a reference leadsheet for chords, and a corpus of queue files, construct the result leadsheet from a series of randomly weighted interpolations of the primary queue towards the set of selected queues. * * autoencoder_connectome={the path to the connectome which the autoencoder will be loaded with} * * primary_queue_path={the path to the queue which will serve as the base for all of the queue combinations (which are the result of sequential interpolations instead of a weighted sum)} * * reference_leadsheet={the path to the leadsheet we will take the chord sequence from (and loop it to match the desired length of our output} * * queue_folder={the path to the folder containing all queue files we can select from} * * output_file_path={the path to the file we will write our result leadsheet to} * * num_reference_queues={the number of reference queues we will pick at random from the queue folder to sample from) * * num_combinations={the number of queue combinations to sample and create the result leadsheet from} * * interpolation_strength={the total magnitude of all interpolation operations for each combination} */ public static void main(String[] args) throws FileNotFoundException, IOException, ConfigurationException { FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>( PropertiesConfiguration.class).configure( new Parameters().properties().setFileName(args[0]).setThrowExceptionOnMissing(true) .setListDelimiterHandler(new DefaultListDelimiterHandler(';')) .setIncludesAllowed(false)); Configuration config = builder.getConfiguration(); LogTimer.initStartTime(); //start our logging timer to keep track of our execution time //switch statement to run the appropriate test switch (config.getString("test_type")) { case "encode+decode": { //load parameter values from config file String autoencoderConnectomePath = config.getString("autoencoder_connectome"); String nameGeneratorConnectomePath = config.getString("name_generator_connectome"); String inputLeadsheetPath = config.getString("input_leadsheet"); String outputFolderPath = config.getString("output_folder"); //initialize networks NameGenerator nameGenerator = initializeNameGenerator(nameGeneratorConnectomePath); ProductCompressingAutoencoder autoencoder = initializeAutoencoder(autoencoderConnectomePath, false); //initialize input sequences and output sequence LeadsheetDataSequence inputSequence = leadsheetToSequence(inputLeadsheetPath); LeadsheetDataSequence outputSequence = inputSequence.copy(); outputSequence.clearMelody(); LeadsheetDataSequence decoderInputSequence = outputSequence.copy(); //encode and decode encodeFromSequence(autoencoder, inputSequence); decodeToSequence(autoencoder, outputSequence, decoderInputSequence); //generate song title String songTitle = nameGenerator.generateName(); //write output to specified directory with same file name + _aeOutput suffix writeLeadsheetFile(outputSequence, outputFolderPath, new File(inputLeadsheetPath).getName(), "_aeOutput", songTitle); } break; case "encode+write_queue": { //load parameter values from config file String autoencoderConnectomePath = config.getString("autoencoder_connectome"); String inputLeadsheetPath = config.getString("input_leadsheet"); String queueFolderPath = config.getString("queue_folder"); //initialize network ProductCompressingAutoencoder autoencoder = initializeAutoencoder(autoencoderConnectomePath, false); //initialize input sequence LeadsheetDataSequence inputSequence = leadsheetToSequence(inputLeadsheetPath); //encode encodeFromSequence(autoencoder, inputSequence); //write to a queue file in the specified queue folder (the write method will handle removing/adding extensions writeQueueFile(autoencoder, queueFolderPath, new File(inputLeadsheetPath).getName()); } break; case "encode+write_queue+decode": { //load parameter values from config file String autoencoderConnectomePath = config.getString("autoencoder_connectome"); String nameGeneratorConnectomePath = config.getString("name_generator_connectome"); String inputLeadsheetPath = config.getString("input_leadsheet"); String queueFolderPath = config.getString("queue_folder"); String outputFolderPath = config.getString("output_folder"); //initialize networks NameGenerator nameGenerator = initializeNameGenerator(nameGeneratorConnectomePath); ProductCompressingAutoencoder autoencoder = initializeAutoencoder(autoencoderConnectomePath, false); //initialize input sequences and output sequence LeadsheetDataSequence inputSequence = leadsheetToSequence(inputLeadsheetPath); LeadsheetDataSequence outputSequence = inputSequence.copy(); outputSequence.clearMelody(); LeadsheetDataSequence decoderInputSequence = outputSequence.copy(); //encode encodeFromSequence(autoencoder, inputSequence); //write to a queue file in the specified queue folder (the write method will handle removing/adding extensions writeQueueFile(autoencoder, queueFolderPath, new File(inputLeadsheetPath).getName()); //decode decodeToSequence(autoencoder, outputSequence, decoderInputSequence); //generate song title String songTitle = nameGenerator.generateName(); //write output to specified directory with same file name + _aeOutput suffix writeLeadsheetFile(outputSequence, outputFolderPath, new File(inputLeadsheetPath).getName(), "_aeOutput", songTitle); } break; case "create_feature_property_vector": { //load parameter values from config file String inputCorpusFolder = config.getString("input_corpus_folder"); int featureSize = config.getInt("feature_size"); String featurePropertiesPath = config.getString("feature_properties_path"); String featureProperty = config.getString("feature_property"); //compile array of valid leadsheet files File[] songFiles = new File(inputCorpusFolder) .listFiles((File dir, String name) -> name.endsWith(".ls")); //construct feature property vector from analyzed feature property values of all songs AVector featurePropertyValues = Vector.createLength(0); int featureIndex = 0; for (File inputFile : songFiles) { LeadsheetDataSequence melodySequence = leadsheetToSequence(inputFile.getPath()); featurePropertyValues.join(melodyFeatureAnalysis(melodySequence, featureProperty, featureSize)); } //write generated feature_properties BufferedWriter writer = new BufferedWriter( new FileWriter(featurePropertiesPath + "_" + featureProperty + ".v")); writer.write(ReadWriteUtilities.getNumpyCSVString(featurePropertyValues)); writer.close(); } break; case "compile_feature_queue_matrix": { //load parameter values from config file String queueFolderPath = config.getString("queue_folder"); String featureMatrixPath = config.getString("feature_matrix_path"); //generate feature matrix from all feature queues in specified queue folder File[] queueFiles = new File(queueFolderPath).listFiles((File dir, String name) -> name.endsWith(".q")); AMatrix totalFeatureMatrix = generateFeatureQueueMatrix(queueFiles); String writeData = ReadWriteUtilities.getNumpyCSVString(totalFeatureMatrix); BufferedWriter writer = new BufferedWriter(new FileWriter(featureMatrixPath)); writer.write(writeData); writer.close(); } break; case "generate_from_feature_queue_matrix": { //load parameter values from config file String autoencoderConnectomePath = config.getString("autoencoder_connectome"); String referenceLeadsheetPath = config.getString("reference_leadsheet"); String featureQueueMatrixPath = config.getString("feature_queue_matrix_path"); String outputFilePath = config.getString("output_file_path"); String songTitle = config.getString("song_title", "Generation from Feature Matrix " + featureQueueMatrixPath); int featureSize = config.getInt("feature_size"); //initialize network ProductCompressingAutoencoder autoencoder = initializeAutoencoder(autoencoderConnectomePath, false); //initialize chord sequence LeadsheetDataSequence chordSequence = leadsheetToSequence(referenceLeadsheetPath); chordSequence.clearMelody(); //call generation method generateFromFeatureMatrix(autoencoder, autoencoderConnectomePath, chordSequence, featureQueueMatrixPath, featureSize, outputFilePath, songTitle); } break; case "population_trade": { //load parameter values from config file String autoencoderConnectomePath = config.getString("autoencoder_connectome"); String inputLeadsheetPath = config.getString("input_leadsheet"); String outputFolderPath = config.getString("output_folder"); int tradingPartSize = config.getInt("trading_part_size"); double interpVariance = config.getDouble("interpolation_variance"); double interpMin = config.getDouble("interpolation_min"); double herdingStrength = config.getDouble("herding_strength"); double mutationStrength = config.getDouble("mutation_strength"); double crossoverStrength = config.getDouble("crossover_strength"); //initialize network ProductCompressingAutoencoder autoencoder = initializeAutoencoder(autoencoderConnectomePath, true); //perform population trading test populationTradingTest(autoencoder, autoencoderConnectomePath, new File(inputLeadsheetPath), new File(outputFolderPath), tradingPartSize, interpVariance, interpMin, herdingStrength, mutationStrength, crossoverStrength); } break; case "interpolation": { //load parameter values from config file String autoencoderConnectomePath = config.getString("autoencoder_connectome"); String inputLeadsheetPath = config.getString("input_leadsheet"); String targetQueuePath = config.getString("target_queue"); String outputFolderPath = config.getString("output_folder"); int numInterpolationDivisions = config.getInt("num_interpolation_divisions"); //initialize network ProductCompressingAutoencoder autoencoder = initializeAutoencoder(autoencoderConnectomePath, false); //perform the interpolation test interpolateTest(autoencoder, autoencoderConnectomePath, new File(inputLeadsheetPath), new File(targetQueuePath), new File(outputFolderPath), numInterpolationDivisions); } break; case "frankenstein": { //load parameter values from config file String autoencoderConnectomePath = config.getString("autoencoder_connectome"); String primaryQueuePath = config.getString("primary_queue_path"); String referenceLeadsheetPath = config.getString("reference_leadsheet"); String queueFolderPath = config.getString("queue_folder"); String outputFilePath = config.getString("output_file_path"); int numReferenceQueues = config.getInt("num_reference_queues"); int numCombinations = config.getInt("num_combinations"); double interpolationMagnitude = config.getDouble("interpolation_strength"); //initialize network ProductCompressingAutoencoder autoencoder = initializeAutoencoder(autoencoderConnectomePath, false); //initialize chord sequence LeadsheetDataSequence chordSequence = leadsheetToSequence(referenceLeadsheetPath); chordSequence.clearMelody(); //perform frankenstein test frankensteinTest(autoencoder, autoencoderConnectomePath, primaryQueuePath, new File(queueFolderPath), outputFilePath, chordSequence, numReferenceQueues, numCombinations, interpolationMagnitude); } break; default: throw new RuntimeException("Unrecognized test type"); } LogTimer.log("Process finished"); //Done! }
From source file:hd3gtv.as5kpc.MainClass.java
static FileBasedConfiguration loadConf(String file) throws ConfigurationException { org.apache.commons.configuration2.builder.fluent.Parameters params = new org.apache.commons.configuration2.builder.fluent.Parameters(); PropertiesBuilderParameters pbp = params.properties().setFileName(file); pbp.setListDelimiterHandler(new DefaultListDelimiterHandler(',')); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>( PropertiesConfiguration.class); builder.configure(pbp);//from ww w. j a v a 2s. co m return builder.getConfiguration(); }
From source file:com.pnf.jebauto.AutoUtil.java
/** * Create an Apache properties object out of a JEB2 configuration file. * /*ww w . java 2s . c o m*/ * @param path path to a JEB2 configuration file, such as jeb-client.cfg or jeb-engines.cfg * @return */ public static PropertiesConfiguration createPropertiesConfiguration(String path) { File configfile = new File(path); if (!configfile.isFile()) { try { configfile.createNewFile(); } catch (IOException e) { throw new RuntimeException(e); } } Parameters params = new Parameters(); FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>( PropertiesConfiguration.class).configure(params.properties().setFileName(path)); builder.setAutoSave(true); try { return builder.getConfiguration(); } catch (ConfigurationException e) { throw new RuntimeException(e); } }
From source file:com.github.mavogel.ilias.utils.ConfigurationsUtils.java
/** * Creates the login configuration and uses defaults if necessary. * * @param propertyFilename the name of the property file * @return the {@link LoginConfiguration} *///from w ww . j a va2 s.c o m public static LoginConfiguration createLoginConfiguration(final String propertyFilename) { Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>( PropertiesConfiguration.class).configure(params.properties().setFileName(propertyFilename)); LoginConfiguration.LOGIN_MODE loginMode = null; String endpoint, client, username, password, loginModeRaw = ""; int maxFolderDepth; Level logLevel; try { Configuration config = builder.getConfiguration(); loginModeRaw = config.getString("login.mode"); loginMode = LoginConfiguration.LOGIN_MODE.valueOf(loginModeRaw); endpoint = config.getString("endpoint"); client = config.getString("login.client"); username = config.getString("login.username"); password = config.getString("login.password"); maxFolderDepth = config.getString("maxFolderDepth", String.valueOf(Defaults.MAX_FOLDER_DEPTH)).isEmpty() ? Defaults.MAX_FOLDER_DEPTH : Integer .valueOf(config.getString("maxFolderDepth", String.valueOf(Defaults.MAX_FOLDER_DEPTH))); logLevel = Level.toLevel(config.getString("log.level", Defaults.LOG_LEVEL.toString()), Defaults.LOG_LEVEL); if (password == null || password.isEmpty()) { Console console = System.console(); if (console != null) { password = String.valueOf(console.readPassword("Enter your password: ")); } else { throw new Exception("Console is not available!"); } } } catch (IllegalArgumentException iae) { throw new RuntimeException(String.format("Login mode '%s' is unknown. Use one of %s", loginModeRaw, Arrays.stream(LoginConfiguration.LOGIN_MODE.values()).map(lm -> lm.name()) .collect(Collectors.joining(", ")))); } catch (ConversionException ce) { throw new RuntimeException("maxFolderDepth property is not an integer"); } catch (Exception ex) { throw new RuntimeException(ex); } // == 1: set log level Logger.getRootLogger().setLevel(logLevel); // == 2: create login configuration switch (loginMode) { case STD: return LoginConfiguration.asStandardLogin(endpoint, client, username, password, maxFolderDepth); case LDAP: return LoginConfiguration.asLDAPLogin(endpoint, client, username, password, maxFolderDepth); case CAS: return LoginConfiguration.asCASLogin(); default: // should not happen return null; } }
From source file:com.tekstosense.segmenter.config.Config.java
/** * Instantiates a new config.//from www. ja v a2s .com */ private Config() { try { Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>( PropertiesConfiguration.class); builder.configure(params.fileBased().setFileName("pdf2xml.properties") .setLocationStrategy(new ClasspathLocationStrategy())); configuration = builder.getConfiguration(); } catch (ConfigurationException e) { LOG.error(e, e); } }
From source file:com.rodaxsoft.junit.mailgun.MailgunManagerTestCase.java
/** * @throws java.lang.Exception/*from www . j ava 2 s. co m*/ */ @BeforeClass public static void setUpBeforeClass() throws Exception { if (null == sMailingListAddress) { FileBasedConfigurationBuilder<FileBasedConfiguration> builder; builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class); Parameters params = new Parameters(); builder.configure(params.properties().setFileName(TESTCASE_PROPERTIES)); Configuration config = builder.getConfiguration(); DynaBean bean = new ConfigurationDynaBean(config); MailgunAccount acct = new MailgunAccount(bean); // Register the MailgunAccount object MailgunManager.register(acct); sMailingListAddress = config.getString("mailing.list"); sFrom = config.getString("email.from"); sTo = config.getString("email.to"); sCampaignId = config.getString("campaign.id"); LOG.info(acct); } }
From source file:com.tekstosense.opennlp.config.Config.java
/** * Instantiates a new config./*from w w w. java 2 s. c om*/ */ private Config() { try { Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>( PropertiesConfiguration.class); builder.configure(params.fileBased().setFileName("nlp.properties") .setLocationStrategy(new ClasspathLocationStrategy())); configuration = builder.getConfiguration(); // Adding TEKSTO_HOME path to Configuration String homePath = System.getenv(TEKSTO_HOME); if (homePath != null && !homePath.isEmpty()) { configuration.setProperty(MODEL_PATH, homePath + "/Models"); } } catch (ConfigurationException e) { LOG.error(e, e); } }
From source file:eu.mangos.configuration.dao.impl.AuthConfigurationDAOImpl.java
@Override public AuthConfiguration readConfiguration() throws ConfigurationException { AuthConfiguration authConfig = new AuthConfiguration(); Parameters params = new Parameters(); this.builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(params.properties().setFile(new File(this.configuration.getSourcePath()))); Configuration config = this.builder.getConfiguration(); authConfig.setVersion(config.getString("ConfVersion")); if (authConfig.getVersion() == null) { logger.error("The selected file does not contain any ConfVersion property."); throw new ConfigurationException("The selected file does not contain any ConfVersion property."); }//from w w w .j a v a 2 s . c o m if (Long.parseLong(authConfig.getVersion()) != AuthConfiguration.CONF_VERSION) { logger.error("The selected file has a version number not compatible with this manager."); throw new ConfigurationException("The selected file is not compatible with this manager."); } String[] loginDBInfo = (config.getString("LoginDatabaseInfo", "").replace("\"", "")).split(";"); if (loginDBInfo.length != 5) { logger.warn("The selected file has a LoginDatabaseInfo property with not enough parameters."); } authConfig.setIp(loginDBInfo.length >= 1 ? loginDBInfo[0] : ""); authConfig.setPort(loginDBInfo.length >= 2 ? Integer.parseInt(loginDBInfo[1]) : 0); authConfig.setUser(loginDBInfo.length >= 3 ? loginDBInfo[2] : ""); authConfig.setPassword(loginDBInfo.length >= 4 ? loginDBInfo[3] : ""); authConfig.setSchema(loginDBInfo.length >= 5 ? loginDBInfo[4] : ""); authConfig.setLogsDirectory(config.getString("LogsDir", "").replace("\"", "")); authConfig.setPidFile(config.getString("PidFile", "").replace("\"", "")); authConfig.setMaxPing(config.getInt("MaxPingTime", 30)); authConfig.setRealmServerPort(config.getInt("RealmServerPort", 3724)); authConfig.setBindIP(config.getString("BindIP", "0.0.0.0").replace("\"", "")); authConfig.setLogConsoleLevel(LogLevel.convert(config.getInt("LogLevel"))); authConfig.setIncludeLogTime((config.getInt("LogTime", 0) != 0)); authConfig.setLogFile(config.getString("LogFile", "realm-list.log").replace("\"", "")); authConfig.setIncludeTimestamp((config.getInt("LogTimestamp", 0) != 0)); authConfig.setLogFileLevel(LogLevel.convert(config.getInt("LogFileLevel"))); String[] logColors = (config.getString("LogColors", "")).replace("\"", "").split(" "); if (logColors.length != 4) { logger.warn("The selected file has a LogColors property with not enough parameters."); } authConfig.setLogNormalColor( logColors.length >= 1 ? LogColor.convert(Integer.parseInt(logColors[0])) : LogColor.NONE); authConfig.setLogDetailsColor( logColors.length >= 2 ? LogColor.convert(Integer.parseInt(logColors[1])) : LogColor.NONE); authConfig.setLogDebugColor( logColors.length >= 3 ? LogColor.convert(Integer.parseInt(logColors[2])) : LogColor.NONE); authConfig.setLogErrorColor( logColors.length >= 4 ? LogColor.convert(Integer.parseInt(logColors[3])) : LogColor.NONE); authConfig.setUseProcessors(config.getInt("UseProcessors", 0)); authConfig.setProcessPriority(ProcessPriority.convert(config.getInt("ProcessPriority", 1))); authConfig.setWaitAtStartupError(config.getInt("WaitAtStartupError", 0) != 0); authConfig.setRealmStateUpdateDelay(config.getInt("RealmsStateUpdateDelay", 20)); authConfig.setNbWrongPass(config.getInt("WrongPass.MaxCount", 3)); authConfig.setBanTime(config.getInt("WrongPass.BanTime", 300)); authConfig.setBanType(BanType.convert(config.getInt("WrongPass.BanType", 0))); logger.info("Configuration file " + this.configuration.getName() + " has been loaded succesfully !"); return authConfig; }