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

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

Introduction

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

Prototype

Double getDouble(String key, Double defaultValue);

Source Link

Document

Get a Double associated with the given configuration key.

Usage

From source file:keel.Algorithms.Neural_Networks.IRPropPlus_Clas.IRPropPlus.java

/**
 * <p>//from   ww w . j a  va2 s  .com
 * @param settings Settings Configuration
 * </p>
 */
public void configure(Configuration settings) {
    initialStepSize = settings.getDouble("initial-step-size[@value]", 0.0125);

    minimumDelta = settings.getDouble("minimum-delta[@value]", 0.0);

    maximumDelta = settings.getDouble("maximum-delta[@value]", 50.0);

    positiveEta = settings.getDouble("positive-eta[@value]", 1.2);

    negativeEta = settings.getDouble("negative-eta[@value]", 0.2);

    epochs = settings.getInt("cycles[@value]", 25);
}

From source file:net.sf.jclal.activelearning.singlelabel.querystrategy.VarianceReductionQueryStrategy.java

/**
 *
 * @param configuration Configuration for variance reduction strategy.
 *
 *The XML labels supported are://www. ja v a2  s  .  c  o  m
 *
 * <ul>
 * <li>epsilon= double</li>
 * <li>epsilon-iteration= int</li>
 * <li>factor-regularization= double</li>
 * </ul>
 */
@Override
public void configure(Configuration configuration) {
    super.configure(configuration);

    //Set epsilon
    double currentEpsilon = configuration.getDouble("epsilon", epsilon);
    setEpsilon(currentEpsilon);

    //Set epsilon iteration
    int currentMaxEpsilonI = configuration.getInt("epsilon-iteration", maxEpsilonIteration);
    setMaxEpsilonIteration(currentMaxEpsilonI);

    //Set factor regularization
    double currentFactorRegularization = configuration.getDouble("factor-regularization", factorRegularization);
    setFactorRegularization(currentFactorRegularization);

}

From source file:edu.berkeley.sparrow.examples.HeterogeneousFrontend.java

public void run(String[] args) {
    try {//from  w  ww .ja  v  a2  s . c o m
        OptionParser parser = new OptionParser();
        parser.accepts("c", "configuration file").withRequiredArg().ofType(String.class);
        parser.accepts("help", "print help statement");
        OptionSet options = parser.parse(args);

        if (options.has("help")) {
            parser.printHelpOn(System.out);
            System.exit(-1);
        }

        // Logger configuration: log to the console
        BasicConfigurator.configure();
        LOG.setLevel(Level.DEBUG);

        Configuration conf = new PropertiesConfiguration();

        if (options.has("c")) {
            String configFile = (String) options.valueOf("c");
            conf = new PropertiesConfiguration(configFile);
        }

        double warmupLambda = conf.getDouble("warmup_job_arrival_rate_s", DEFAULT_WARMUP_JOB_ARRIVAL_RATE_S);
        int warmupDurationS = conf.getInt("warmup_s", DEFAULT_WARMUP_S);
        int postWarmupS = conf.getInt("post_warmup_s", DEFAULT_POST_WARMUP_S);

        double lambda = conf.getDouble("job_arrival_rate_s", DEFAULT_JOB_ARRIVAL_RATE_S);
        int experimentDurationS = conf.getInt("experiment_s", DEFAULT_EXPERIMENT_S);
        LOG.debug("Using arrival rate of  " + lambda + " tasks per second and running experiment for "
                + experimentDurationS + " seconds.");
        int tasksPerJob = conf.getInt("tasks_per_job", DEFAULT_TASKS_PER_JOB);
        int numPreferredNodes = conf.getInt("num_preferred_nodes", DEFAULT_NUM_PREFERRED_NODES);
        LOG.debug("Using " + numPreferredNodes + " preferred nodes for each task.");
        int benchmarkIterations = conf.getInt("benchmark.iterations", DEFAULT_BENCHMARK_ITERATIONS);
        int benchmarkId = conf.getInt("benchmark.id", DEFAULT_TASK_BENCHMARK);

        List<String> backends = new ArrayList<String>();
        if (numPreferredNodes > 0) {
            /* Attempt to parse the list of slaves, which we'll need to (randomly) select preferred
             * nodes. */
            if (!conf.containsKey(BACKENDS)) {
                LOG.fatal("Missing configuration backend list, which is needed to randomly select "
                        + "preferred nodes (num_preferred_nodes set to " + numPreferredNodes + ")");
            }
            for (String node : conf.getStringArray(BACKENDS)) {
                backends.add(node);
            }
            if (backends.size() < numPreferredNodes) {
                LOG.fatal("Number of backends smaller than number of preferred nodes!");
            }
        }

        List<UserInfo> users = new ArrayList<UserInfo>();
        if (conf.containsKey(USERS)) {
            for (String userSpecification : conf.getStringArray(USERS)) {
                LOG.debug("Reading user specification: " + userSpecification);
                String[] parts = userSpecification.split(":");
                if (parts.length != 3) {
                    LOG.error("Unexpected user specification string: " + userSpecification + "; ignoring user");
                    continue;
                }
                users.add(new UserInfo(parts[0], Integer.parseInt(parts[1]), Integer.parseInt(parts[2])));
            }
        }
        if (users.size() == 0) {
            // Add a dummy user.
            users.add(new UserInfo("defaultUser", 1, 0));
        }

        SparrowFrontendClient client = new SparrowFrontendClient();
        int schedulerPort = conf.getInt("scheduler_port", SchedulerThrift.DEFAULT_SCHEDULER_THRIFT_PORT);
        client.initialize(new InetSocketAddress("localhost", schedulerPort), APPLICATION_ID, this);

        if (warmupDurationS > 0) {
            LOG.debug("Warming up for " + warmupDurationS + " seconds at arrival rate of " + warmupLambda
                    + " jobs per second");
            launchTasks(users, warmupLambda, warmupDurationS, tasksPerJob, numPreferredNodes,
                    benchmarkIterations, benchmarkId, backends, client);
            LOG.debug("Waiting for queues to drain after warmup (waiting " + postWarmupS + " seconds)");
            Thread.sleep(postWarmupS * 1000);
        }
        LOG.debug("Launching experiment for " + experimentDurationS + " seconds");
        launchTasks(users, lambda, experimentDurationS, tasksPerJob, numPreferredNodes, benchmarkIterations,
                benchmarkId, backends, client);
    } catch (Exception e) {
        LOG.error("Fatal exception", e);
    }
}

From source file:edu.berkeley.sparrow.examples.FairnessTestingFrontend.java

