All Downloads are FREE. Search and download functionalities are using the official Maven repository.

moa.tasks.RunTasks Maven / Gradle / Ivy

Go to download

Massive On-line Analysis is an environment for massive data mining. MOA provides a framework for data stream mining and includes tools for evaluation and a collection of machine learning algorithms. Related to the WEKA project, also written in Java, while scaling to more demanding problems.

There is a newer version: 2024.07.0
Show newest version
/*
 *    RunTasks.java
 *    Copyright (C) 2011 University of Waikato, Hamilton, New Zealand
 *    @author Richard Kirkby ([email protected])
 *    @author Albert Bifet (abifet at cs dot waikato dot ac dot nz)
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program. If not, see .
 *    
 */
package moa.tasks;

import moa.core.ObjectRepository;
import moa.options.ClassOption;
import com.github.javacliparser.FloatOption;
import com.github.javacliparser.StringOption;

/**
 * Task for running several experiments modifying values of parameters.
 *
 * @author Richard Kirkby ([email protected])
 * @author Albert Bifet (abifet at cs dot waikato dot ac dot nz)
 * @version $Revision: 7 $
 */
public class RunTasks extends AuxiliarMainTask {

    @Override
    public String getPurposeString() {
        return "Runs several experiments modifying values of parameters.";
    }

    private static final long serialVersionUID = 1L;

    public ClassOption taskOption = new ClassOption("task", 't',
            "Task to do.", Task.class, "EvaluatePrequential -l active.ALUncertainty -i 1000000 -d temp.txt");

    public StringOption classifierParameterOption = new StringOption("classifierParameter", 'p',
            "Classifier parameter to vary.", "b");

    public FloatOption firstValueOption = new FloatOption("firstValue",
            'f', "First value", 0.0);

    public FloatOption lastValueOption = new FloatOption("lastValue",
            'l', "Last value", 1.0);

    public FloatOption incrementValueOption = new FloatOption("incrementValue",
            'i', "Increment value", 0.1);

    @Override
    public Class getTaskResultType() {
        return this.task.getTaskResultType();
    }

    protected Task task;

    @Override
    protected Object doMainTask(TaskMonitor monitor, ObjectRepository repository) {
        Object result = null;

        String commandString = this.taskOption.getValueAsCLIString();
        //for each possible value of the parameter
        for (double valueParameter = this.firstValueOption.getValue();
                valueParameter <= this.lastValueOption.getValue();
                valueParameter += this.incrementValueOption.getValue()) {
            //Add parameter
            this.task = (Task) getPreparedClassOption(this.taskOption);
            if (this.task instanceof EvaluatePrequential) {
                String classifier = ((EvaluatePrequential) this.task).learnerOption.getValueAsCLIString();
                ((EvaluatePrequential) this.task).learnerOption.setValueViaCLIString(classifier + " -" + classifierParameterOption.getValue() + " " + valueParameter);
            }
            if (this.task instanceof EvaluateInterleavedTestThenTrain) {
                String classifier = ((EvaluateInterleavedTestThenTrain) this.task).learnerOption.getValueAsCLIString();
                ((EvaluateInterleavedTestThenTrain) this.task).learnerOption.setValueViaCLIString(classifier + " -" + classifierParameterOption.getValue() + " " + valueParameter);
            }
            //Run task
            result = this.task.doTask(monitor, repository);
            //System.out.println(((AbstractOptionHandler) this.task).getCLICreationString(Task.class));
        }
        return result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy