public double[][] trainWeights(
      GeneralDataset<L, F> dataset,
      double[] initial,
      boolean bypassTuneSigma,
      Minimizer<DiffFunction> minimizer) {
    if (minimizer == null) minimizer = minimizerCreator.create();
    if (dataset instanceof RVFDataset) ((RVFDataset<L, F>) dataset).ensureRealValues();
    double[] interimWeights = null;
    if (!bypassTuneSigma) {
      if (tuneSigmaHeldOut) {
        interimWeights =
            heldOutSetSigma(
                dataset); // the optimum interim weights from held-out training data have already
                          // been found.
      } else if (tuneSigmaCV) {
        crossValidateSetSigma(
            dataset, folds); // TODO: assign optimum interim weights as part of this process.
      }
    }
    LogConditionalObjectiveFunction<L, F> objective =
        new LogConditionalObjectiveFunction<L, F>(dataset, logPrior);
    if (initial == null && interimWeights != null && !retrainFromScratchAfterSigmaTuning) {
      // System.err.println("## taking advantage of interim weights as starting point.");
      initial = interimWeights;
    }
    if (initial == null) {
      initial = objective.initial();
    }

    double[] weights = minimizer.minimize(objective, TOL, initial);
    return objective.to2D(weights);
  }
 public void crossValidateSetSigma(
     GeneralDataset<L, F> dataset, int kfold, LineSearcher minimizer) {
   crossValidateSetSigma(
       dataset,
       kfold,
       new MultiClassAccuracyStats<L>(MultiClassAccuracyStats.USE_LOGLIKELIHOOD),
       minimizer);
 }
 /**
  * callls the method {@link #crossValidateSetSigma(GeneralDataset, int, Scorer, LineSearcher)}
  * with multi-class log-likelihood scoring (see {@link MultiClassAccuracyStats}) and
  * golden-section line search (see {@link GoldenSectionLineSearch}).
  *
  * @param dataset the data set to optimize sigma on.
  */
 public void crossValidateSetSigma(GeneralDataset<L, F> dataset, int kfold) {
   System.err.println("##you are here.");
   crossValidateSetSigma(
       dataset,
       kfold,
       new MultiClassAccuracyStats<L>(MultiClassAccuracyStats.USE_LOGLIKELIHOOD),
       new GoldenSectionLineSearch(true, 1e-2, min, max));
 }
 public void crossValidateSetSigma(
     GeneralDataset<L, F> dataset, int kfold, final Scorer<L> scorer) {
   crossValidateSetSigma(
       dataset, kfold, scorer, new GoldenSectionLineSearch(true, 1e-2, min, max));
 }
 /**
  * Calls the method {@link #crossValidateSetSigma(GeneralDataset, int)} with 5-fold
  * cross-validation.
  *
  * @param dataset the data set to optimize sigma on.
  */
 public void crossValidateSetSigma(GeneralDataset<L, F> dataset) {
   crossValidateSetSigma(dataset, 5);
 }