本文整理汇总了C#中IDataset.GetDoubleValue方法的典型用法代码示例。如果您正苦于以下问题:C# IDataset.GetDoubleValue方法的具体用法?C# IDataset.GetDoubleValue怎么用?C# IDataset.GetDoubleValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataset
的用法示例。
在下文中一共展示了IDataset.GetDoubleValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindClosestCenters
public static IEnumerable<int> FindClosestCenters(IEnumerable<double[]> centers, IDataset dataset, IEnumerable<string> allowedInputVariables, IEnumerable<int> rows) {
int nRows = rows.Count();
int nCols = allowedInputVariables.Count();
int[] closestCenter = new int[nRows];
double[] bestCenterDistance = Enumerable.Repeat(double.MaxValue, nRows).ToArray();
int centerIndex = 1;
foreach (double[] center in centers) {
if (nCols != center.Length) throw new ArgumentException();
int rowIndex = 0;
foreach (var row in rows) {
// calc euclidian distance of point to center
double centerDistance = 0;
int col = 0;
foreach (var inputVariable in allowedInputVariables) {
double d = center[col++] - dataset.GetDoubleValue(inputVariable, row);
d = d * d; // square;
centerDistance += d;
if (centerDistance > bestCenterDistance[rowIndex]) break;
}
if (centerDistance < bestCenterDistance[rowIndex]) {
bestCenterDistance[rowIndex] = centerDistance;
closestCenter[rowIndex] = centerIndex;
}
rowIndex++;
}
centerIndex++;
}
return closestCenter;
}
示例2: CalculateIntraClusterSumOfSquares
public static double CalculateIntraClusterSumOfSquares(KMeansClusteringModel model, IDataset dataset, IEnumerable<int> rows) {
List<int> clusterValues = model.GetClusterValues(dataset, rows).ToList();
List<string> allowedInputVariables = model.AllowedInputVariables.ToList();
int nCols = allowedInputVariables.Count;
Dictionary<int, List<double[]>> clusterPoints = new Dictionary<int, List<double[]>>();
Dictionary<int, double[]> clusterMeans = new Dictionary<int, double[]>();
foreach (var clusterValue in clusterValues.Distinct()) {
clusterPoints.Add(clusterValue, new List<double[]>());
}
// collect points of clusters
int clusterValueIndex = 0;
foreach (var row in rows) {
double[] p = new double[allowedInputVariables.Count];
for (int i = 0; i < nCols; i++) {
p[i] = dataset.GetDoubleValue(allowedInputVariables[i], row);
}
clusterPoints[clusterValues[clusterValueIndex++]].Add(p);
}
// calculate cluster means
foreach (var pair in clusterPoints) {
double[] mean = new double[nCols];
foreach (var p in pair.Value) {
for (int i = 0; i < nCols; i++) {
mean[i] += p[i];
}
}
for (int i = 0; i < nCols; i++) {
mean[i] /= pair.Value.Count;
}
clusterMeans[pair.Key] = mean;
}
// calculate distances
double allCenterDistances = 0;
foreach (var pair in clusterMeans) {
double[] mean = pair.Value;
double centerDistances = 0;
foreach (var clusterPoint in clusterPoints[pair.Key]) {
double centerDistance = 0;
for (int i = 0; i < nCols; i++) {
double d = mean[i] - clusterPoint[i];
d = d * d;
centerDistance += d;
}
centerDistances += centerDistance;
}
allCenterDistances += centerDistances;
}
return allCenterDistances;
}
示例3: PCAReduce
private static double[,] PCAReduce(IDataset dataset, IEnumerable<int> rows, IEnumerable<string> variables) {
var instances = rows.ToArray();
var attributes = variables.ToArray();
var data = new double[instances.Length, attributes.Length + 1];
for (int j = 0; j < attributes.Length; j++) {
int i = 0;
var values = dataset.GetDoubleValues(attributes[j], instances);
foreach (var v in values) {
data[i++, j] = v;
}
}
int info;
double[] variances;
var matrix = new double[0, 0];
alglib.pcabuildbasis(data, instances.Length, attributes.Length, out info, out variances, out matrix);
var result = new double[instances.Length, matrix.GetLength(1)];
int r = 0;
foreach (var inst in instances) {
int i = 0;
foreach (var attrib in attributes) {
double val = dataset.GetDoubleValue(attrib, inst);
for (int j = 0; j < result.GetLength(1); j++)
result[r, j] += val * matrix[i, j];
i++;
}
r++;
}
return result;
}