This class implements the Proximal Stochastic Dual Coordinate Ascent (SDCA) algorithm for learning general linear models with Elastic-Net regularization. It is a fast learning algorithm, and can be used for generic Logistic or least-squares regression with elastic-net regularization. It can work
| 62 | * @author Edward Raff <Raff.Edward@gmail.com> |
| 63 | */ |
| 64 | public class SDCA implements Classifier, Regressor, Parameterized, SimpleWeightVectorModel, WarmClassifier, WarmRegressor |
| 65 | { |
| 66 | private LossFunc loss; |
| 67 | private boolean useBias = true; |
| 68 | private double tol = 0.001; |
| 69 | private double lambda; |
| 70 | private double alpha = 0.5; |
| 71 | private int max_epochs = 200; |
| 72 | private double[] dual_alphas; |
| 73 | /** |
| 74 | * Returns the number of epochs SDCA took until reaching convergence. |
| 75 | */ |
| 76 | protected int epochs_taken; |
| 77 | |
| 78 | private Vec[] ws; |
| 79 | private double[] bs; |
| 80 | |
| 81 | /** |
| 82 | * Creates a new SDCA learner for {@link LogisticLoss logistic-regression}. |
| 83 | * Pure L2 or L1 regularization can be obtained using the |
| 84 | * {@link #setAlpha(double) alpha} parameter. |
| 85 | */ |
| 86 | public SDCA() |
| 87 | { |
| 88 | this(1e-5); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * <br>The implementation will use Elastic-Net regularization by default. |
| 93 | * Pure L2 or L1 regularization can be obtained using the |
| 94 | * {@link #setAlpha(double) alpha} parameter. |
| 95 | * @param lambda the regularization penalty to use. |
| 96 | */ |
| 97 | public SDCA(double lambda) |
| 98 | { |
| 99 | this(lambda, new LogisticLoss()); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Creates a new SDCA learner for either a classification or regression |
| 104 | * problem, the type of which is determined by the LossFunction given. |
| 105 | * <br>The implementation will use Elastic-Net regularization by default. |
| 106 | * Pure L2 or L1 regularization can be obtained using the |
| 107 | * {@link #setAlpha(double) alpha} parameter. |
| 108 | * |
| 109 | * @param lambda the regularization penalty to use. |
| 110 | * @param loss the loss function to use for training, which determines if it |
| 111 | * implements classification or regression |
| 112 | */ |
| 113 | public SDCA(double lambda, LossFunc loss) |
| 114 | { |
| 115 | setLoss(loss); |
| 116 | setLambda(lambda); |
| 117 | } |
| 118 | |
| 119 | |
| 120 | /** |
| 121 | * Copy Constructor |
nothing calls this directly
no outgoing calls
no test coverage detected