Example usage for org.apache.commons.configuration Configuration subset

List of usage examples for org.apache.commons.configuration Configuration subset

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration subset.

Prototype

Configuration subset(String prefix);

Source Link

Document

Return a decorator Configuration containing every key from the current Configuration that starts with the specified prefix.

Usage

From source file:net.sf.jclal.evaluation.method.AbstractEvaluationMethod.java

/**
 *
 * @param configuration The configuration of the Algorithm.
 * <p>/*from   w w w  . j  a va 2 s  .c  o  m*/
 * <b>algorithm type= class</b>
 * </p>
 * <p>
 * Package: net.sf.jclal.activelearning
 * </p>
 * <p>
 * Class: All
 * </p>
 */
protected void setAlgorithmSettings(Configuration configuration) {

    String algorithmError = "algorithm type= ";
    try {
        // algorithm classname
        String algorithmClassname = configuration.getString("algorithm[@type]");
        algorithmError += algorithmClassname;
        // algorithm class
        Class<? extends AbstractALAlgorithm> algorithmClass = (Class<? extends AbstractALAlgorithm>) Class
                .forName(algorithmClassname);
        // algorithm instance
        AbstractALAlgorithm algorithm = algorithmClass.newInstance();
        // Configure algorithm (if necessary)
        if (algorithm instanceof IConfigure) {
            ((IConfigure) algorithm).configure(configuration.subset("algorithm"));
        }
        // Add the algorithm
        setAlgorithm(algorithm);
    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("\nIllegal algorithm classname: " + algorithmError, e);
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("\nIllegal algorithm classname: " + algorithmError, e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("\nIllegal algorithm classname: " + algorithmError, e);
    }
}

From source file:com.linkedin.pinot.broker.broker.helix.HelixBrokerStarter.java

public HelixBrokerStarter(String helixClusterName, String zkServer, Configuration pinotHelixProperties)
        throws Exception {
    LOGGER.info("Starting Pinot broker");

    _liveInstancesListener = new LiveInstancesChangeListenerImpl(helixClusterName);

    _pinotHelixProperties = DefaultHelixBrokerConfig.getDefaultBrokerConf(pinotHelixProperties);
    final String brokerId = _pinotHelixProperties.getString("instanceId",
            CommonConstants.Helix.PREFIX_OF_BROKER_INSTANCE + NetUtil.getHostAddress() + "_"
                    + _pinotHelixProperties.getInt(CommonConstants.Helix.KEY_OF_BROKER_QUERY_PORT,
                            CommonConstants.Helix.DEFAULT_BROKER_QUERY_PORT));

    _pinotHelixProperties.addProperty(BrokerRequestHandler.BROKER_ID_CONFIG_KEY, brokerId);
    setupHelixSystemProperties();//  ww w.j av a  2s . c o  m

    // Remove all white-spaces from the list of zkServers (if any).
    String zkServers = zkServer.replaceAll("\\s+", "");

    LOGGER.info("Starting Zookeeper client");
    _zkClient = new ZkClient(getZkAddressForBroker(zkServers, helixClusterName),
            ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
    _propertyStore = new ZkHelixPropertyStore<ZNRecord>(new ZkBaseDataAccessor<ZNRecord>(_zkClient), "/", null);
    RoutingTableSelector selector = RoutingTableSelectorFactory
            .getRoutingTableSelector(pinotHelixProperties.subset(ROUTING_TABLE_SELECTOR_SUBSET_KEY));
    _helixExternalViewBasedRouting = new HelixExternalViewBasedRouting(_propertyStore, selector);

    LOGGER.info("Connecting Helix components");
    // _brokerServerBuilder = startBroker();
    _brokerServerBuilder = startBroker(_pinotHelixProperties);
    _helixManager = HelixManagerFactory.getZKHelixManager(helixClusterName, brokerId, InstanceType.PARTICIPANT,
            zkServers);
    final StateMachineEngine stateMachineEngine = _helixManager.getStateMachineEngine();
    final StateModelFactory<?> stateModelFactory = new BrokerResourceOnlineOfflineStateModelFactory(
            _helixManager, _helixExternalViewBasedRouting);
    stateMachineEngine.registerStateModelFactory(
            BrokerResourceOnlineOfflineStateModelFactory.getStateModelDef(), stateModelFactory);
    _helixManager.connect();
    _helixAdmin = _helixManager.getClusterManagmentTool();
    _helixBrokerRoutingTable = new HelixBrokerRoutingTable(_helixExternalViewBasedRouting, brokerId,
            _helixManager);
    addInstanceTagIfNeeded(helixClusterName, brokerId);
    _helixManager.addExternalViewChangeListener(_helixBrokerRoutingTable);
    _helixManager.addInstanceConfigChangeListener(_helixBrokerRoutingTable);
    _helixManager.addLiveInstanceChangeListener(_liveInstancesListener);

    _brokerServerBuilder.getBrokerMetrics().addCallbackGauge("helix.connected", new Callable<Long>() {
        @Override
        public Long call() throws Exception {
            return _helixManager.isConnected() ? 1L : 0L;
        }
    });

    _helixManager.addPreConnectCallback(new PreConnectCallback() {
        @Override
        public void onPreConnect() {
            _brokerServerBuilder.getBrokerMetrics()
                    .addMeteredGlobalValue(BrokerMeter.HELIX_ZOOKEEPER_RECONNECTS, 1L);
        }
    });
}

From source file:net.sf.jclal.evaluation.method.AbstractEvaluationMethod.java

/**
 *
 * @param configuration The configuration of the random generator.
 * <p>//from   www.  j a v a2s  . c o m
 * rand-gen-factory type= class</p>
 *
 */
@SuppressWarnings("unchecked")
protected void setRandGenSettings(Configuration configuration) {
    // Random generators factory
    String randomError = "rand-gen-factory type= ";
    try {
        // Species classname
        String randGenFactoryClassname = configuration.getString("rand-gen-factory[@type]");
        randomError += randGenFactoryClassname;
        // Species class
        Class<? extends IRandGenFactory> randGenFactoryClass = (Class<? extends IRandGenFactory>) Class
                .forName(randGenFactoryClassname);
        // Species instance
        IRandGenFactory randGenFactory = randGenFactoryClass.newInstance();
        // Configure species
        if (randGenFactory instanceof IConfigure) {
            ((IConfigure) randGenFactory).configure(configuration.subset("rand-gen-factory"));
        }
        // Set species
        setRandGenFactory(randGenFactory);
    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException(
                "\nIllegal random generators factory classname: " + randomError);
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException(
                "\nProblems creating an instance of random generators factory: " + randomError, e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException(
                "\nProblems creating an instance of random generators factory: " + randomError, e);
    }
}

From source file:net.sf.jclal.activelearning.multilabel.querystrategy.MultiLabelDensityDiversityQueryStrategy.java

/**
 *
 * @param configuration Configuration object for density diversity strategy.
 *
 * The XML labels supported are:/*  w ww .j ava2s  . co  m*/
 * <ul>
 * <li><b>importance-density= double</b></li>
 * <li>
 * <b>distance-function type= class</b>
 * <p>
 * Package: net.sf.jclal.util.distancefunction
 * </p>
 * <p>
 * Class: All
 * </p>
 * <p>
 * Package: weka.core
 * </p>
 * <p>
 * Class: EuclideanDistance || ManhattanDistance || MinkowskiDistance...</p>
 * </li>
 * <li>matrix-file= boolean</li>
 * <li>
 * <b>sub-query-strategy type= class</b>
 * <p>
 * Package: net.sf.jclal.activelearning.multilabel.querystrategy</p>
 * <p>
 * Class: All</p>
 * </li>
 * </ul>
 */
@Override
public void configure(Configuration configuration) {

    try {
        super.configure(configuration);
    } catch (Exception e) {
    }

    // Set relativeImportanceOfDensity
    double currentImportance = configuration.getDouble("importance-density", relativeImportanceOfDensity);

    setRelativeImportanceOfDensity(currentImportance);

    String distanceError = "distance-function type= ";
    try {

        // Set the distance classname
        String distanceClassname = configuration.getString("distance-function[@type]");
        distanceError += distanceClassname;

        // the distance class
        Class<? extends NormalizableDistance> distance = (Class<? extends NormalizableDistance>) Class
                .forName(distanceClassname);

        // the distance instance
        NormalizableDistance currentDistance = distance.newInstance();

        // Configure the distance
        if (currentDistance instanceof IConfigure) {
            ((IConfigure) currentDistance).configure(configuration.subset("distance-function"));
        }

        // Set the distance
        setTypeOfDistance(currentDistance);
    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("Illegal distance classname: " + distanceError, e);
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("Illegal distance classname: " + distanceError, e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("Illegal distance classname: " + distanceError, e);
    }

    // Set the sub query strategy
    String subError = "sub-query-strategy type= ";
    try {
        // sub Query strategy classname
        String strategyClassname = configuration.getString("sub-query-strategy[@type]");
        subError += strategyClassname;
        // sub Query strategy class
        Class<? extends IQueryStrategy> strategyClass = (Class<? extends IQueryStrategy>) Class
                .forName(strategyClassname);
        // sub Query strategy instance
        IQueryStrategy currentSubStrategy = strategyClass.newInstance();

        // Configure sub Query strategy (if necessary)
        if (currentSubStrategy instanceof IConfigure) {
            ((IConfigure) currentSubStrategy).configure(configuration.subset("sub-query-strategy"));
        }
        // Set the sub Query strategy
        setSubQueryStrategy(currentSubStrategy);
    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("Illegal sub-query-strategy classname: " + subError, e);
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("Illegal sub-query-strategy classname: " + subError, e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("Illegal sub-query-strategy classname: " + subError, e);
    }

    //Set if handle the matrix over a file and not over the main memory
    boolean matrixFile = configuration.getBoolean("matrix-file", matrixOverFile);

    setMatrixOverFile(matrixFile);
}

From source file:net.sf.jclal.activelearning.algorithm.ClassicalALAlgorithm.java

/**
 * Establishes the configuration of the stop criterion
 *
 * @param configuration/*from w  ww .ja  v  a  2s.c  o  m*/
 *            The configuration object to use
 */
public void setStopCriterionConfigure(Configuration configuration) {

    // Number of defined stopCriterio
    int stopCriterioValue = configuration.getList("stop-criterion[@type]").size();
    // For each listener in list
    for (int i = 0; i < stopCriterioValue; i++) {
        String header = "stop-criterion(" + i + ")";
        // stopCriterio
        String stopError = "stop-criterion type= ";
        try {
            // stopCriterio classname
            String stopCriterioClassname = configuration.getString(header + "[@type]");

            stopError += stopCriterioClassname;
            // stopCriterio class
            Class<? extends IStopCriterion> stopCriterioClass = (Class<? extends IStopCriterion>) Class
                    .forName(stopCriterioClassname);
            // stopCriterio instance
            IStopCriterion stopCriterio = stopCriterioClass.newInstance();
            // Configure stopCriterio (if necessary)
            if (stopCriterio instanceof IConfigure) {
                ((IConfigure) stopCriterio).configure(configuration.subset(header));
            }
            // Add this stopCriterio to the algorithm
            addStopCriterion(stopCriterio);
        } catch (ClassNotFoundException e) {
            throw new ConfigurationRuntimeException("\nIllegal stopCriterion classname: " + stopError, e);
        } catch (InstantiationException e) {
            throw new ConfigurationRuntimeException("\nIllegal stopCriterion classname: " + stopError, e);
        } catch (IllegalAccessException e) {
            throw new ConfigurationRuntimeException("\nIllegal stopCriterion classname: " + stopError, e);
        }

    }

}

From source file:keel.Algorithms.Neural_Networks.NNEP_Common.algorithm.NeuralNetAlgorithm.java

/**
 * <p>//w w w  .  j  a  v a  2 s  .c o  m
 * Configuration parameters for NeuralNetAlgorithm class are:
 * 
 * <ul>
 * <li>
 * <code>species: ISpecies (complex)</code></p>
 * Individual species
 * </li><li>
 * <code>evaluator IEvaluator (complex)</code></p>
 * Individuals evaluator
 * </li><li>
 * <code>population-size (int)</code></p>
 * Population size
 * </li><li>
 * <code>max-of-generations (int)</code></p>
 * Maximum number of generations
 * </li>
 * <li>
 * <code>provider: IProvider (complex)</code></p>
 * Individuals provider
 * </li>
 * <li>
 * <code>mutator1: IMutator<I> (complex)</code></p>
 * Individuals mutator1
 * </li>
 * <li>
 * <code>mutator2: IMutator<I> (complex)</code></p>
 * Individuals mutator2
 * </li>
 * <li>
 * <code>creation-ratio (double)</code></p>
 * Ratio "elements created"/"elements remaining"
 * </li>
 * <li>
 * <code>percentage-second-mutator (int)</code></p>
 * Percentage of individuals mutated with second mutator
 * </li>
 * <li>
 * <code>max-generations-without-improving-mean (int)</code></p>
 * Maximum number of generations without improving mean fitness
 * </li>
 * <li>
 * <code>max-generations-without-improving-best (int)</code></p>
 * Maximum number of generations without improving best fitness
 * </li>
 * <li>
 * <code>fitness-difference (double)</code></p>
 * Difference between two fitness that we consider
  * enough to say that the fitness has improved
 * </li>
 * </ul>
 * </p>
 * @param configuration Configuration object to obtain the parameters
 */
@SuppressWarnings("unchecked")
public void configure(Configuration configuration) {

    // Random generators factory
    try {
        // Species classname
        String randGenFactoryClassname = configuration.getString("rand-gen-factory[@type]");
        // Species class
        Class<? extends IRandGenFactory> randGenFactoryClass = (Class<? extends IRandGenFactory>) Class
                .forName(randGenFactoryClassname);
        // Species instance
        IRandGenFactory randGenFactory = randGenFactoryClass.newInstance();
        // Configure species
        if (randGenFactory instanceof IConfigure) {
            ((IConfigure) randGenFactory).configure(configuration.subset("rand-gen-factory"));
        }
        // Set species
        setRandGenFactory(randGenFactory);
    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("Illegal random generators factory classname");
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of random generators factory",
                e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of random generators factory",
                e);
    }
    // Individual species
    try {
        // Species classname
        String speciesClassname = configuration.getString("species[@type]");
        // Species class
        Class<ISpecies<I>> speciesClass = (Class<ISpecies<I>>) Class.forName(speciesClassname);
        // Species instance
        ISpecies<I> species = speciesClass.newInstance();
        // Configure species if neccesary
        if (species instanceof IConfigure) {
            // Extract species configuration
            Configuration speciesConfiguration = configuration.subset("species");
            // Configure species
            ((IConfigure) species).configure(speciesConfiguration);
        }
        // Set species
        setSpecies(species);
    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("Illegal species classname");
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of species", e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of species", e);
    }
    // Individuals evaluator
    try {
        // Evaluator classname
        String evaluatorClassname = configuration.getString("evaluator[@type]");
        // Evaluator class
        Class<IEvaluator<I>> evaluatorClass = (Class<IEvaluator<I>>) Class.forName(evaluatorClassname);
        // Evaluator instance
        IEvaluator<I> evaluator = evaluatorClass.newInstance();
        // Configure evaluator if neccesary
        if (evaluator instanceof IConfigure) {
            // Extract species configuration
            Configuration evaluatorConfiguration = configuration.subset("evaluator");
            // Configure evaluator
            ((IConfigure) evaluator).configure(evaluatorConfiguration);
        }
        // Set species
        setEvaluator(evaluator);
    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("Illegal evaluator classname");
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of evaluator", e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of evaluator", e);
    }
    // Population size
    int populationSize = configuration.getInt("population-size");
    setPopulationSize(populationSize);
    // Maximum of generations
    int maxOfGenerations = configuration.getInt("max-of-generations");
    setMaxOfGenerations(maxOfGenerations);
    // Individuals provider
    try {
        // Provider classname
        String providerClassname = configuration.getString("provider[@type]");
        // Provider class
        Class<IProvider<I>> providerClass = (Class<IProvider<I>>) Class.forName(providerClassname);
        // Provider instance
        IProvider<I> provider = providerClass.newInstance();
        // Configure provider if neccesary
        if (provider instanceof IConfigure) {
            // Extract provider configuration
            Configuration providerConfiguration = configuration.subset("provider");
            // Configure provider
            ((IConfigure) provider).configure(providerConfiguration);
        }
        // Set provider
        setProvider(provider);
    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("Illegal provider classname");
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of provider", e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of provider", e);
    }
    // Individuals mutator1
    try {
        // Mutator1 classname
        String mutator1Classname = configuration.getString("mutator1[@type]");
        // Mutator1 classe
        Class<IMutator<I>> mutator1Class = (Class<IMutator<I>>) Class.forName(mutator1Classname);
        // Mutator1 instance
        IMutator<I> mutator1 = mutator1Class.newInstance();
        // Configure mutator1 if neccesary
        if (mutator1 instanceof IConfigure) {
            // Extract mutator1 configuration
            Configuration mutator1Configuration = configuration.subset("mutator1");
            // Configure mutator1
            ((IConfigure) mutator1).configure(mutator1Configuration);
        }
        // Set mutator1
        setMutator1(mutator1);
    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("Illegal mutator1 classname");
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of mutator1", e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of mutator1", e);
    }
    // Individuals mutator2
    try {
        // Mutator2 classname
        String mutator2Classname = configuration.getString("mutator2[@type]");
        // Mutator2 class
        Class<IMutator<I>> mutator2Class = (Class<IMutator<I>>) Class.forName(mutator2Classname);
        // Mutator2 instance
        IMutator<I> mutator2 = mutator2Class.newInstance();
        // Configure mutator2 if neccesary
        if (mutator2 instanceof IConfigure) {
            // Extract mutator2 configuration
            Configuration mutator2Configuration = configuration.subset("mutator2");
            // Configure mutator2 
            ((IConfigure) mutator2).configure(mutator2Configuration);
        }
        // Set mutator2
        setMutator2(mutator2);
    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("Illegal mutator2 classname");
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of mutator2", e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of mutator2", e);
    }
    // Creation ratio
    double cratio = configuration.getDouble("creation-ratio");
    setCratio(cratio);
    // Percentage of individuals mutated with second mutator
    int percenageMutator2 = configuration.getInt("percentage-second-mutator");
    setPercentageSecondMutator(percenageMutator2);
    // Maximum of generations without improving mean fitness
    int mogmean = configuration.getInt("max-generations-without-improving-mean");
    setMogmean(mogmean);
    // Maximum of generations without improving best fitness
    int mogbest = configuration.getInt("max-generations-without-improving-best");
    setMogbest(mogbest);
    // Significative fitness difference
    double fitDif = configuration.getDouble("fitness-difference");
    setFitDif(fitDif);
}

