Search in sources :

Example 1 with SolverType

use of de.bwaldvogel.liblinear.SolverType in project dkpro-tc by dkpro.

the class LiblinearUtils method getSolver.

public static SolverType getSolver(List<Object> classificationArguments) {
    if (classificationArguments == null) {
        return SolverType.L2R_LR;
    }
    SolverType type = null;
    for (int i = 1; i < classificationArguments.size(); i++) {
        String e = (String) classificationArguments.get(i);
        if (e.equals("-s")) {
            if (i + 1 >= classificationArguments.size()) {
                throw new IllegalArgumentException("Found parameter [-s] but no solver type was specified");
            }
            String algo = (String) classificationArguments.get(i + 1);
            switch(algo) {
                case "0":
                    type = SolverType.L2R_LR;
                    break;
                case "1":
                    type = SolverType.L2R_L2LOSS_SVC_DUAL;
                    break;
                case "2":
                    type = SolverType.L2R_L2LOSS_SVC;
                    break;
                case "3":
                    type = SolverType.L2R_L1LOSS_SVC_DUAL;
                    break;
                case "4":
                    type = SolverType.MCSVM_CS;
                    break;
                case "5":
                    type = SolverType.L1R_L2LOSS_SVC;
                    break;
                case "6":
                    type = SolverType.L1R_LR;
                    break;
                case "7":
                    type = SolverType.L2R_LR_DUAL;
                    break;
                case "11":
                    type = SolverType.L2R_L2LOSS_SVR;
                    break;
                case "12":
                    type = SolverType.L2R_L2LOSS_SVR_DUAL;
                    break;
                case "13":
                    type = SolverType.L2R_L1LOSS_SVR_DUAL;
                    break;
                default:
                    throw new IllegalArgumentException("An unknown solver was specified [" + algo + "] which is unknown i.e. check parameter [-s] in your configuration");
            }
        }
    }
    if (type == null) {
        // parameter -s was not specified in the parameters so we set a default value
        type = SolverType.L2R_LR;
    }
    LogFactory.getLog(LiblinearUtils.class).info("Will use solver " + type.toString() + ")");
    return type;
}
Also used : SolverType(de.bwaldvogel.liblinear.SolverType)

Example 2 with SolverType

use of de.bwaldvogel.liblinear.SolverType in project dkpro-tc by dkpro.

the class LiblinearTestTask method trainModel.

@Override
protected Object trainModel(TaskContext aContext) throws Exception {
    File fileTrain = getTrainFile(aContext);
    // default for bias is -1, documentation says to set it to 1 in order to
    // get results closer
    // to libsvm
    // writer adds bias, so if we de-activate that here for some reason, we
    // need to also
    // deactivate it there
    Problem train = Problem.readFromFile(fileTrain, 1.0);
    SolverType solver = LiblinearUtils.getSolver(classificationArguments);
    double C = LiblinearUtils.getParameterC(classificationArguments);
    double eps = LiblinearUtils.getParameterEpsilon(classificationArguments);
    Linear.setDebugOutput(null);
    Parameter parameter = new Parameter(solver, C, eps);
    Model model = Linear.train(train, parameter);
    return model;
}
Also used : Model(de.bwaldvogel.liblinear.Model) Parameter(de.bwaldvogel.liblinear.Parameter) Problem(de.bwaldvogel.liblinear.Problem) SolverType(de.bwaldvogel.liblinear.SolverType) File(java.io.File)

Example 3 with SolverType

use of de.bwaldvogel.liblinear.SolverType in project dkpro-tc by dkpro.

the class LiblinearSerializeModelConnector method trainModel.

@Override
protected void trainModel(TaskContext aContext, File fileTrain) throws Exception {
    SolverType solver = LiblinearUtils.getSolver(classificationArguments);
    double C = LiblinearUtils.getParameterC(classificationArguments);
    double eps = LiblinearUtils.getParameterEpsilon(classificationArguments);
    Linear.setDebugOutput(null);
    Parameter parameter = new Parameter(solver, C, eps);
    Problem train = Problem.readFromFile(fileTrain, 1.0);
    Model model = Linear.train(train, parameter);
    model.save(new File(outputFolder, MODEL_CLASSIFIER));
}
Also used : Model(de.bwaldvogel.liblinear.Model) Parameter(de.bwaldvogel.liblinear.Parameter) Problem(de.bwaldvogel.liblinear.Problem) SolverType(de.bwaldvogel.liblinear.SolverType) File(java.io.File)

Aggregations

SolverType (de.bwaldvogel.liblinear.SolverType)3 Model (de.bwaldvogel.liblinear.Model)2 Parameter (de.bwaldvogel.liblinear.Parameter)2 Problem (de.bwaldvogel.liblinear.Problem)2 File (java.io.File)2