#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 HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Operators;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Encodings.ConditionActionEncoding {
[Item("CalculateAccuracy", "")]
[StorableClass]
public class CalculateAccuracy : SingleSuccessorOperator {
public ILookupParameter AlphaParameter {
get { return (ILookupParameter)Parameters["Alpha"]; }
}
public ILookupParameter ErrorParameter {
get { return (ILookupParameter)Parameters["Error"]; }
}
public ILookupParameter ErrorZeroParameter {
get { return (ILookupParameter)Parameters["ErrorZero"]; }
}
public ILookupParameter PowerParameter {
get { return (ILookupParameter)Parameters["v"]; }
}
public IValueLookupParameter AccuracyParameter {
get { return (IValueLookupParameter)Parameters["Accuracy"]; }
}
private double Error {
get { return ErrorParameter.ActualValue.Value; }
}
private double ErrorZero {
get { return ErrorZeroParameter.ActualValue.Value; }
}
private double Alpha {
get { return AlphaParameter.ActualValue.Value; }
}
private double Power {
get { return PowerParameter.ActualValue.Value; }
}
[StorableConstructor]
protected CalculateAccuracy(bool deserializing) : base(deserializing) { }
protected CalculateAccuracy(CalculateAccuracy original, Cloner cloner)
: base(original, cloner) {
}
public CalculateAccuracy()
: base() {
Parameters.Add(new LookupParameter("Alpha"));
Parameters.Add(new LookupParameter("Error"));
Parameters.Add(new LookupParameter("ErrorZero"));
Parameters.Add(new LookupParameter("v"));
Parameters.Add(new ValueLookupParameter("Accuracy"));
}
public override IDeepCloneable Clone(Cloner cloner) {
return new CalculateAccuracy(this, cloner);
}
public override IOperation Apply() {
if (Error < ErrorZero) {
AccuracyParameter.ActualValue = new DoubleValue(1);
} else {
AccuracyParameter.ActualValue = new DoubleValue(Alpha * Math.Pow(Error / ErrorZero, -Power));
}
return base.Apply();
}
}
}