[10539] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
[10236] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 |
|
---|
| 26 | namespace HeuristicLab.DataPreprocessing {
|
---|
[10557] | 27 | public class SearchLogic : ISearchLogic {
|
---|
[10586] | 28 | private readonly ITransactionalPreprocessingData preprocessingData;
|
---|
[10236] | 29 |
|
---|
[10586] | 30 | public SearchLogic(ITransactionalPreprocessingData thePreprocessingData) {
|
---|
[10236] | 31 | preprocessingData = thePreprocessingData;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | public IDictionary<string, IEnumerable<int>> GetMissingValueIndices() {
|
---|
| 35 | var dic = new Dictionary<string, IEnumerable<int>>();
|
---|
| 36 | foreach (string variableName in preprocessingData.VariableNames) {
|
---|
[10367] | 37 | dic.Add(variableName, GetMissingValueIndices(preprocessingData.GetColumnIndex(variableName)));
|
---|
[10236] | 38 | }
|
---|
| 39 | return dic;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
[10367] | 42 | public bool IsMissingValue(int columnIndex, int rowIndex) {
|
---|
| 43 | if (preprocessingData.IsType<double>(columnIndex)) {
|
---|
| 44 | return double.IsNaN(preprocessingData.GetCell<double>(columnIndex, rowIndex));
|
---|
| 45 | } else if (preprocessingData.IsType<string>(columnIndex)) {
|
---|
| 46 | return string.IsNullOrEmpty(preprocessingData.GetCell<string>(columnIndex, rowIndex));
|
---|
| 47 | } else if (preprocessingData.IsType<DateTime>(columnIndex)) {
|
---|
| 48 | return preprocessingData.GetCell<DateTime>(columnIndex, rowIndex).Equals(DateTime.MinValue);
|
---|
[10236] | 49 | } else {
|
---|
[10367] | 50 | throw new ArgumentException("cell in column " + columnIndex + " and row index " + rowIndex + " contains a non supported type.");
|
---|
[10236] | 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[10367] | 54 | public IEnumerable<int> GetMissingValueIndices(int columnIndex) {
|
---|
| 55 | if (preprocessingData.IsType<double>(columnIndex)) {
|
---|
| 56 | return preprocessingData.GetValues<double>(columnIndex).Select((s, i) => new { i, s }).Where(t => double.IsNaN(t.s)).Select(t => t.i);
|
---|
| 57 | } else if (preprocessingData.IsType<string>(columnIndex)) {
|
---|
| 58 | return preprocessingData.GetValues<string>(columnIndex).Select((s, i) => new { i, s }).Where(t => string.IsNullOrEmpty(t.s)).Select(t => t.i);
|
---|
| 59 | } else if (preprocessingData.IsType<DateTime>(columnIndex)) {
|
---|
| 60 | return preprocessingData.GetValues<DateTime>(columnIndex).Select((s, i) => new { i, s }).Where(t => t.s.Equals(DateTime.MinValue)).Select(t => t.i);
|
---|
[10236] | 61 | } else {
|
---|
[10367] | 62 | throw new ArgumentException("column " + columnIndex + " contains a non supported type.");
|
---|
[10236] | 63 | }
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | }
|
---|
| 67 | }
|
---|