From source file:net.sf.jclal.listener.ClassicalReporterListener.java

/**
 *
 * @param configuration The configuration of Classical Reporter Listener.
 *
 * The XML labels supported are:/*from w  w  w  .  j  a  v a2 s  .  c o m*/
 *
 * <ul>
 * <li><b>report-title= String</b>, default= untitled</li>
 * <li><b>report-directory= String</b>, default= reports</li>
 * <li><b>report-frequency= int</b></li>
 * <li><b>report-on-console= boolean</b></li>
 * <li><b>report-on-file= boolean</b></li>
 * <li><b>send-email= class</b>
 * <p>
 * Package: net.sf.jclal.util.mail</p>
 * Class: All
 * </li>
 * </ul>
 */
@Override
public void configure(Configuration configuration) {

    // Set report title (default "untitled")
    String reportTitleT = configuration.getString("report-title", reportTitle);
    setReportTitle(reportTitleT);

    // Set report title (default "reports/")
    String reportDirectoryT = configuration.getString("report-directory", reportDirectory);
    setReportDirectory(reportDirectoryT);

    // Set report frequency (default 1 iteration)
    int reportFrequencyT = configuration.getInt("report-frequency", reportFrequency);
    setReportFrequency(reportFrequencyT);

    // Set console report (default on)
    boolean reportOnConsoleT = configuration.getBoolean("report-on-console", reportOnConsole);
    setReportOnConsole(reportOnConsoleT);

    // Set file report (default off)
    boolean reportOnFileT = configuration.getBoolean("report-on-file", reportOnFile);
    setReportOnFile(reportOnFileT);

    String sendError = "send-email type= ";
    try {

        String senderEmailClassname = configuration.getString("send-email[@type]");
        sendError += senderEmailClassname;
        //If a email sender was especified
        if (senderEmailClassname != null) {
            // sender email class
            Class<?> senderEmailClass = Class.forName(senderEmailClassname);

            SenderEmail senderEmailT = (SenderEmail) senderEmailClass.newInstance();

            // Configure listener (if necessary)
            if (senderEmailT instanceof IConfigure) {
                ((IConfigure) senderEmailT).configure(configuration.subset("send-email"));
            }

            setSenderEmail(senderEmailT);
        }

    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("\nIllegal sender email classname: " + sendError, e);
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("\nIllegal sender email classname: " + sendError, e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("\nIllegal sender email classname: " + sendError, e);
    }
}

From source file:es.udc.gii.common.eaf.algorithm.CMAEvolutionaryAlgorithm.java

@Override
public void configure(Configuration conf) {
    super.configure(conf);

    try {//from  www.j  a  va2 s .  c  o m

        if (conf.containsKey("InitialX")) {

            double x = conf.getDouble("InitialX");
            this.xMean = new double[] { x };

        } else {
            this.xMean = new double[] { 0.0 };
            ConfWarning w = new ConfWarning("EvolutionaryAlgorithm.InitialX", 0.0);
            w.warn();

        }

        if (conf.containsKey("TypicalX")) {
            double x = conf.getDouble("TypicalX");
            this.typicalX = new double[] { x };
        } else {
            this.typicalX = null;
            ConfWarning w = new ConfWarning("EvolutionaryAlgorithm.TypicalX", 0.0);
            w.warn();

        }

        if (conf.containsKey("InitialStandardDeviation")) {

            this.startsigma = new double[] { conf.getDouble("InitialStandardDeviation") };

        } else {

            this.startsigma = new double[] { 1.0 };
            ConfWarning w = new ConfWarning("EvolutionaryAlgorithm.InitialStandardDeviation", 1.0);
            w.warn();

        }

        if (conf.containsKey("Mu")) {

            this.mu = conf.getInt("Mu");

        } else {

            this.mu = -1;
            ConfWarning w = new ConfWarning("EvolutionaryAlgorithm.Mu", this.mu);
            w.warn();

        }

        if (conf.containsKey("RecombinationType")) {

            this.recombinationType = (RecombinationType) Class
                    .forName(conf.getString("RecombinationType.Class")).newInstance();
            this.recombinationType.configure(conf.subset("RecombinationType"));
        } else {
            ConfWarning w = new ConfWarning("EvolutionaryAlgorithm.RecombinationType",
                    this.recombinationType.toString());
            w.warn();
        }

        if (conf.containsKey("Cs")) {
            this.cs = conf.getDouble("Cs");
        } else {
            this.cs = -1;
            ConfWarning w = new ConfWarning("CMAEvolutionaryAlgorithm.Cs", this.cs);
            w.warn();
        }

        if (conf.containsKey("Damps")) {
            this.damps = conf.getDouble("Damps");
        } else {

            this.damps = -1;
            ConfWarning w = new ConfWarning("CMAEvolutionaryAlgorithm.Damps", this.damps);
            w.warn();

        }

        if (conf.containsKey("DiagonalCovarianceMatrix")) {
            this.diagonalCovarianceMatrix = conf.getInt("DiagonalCovarianceMatrix");

        } else {
            this.diagonalCovarianceMatrix = -1;
            ConfWarning w = new ConfWarning("CMAEvolutionaryAlgorithm.DiagonalCovarianceMatrix",
                    this.diagonalCovarianceMatrix);
            w.warn();
        }

    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

From source file:keel.Algorithms.Neural_Networks.NNEP_Common.NeuralNetIndividualSpecies.java

/**
 * <p>/*  w w w .j a va 2  s . co m*/
 * Configuration parameters for this species are:
 * 
 * 
 * input-layer.number-of-inputs (int)
 *  Number of inputs. Number of inputs of this species neural nets.
 *
 * output-layer.number-of-outputs (int)
 *  Number of inputs. Number of outputs of this species neural nets.
 * 
 * hidden-layer(i).weight-range (complex)
 *  Weigth range of the hidden layer number "i".
 * 
 * output-layer.weight-range (complex)
 *  Weigth range of the outputlayer.
 *  
 * hidden-layer(i).maximum-number-of-neurons (int)
 *  Maximum number of neurons of hidden layer number "i".
 * 
 * hidden-layer(i).initial-number-of-neurons (int)
 *  Initial number of neurons of hidden layer number "i".
 * 
 * hidden-layer(i)[@type] (string)
 *  Layer type of the hidden layer number "i".
 *  
 * output-layer[@type] (string)
 *  Layer type of the output layer.
 * 
 * hidden-layer(i)[@biased] (string)
 *  Boolean indicating if hidden layer number "i" is biased.
 * 
 * output-layer[@type] (string)
 *  Boolean indicating if the output layer is biased.
 *  
 *  @param configutation Configuration if the Individual
 * </p>
 */

@SuppressWarnings("unchecked")
public void configure(Configuration configuration) {
    // -------------------------------------- Setup neuralNetType
    neuralNetType = configuration.getString("neural-net-type");

    // -------------------------------------- Setup nOfHiddenLayers 
    nOfHiddenLayers = configuration.getList("hidden-layer[@type]").size();

    // -------------------------------------- Setup nOfInputs 
    //nOfInputs = configuration.getInt("input-layer.number-of-inputs");

    // -------------------------------------- Setup nOfOutputs
    //nOfOutputs = configuration.getInt("output-layer.number-of-outputs");

    // Initialize arrays
    maxNofneurons = new int[nOfHiddenLayers];
    minNofneurons = new int[nOfHiddenLayers];
    initialMaxNofneurons = new int[nOfHiddenLayers];
    type = new String[nOfHiddenLayers + 1];
    initiator = new String[nOfHiddenLayers + 1];
    biased = new boolean[nOfHiddenLayers + 1];

    weightRanges = new Interval[nOfHiddenLayers + 1][];
    neuronTypes = new String[nOfHiddenLayers + 1][];
    percentages = new double[nOfHiddenLayers + 1][];
    initiatorNeuronTypes = new String[nOfHiddenLayers + 1][];
    for (int i = 0; i < nOfHiddenLayers + 1; i++) {
        String header;

        if (i != nOfHiddenLayers) {
            header = "hidden-layer(" + i + ")";
            // ---------------------------------- Setup maxNofneurons array
            maxNofneurons[i] = configuration.getInt(header + ".maximum-number-of-neurons");
            // ---------------------------------- Setup minNofneurons array
            minNofneurons[i] = configuration.getInt(header + ".minimum-number-of-neurons");
            // ---------------------------------- Setup initialMaxNofneurons array
            initialMaxNofneurons[i] = configuration.getInt(header + ".initial-maximum-number-of-neurons");
            // ---------------------------------- Setup initiator array
            initiator[i] = configuration.getString(header + ".initiator-of-links");
        } else {
            header = "output-layer";
            // ---------------------------------- Setup initiator array
            initiator[i] = configuration.getString(header + ".initiator-of-links");
        }

        //  ----------------------------------------- Setup type array
        type[i] = configuration.getString(header + "[@type]");

        //  ----------------------------------------- Setup biased array
        biased[i] = configuration.getBoolean(header + "[@biased]");

        // -------------------------------------- Setup weight ranges array
        weightRanges[i] = new Interval[1];
        try {
            // Range name
            String rangeName = header + ".weight-range";
            // Range classname
            String rangeClassname = configuration.getString(rangeName + "[@type]");
            // Range class
            Class<Interval> rangeClass = (Class<Interval>) Class.forName(rangeClassname);
            // Range instance
            Interval range = rangeClass.newInstance();
            // Configura range
            range.configure(configuration.subset(rangeName));
            // Set range
            if (i != nOfHiddenLayers)
                setHiddenLayerWeightRange(i, 0, range);
            else
                setOutputLayerWeightRange(0, range);
        } catch (ClassNotFoundException e) {
            throw new ConfigurationRuntimeException("Illegal range classname");
        } catch (InstantiationException e) {
            throw new ConfigurationRuntimeException("Problems creating an instance of range", e);
        } catch (IllegalAccessException e) {
            throw new ConfigurationRuntimeException("Problems creating an instance of range", e);
        }
    }
}

From source file:com.appeligo.channelfeed.CapturePreviews.java

@Override
protected void openSources(Configuration provider) {

    XMLConfiguration config = getConfig();

    String frameSize = config.getString("videoParams[@frameSize]");
    int frameRate = config.getInt("videoParams[@frameRate]", -1);
    int audioSyncSamplesPerSecond = config.getInt("videoParams[@audioSyncSamplesPerSecond]", -1);
    int audioSamplingFrequency = config.getInt("videoParams[@audioSamplingFrequency]", -1);
    int audioBitRate = config.getInt("videoParams[@audioBitRate]", -1);
    int audioChannels = config.getInt("videoParams[@audioChannels]", -1);
    String outputFormat = config.getString("videoParams[@outputFormat]");

    log.info("frameSize=" + frameSize + ", frameRate=" + frameRate + ", audioSyncSamplesPerSecond="
            + audioSyncSamplesPerSecond + ", audioSamplingFrequency=" + audioSamplingFrequency
            + ", audioBitRate=" + audioBitRate + ", audioChannels=" + audioChannels + ", outputFormat="
            + outputFormat);//  ww w  .j  a  va 2s  .  c om

    int clipLengthSeconds = config.getInt("previewRules[@clipLengthSeconds]", -1);
    int delaySeconds = config.getInt("previewRules[@delaySeconds]", -1);
    // This delaySeconds could be set directly on the TVCapturer, but we want the PreviewThread to be aware
    int earliestClipSeconds = config.getInt("previewRules[@earliestClipSeconds]", -1);
    int latestClipSeconds = config.getInt("previewRules[@latestClipSeconds]", -1);
    int latestClipPercentOfDuration = config.getInt("previewRules[@latestClipPercentOfDuration]", -1);
    int maxClips = config.getInt("previewRules[@maxClips]", -1);
    int minSecondsBetweenClips = config.getInt("previewRules[@minSecondsBetweenClips]", -1);

    log.info("clipLengthSeconds=" + clipLengthSeconds + ", delaySeconds=" + delaySeconds
            + ", earliestClipSeconds=" + earliestClipSeconds + ", latestClipSeconds=" + latestClipSeconds
            + ", latestClipPercentOfDuration=" + latestClipPercentOfDuration + ", maxClips=" + maxClips
            + ", minSecondsBetweenClips=" + minSecondsBetweenClips);

    int tunerCount = provider.getList("tuners.tuner[@deviceNumber]").size();

    for (int j = 0; j < tunerCount; j++) {

        String deviceNumber = provider.getString("tuners.tuner(" + j + ")[@deviceNumber]");
        log.info("deviceNumber=" + deviceNumber);

        try {

            VideoDevice videoDevice = new VideoDevice(Integer.parseInt(deviceNumber), getFrequencyStandard());

            TVCapturer tvCapturer = new TVCapturer(videoDevice);

            if (frameSize != null && (frameSize.trim().length() > 0)) {
                tvCapturer.setFrameSize(frameSize);
            }
            if (frameRate >= 0) {
                tvCapturer.setFrameRate(frameRate);
            }
            if (audioSyncSamplesPerSecond >= 0) {
                tvCapturer.setAudioSyncSamplesPerSecond(audioSyncSamplesPerSecond);
            }
            if (audioSamplingFrequency >= 0) {
                tvCapturer.setAudioSamplingFrequency(audioSamplingFrequency);
            }
            if (audioBitRate >= 0) {
                tvCapturer.setAudioBitRate(audioBitRate);
            }
            if (audioChannels >= 0) {
                tvCapturer.setAudioChannels(audioChannels);
            }
            if (outputFormat != null && outputFormat.trim().length() > 0) {
                tvCapturer.setOutputFormat(outputFormat);
            }

            PreviewThread previewThread = new PreviewThread("Preview thread for device #" + deviceNumber);
            previewThread.setPreviewDocumentRoot(getPreviewDocumentRoot());
            previewThread.setTVCapturer(tvCapturer);
            previewThread.setEpgService(getEpgService());
            previewThread.setLineupID(getLineupID());

            if (clipLengthSeconds >= 0) {
                previewThread.setClipLengthSeconds(clipLengthSeconds);
            }
            if (delaySeconds >= 0) {
                previewThread.setDelaySeconds(delaySeconds);
            }
            if (earliestClipSeconds >= 0) {
                previewThread.setEarliestClipSeconds(earliestClipSeconds);
            }
            if (latestClipSeconds >= 0) {
                previewThread.setLatestClipSeconds(latestClipSeconds);
            }
            if (latestClipPercentOfDuration >= 0) {
                previewThread.setLatestClipPercentOfDuration(latestClipPercentOfDuration);
            }
            if (maxClips >= 0) {
                previewThread.setMaxClips(maxClips);
            }
            if (minSecondsBetweenClips >= 0) {
                previewThread.setMinSecondsBetweenClips(minSecondsBetweenClips);
            }

            Configuration tuner = provider.subset("tuners.tuner(" + j + ")");
            int stationCount = tuner.getList("stations.station[@channel]").size();
            for (int k = 0; k < stationCount; k++) {

                String channel = tuner.getString("stations.station(" + k + ")[@channel]");
                String callsign = tuner.getString("stations.station(" + k + ")[@callsign]");

                log.info("channel=" + channel + ", callsign=" + callsign);

                previewThread.addStation(callsign, channel);
            }

            previewThread.start();
        } catch (MalformedURLException e1) {
            log.error("Exception on a channel", e1);
        } catch (NumberFormatException e1) {
            log.error("Exception on a channel", e1);
        } catch (IOException e1) {
            log.error("Exception on a channel", e1);
        }
    }
}