Esempio n. 1
0
 private static void collectDatum(
     List<Project> projects,
     List<Posting> postings,
     List<Issue> issues,
     List<PullRequest> pullRequests,
     List<Milestone> milestones,
     int daysAgo) {
   // collect all postings, issues, pullrequests and milesotnes that are contained in the projects.
   for (Project project : projects) {
     if (AccessControl.isAllowed(UserApp.currentUser(), project.asResource(), Operation.READ)) {
       postings.addAll(Posting.findRecentlyCreatedByDaysAgo(project, daysAgo));
       issues.addAll(Issue.findRecentlyOpendIssuesByDaysAgo(project, daysAgo));
       pullRequests.addAll(PullRequest.findOpendPullRequestsByDaysAgo(project, daysAgo));
       milestones.addAll(Milestone.findOpenMilestones(project.id));
     }
   }
 }
Esempio n. 2
0
  public List<TrainAndTestReportInterval> computeAllIntTSAvgs(
      List<TrainAndTestReportInterval> reportsIntTS) throws IllegalArgumentException {
    List<TrainAndTestReportInterval> avgReports = new ArrayList<>();

    if (reportsIntTS.isEmpty()) {
      return avgReports;
    }

    if (avgIntTSperM) {
      avgReports.addAll(computeAvgIntTSperM(reportsIntTS));
    }
    if (avgIntTS) {
      if (computeAvgIntTS(reportsIntTS) != null) {
        avgReports.add(computeAvgIntTS(reportsIntTS));
      } else {
        throw new IllegalArgumentException("not the same percentTrain");
      }
    }

    return avgReports;
  }
