Changeset 8678


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

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

Location:
trunk/sources
Files:
1 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/GaussianProcessRegressionSolutionLineChartView.cs

    r8580 r8678  
    2929
    3030namespace HeuristicLab.Algorithms.DataAnalysis.Views {
    31   [View("Line Chart 2")]
     31  [View("Line Chart (95% confidence interval)")]
    3232  [Content(typeof(GaussianProcessRegressionSolution))]
    3333  public partial class GaussianProcessRegressionSolutionLineChartView : DataAnalysisSolutionEvaluationView {
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceConst.cs

    r8612 r8678  
    9191    }
    9292
    93     public double GetCovariance(double[,] x, int i, int j) {
     93    public double GetCovariance(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
    9494      return scale;
    9595    }
    9696
    97     public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
     97    public IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
    9898      yield return 2.0 * scale;
    9999    }
    100100
    101     public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
     101    public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j, IEnumerable<int> columnIndices) {
    102102      return scale;
    103103    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceLinear.cs

    r8612 r8678  
    5151    }
    5252
    53     public double GetCovariance(double[,] x, int i, int j) {
    54       return Util.ScalarProd(x, i, j);
     53    public double GetCovariance(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
     54      return Util.ScalarProd(x, i, j, 1, columnIndices);
    5555    }
    5656
    57     public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
     57    public IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
    5858      yield break;
    5959    }
    6060
    61     public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
     61    public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j, IEnumerable<int> columnIndices) {
    6262      return Util.ScalarProd(x, i, xt, j);
    6363    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceLinearArd.cs

    r8612 r8678  
    9292    }
    9393
    94     public double GetCovariance(double[,] x, int i, int j) {
    95       return Util.ScalarProd(x, i, j, inverseLength);
     94    public double GetCovariance(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
     95      return Util.ScalarProd(x, i, j, inverseLength, columnIndices);
    9696    }
    9797
    98     public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
    99       for (int k = 0; k < inverseLength.Length; k++) {
     98    public IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
     99      if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));
     100
     101      foreach (int k in columnIndices) {
    100102        yield return -2.0 * x[i, k] * x[j, k] * inverseLength[k] * inverseLength[k];
    101103      }
    102104    }
    103105
    104     public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
    105       return Util.ScalarProd(x, i, xt, j, inverseLength);
     106    public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j, IEnumerable<int> columnIndices) {
     107      return Util.ScalarProd(x, i, xt, j, inverseLength, columnIndices);
    106108    }
    107109  }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceMaternIso.cs

    r8612 r8678  
    154154    }
    155155
    156     public double GetCovariance(double[,] x, int i, int j) {
     156    public double GetCovariance(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
    157157      double dist = i == j
    158158                   ? 0.0
    159                    : Math.Sqrt(Util.SqrDist(x, i, j, Math.Sqrt(d) * inverseLength));
     159                   : Math.Sqrt(Util.SqrDist(x, i, j, Math.Sqrt(d) * inverseLength, columnIndices));
    160160      return sf2 * m(dist);
    161161    }
    162162
    163     public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
     163    public IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
    164164      double dist = i == j
    165165                   ? 0.0
    166                    : Math.Sqrt(Util.SqrDist(x, i, j, Math.Sqrt(d) * inverseLength));
     166                   : Math.Sqrt(Util.SqrDist(x, i, j, Math.Sqrt(d) * inverseLength, columnIndices));
    167167
    168168      yield return sf2 * dm(dist);
     
    170170    }
    171171
    172     public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
    173       double dist = Math.Sqrt(Util.SqrDist(x, i, xt, j, Math.Sqrt(d) * inverseLength));
     172    public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j, IEnumerable<int> columnIndices) {
     173      double dist = Math.Sqrt(Util.SqrDist(x, i, xt, j, Math.Sqrt(d) * inverseLength, columnIndices));
    174174      return sf2 * m(dist);
    175175    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceNoise.cs

    r8612 r8678  
    9090    }
    9191
    92     public double GetCovariance(double[,] x, int i, int j) {
     92    public double GetCovariance(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
    9393      return sf2;
    9494    }
    9595
    96     public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
     96    public IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
    9797      yield return 2 * sf2;
    9898    }
    9999
    100     public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
     100    public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j, IEnumerable<int> columnIndices) {
    101101      return 0.0;
    102102    }
  • 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  }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceProduct.cs

    r8620 r8678  
    7676    }
    7777
    78     public double GetCovariance(double[,] x, int i, int j) {
    79       return factors.Select(f => f.GetCovariance(x, i, j)).Aggregate((a, b) => a * b);
     78    public double GetCovariance(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
     79      return factors.Select(f => f.GetCovariance(x, i, j, columnIndices)).Aggregate((a, b) => a * b);
    8080    }
    8181
    82     public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
    83       var covariances = factors.Select(f => f.GetCovariance(x, i, j)).ToArray();
     82    public IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
     83      var covariances = factors.Select(f => f.GetCovariance(x, i, j, columnIndices)).ToArray();
    8484      for (int ii = 0; ii < factors.Count; ii++) {
    85         foreach (var g in factors[ii].GetGradient(x, i, j)) {
     85        foreach (var g in factors[ii].GetGradient(x, i, j, columnIndices)) {
    8686          double res = g;
    8787          for (int jj = 0; jj < covariances.Length; jj++)
     
    9292    }
    9393
    94     public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
    95       return factors.Select(f => f.GetCrossCovariance(x, xt, i, j)).Aggregate((a, b) => a * b);
     94    public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j, IEnumerable<int> columnIndices) {
     95      return factors.Select(f => f.GetCrossCovariance(x, xt, i, j, columnIndices)).Aggregate((a, b) => a * b);
    9696    }
    9797  }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceRationalQuadraticArd.cs

    r8615 r8678  
    135135
    136136
    137     public double GetCovariance(double[,] x, int i, int j) {
     137    public double GetCovariance(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
    138138      double d = i == j
    139139                   ? 0.0
    140                    : Util.SqrDist(x, i, j, inverseLength);
     140                   : Util.SqrDist(x, i, j, inverseLength, columnIndices);
    141141      return sf2 * Math.Pow(1 + 0.5 * d / shape, -shape);
    142142    }
    143143
    144     public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
     144    public IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
    145145      double d = i == j
    146146                   ? 0.0
    147                    : Util.SqrDist(x, i, j, inverseLength);
     147                   : Util.SqrDist(x, i, j, inverseLength, columnIndices);
    148148      double b = 1 + 0.5 * d / shape;
    149149      for (int k = 0; k < inverseLength.Length; k++) {
     
    154154    }
    155155
    156     public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
    157       double d = Util.SqrDist(x, i, xt, j, inverseLength);
     156    public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j, IEnumerable<int> columnIndices) {
     157      double d = Util.SqrDist(x, i, xt, j, inverseLength, columnIndices);
    158158      return sf2 * Math.Pow(1 + 0.5 * d / shape, -shape);
    159159    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceRationalQuadraticIso.cs

    r8615 r8678  
    125125
    126126
    127     public double GetCovariance(double[,] x, int i, int j) {
     127    public double GetCovariance(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
    128128      double d = i == j
    129129                   ? 0.0
    130                    : Util.SqrDist(x, i, j, inverseLength);
     130                   : Util.SqrDist(x, i, j, inverseLength, columnIndices);
    131131      return sf2 * Math.Pow(1 + 0.5 * d / shape, -shape);
    132132    }
    133133
    134     public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
     134    public IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
    135135      double d = i == j
    136136                   ? 0.0
    137                    : Util.SqrDist(x, i, j, inverseLength);
     137                   : Util.SqrDist(x, i, j, inverseLength, columnIndices);
    138138
    139139      double b = 1 + 0.5 * d / shape;
     
    143143    }
    144144
    145     public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
    146       double d = Util.SqrDist(x, i, xt, j, inverseLength);
     145    public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j, IEnumerable<int> columnIndices) {
     146      double d = Util.SqrDist(x, i, xt, j, inverseLength, columnIndices);
    147147      return sf2 * Math.Pow(1 + 0.5 * d / shape, -shape);
    148148    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceScale.cs

    r8620 r8678  
    7272      this.scaleParameter = new HyperParameter<DoubleValue>("Scale", "The scale parameter.");
    7373      this.covParameter = new ValueParameter<ICovarianceFunction>("CovarianceFunction", "The covariance function that should be scaled.", new CovarianceSquaredExponentialIso());
     74      cov = covParameter.Value;
    7475
    7576      Parameters.Add(this.scaleParameter);
     
    106107    }
    107108
    108     public double GetCovariance(double[,] x, int i, int j) {
    109       return sf2 * cov.GetCovariance(x, i, j);
     109    public double GetCovariance(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
     110      return sf2 * cov.GetCovariance(x, i, j, columnIndices);
    110111    }
    111112
    112     public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
    113       yield return 2 * sf2 * cov.GetCovariance(x, i, j);
    114       foreach (var g in cov.GetGradient(x, i, j))
     113    public IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
     114      yield return 2 * sf2 * cov.GetCovariance(x, i, j, columnIndices);
     115      foreach (var g in cov.GetGradient(x, i, j, columnIndices))
    115116        yield return sf2 * g;
    116117    }
    117118
    118     public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
    119       return sf2 * cov.GetCrossCovariance(x, xt, i, j);
     119    public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j, IEnumerable<int> columnIndices) {
     120      return sf2 * cov.GetCrossCovariance(x, xt, i, j, columnIndices);
    120121    }
    121122  }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSquaredExponentialArd.cs

    r8615 r8678  
    110110    }
    111111
    112     public double GetCovariance(double[,] x, int i, int j) {
     112    public double GetCovariance(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
    113113      double d = i == j
    114114                   ? 0.0
    115                    : Util.SqrDist(x, i, j, inverseLength);
     115                   : Util.SqrDist(x, i, j, inverseLength, columnIndices);
    116116      return sf2 * Math.Exp(-d / 2.0);
    117117    }
    118118
    119     public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
     119    public IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
    120120      double d = i == j
    121121                   ? 0.0
    122                    : Util.SqrDist(x, i, j, inverseLength);
     122                   : Util.SqrDist(x, i, j, inverseLength, columnIndices);
    123123
    124124      for (int ii = 0; ii < inverseLength.Length; ii++) {
     
    129129    }
    130130
    131     public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
    132       double d = Util.SqrDist(x, i, xt, j, inverseLength);
     131    public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j, IEnumerable<int> columnIndices) {
     132      double d = Util.SqrDist(x, i, xt, j, inverseLength, columnIndices);
    133133      return sf2 * Math.Exp(-d / 2.0);
    134134    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSquaredExponentialIso.cs

    r8615 r8678  
    108108
    109109
    110     public double GetCovariance(double[,] x, int i, int j) {
     110    public double GetCovariance(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
    111111      double d = i == j
    112112                   ? 0.0
    113                    : Util.SqrDist(x, i, j, inverseLength);
     113                   : Util.SqrDist(x, i, j, inverseLength, columnIndices);
    114114      return sf2 * Math.Exp(-d / 2.0);
    115115    }
    116116
    117     public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
     117    public IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
    118118      double d = i == j
    119119                   ? 0.0
    120                    : Util.SqrDist(x, i, j, inverseLength);
     120                   : Util.SqrDist(x, i, j, inverseLength, columnIndices);
    121121      double g = Math.Exp(-d / 2.0);
    122122      yield return sf2 * g * d;
     
    124124    }
    125125
    126     public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
    127       double d = Util.SqrDist(x, i, xt, j, inverseLength);
     126    public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j, IEnumerable<int> columnIndices) {
     127      double d = Util.SqrDist(x, i, xt, j, inverseLength, columnIndices);
    128128      return sf2 * Math.Exp(-d / 2.0);
    129129    }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSum.cs

    r8612 r8678  
    7676    }
    7777
    78     public double GetCovariance(double[,] x, int i, int j) {
    79       return terms.Select(t => t.GetCovariance(x, i, j)).Sum();
     78    public double GetCovariance(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
     79      return terms.Select(t => t.GetCovariance(x, i, j, columnIndices)).Sum();
    8080    }
    8181
    82     public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
    83       return terms.Select(t => t.GetGradient(x, i, j)).Aggregate(Enumerable.Concat);
     82    public IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
     83      return terms.Select(t => t.GetGradient(x, i, j, columnIndices)).Aggregate(Enumerable.Concat);
    8484    }
    8585
    86     public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
    87       return terms.Select(t => t.GetCrossCovariance(x, xt, i, j)).Sum();
     86    public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j, IEnumerable<int> columnIndices) {
     87      return terms.Select(t => t.GetCrossCovariance(x, xt, i, j, columnIndices)).Sum();
    8888    }
    8989  }
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/ICovarianceFunction.cs

    r8562 r8678  
    2727    int GetNumberOfParameters(int numberOfVariables);
    2828    void SetParameter(double[] hyp);
    29     double GetCovariance(double[,] x, int i, int j);
    30     IEnumerable<double> GetGradient(double[,] x, int i, int j);
    31     double GetCrossCovariance(double[,] x, double[,] xt, int i, int j);
     29    double GetCovariance(double[,] x, int i, int j, IEnumerable<int> columnIndices = null);
     30    IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices = null);
     31    double GetCrossCovariance(double[,] x, double[,] xt, int i, int j, IEnumerable<int> columnIndices = null);
    3232  }
    3333}
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/Util.cs

    r8612 r8678  
    4141    }
    4242
    43     public static double SqrDist(double[,] x, int i, int j, double scale = 1.0) {
    44       return SqrDist(x, i, x, j, scale);
     43    public static double SqrDist(double[,] x, int i, int j, double scale = 1.0, IEnumerable<int> columnIndices = null) {
     44      return SqrDist(x, i, x, j, scale, columnIndices);
    4545    }
    4646
    47     public static double SqrDist(double[,] x, int i, double[,] xt, int j, double scale = 1.0) {
     47    public static double SqrDist(double[,] x, int i, double[,] xt, int j, double scale = 1.0, IEnumerable<int> columnIndices = null) {
    4848      double ss = 0.0;
    49       for (int k = 0; k < x.GetLength(1); k++) {
     49      if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));
     50      foreach (int k in columnIndices) {
    5051        double d = x[i, k] - xt[j, k];
    5152        ss += d * d;
     
    5455    }
    5556
    56     public static double SqrDist(double[,] x, int i, int j, double[] scale) {
     57    public static double SqrDist(double[,] x, int i, int j, double[] scale, IEnumerable<int> columnIndices = null) {
    5758      return SqrDist(x, i, x, j, scale);
    5859    }
    5960
    60     public static double SqrDist(double[,] x, int i, double[,] xt, int j, double[] scale) {
     61    public static double SqrDist(double[,] x, int i, double[,] xt, int j, double[] scale, IEnumerable<int> columnIndices = null) {
    6162      double ss = 0.0;
    62       for (int k = 0; k < x.GetLength(1); k++) {
     63      if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));
     64      foreach (int k in columnIndices) {
    6365        double d = x[i, k] - xt[j, k];
    6466        ss += d * d * scale[k] * scale[k];
     
    6668      return ss;
    6769    }
    68     public static double ScalarProd(double[,] x, int i, int j, double scale = 1.0) {
    69       return ScalarProd(x, i, x, j, scale);
     70    public static double ScalarProd(double[,] x, int i, int j, double scale = 1.0, IEnumerable<int> columnIndices = null) {
     71      return ScalarProd(x, i, x, j, scale, columnIndices);
    7072    }
    7173
    72     public static double ScalarProd(double[,] x, int i, double[,] xt, int j, double scale = 1.0) {
     74    public static double ScalarProd(double[,] x, int i, double[,] xt, int j, double scale = 1.0, IEnumerable<int> columnIndices = null) {
    7375      double sum = 0.0;
    74       for (int k = 0; k < x.GetLength(1); k++) {
     76      if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));
     77      foreach (int k in columnIndices) {
    7578        sum += x[i, k] * xt[j, k];
    7679      }
    7780      return scale * scale * sum;
    7881    }
    79     public static double ScalarProd(double[,] x, int i, int j, double[] scale) {
    80       return ScalarProd(x, i, x, j, scale);
     82    public static double ScalarProd(double[,] x, int i, int j, double[] scale, IEnumerable<int> columnIndices = null) {
     83      return ScalarProd(x, i, x, j, scale, columnIndices);
    8184    }
    8285
    83     public static double ScalarProd(double[,] x, int i, double[,] xt, int j, double[] scale) {
     86    public static double ScalarProd(double[,] x, int i, double[,] xt, int j, double[] scale, IEnumerable<int> columnIndices = null) {
    8487      double sum = 0.0;
    85       for (int k = 0; k < x.GetLength(1); k++) {
     88      if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));
     89      foreach (int k in columnIndices) {
    8690        sum += x[i, k] * scale[k] * xt[j, k] * scale[k];
    8791      }
Note: See TracChangeset for help on using the changeset viewer.