Line | |
---|
1 |
|
---|
2 |
|
---|
3 | using System;
|
---|
4 | using System.Collections.Generic;
|
---|
5 | using System.Linq;
|
---|
6 |
|
---|
7 | namespace 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 | public static IEnumerable<double> GetCol(double[,] x, int c) {
|
---|
27 | int rows = x.GetLength(0);
|
---|
28 | return Enumerable.Range(0, rows).Select(r => x[r, c]);
|
---|
29 | }
|
---|
30 | }
|
---|
31 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.