public void run(String[] args) {
    try {/*ww  w.  j a  v a 2s .  c o  m*/
        OptionParser parser = new OptionParser();
        parser.accepts("c", "configuration file").withRequiredArg().ofType(String.class);
        parser.accepts("help", "print help statement");
        OptionSet options = parser.parse(args);

        if (options.has("help")) {
            parser.printHelpOn(System.out);
            System.exit(-1);
        }

        // Logger configuration: log to the console
        BasicConfigurator.configure();
        LOG.setLevel(Level.DEBUG);

        Configuration conf = new PropertiesConfiguration();

        if (options.has("c")) {
            String configFile = (String) options.valueOf("c");
            conf = new PropertiesConfiguration(configFile);
        }

        double warmup_lambda = conf.getDouble("warmup_job_arrival_rate_s", DEFAULT_WARMUP_JOB_ARRIVAL_RATE_S);
        int warmup_duration_s = conf.getInt("warmup_s", DEFAULT_WARMUP_S);
        int post_warmup_s = conf.getInt("post_warmup_s", DEFAULT_POST_WARMUP_S);

        // We use this to represent the the rate to fully load the cluster. This is a hack.
        double lambda = conf.getDouble("job_arrival_rate_s", DEFAULT_JOB_ARRIVAL_RATE_S);
        int experiment_duration_s = conf.getInt("experiment_s", DEFAULT_EXPERIMENT_S);
        LOG.debug("Using arrival rate of  " + lambda + " tasks per second and running experiment for "
                + experiment_duration_s + " seconds.");
        int tasksPerJob = conf.getInt("tasks_per_job", DEFAULT_TASKS_PER_JOB);
        int numPreferredNodes = conf.getInt("num_preferred_nodes", DEFAULT_NUM_PREFERRED_NODES);
        LOG.debug("Using " + numPreferredNodes + " preferred nodes for each task.");
        int benchmarkIterations = conf.getInt("benchmark.iterations", DEFAULT_BENCHMARK_ITERATIONS);
        int benchmarkId = conf.getInt("benchmark.id", DEFAULT_TASK_BENCHMARK);

        List<String> backends = new ArrayList<String>();
        if (numPreferredNodes > 0) {
            /* Attempt to parse the list of slaves, which we'll need to (randomly) select preferred
             * nodes. */
            if (!conf.containsKey(BACKENDS)) {
                LOG.fatal("Missing configuration backend list, which is needed to randomly select "
                        + "preferred nodes (num_preferred_nodes set to " + numPreferredNodes + ")");
            }
            for (String node : conf.getStringArray(BACKENDS)) {
                backends.add(node);
            }
            if (backends.size() < numPreferredNodes) {
                LOG.fatal("Number of backends smaller than number of preferred nodes!");
            }
        }

        List<SubExperiment> experiments = new ArrayList<SubExperiment>();
        double fullyUtilizedArrivalRate = lambda;

        // For the first twenty seconds, the first user submits at a rate to fully utilize the cluster.
        List<UserInfo> onlyUser0 = new ArrayList<UserInfo>();
        onlyUser0.add(new UserInfo("user0", 1, 0));
        experiments.add(new SubExperiment(onlyUser0, 20, fullyUtilizedArrivalRate));

        // For the next 10 seconds, user1 increases her rate to 25% of the cluster.
        List<UserInfo> user1QuarterDemand = new ArrayList<UserInfo>();
        user1QuarterDemand.add(new UserInfo("user0", 4, 0));
        user1QuarterDemand.add(new UserInfo("user1", 5, 0));
        experiments.add(new SubExperiment(user1QuarterDemand, 10, 1.25 * fullyUtilizedArrivalRate));

        // For the next 10 seconds, user 1 increases her rate to 50% of the cluster (using exactly
        // her share, but no more).
        List<UserInfo> user1HalfDemand = new ArrayList<UserInfo>();
        user1HalfDemand.add(new UserInfo("user0", 2, 0));
        user1HalfDemand.add(new UserInfo("user1", 3, 0));
        experiments.add(new SubExperiment(user1HalfDemand, 10, 1.5 * fullyUtilizedArrivalRate));

        // Next user 1 goes back down to 25%.
        experiments.add(new SubExperiment(user1QuarterDemand, 10, 1.25 * fullyUtilizedArrivalRate));

        // Finally user 1 goes back to 0.
        experiments.add(new SubExperiment(onlyUser0, 20, fullyUtilizedArrivalRate));

        SparrowFrontendClient client = new SparrowFrontendClient();
        int schedulerPort = conf.getInt("scheduler_port", SchedulerThrift.DEFAULT_SCHEDULER_THRIFT_PORT);
        client.initialize(new InetSocketAddress("localhost", schedulerPort), APPLICATION_ID, this);

        if (warmup_duration_s > 0) {
            List<SubExperiment> warmupExperiment = new ArrayList<SubExperiment>();
            List<UserInfo> warmupUsers = new ArrayList<UserInfo>();
            warmupUsers.add(new UserInfo("warmupUser", 1, 0));
            warmupExperiment.add(new SubExperiment(warmupUsers, warmup_duration_s, warmup_lambda));
            LOG.debug("Warming up for " + warmup_duration_s + " seconds at arrival rate of " + warmup_lambda
                    + " jobs per second");
            launchTasks(warmupExperiment, tasksPerJob, numPreferredNodes, benchmarkIterations, benchmarkId,
                    backends, client);
            LOG.debug("Waiting for queues to drain after warmup (waiting " + post_warmup_s + " seconds)");
            Thread.sleep(post_warmup_s * 1000);
        }
        LOG.debug("Launching experiment for " + experiment_duration_s + " seconds");
        launchTasks(experiments, tasksPerJob, numPreferredNodes, benchmarkIterations, benchmarkId, backends,
                client);
    } catch (Exception e) {
        LOG.error("Fatal exception", e);
    }
}

