Esempio n. 1
0
  private double score(Node y, List<Node> parents) {
    if (score == Score.andersonDarling) {
      return andersonDarlingPASquareStar(y, parents);
    } else if (score == Score.kurtosis) {
      return Math.abs(StatUtils.kurtosis(residual(y, parents)));
    } else if (score == Score.skew) {
      return Math.abs(StatUtils.skewness(residual(y, parents)));
    } else if (score == Score.fifthMoment) {
      return Math.abs(StatUtils.standardizedFifthMoment(residual(y, parents)));
    } else if (score == Score.absoluteValue) {
      return localScoreA(y, parents);
    }

    throw new IllegalStateException();
  }
Esempio n. 2
0
  private double localScoreB(Node node, List<Node> parents) {

    double score = 0.0;
    double maxScore = Double.NEGATIVE_INFINITY;

    Node _target = node;
    List<Node> _regressors = parents;
    Node target = getVariable(variables, _target.getName());
    List<Node> regressors = new ArrayList<Node>();

    for (Node _regressor : _regressors) {
      Node variable = getVariable(variables, _regressor.getName());
      regressors.add(variable);
    }

    DATASET:
    for (int m = 0; m < dataSets.size(); m++) {
      RegressionResult result = regressions.get(m).regress(target, regressors);
      TetradVector residualsSingleDataset = result.getResiduals();
      DoubleArrayList _residualsSingleDataset =
          new DoubleArrayList(residualsSingleDataset.toArray());

      for (int h = 0; h < residualsSingleDataset.size(); h++) {
        if (Double.isNaN(residualsSingleDataset.get(h))) {
          continue DATASET;
        }
      }

      double mean = Descriptive.mean(_residualsSingleDataset);
      double std =
          Descriptive.standardDeviation(
              Descriptive.variance(
                  _residualsSingleDataset.size(),
                  Descriptive.sum(_residualsSingleDataset),
                  Descriptive.sumOfSquares(_residualsSingleDataset)));

      for (int i2 = 0; i2 < _residualsSingleDataset.size(); i2++) {
        _residualsSingleDataset.set(i2, (_residualsSingleDataset.get(i2) - mean) / std);
      }

      double[] _f = new double[_residualsSingleDataset.size()];

      for (int k = 0; k < _residualsSingleDataset.size(); k++) {
        _f[k] = _residualsSingleDataset.get(k);
      }

      DoubleArrayList f = new DoubleArrayList(_f);

      for (int k = 0; k < f.size(); k++) {
        f.set(k, Math.abs(f.get(k)));
      }

      double _mean = Descriptive.mean(f);
      double diff = _mean - Math.sqrt(2.0 / Math.PI);
      score += diff * diff;

      if (score > maxScore) {
        maxScore = score;
      }
    }

    double avg = score / dataSets.size();

    return avg;
  }