001/*
002 * Copyright (c) 2015-2020, Oracle and/or its affiliates. All rights reserved.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.tribuo.classification.liblinear;
018
019import com.oracle.labs.mlrg.olcut.config.Option;
020import org.tribuo.classification.ClassificationOptions;
021import org.tribuo.classification.liblinear.LinearClassificationType.LinearType;
022
023/**
024 * Command line options for working with a classification liblinear model.
025 */
026public class LibLinearOptions implements ClassificationOptions<LibLinearClassificationTrainer> {
027
028    @Override
029    public String getOptionsDescription() {
030        return "Options for parameterising a LibLinear classification trainer.";
031    }
032
033    @Option(longName = "liblinear-solver-type", usage = "Type of linear model, defaults to L2R_L2LOSS_SVC_DUAL.")
034    LinearType liblinearSolverType = LinearType.L1R_LR;
035
036    @Option(longName = "liblinear-cost", usage = "cost")
037    double liblinearCost = 1.0d;
038
039    @Option(longName = "liblinear-eps", usage = "stopping criteria")
040    double liblinearEps = 0.01d; //TODO or 0.1?
041
042    @Option(longName = "liblinear-maxiters", usage = "max iterations")
043    int liblinearMaxiters = 1000;
044
045    @Override
046    public LibLinearClassificationTrainer getTrainer() {
047        return new LibLinearClassificationTrainer(new LinearClassificationType(liblinearSolverType), liblinearCost, liblinearMaxiters, liblinearEps);
048    }
049}