From source file:com.hello2morrow.sonarplugin.SonargraphSensor.java

void analyse(IProject project, SensorContext sensorContext, ReportContext report) {
    this.sensorContext = sensorContext;
    Configuration configuration = project.getConfiguration();
    this.indexCost = configuration.getDouble(SonargraphPluginBase.COST_PER_INDEX_POINT,
            SonargraphPluginBase.COST_PER_INDEX_POINT_DEFAULT);

    XsdBuildUnits buildUnits = report.getBuildUnits();
    List<XsdAttributeRoot> buildUnitList = buildUnits.getBuildUnit();

    if (buildUnitList.size() == 1) {
        XsdAttributeRoot sonarBuildUnit = buildUnitList.get(0);
        String buName = getBuildUnitName(sonarBuildUnit.getName());

        analyse(project, sonarBuildUnit, buName, report);
    } else if (buildUnitList.size() > 1) {
        boolean foundMatchingBU = false;
        for (XsdAttributeRoot sonarBuildUnit : buildUnitList) {
            String buName = getBuildUnitName(sonarBuildUnit.getName());
            if (buildUnitMatchesAnalyzedProject(buName, project)) {
                analyse(project, sonarBuildUnit, buName, report);
                foundMatchingBU = true;/*from w w  w . java  2  s .  c  o m*/
                break;
            }
        }
        if (!foundMatchingBU) {
            LOG.warn("Project " + project.getName()
                    + " could not be mapped to a build unit. The project will not be analyzed. Check the build unit configuration of your Sonargraph system.");
        }
    } else {
        LOG.error("No build units found in report file!");
    }
}

From source file:com.hello2morrow.sonarplugin.SonarJSensor.java

public SonarJSensor(Configuration config, RulesManager rulesManager, RulesProfile rulesProfile) {
    indexCost = config.getDouble(COST_PER_INDEX_POINT, 12.0);
    this.rulesManager = rulesManager;
    this.rulesProfile = rulesProfile;
    if (rulesManager == null) {
        LOG.warn("No RulesManager provided to sensor");
    }/*  ww  w.j a v a  2  s  .c o m*/
    if (rulesProfile == null) {
        LOG.warn("No RulesProfile given to sensor");
    }
}

From source file:keel.Algorithms.Neural_Networks.NNEP_Common.mutators.parametric.ParametricMutator.java

/**
 * <p>/*from   w  ww.j  a  v a 2  s.c o m*/
 * Configuration parameters for ParametricMutator are:
 * </p>
 * <ul>
 * <li>
 * <code>[@selective] boolean (default=false)</code></p>
 * If this parameter is set to <code>true</true> only certain randomly
 * selected nodes are parametrically mutated.
 * </li>
 * <li>
 * <code>temperature-exponent[@value] double (default=1)</code></p>
 * Temperature exponent to be used for obtaining temperature
 * of each indivual mutated.
 * </li>
 * <li>
 * <code>amplitude[@value] double (default=5)</code></p>
 * Amplitude factor to increase the range of parametric variations
 * of mutated weights.
 * </li>
 * <li>
 * <code>fitness-difference[@value] double (default=0.0000001)</code></p>
 * Difference between two fitnesses that we consider
  * enoung to say that the fitness has improved
 * </li>
 * <li>
 * <code>initial-alpha-values: complex</code></p> 
 * Initial values of alpha parameters.
 * <ul>
 *       <li>
 *       <code>initial-alpha-values[@input] double (default=0.5)</code></p>
 *       Initial value of alpha parameter used for input weights.
 *       </li>
 *       <li>
 *       <code>initial-alpha-values[@ouput] double (default=1)</code></p>
 *       Initial value of alpha parameter used for output weights.
 *       </li>
 * </ul> 
 * </li>
 * </ul>
 */

