#region License Information /* HeuristicLab * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Problems.DataAnalysis; namespace HeuristicLab.Encodings.ConditionActionEncoding { [StorableClass] [Item("ConditionActionEnsembleProblemData", "")] public class ConditionActionEnsembleProblemData : ParameterizedNamedItem, IConditionActionEnsembleProblemData { public IValueParameter ProblemDataParameter { get { return (IValueParameter)Parameters["ProblemData"]; } } public bool IsTrainingSample(int index) { return index >= 0 && index < Dataset.Rows && TrainingPartition.Start <= index && index < TrainingPartition.End; } public bool IsTestSample(int index) { return index >= 0 && index < Dataset.Rows && TestPartition.Start <= index && index < TestPartition.End; } public IEnumerable TrainingIndices { get { return Enumerable.Range(TrainingPartition.Start, Math.Max(0, TrainingPartition.End - TrainingPartition.Start)) .Where(IsTrainingSample); } } public IEnumerable TestIndices { get { return Enumerable.Range(TestPartition.Start, Math.Max(0, TestPartition.End - TestPartition.Start)) .Where(IsTestSample); } } [Storable] private IConditionActionProblemData problemData; [StorableConstructor] protected ConditionActionEnsembleProblemData(bool deserializing) : base(deserializing) { } protected ConditionActionEnsembleProblemData(ConditionActionEnsembleProblemData original, Cloner cloner) : base(original, cloner) { problemData = (IConditionActionProblemData)original.problemData.Clone(); } public ConditionActionEnsembleProblemData() : base() { Parameters.Add(new ValueParameter("ProblemData", "")); } public ConditionActionEnsembleProblemData(IConditionActionProblemData problemData) : base() { this.problemData = problemData; Parameters.Add(new ValueParameter("ProblemData", "", problemData)); } public override IDeepCloneable Clone(Cloner cloner) { return new ConditionActionEnsembleProblemData(this, cloner); } public IConditionActionProblemData GetConditionActionProblemData() { return (IConditionActionProblemData)problemData.Clone(); } #region IConditionActionProblemData Members public ICheckedItemList ConditionVariables { get { return problemData.ConditionVariables; } } public IEnumerable AllowedConditionVariables { get { return problemData.AllowedConditionVariables; } } public IInput FetchInput(int row) { return problemData.FetchInput(row); } public IEnumerable FetchInput(IEnumerable rows) { return problemData.FetchInput(rows); } public IEnumerable FetchAction(IEnumerable rows) { return problemData.FetchAction(rows); } public IAction FetchAction(int rows) { return problemData.FetchAction(rows); } public ICheckedItemList ActionVariables { get { return problemData.ActionVariables; } } public IEnumerable AllowedActionVariables { get { return problemData.AllowedActionVariables; } } public IClassifierComparer ClassifierComparer { get { return problemData.ClassifierComparer; } } #endregion #region IDataAnalysisProblemData Members public bool IsEmpty { get { return problemData.IsEmpty; } } public Dataset Dataset { get { return problemData.Dataset; } } public ICheckedItemList InputVariables { get { return problemData.InputVariables; } } public IEnumerable AllowedInputVariables { get { return problemData.AllowedInputVariables; } } public IntRange TrainingPartition { get { return problemData.TrainingPartition; } } public IntRange TestPartition { get { return problemData.TestPartition; } } public event System.EventHandler Changed; #endregion } }