Changeset 15973 for branches/2522_RefactorPluginInfrastructure/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/Util.cs
- Timestamp:
- 06/28/18 11:13:37 (6 years ago)
- Location:
- branches/2522_RefactorPluginInfrastructure
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2522_RefactorPluginInfrastructure
- Property svn:ignore
-
old new 24 24 protoc.exe 25 25 obj 26 .vs
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
-
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Algorithms.DataAnalysis/3.4
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/stable/HeuristicLab.Algorithms.DataAnalysis/3.4 merged eligible /trunk/HeuristicLab.Algorithms.DataAnalysis/3.4 merged eligible /branches/1721-RandomForestPersistence/HeuristicLab.Algorithms.DataAnalysis/3.4 10321-10322 /branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4 13329-15286 /branches/Benchmarking/sources/HeuristicLab.Algorithms.DataAnalysis/3.4 6917-7005 /branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4 9070-13099 /branches/CloningRefactoring/HeuristicLab.Algorithms.DataAnalysis/3.4 4656-4721 /branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4 5471-5808 /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Algorithms.DataAnalysis/3.4 5815-6180 /branches/DataAnalysis/HeuristicLab.Algorithms.DataAnalysis/3.4 4458-4459,4462,4464 /branches/DataPreprocessing/HeuristicLab.Algorithms.DataAnalysis/3.4 10085-11101 /branches/GP.Grammar.Editor/HeuristicLab.Algorithms.DataAnalysis/3.4 6284-6795 /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Algorithms.DataAnalysis/3.4 5060 /branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Algorithms.DataAnalysis/3.4 11570-12508 /branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Algorithms.DataAnalysis/3.4 11130-12721 /branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Algorithms.DataAnalysis/3.4 13819-14091 /branches/HeuristicLab.TimeSeries/HeuristicLab.Algorithms.DataAnalysis/3.4 8116-8789 /branches/LogResidualEvaluator/HeuristicLab.Algorithms.DataAnalysis/3.4 10202-10483 /branches/NET40/sources/HeuristicLab.Algorithms.DataAnalysis/3.4 5138-5162 /branches/ParallelEngine/HeuristicLab.Algorithms.DataAnalysis/3.4 5175-5192 /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Algorithms.DataAnalysis/3.4 7773-7810 /branches/QAPAlgorithms/HeuristicLab.Algorithms.DataAnalysis/3.4 6350-6627 /branches/Restructure trunk solution/HeuristicLab.Algorithms.DataAnalysis/3.4 6828 /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Algorithms.DataAnalysis/3.4 10204-10479 /branches/SuccessProgressAnalysis/HeuristicLab.Algorithms.DataAnalysis/3.4 5370-5682 /branches/Trunk/HeuristicLab.Algorithms.DataAnalysis/3.4 6829-6865 /branches/VNS/HeuristicLab.Algorithms.DataAnalysis/3.4 5594-5752 /branches/Weighted TSNE/3.4 15451-15531 /branches/histogram/HeuristicLab.Algorithms.DataAnalysis/3.4 5959-6341 /branches/symbreg-factors-2650/HeuristicLab.Algorithms.DataAnalysis/3.4 14232-14825 /trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4 13402-15674
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/Util.cs
r12012 r15973 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Core;26 using HeuristicLab.Data;27 25 28 26 namespace HeuristicLab.Algorithms.DataAnalysis { 29 27 internal static class Util { 30 public static double ScalarProd(IEnumerable<double> v, IEnumerable<double> u) { 31 return v.Zip(u, (vi, ui) => vi * ui).Sum(); 28 public static double ScalarProd(double[] v, double[] u) { 29 if (v.Length != u.Length) throw new InvalidOperationException(); 30 double prod = 0.0; 31 for (int i = 0; i < v.Length; i++) 32 prod += v[i] * u[i]; 33 return prod; 32 34 } 33 35 … … 41 43 } 42 44 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);45 public static double SqrDist(double[,] x, int i, int j, int[] columnIndices, double scale = 1.0) { 46 return SqrDist(x, i, x, j, columnIndices, scale); 45 47 } 46 48 47 public static double SqrDist(double[,] x, int i, double[,] xt, int j, double scale = 1.0, IEnumerable<int> columnIndices = null) {49 public static double SqrDist(double[,] x, int i, double[,] xt, int j, int[] columnIndices, double scale = 1.0) { 48 50 double ss = 0.0; 49 if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1)); 50 foreach (int columnIndex in columnIndices) { 51 if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1)).ToArray(); 52 for (int c = 0; c < columnIndices.Length; c++) { 53 var columnIndex = columnIndices[c]; 51 54 double d = x[i, columnIndex] - xt[j, columnIndex]; 52 55 ss += d * d; … … 55 58 } 56 59 57 public static double SqrDist(double[,] x, int i, int j, double[] scale, IEnumerable<int> columnIndices = null) {60 public static double SqrDist(double[,] x, int i, int j, double[] scale, int[] columnIndices) { 58 61 return SqrDist(x, i, x, j, scale, columnIndices); 59 62 } 60 63 61 public static double SqrDist(double[,] x, int i, double[,] xt, int j, double[] scale, IEnumerable<int> columnIndices = null) {64 public static double SqrDist(double[,] x, int i, double[,] xt, int j, double[] scale, int[] columnIndices) { 62 65 double ss = 0.0; 63 if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));64 66 int scaleIndex = 0; 65 foreach (int columnIndex in columnIndices) { 67 for (int c = 0; c < columnIndices.Length; c++) { 68 var columnIndex = columnIndices[c]; 66 69 double d = x[i, columnIndex] - xt[j, columnIndex]; 67 70 ss += d * d * scale[scaleIndex] * scale[scaleIndex]; … … 73 76 return ss; 74 77 } 75 public static double ScalarProd(double[,] x, int i, int j, double scale = 1.0, IEnumerable<int> columnIndices = null) {76 return ScalarProd(x, i, x, j, scale, columnIndices);78 public static double ScalarProd(double[,] x, int i, int j, int[] columnIndices, double scale = 1.0) { 79 return ScalarProd(x, i, x, j, columnIndices, scale); 77 80 } 78 81 79 public static double ScalarProd(double[,] x, int i, double[,] xt, int j, double scale = 1.0, IEnumerable<int> columnIndices = null) {82 public static double ScalarProd(double[,] x, int i, double[,] xt, int j, int[] columnIndices, double scale = 1.0) { 80 83 double sum = 0.0; 81 if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));82 foreach (int columnIndex in columnIndices) {84 for (int c = 0; c < columnIndices.Length; c++) { 85 var columnIndex = columnIndices[c]; 83 86 sum += x[i, columnIndex] * xt[j, columnIndex]; 84 87 } 85 88 return scale * scale * sum; 86 89 } 87 public static double ScalarProd(double[,] x, int i, int j, double[] scale, IEnumerable<int> columnIndices = null) {90 public static double ScalarProd(double[,] x, int i, int j, double[] scale, int[] columnIndices) { 88 91 return ScalarProd(x, i, x, j, scale, columnIndices); 89 92 } 90 93 91 public static double ScalarProd(double[,] x, int i, double[,] xt, int j, double[] scale, IEnumerable<int> columnIndices = null) {94 public static double ScalarProd(double[,] x, int i, double[,] xt, int j, double[] scale, int[] columnIndices) { 92 95 double sum = 0.0; 93 if (columnIndices == null) columnIndices = Enumerable.Range(0, x.GetLength(1));94 96 int scaleIndex = 0; 95 foreach (int columnIndex in columnIndices) { 97 for (int c = 0; c < columnIndices.Length; c++, scaleIndex++) { 98 var columnIndex = columnIndices[c]; 96 99 sum += x[i, columnIndex] * scale[scaleIndex] * xt[j, columnIndex] * scale[scaleIndex]; 97 scaleIndex++;98 100 } 99 101 // must be at the end of scale after iterating over columnIndices
Note: See TracChangeset
for help on using the changeset viewer.