public double sfaError() {

    int nPieceWiseParmsExp = expSpikePatternData.getSpikePatternClass().getnPieceWiseParms();
    int nPieceWiseParmsModel = patternClassifier.getSpikePatternClass().getnPieceWiseParms();
    double possibleWeightForFutureNEAR = nPieceWiseParmsExp - nPieceWiseParmsModel; // coarse!!

    double error = 0;
    double minError = 0;
    double maxMerror = 1;
    double maxCerror = 2;
    double maxNsfaError = expSpikePatternData.getCurrentDuration() * 0.3;

    SolverResultsStat modelStats =
        patternClassifier.getSolverResultsStats()[nPieceWiseParmsExp - 1];
    int modelNsfaISIs1 = modelStats.getBreakPoint();
    int modelNsfaISIs2 = modelSpikePattern.getISIs().length - modelNsfaISIs1;
    double[] model =
        new double[] {
          modelStats.getM1(),
          modelStats.getM2(),
          modelStats.getC1(),
          modelStats.getC2(),
          modelNsfaISIs1,
          modelNsfaISIs2
        };
    double[] exp =
        new double[] {
          expSpikePatternData.getSfaLinearM1().getValue(),
          expSpikePatternData.getSfaLinearM2().getValue(),
          expSpikePatternData.getSfaLinearb1().getValue(),
          expSpikePatternData.getSfaLinearb2().getValue(),
          expSpikePatternData.getNSfaISIs1().getValue(),
          expSpikePatternData.getNSfaISIs2().getValue(),
        };

    for (int i = 0; i < 6; i++) {
      if (i < 2) { // slopes
        error += StatUtil.calculate0to1NormalizedError(exp[i], model[i], minError, maxMerror);
      } else {
        if (i < 4) { // intercepts
          error += StatUtil.calculate0to1NormalizedError(exp[i], model[i], minError, maxCerror);
        } else {
          error += StatUtil.calculate0to1NormalizedError(exp[i], model[i], minError, maxNsfaError);
        }
      }
    }

    error =
        patternClassifier.getDynamicFeatWeightMatrix().get(PatternFeatureID.n_sfa_isis2) * error;

    if (display) {
      displayRoutineForSFA(null, model, error);
    }
    return error;
  }
  public double sfa() {

    // int nPieceWiseParmsExp = expSpikePatternData.getSpikePatternClass().getnPieceWiseParms();
    int nPieceWiseParmsModel = patternClassifier.getSpikePatternClass().getnPieceWiseParms();
    SolverResultsStat modelStats = null;
    if (nPieceWiseParmsModel > 0) { // ASP, NASP, X
      modelStats = patternClassifier.getSolverResultsStats()[nPieceWiseParmsModel - 1];
    } else { // ASP error for other comps. for example, TSWB
      return 0;
    }

    return modelStats.getM1();
  }
 public double NburstsError() {
   PatternFeature feature = expSpikePatternData.getnBursts();
   double error =
       patternClassifier.getDynamicFeatWeightMatrix().get(PatternFeatureID.nbursts)
           * NormalizedErrorObsNormed(feature, modelSpikePattern.getBurstPattern().getNBursts());
   displayRoutine(
       PatternFeatureID.nbursts, feature, modelSpikePattern.getBurstPattern().getNBursts(), error);
   return error;
 }
 public double PSSError() {
   PatternFeature feature = expSpikePatternData.getPss();
   double minError = 0;
   double maxError = expSpikePatternData.getCurrentDuration();
   double error =
       patternClassifier.getDynamicFeatWeightMatrix().get(PatternFeatureID.pss)
           * NormalizedError(feature, modelSpikePattern.getPSS(), minError, maxError);
   displayRoutine(PatternFeatureID.pss, feature, modelSpikePattern.getPSS(), error);
   return error;
 }
 public double NSpikesErrorObsNormed() {
   PatternFeature feature = expSpikePatternData.getnSpikes();
   // double minError = 0;
   // double maxError = expSpikePatternData.getCurrentDuration();
   double error =
       patternClassifier.getDynamicFeatWeightMatrix().get(PatternFeatureID.n_spikes)
           * NormalizedErrorObsNormed(feature, modelSpikePattern.getNoOfSpikes());
   displayRoutine(PatternFeatureID.n_spikes, feature, modelSpikePattern.getNoOfSpikes(), error);
   return error;
 }
 public double FSLErrorObsNormed() {
   //	System.out.println("SPE:: fsl Error entry..");
   PatternFeature feature = expSpikePatternData.getFsl();
   // double minError = 0;
   // double maxError = expSpikePatternData.getCurrentDuration();
   double error =
       patternClassifier.getDynamicFeatWeightMatrix().get(PatternFeatureID.fsl)
           * NormalizedErrorObsNormed(feature, modelSpikePattern.getFSL());
   displayRoutine(PatternFeatureID.fsl, feature, modelSpikePattern.getFSL(), error);
   return error;
 }
  public SpikePatternEvaluatorV2(
      SpikePatternAdapting modelSpikePattern,
      InputSpikePatternConstraint expSpikePatternData,
      double[] patternRepWeights,
      double modelVmin,
      double modelVr,
      double modelVt,
      boolean display,
      boolean displayOnlyClass,
      boolean externalSimUsed) {
    this.modelSpikePattern = modelSpikePattern;
    this.expSpikePatternData = expSpikePatternData;
    this.patternRepairWeights = patternRepWeights;
    this.modelVmin = modelVmin;
    this.modelVr = modelVr;
    this.modelVt = modelVt;
    this.display = display;

    /*if(display){
    	StatAnalyzer.display_stats = true;
    }*/
    patternClassifier = new SpikePatternClassifier(modelSpikePattern);
    if (externalSimUsed) { // HACK!!! no voltage for swa
      modelSpikePattern.setSwa(1);
    } else {
      modelSpikePattern.setSwa(measureSWA());
    }

    double swa = modelSpikePattern.getSwa(); // 1;//

    patternClassifier.classifySpikePattern(swa, true); // 1);//
    if (display || displayOnlyClass) {
      patternClassifier.getSpikePatternClass().display();
    }

    if (!ECJStarterV2.TURN_OFF_CLASSIFIER) {
      patternClassifier.determineWeightsForFeatures(expSpikePatternData.getSpikePatternClass());
    } else {
      patternClassifier.populateNullWeights();
    }
  }
  public double sfaErrorObsNormed() {
    // System.out.println("****"+sfa()+"****");
    // int nPieceWiseParmsExp = expSpikePatternData.getSpikePatternClass().getnPieceWiseParms();
    int nPieceWiseParmsModel = patternClassifier.getSpikePatternClass().getnPieceWiseParms();
    double error = 0;
    SolverResultsStat modelStats = null;
    if (nPieceWiseParmsModel > 0) { // ASP, NASP, X
      modelStats = patternClassifier.getSolverResultsStats()[nPieceWiseParmsModel - 1];
    } else { // ASP error for other comps. for example, TSWB
      patternClassifier.calculateAdaptationForNonSP(0);
      modelStats = patternClassifier.getSolverResultsStats()[1]; // idx 1 for linear regression
    }

    int modelNsfaISIs1 = 1 + modelStats.getBreakPoint(); // 0-based idx ; hence +1
    int modelNsfaISIs2 = modelSpikePattern.getISIs().length - modelNsfaISIs1; // remaining
    double[] model =
        new double[] {
          modelStats.getM1(),
          modelStats.getC1(),
          modelNsfaISIs1,
          modelStats.getM2(),
          modelStats.getC2(),
          modelNsfaISIs2
        };
    PatternFeature[] exp =
        new PatternFeature[] {
          expSpikePatternData.getSfaLinearM1(),
          expSpikePatternData.getSfaLinearb1(),
          expSpikePatternData.getNSfaISIs1(),
          expSpikePatternData.getSfaLinearM2(),
          expSpikePatternData.getSfaLinearb2(),
          expSpikePatternData.getNSfaISIs2()
        };

    // System.out.println(patternClassifier.getDynamicFeatWeightMatrix().size());
    float sfa1Weight =
        patternClassifier.getDynamicFeatWeightMatrix().get(PatternFeatureID.n_sfa_isis1);
    float sfa2weight =
        patternClassifier.getDynamicFeatWeightMatrix().get(PatternFeatureID.n_sfa_isis2);

    for (int i = 0; i < 6; i++) {
      // SFA 1
      if (i == 0) { // m1
        error += sfa1Weight * NormalizedErrorObsNormed(exp[i], model[i]);
        continue;
      }
      if (i == 1) { // b1
        error += sfa1Weight * NormalizedErrorObsNormed(exp[i], model[i]);
        continue;
      }
      if (i == 2) { // nsfaisis1		
        error += sfa1Weight * NormalizedErrorObsNormed(exp[i], model[i]);
        continue;
      }
      // SFA 2
      if (i == 3) { // m2
        error += sfa2weight * NormalizedErrorObsNormed(exp[i], model[i]);
        continue;
      }
      if (i == 4) { // b2
        error += sfa2weight * NormalizedErrorObsNormed(exp[i], model[i]);
        continue;
      }
      if (i == 5) { // nsfaisis 2
        error += sfa2weight * NormalizedErrorObsNormed(exp[i], model[i]);
        continue;
      }
    }

    if (display) {
      displayRoutineForSFA(exp, model, error);
    }
    return error;
  }