public void configure(Configuration settings) {
    // Setup selective
    selective = settings.getBoolean("[@selective]", false);

    // Setup temperExponent
    temperExponent = settings.getDouble("temperature-exponent[@value]", 1);

    // Setup amplitude
    amplitude = settings.getDouble("amplitude[@value]", 5);

    // Setup fitDif
    fitDif = settings.getDouble("fitness-difference[@value]", 0.0000001);

    // Setup alphaInput
    initialAlphaInput = settings.getDouble("initial-alpha-values[@input]", 0.5);

    // Setup alphaOutput
    initialAlphaOutput = settings.getDouble("initial-alpha-values[@output]", 1);

}

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

/**
 *
 * @param configuration Configuration object for density diversity strategy.
 *
 * The XML labels supported are://from   w w w  .  j a  va2  s . c o  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.sampling.supervised.Resample.java

/**
 *
 * @param configuration The configuration object for Resample.
 * The XML labels supported are://  w  w  w.j  a va2 s.c  om
 * <ul>
 * <li><b>no-replacement= boolean</b></li>
 * <li><b>invert-selection= boolean</b></li>
 * <li><b>m_BiasToUniformClass= double</b></li>
 * </ul>
 */
@Override
public void configure(Configuration configuration) {

    super.configure(configuration);

    boolean noReplacementT = configuration.getBoolean("no-replacement", noReplacement);

    setNoReplacement(noReplacementT);

    boolean invert = configuration.getBoolean("invert-selection", invertSelection);

    setInvertSelection(invert);

    double mBias = configuration.getDouble("bias-to-uniform-class", biasToUniformClass);

    setBiasToUniformClass(mBias);
}

From source file:edu.berkeley.sparrow.daemon.scheduler.Scheduler.java

public void initialize(Configuration conf, InetSocketAddress socket) throws IOException {
    address = Network.socketAddressToThrift(socket);
    String mode = conf.getString(SparrowConf.DEPLYOMENT_MODE, "unspecified");
    this.conf = conf;
    if (mode.equals("standalone")) {
        state = new StandaloneSchedulerState();
    } else if (mode.equals("configbased")) {
        state = new ConfigSchedulerState();
    } else {//  w  w w .j  a va 2s .c  om
        throw new RuntimeException("Unsupported deployment mode: " + mode);
    }

    state.initialize(conf);

    defaultProbeRatioUnconstrained = conf.getDouble(SparrowConf.SAMPLE_RATIO, SparrowConf.DEFAULT_SAMPLE_RATIO);
    defaultProbeRatioConstrained = conf.getDouble(SparrowConf.SAMPLE_RATIO_CONSTRAINED,
            SparrowConf.DEFAULT_SAMPLE_RATIO_CONSTRAINED);

    requestTaskPlacers = Maps.newConcurrentMap();

    useCancellation = conf.getBoolean(SparrowConf.CANCELLATION, SparrowConf.DEFAULT_CANCELLATION);
    if (useCancellation) {
        LOG.debug("Initializing cancellation service");
        cancellationService = new CancellationService(nodeMonitorClientPool);
        new Thread(cancellationService).start();
    } else {
        LOG.debug("Not using cancellation");
    }

    spreadEvenlyTaskSetSize = conf.getInt(SparrowConf.SPREAD_EVENLY_TASK_SET_SIZE,
            SparrowConf.DEFAULT_SPREAD_EVENLY_TASK_SET_SIZE);
}