Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/Util.cs @ 8323

Last change on this file since 8323 was 8323, checked in by gkronber, 12 years ago

#1902 initial import of Gaussian process regression algorithm

File size: 788 bytes
Line 
1
2
3using System;
4using System.Collections.Generic;
5using System.Linq;
6
7namespace HeuristicLab.Algorithms.DataAnalysis.GaussianProcess {
8  public static class Util {
9    public static double ScalarProd(IEnumerable<double> v, IEnumerable<double> u) {
10      return v.Zip(u, (vi, ui) => vi * ui).Sum();
11    }
12
13    public static double SqrDist(double x, double y) {
14      double d = x - y;
15      return Math.Max(d * d, 0.0);
16    }
17
18    public static double SqrDist(IEnumerable<double> x, IEnumerable<double> y) {
19      return Math.Max(x.Zip(y, (a, b) => (a - b) * (a - b)).Sum(), 0);
20    }
21
22    public static IEnumerable<double> GetRow(double[,] x, int r) {
23      int cols = x.GetLength(1);
24      return Enumerable.Range(0, cols).Select(c => x[r, c]);
25    }
26  }
27}
Note: See TracBrowser for help on using the repository browser.