Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/21/12 18:45:15 (12 years ago)
Author:
gkronber
Message:

#1902: added masking covariance function and made necessary changes to interface and utility class.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovariancePeriodic.cs

    r8612 r8678  
    7676      Name = ItemName;
    7777      Description = ItemDescription;
    78      
     78
    7979      scaleParameter = new HyperParameter<DoubleValue>("Scale", "The scale of the periodic covariance function.");
    8080      inverseLengthParameter = new HyperParameter<DoubleValue>("InverseLength", "The inverse length parameter for the periodic covariance function.");
     
    125125    }
    126126
    127     public double GetCovariance(double[,] x, int i, int j) {
    128       double k = i == j ? 0.0 : GetDistance(x, x, i, j);
     127    public double GetCovariance(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
     128      if (columnIndices == null || columnIndices.Count() != 1)
     129        throw new ArgumentException("The periodic covariance function can only be used for one dimension.", "columnIndices");
     130      double k = i == j ? 0.0 : GetDistance(x, x, i, j, columnIndices);
    129131      k = Math.PI * k / period;
    130132      k = Math.Sin(k) * inverseLength;
     
    134136    }
    135137
    136     public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
    137       double v = i == j ? 0.0 : Math.PI * GetDistance(x, x, i, j) / period;
     138    public IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
     139      if (columnIndices == null || columnIndices.Count() != 1)
     140        throw new ArgumentException("The periodic covariance function can only be used for one dimension.", "columnIndices");
     141      double v = i == j ? 0.0 : Math.PI * GetDistance(x, x, i, j, columnIndices) / period;
    138142      double gradient = Math.Sin(v) * inverseLength;
    139143      gradient *= gradient;
     
    144148    }
    145149
    146     public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
    147       double k = GetDistance(x, xt, i, j);
     150    public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j, IEnumerable<int> columnIndices) {
     151      if (columnIndices == null || columnIndices.Count() != 1)
     152        throw new ArgumentException("The periodic covariance function can only be used for one dimension.", "columnIndices");
     153      double k = GetDistance(x, xt, i, j, columnIndices);
    148154      k = Math.PI * k / period;
    149155      k = Math.Sin(k) * inverseLength;
     
    153159    }
    154160
    155     private double GetDistance(double[,] x, double[,] xt, int i, int j) {
    156       return Math.Sqrt(Util.SqrDist(x, i, xt, j));
     161    private double GetDistance(double[,] x, double[,] xt, int i, int j, IEnumerable<int> columnIndices) {
     162      return Math.Sqrt(Util.SqrDist(x, i, xt, j, 1, columnIndices));
    157163    }
    158164  }
Note: See TracChangeset for help on using the changeset viewer.