Esempio n. 3
0
  public TrainAndTestReportInterval computeAvgIntTS(
      List<TrainAndTestReportInterval> reportsIntTS, Model model) {
    if (!allTheSamePercentTrain(reportsIntTS)) { // throw an error, we cannot compute it like this
      return null;
    } else {
      MyRengine rengine = MyRengine.getRengine();

      if (reportsIntTS.size() == 1) { // does not make sense to compute average over one series
        return reportsIntTS.get(0);
      } else {
        StringBuilder avgAllLowersTrain = new StringBuilder("(");
        StringBuilder avgAllLowersTest = new StringBuilder("(");
        StringBuilder avgAllLowersFuture = new StringBuilder("(");
        StringBuilder avgAllUppersTrain = new StringBuilder("(");
        StringBuilder avgAllUppersTest = new StringBuilder("(");
        StringBuilder avgAllUppersFuture = new StringBuilder("(");
        StringBuilder sumWeightsTrain = new StringBuilder("(");
        StringBuilder sumWeightsTest = new StringBuilder("(");
        StringBuilder sumWeightsFuture = new StringBuilder("(");
        boolean next = false;
        for (TrainAndTestReportInterval r : reportsIntTS) {
          if (next) {
            avgAllLowersTrain.append(" + ");
            avgAllLowersTest.append(" + ");
            avgAllLowersFuture.append(" + ");
            avgAllUppersTrain.append(" + ");
            avgAllUppersTest.append(" + ");
            avgAllUppersFuture.append(" + ");
            sumWeightsTrain.append(" + ");
            sumWeightsTest.append(" + ");
            sumWeightsFuture.append(" + ");
          } else {
            next = true;
          }

          double weightTrain = getWeightForModelTrain(r);
          double weightTest = getWeightForModelTest(r);
          double weightFuture = getWeightForModelFuture(r);
          weightsInterval.put(r.toString(), weightFuture);

          sumWeightsTrain.append(weightTrain);
          sumWeightsTest.append(weightTest);

          avgAllLowersTrain
              .append(weightTrain)
              .append("*")
              .append(Utils.arrayToRVectorString(r.getFittedValuesLowers()));
          avgAllLowersTest
              .append(weightTest)
              .append("*")
              .append(Utils.arrayToRVectorString(r.getForecastValuesTestLowers()));

          avgAllUppersTrain
              .append(weightTrain)
              .append("*")
              .append(Utils.arrayToRVectorString(r.getFittedValuesUppers()));
          avgAllUppersTest
              .append(weightTest)
              .append("*")
              .append(Utils.arrayToRVectorString(r.getForecastValuesTestUppers()));

          avgAllLowersFuture.append(weightFuture).append("*");
          avgAllUppersFuture.append(weightFuture).append("*");
          if (r.getForecastValuesFuture().size() > 0) {
            avgAllLowersFuture.append(
                Utils.arrayToRVectorString(r.getForecastValuesFutureLowers()));
            avgAllUppersFuture.append(
                Utils.arrayToRVectorString(r.getForecastValuesFutureUppers()));

            sumWeightsFuture.append(weightFuture);
          } else {
            avgAllLowersFuture.append("0");
            avgAllUppersFuture.append("0");

            sumWeightsFuture.append("0");
          }
        }
        sumWeightsTrain.append(")");
        sumWeightsTest.append(")");
        sumWeightsFuture.append(")");

        avgAllLowersTrain.append(")/").append(sumWeightsTrain);
        avgAllLowersTest.append(")/").append(sumWeightsTest);
        avgAllLowersFuture.append(")/").append(sumWeightsFuture);
        avgAllUppersTrain.append(")/").append(sumWeightsTrain);
        avgAllUppersTest.append(")/").append(sumWeightsTest);
        avgAllUppersFuture.append(")/").append(sumWeightsFuture);

        rengine.eval("lowerTrain <- " + avgAllLowersTrain.toString());
        rengine.eval("lowerTest <- " + avgAllLowersTest.toString());
        rengine.eval("lowerFuture <- " + avgAllLowersFuture.toString());
        rengine.eval("upperTrain <- " + avgAllUppersTrain.toString());
        rengine.eval("upperTest <- " + avgAllUppersTest.toString());
        rengine.eval("upperFuture <- " + avgAllUppersFuture.toString());

        // add report:
        List<Double> allLowersTrainList = rengine.evalAndReturnList("lowerTrain");
        List<Double> allLowersTestList = rengine.evalAndReturnList("lowerTest");
        List<Double> allUppersTrainList = rengine.evalAndReturnList("upperTrain");
        List<Double> allUppersTestList = rengine.evalAndReturnList("upperTest");
        List<Interval> allIntervalsTrain =
            Utils.zipLowerUpperToIntervals(allLowersTrainList, allUppersTrainList);
        List<Interval> allIntervalsTest =
            Utils.zipLowerUpperToIntervals(allLowersTestList, allUppersTestList);

        List<Double> realValuesLowers = reportsIntTS.get(0).getRealValuesLowers();
        List<Double> realValuesUppers = reportsIntTS.get(0).getRealValuesUppers();
        List<Double> realValuesLowersTrain =
            realValuesLowers.subList(0, reportsIntTS.get(0).getNumTrainingEntries());
        List<Double> realValuesUppersTrain =
            realValuesUppers.subList(0, reportsIntTS.get(0).getNumTrainingEntries());
        List<Double> realValuesLowersTest =
            realValuesLowers.subList(
                reportsIntTS.get(0).getNumTrainingEntries(), realValuesLowers.size());
        List<Double> realValuesUppersTest =
            realValuesUppers.subList(
                reportsIntTS.get(0).getNumTrainingEntries(), realValuesUppers.size());

        List<Interval> realValuesTrain =
            Utils.zipLowerUpperToIntervals(realValuesLowersTrain, realValuesUppersTrain);
        List<Interval> realValuesTest =
            Utils.zipLowerUpperToIntervals(realValuesLowersTest, realValuesUppersTest);

        ErrorMeasuresInterval errorMeasures =
            ErrorMeasuresUtils.computeAllErrorMeasuresInterval(
                realValuesTrain,
                realValuesTest,
                allIntervalsTrain,
                allIntervalsTest,
                new WeightedEuclideanDistance(0.5),
                0);
        // TODO chg; for now takes WeightedEuclid, but allow any distance

        TrainAndTestReportInterval reportAvgAllITS =
            new TrainAndTestReportInterval(model, "_int(" + getName() + ")", true);
        reportAvgAllITS.setErrorMeasures(errorMeasures);
        reportAvgAllITS.setFittedValues(allIntervalsTrain);
        reportAvgAllITS.setForecastValuesTest(allIntervalsTest);

        List<Double> allLowersFutureList = rengine.evalAndReturnList("lowerFuture");
        List<Double> allUppersFutureList = rengine.evalAndReturnList("upperFuture");
        List<Interval> allIntervalsFuture =
            Utils.zipLowerUpperToIntervals(allLowersFutureList, allUppersFutureList);
        reportAvgAllITS.setForecastValuesFuture(allIntervalsFuture);
        reportAvgAllITS.setNumTrainingEntries(reportsIntTS.get(0).getNumTrainingEntries());
        realValuesTrain.addAll(realValuesTest);
        reportAvgAllITS.setRealValues(realValuesTrain);

        rengine.rm(
            "lowerTrain", "lowerTest", "lowerFuture", "upperTrain", "upperTest", "upperFuture");

        return reportAvgAllITS;
      }
    }
  }