Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17456 for branches


Ignore:
Timestamp:
02/28/20 10:43:50 (5 years ago)
Author:
pfleck
Message:

#3040 Merged trunk to branch

Location:
branches/3040_VectorBasedGP
Files:
54 edited
3 copied

Legend:

Unmodified
Added
Removed
  • branches/3040_VectorBasedGP

  • branches/3040_VectorBasedGP/HeuristicLab.Algorithms.DataAnalysis

  • branches/3040_VectorBasedGP/HeuristicLab.Algorithms.DataAnalysis.Views

  • branches/3040_VectorBasedGP/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/CrossValidationView.cs

    r17180 r17456  
    223223
    224224    private async void startButton_Click(object sender, EventArgs e) {
    225       await Content.StartAsync();
     225      try {
     226        await Content.StartAsync();
     227      } catch (Exception ex) {
     228        ErrorHandling.ShowErrorDialog(this, ex);
     229      }
    226230    }
    227231    private void pauseButton_Click(object sender, EventArgs e) {
  • branches/3040_VectorBasedGP/HeuristicLab.Algorithms.DataAnalysis/3.4

  • branches/3040_VectorBasedGP/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessBase.cs

    r17180 r17456  
    2222
    2323using System.Linq;
     24using HEAL.Attic;
    2425using HeuristicLab.Algorithms.GradientDescent;
    2526using HeuristicLab.Common;
     
    2930using HeuristicLab.Optimization;
    3031using HeuristicLab.Parameters;
    31 using HEAL.Attic;
     32using HeuristicLab.PluginInfrastructure;
    3233using HeuristicLab.Problems.DataAnalysis;
    3334
     
    5758
    5859    #region parameter properties
    59     public IValueParameter<IMeanFunction> MeanFunctionParameter {
    60       get { return (IValueParameter<IMeanFunction>)Parameters[MeanFunctionParameterName]; }
    61     }
    62     public IValueParameter<ICovarianceFunction> CovarianceFunctionParameter {
    63       get { return (IValueParameter<ICovarianceFunction>)Parameters[CovarianceFunctionParameterName]; }
     60    public IConstrainedValueParameter<IMeanFunction> MeanFunctionParameter {
     61      get { return (IConstrainedValueParameter<IMeanFunction>)Parameters[MeanFunctionParameterName]; }
     62    }
     63    public IConstrainedValueParameter<ICovarianceFunction> CovarianceFunctionParameter {
     64      get { return (IConstrainedValueParameter<ICovarianceFunction>)Parameters[CovarianceFunctionParameterName]; }
    6465    }
    6566    public IValueParameter<IntValue> MinimizationIterationsParameter {
     
    106107      : base() {
    107108      Problem = problem;
    108       Parameters.Add(new ValueParameter<IMeanFunction>(MeanFunctionParameterName, "The mean function to use.", new MeanConst()));
    109       Parameters.Add(new ValueParameter<ICovarianceFunction>(CovarianceFunctionParameterName, "The covariance function to use.", new CovarianceSquaredExponentialIso()));
     109      Parameters.Add(new ConstrainedValueParameter<IMeanFunction>(MeanFunctionParameterName, "The mean function to use."));
     110      Parameters.Add(new ConstrainedValueParameter<ICovarianceFunction>(CovarianceFunctionParameterName, "The covariance function to use."));
    110111      Parameters.Add(new ValueParameter<IntValue>(MinimizationIterationsParameterName, "The number of iterations for likelihood optimization with LM-BFGS.", new IntValue(20)));
    111112      Parameters.Add(new ValueParameter<IntValue>(SeedParameterName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
     
    193194
    194195      solutionCreator.OperatorParameter.ActualName = SolutionCreatorParameterName;
     196
     197      foreach (var meanfunction in ApplicationManager.Manager.GetInstances<IMeanFunction>().OrderBy(s => s.ItemName))
     198        MeanFunctionParameter.ValidValues.Add(meanfunction);
     199
     200      var defaultMeanFunction = MeanFunctionParameter.ValidValues.OfType<MeanConst>().FirstOrDefault();
     201      if (defaultMeanFunction != null) {
     202        MeanFunctionParameter.Value = defaultMeanFunction;
     203      }
     204
     205      foreach (var covarianceFunction in ApplicationManager.Manager.GetInstances<ICovarianceFunction>().OrderBy(s => s.ItemName))
     206        CovarianceFunctionParameter.ValidValues.Add(covarianceFunction);
     207
     208      var defaultCovarianceFunctionParameter = CovarianceFunctionParameter.ValidValues.OfType<CovarianceSquaredExponentialIso>().FirstOrDefault();
     209      if (defaultCovarianceFunctionParameter != null) {
     210        CovarianceFunctionParameter.Value = defaultCovarianceFunctionParameter;
     211      }
    195212    }
    196213
  • branches/3040_VectorBasedGP/HeuristicLab.Clients.Hive

  • branches/3040_VectorBasedGP/HeuristicLab.Clients.Hive.Slave

  • branches/3040_VectorBasedGP/HeuristicLab.Clients.Hive.Slave/3.3/Executor.cs

    r17180 r17456  
    4646    public bool IsStopping { get; set; }
    4747    public bool IsPausing { get; set; }
     48    public bool HasFailed { get; set; }
    4849
    4950    public Exception CurrentException;
     
    8485
    8586        task.Start();
    86         if (!startTaskSem.WaitOne(Settings.Default.ExecutorSemTimeouts)) {
     87        if (!startTaskSem.WaitOne(Settings.Default.ExecutorSemTimeouts) && !HasFailed) {
    8788          throw new TimeoutException("Timeout when starting the task. TaskStarted event was not fired.");
    8889        }
     
    159160    #region Task Events
    160161    private void Task_TaskFailed(object sender, EventArgs e) {
     162      HasFailed = true;
    161163      IsStopping = true;
    162164      EventArgs<Exception> ex = (EventArgs<Exception>)e;
    163165      CurrentException = ex.Value;
    164166      executorQueue.AddMessage(ExecutorMessageType.TaskFailed);
     167      startTaskSem.Set(); // cancel waiting for startup
    165168    }
    166169
  • branches/3040_VectorBasedGP/HeuristicLab.Clients.Hive/3.3/Tasks/EngineTask.cs

    r17180 r17456  
    8080
    8181    public override async void Start() {
    82       Item.Prepare(initialOperation);
    83       await Item.StartAsync();
     82      try {
     83        Item.Prepare(initialOperation);
     84        await Item.StartAsync();
     85      } catch (Exception e) {
     86        engine_ExceptionOccurred(Item, new EventArgs<Exception>(e));
     87      }
    8488    }
    8589
  • branches/3040_VectorBasedGP/HeuristicLab.Clients.Hive/3.3/Tasks/OptimizerTask.cs

    r17180 r17456  
    101101        OnTaskStopped();
    102102      } else {
    103         await Item.StartAsync();
     103        try {
     104          await Item.StartAsync();
     105        } catch (Exception e) {
     106          optimizer_ExceptionOccurred(Item, new EventArgs<Exception>(e));
     107        }
    104108      }
    105109    }
  • branches/3040_VectorBasedGP/HeuristicLab.Clients.OKB.Views

  • branches/3040_VectorBasedGP/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBAlgorithmView.cs

    r17180 r17456  
    325325    }
    326326    private async void startButton_Click(object sender, EventArgs e) {
    327       await Content.StartAsync();
     327      try {
     328        await Content.StartAsync();
     329      } catch (Exception ex) {
     330        ErrorHandling.ShowErrorDialog(this, ex);
     331      }
    328332    }
    329333    private void pauseButton_Click(object sender, EventArgs e) {
  • branches/3040_VectorBasedGP/HeuristicLab.CodeEditor/3.4/CodeEditor.cs

    r17180 r17456  
    282282    public override void ScrollToPosition(int line, int column) {
    283283      var segment = GetSegmentAtLocation(line, column);
    284       TextEditor.CaretOffset = segment.Offset + segment.Length;
     284      TextEditor.CaretOffset = segment.Offset;
    285285      TextEditor.ScrollToLine(line);
    286286    }
  • branches/3040_VectorBasedGP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding

  • branches/3040_VectorBasedGP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/BalancedTreeCreator.cs

    r17347 r17456  
    7676    }
    7777
    78     private class SymbolCacheEntry {
    79       public int MinSubtreeCount;
    80       public int MaxSubtreeCount;
    81       public int[] MaxChildArity;
    82     }
    83 
    84     private class SymbolCache {
    85       public SymbolCache(ISymbolicExpressionGrammarBase grammar) {
    86         Grammar = grammar;
    87       }
    88 
    89       public ISymbolicExpressionTreeNode SampleNode(IRandom random, ISymbol parent, int childIndex, int minArity, int maxArity) {
    90         var symbols = new List<ISymbol>();
    91         var weights = new List<double>();
    92         foreach (var child in AllowedSymbols.Where(x => !(x is StartSymbol || x is Defun))) {
    93           var t = Tuple.Create(parent, child);
    94           if (!allowedCache.TryGetValue(t, out bool[] allowed)) { continue; }
    95           if (!allowed[childIndex]) { continue; }
    96 
    97           if (symbolCache.TryGetValue(child, out SymbolCacheEntry cacheItem)) {
    98             if (cacheItem.MinSubtreeCount < minArity) { continue; }
    99             if (cacheItem.MaxSubtreeCount > maxArity) { continue; }
    100           }
    101 
    102           symbols.Add(child);
    103           weights.Add(child.InitialFrequency);
    104         }
    105         if (symbols.Count == 0) {
    106           throw new ArgumentException("SampleNode: parent symbol " + parent.Name
    107             + " does not have any allowed child symbols with min arity " + minArity
    108             + " and max arity " + maxArity + ". Please ensure the grammar is properly configured.");
    109         }
    110         var symbol = symbols.SampleProportional(random, 1, weights).First();
    111         var node = symbol.CreateTreeNode();
    112         if (node.HasLocalParameters) {
    113           node.ResetLocalParameters(random);
    114         }
    115         return node;
    116       }
    117 
    118       public ISymbolicExpressionGrammarBase Grammar {
    119         get { return grammar; }
    120         set {
    121           grammar = value;
    122           RebuildCache();
    123         }
    124       }
    125 
    126       public IList<ISymbol> AllowedSymbols { get; private set; }
    127 
    128       public SymbolCacheEntry this[ISymbol symbol] {
    129         get { return symbolCache[symbol]; }
    130       }
    131 
    132       public bool[] this[ISymbol parent, ISymbol child] {
    133         get { return allowedCache[Tuple.Create(parent, child)]; }
    134       }
    135 
    136       public bool HasUnarySymbols { get; private set; }
    137 
    138       private void RebuildCache() {
    139         AllowedSymbols = Grammar.AllowedSymbols.Where(x => x.InitialFrequency > 0 && !(x is ProgramRootSymbol)).ToList();
    140 
    141         allowedCache = new Dictionary<Tuple<ISymbol, ISymbol>, bool[]>();
    142         symbolCache = new Dictionary<ISymbol, SymbolCacheEntry>();
    143 
    144         SymbolCacheEntry TryAddItem(ISymbol symbol) {
    145           if (!symbolCache.TryGetValue(symbol, out SymbolCacheEntry cacheItem)) {
    146             cacheItem = new SymbolCacheEntry {
    147               MinSubtreeCount = Grammar.GetMinimumSubtreeCount(symbol),
    148               MaxSubtreeCount = Grammar.GetMaximumSubtreeCount(symbol)
    149             };
    150             symbolCache[symbol] = cacheItem;
    151           }
    152           return cacheItem;
    153         }
    154 
    155         foreach (var parent in AllowedSymbols) {
    156           var parentCacheEntry = TryAddItem(parent);
    157           var maxChildArity = new int[parentCacheEntry.MaxSubtreeCount];
    158 
    159           if (!(parent is StartSymbol || parent is Defun)) {
    160             HasUnarySymbols |= parentCacheEntry.MaxSubtreeCount == 1;
    161           }
    162 
    163           foreach (var child in AllowedSymbols) {
    164             var childCacheEntry = TryAddItem(child);
    165             var allowed = new bool[parentCacheEntry.MaxSubtreeCount];
    166 
    167             for (int childIndex = 0; childIndex < parentCacheEntry.MaxSubtreeCount; ++childIndex) {
    168               allowed[childIndex] = Grammar.IsAllowedChildSymbol(parent, child, childIndex);
    169               maxChildArity[childIndex] = Math.Max(maxChildArity[childIndex], allowed[childIndex] ? childCacheEntry.MaxSubtreeCount : 0);
    170             }
    171             allowedCache[Tuple.Create(parent, child)] = allowed;
    172           }
    173           parentCacheEntry.MaxChildArity = maxChildArity;
    174         }
    175       }
    176 
    177       private ISymbolicExpressionGrammarBase grammar;
    178       private Dictionary<Tuple<ISymbol, ISymbol>, bool[]> allowedCache;
    179       private Dictionary<ISymbol, SymbolCacheEntry> symbolCache;
    180     }
    181 
    18278    public static ISymbolicExpressionTree CreateExpressionTree(IRandom random, ISymbolicExpressionGrammar grammar, int targetLength, int maxDepth, double irregularityBias = 1) {
    18379      // even lengths cannot be achieved without symbols of odd arity
    18480      // therefore we randomly pick a neighbouring odd length value
    18581      var tree = MakeStump(random, grammar); // create a stump consisting of just a ProgramRootSymbol and a StartSymbol
    186       CreateExpression(random, tree.Root.GetSubtree(0), targetLength - 2, maxDepth - 2, irregularityBias); // -2 because the stump has length 2 and depth 2
     82      CreateExpression(random, tree.Root.GetSubtree(0), targetLength - tree.Length, maxDepth - 2, irregularityBias); // -2 because the stump has length 2 and depth 2
    18783      return tree;
     84    }
     85
     86    private static ISymbolicExpressionTreeNode SampleNode(IRandom random, ISymbolicExpressionTreeGrammar grammar, IEnumerable<ISymbol> allowedSymbols, int minChildArity, int maxChildArity) {
     87      var candidates = new List<ISymbol>();
     88      var weights = new List<double>();
     89
     90      foreach (var s in allowedSymbols) {
     91        var minSubtreeCount = grammar.GetMinimumSubtreeCount(s);
     92        var maxSubtreeCount = grammar.GetMaximumSubtreeCount(s);
     93
     94        if (maxChildArity < minSubtreeCount || minChildArity > maxSubtreeCount) { continue; }
     95
     96        candidates.Add(s);
     97        weights.Add(s.InitialFrequency);
     98      }
     99      var symbol = candidates.SampleProportional(random, 1, weights).First();
     100      var node = symbol.CreateTreeNode();
     101      if (node.HasLocalParameters) {
     102        node.ResetLocalParameters(random);
     103      }
     104      return node;
    188105    }
    189106
    190107    public static void CreateExpression(IRandom random, ISymbolicExpressionTreeNode root, int targetLength, int maxDepth, double irregularityBias = 1) {
    191108      var grammar = root.Grammar;
    192       var symbolCache = new SymbolCache(grammar);
    193       var entry = symbolCache[root.Symbol];
    194       var arity = random.Next(entry.MinSubtreeCount, entry.MaxSubtreeCount + 1);
     109      var minSubtreeCount = grammar.GetMinimumSubtreeCount(root.Symbol);
     110      var maxSubtreeCount = grammar.GetMinimumSubtreeCount(root.Symbol);
     111      var arity = random.Next(minSubtreeCount, maxSubtreeCount + 1);
     112      int openSlots = arity;
     113
     114      var allowedSymbols = grammar.AllowedSymbols.Where(x => !(x is ProgramRootSymbol || x is GroupSymbol || x is Defun || x is StartSymbol)).ToList();
     115      bool hasUnarySymbols = allowedSymbols.Any(x => grammar.GetMinimumSubtreeCount(x) <= 1 && grammar.GetMaximumSubtreeCount(x) >= 1);
     116
     117      if (!hasUnarySymbols && targetLength % 2 == 0) {
     118        // without functions of arity 1 some target lengths cannot be reached
     119        targetLength = random.NextDouble() < 0.5 ? targetLength - 1 : targetLength + 1;
     120      }
     121
    195122      var tuples = new List<NodeInfo>(targetLength) { new NodeInfo { Node = root, Depth = 0, Arity = arity } };
    196       int openSlots = arity;
    197 
     123
     124      // we use tuples.Count instead of targetLength in the if condition
     125      // because depth limits may prevent reaching the target length
    198126      for (int i = 0; i < tuples.Count; ++i) {
    199127        var t = tuples[i];
    200128        var node = t.Node;
    201         var parentEntry = symbolCache[node.Symbol];
    202129
    203130        for (int childIndex = 0; childIndex < t.Arity; ++childIndex) {
    204131          // min and max arity here refer to the required arity limits for the child node
    205           int maxChildArity = t.Depth == maxDepth - 1 ? 0 : Math.Min(parentEntry.MaxChildArity[childIndex], targetLength - openSlots);
    206           int minChildArity = Math.Min((openSlots - tuples.Count > 1 && random.NextDouble() < irregularityBias) ? 0 : 1, maxChildArity);
    207           var child = symbolCache.SampleNode(random, node.Symbol, childIndex, minChildArity, maxChildArity);
    208           var childEntry = symbolCache[child.Symbol];
    209           var childArity = random.Next(childEntry.MinSubtreeCount, childEntry.MaxSubtreeCount + 1);
     132          int minChildArity = 0;
     133          int maxChildArity = 0;
     134
     135          var allowedChildSymbols = allowedSymbols.Where(x => grammar.IsAllowedChildSymbol(node.Symbol, x, childIndex)).ToList();
     136
     137          // if we are reaching max depth we have to fill the slot with a leaf node (max arity will be zero)
     138          // otherwise, find the maximum value from the grammar which does not exceed the length limit
     139          if (t.Depth < maxDepth - 1 && openSlots < targetLength) {
     140
     141            // we don't want to allow sampling a leaf symbol if it prevents us from reaching the target length
     142            // this should be allowed only when we have enough open expansion points (more than one)
     143            // the random check against the irregularity bias helps to increase shape variability when the conditions are met
     144            int minAllowedArity = allowedChildSymbols.Min(x => grammar.GetMaximumSubtreeCount(x));
     145            if (minAllowedArity == 0 && (openSlots - tuples.Count <= 1 || random.NextDouble() > irregularityBias)) {
     146              minAllowedArity = 1;
     147            }
     148
     149            // finally adjust min and max arity according to the expansion limits
     150            int maxAllowedArity = allowedChildSymbols.Max(x => grammar.GetMaximumSubtreeCount(x));
     151            maxChildArity = Math.Min(maxAllowedArity, targetLength - openSlots);
     152            minChildArity = Math.Min(minAllowedArity, maxChildArity);
     153          }
     154         
     155          // sample a random child with the arity limits
     156          var child = SampleNode(random, grammar, allowedChildSymbols, minChildArity, maxChildArity);
     157
     158          // get actual child arity limits
     159          minChildArity = Math.Max(minChildArity, grammar.GetMinimumSubtreeCount(child.Symbol));
     160          maxChildArity = Math.Min(maxChildArity, grammar.GetMaximumSubtreeCount(child.Symbol));
     161          minChildArity = Math.Min(minChildArity, maxChildArity);
     162
     163          // pick a random arity for the new child node
     164          var childArity = random.Next(minChildArity, maxChildArity + 1);
    210165          var childDepth = t.Depth + 1;
    211166          node.AddSubtree(child);
     
    244199      return tree;
    245200    }
     201
     202    public void CreateExpression(IRandom random, ISymbolicExpressionTreeNode seedNode, int maxTreeLength, int maxTreeDepth) {
     203      CreateExpression(random, seedNode, maxTreeLength, maxTreeDepth, IrregularityBias);
     204    }
    246205    #endregion
    247206  }
  • branches/3040_VectorBasedGP/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ProgressView.cs

    r17180 r17456  
    2525namespace HeuristicLab.MainForm.WindowsForms {
    2626  internal sealed partial class ProgressView : UserControl {
    27     private readonly Control control;
    28     public Control Control {
    29       get { return control; }
    30     }
    31 
    32     private readonly IProgress content;
    33     public IProgress Content {
    34       get { return content; }
    35     }
    36 
    37     public ProgressView(Control control, IProgress content)
     27    public Control TargetControl { get; }
     28    public IProgress Content { get; }
     29
     30    public ProgressView(Control targetControl, IProgress content)
    3831      : base() {
    39       if (control == null) throw new ArgumentNullException("control");
    40       if (control.Parent == null) throw new InvalidOperationException("A Progress can only be shown on controls that have a Parent-control. Therefore, Dialogs and Forms cannot have an associated ProgressView.");
    41       if (content == null) throw new ArgumentNullException("content");
     32      if (targetControl == null) throw new ArgumentNullException(nameof(targetControl));
     33      if (targetControl.Parent == null) throw new InvalidOperationException("A Progress can only be shown on controls that have a Parent-control. Therefore, Dialogs and Forms cannot have an associated ProgressView.");
     34      if (content == null) throw new ArgumentNullException(nameof(content));
    4235      InitializeComponent();
    4336
    44       this.control = control;
    45       this.content = content;
     37      this.TargetControl = targetControl;
     38      this.Content = content;
    4639
    4740      if (content.ProgressState != ProgressState.Finished)
     
    5245    protected override void Dispose(bool disposing) {
    5346      DeregisterContentEvents();
    54       HideProgress();
    55 
    56       if (disposing && (components != null)) {
     47
     48      if (!TargetControl.IsDisposed)
     49        HideProgress();
     50
     51      if (disposing && components != null) {
    5752        components.Dispose();
    5853      }
     
    10196
    10297    private void ShowProgress() {
    103       if (Control.InvokeRequired) {
    104         Control.Invoke((Action)ShowProgress);
     98      if (TargetControl.InvokeRequired) {
     99        TargetControl.Invoke((Action)ShowProgress);
    105100        return;
    106101      }
    107102      if (Parent != null) return;
    108103
    109       Left = (Control.ClientRectangle.Width / 2) - (Width / 2);
    110       Top = (Control.ClientRectangle.Height / 2) - (Height / 2);
     104      Left = (TargetControl.ClientRectangle.Width / 2) - (Width / 2);
     105      Top = (TargetControl.ClientRectangle.Height / 2) - (Height / 2);
    111106      Anchor = AnchorStyles.None;
    112107
     
    115110      UpdateButtonsState();
    116111
    117       Control.SuspendRepaint();
    118       Control.Enabled = false;
    119       Parent = Control.Parent;
     112      TargetControl.SuspendRepaint();
     113      TargetControl.Enabled = false;
     114      RegisterTargetControlEvents();
     115      Parent = TargetControl.Parent;
    120116      BringToFront();
    121       Control.ResumeRepaint(true);
     117      TargetControl.ResumeRepaint(true);
    122118      Visible = true;
    123119    }
    124120
    125121    private void HideProgress() {
    126       if (Control.InvokeRequired) {
    127         Control.Invoke((Action)HideProgress);
     122      if (TargetControl.InvokeRequired) {
     123        TargetControl.Invoke((Action)HideProgress);
    128124        return;
    129125      }
     
    131127
    132128      Visible = false;
    133       Control.SuspendRepaint();
    134       Control.Enabled = true;
    135       Control.ResumeRepaint(true);
     129      TargetControl.SuspendRepaint();
     130      TargetControl.Enabled = true;
     131      DeregisterTargetControlEvents();
    136132      Parent = null;
     133      TargetControl.ResumeRepaint(TargetControl.Visible);
     134    }
     135
     136
     137    private void RegisterTargetControlEvents() {
     138      TargetControl.Disposed += TargetControl_Disposed;
     139      TargetControl.VisibleChanged += TargetControl_VisibleChanged;
     140      TargetControl.ParentChanged += TargetControl_ParentChanged;
     141    }
     142
     143    private void DeregisterTargetControlEvents() {
     144      TargetControl.Disposed -= TargetControl_Disposed;
     145      TargetControl.VisibleChanged -= TargetControl_VisibleChanged;
     146      TargetControl.ParentChanged -= TargetControl_ParentChanged;
     147    }
     148
     149    private void TargetControl_Disposed(object sender, EventArgs e) {
     150      Dispose();
     151    }
     152    private void TargetControl_VisibleChanged(object sender, EventArgs e) {
     153      Visible = TargetControl.Visible;
     154    }
     155    private void TargetControl_ParentChanged(object sender, EventArgs e) {
     156      Parent = TargetControl.Parent;
    137157    }
    138158
    139159    private void UpdateProgressState() {
    140       if (Control.InvokeRequired) {
    141         Control.Invoke((Action)UpdateProgressState);
     160      if (TargetControl.InvokeRequired) {
     161        TargetControl.Invoke((Action)UpdateProgressState);
    142162        return;
    143163      }
     
    150170
    151171    private void UpdateProgressMessage() {
    152       if (Control.InvokeRequired) {
    153         Control.Invoke((Action)UpdateProgressMessage);
    154         return;
    155       }
    156 
    157       messageLabel.Text = content.Message;
     172      if (TargetControl.InvokeRequired) {
     173        TargetControl.Invoke((Action)UpdateProgressMessage);
     174        return;
     175      }
     176
     177      messageLabel.Text = Content.Message;
    158178    }
    159179
     
    167187        case ProgressMode.Determinate:
    168188          progressBar.Style = ProgressBarStyle.Continuous;
    169           progressBar.Value = (int)Math.Round(progressBar.Minimum + content.ProgressValue * (progressBar.Maximum - progressBar.Minimum));
     189          progressBar.Value = (int)Math.Round(progressBar.Minimum + Content.ProgressValue * (progressBar.Maximum - progressBar.Minimum));
    170190          break;
    171191        case ProgressMode.Indeterminate:
     
    174194          break;
    175195        default:
    176           throw new NotImplementedException($"Invalid Progress Mode: {content.ProgressMode}");
     196          throw new NotImplementedException($"Invalid Progress Mode: {Content.ProgressMode}");
    177197      }
    178198    }
    179199
    180200    private void UpdateButtonsState() {
    181       if (Control.InvokeRequired) {
    182         Control.Invoke((Action)UpdateButtonsState);
     201      if (TargetControl.InvokeRequired) {
     202        TargetControl.Invoke((Action)UpdateButtonsState);
    183203        return;
    184204      }
    185205
    186206      stopButton.Visible = Content.CanBeStopped;
    187       stopButton.Enabled = Content.CanBeStopped && content.ProgressState == ProgressState.Started;
     207      stopButton.Enabled = Content.CanBeStopped && Content.ProgressState == ProgressState.Started;
    188208
    189209      cancelButton.Visible = Content.CanBeCanceled;
    190       cancelButton.Enabled = Content.CanBeCanceled && content.ProgressState == ProgressState.Started;
     210      cancelButton.Enabled = Content.CanBeCanceled && Content.ProgressState == ProgressState.Started;
    191211    }
    192212
  • branches/3040_VectorBasedGP/HeuristicLab.Optimization.Views

  • branches/3040_VectorBasedGP/HeuristicLab.Optimization.Views/3.3/IOptimizerView.cs

    r17180 r17456  
    137137    #region Control events
    138138    protected virtual async void startButton_Click(object sender, EventArgs e) {
    139       await Content.StartAsync();
     139      try {
     140        await Content.StartAsync();
     141      } catch (Exception ex) {
     142        ErrorHandling.ShowErrorDialog(this, ex);
     143      }
    140144    }
    141145    protected virtual void pauseButton_Click(object sender, EventArgs e) {
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis

  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic

  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification

  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views

  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/SolutionComparisonView.cs

    r17180 r17456  
    9191      var newDs = new Dataset(variableNames, variableValues);
    9292      var newProblemData = new ClassificationProblemData(newDs, variableNames.Take(variableNames.Length - 1), variableNames.Last());
     93
     94      foreach (var classValue in problemData.ClassValues) {
     95        newProblemData.SetClassName(classValue, problemData.GetClassName(classValue));
     96      }
    9397      newProblemData.PositiveClass = problemData.PositiveClass;
     98
    9499      newProblemData.TrainingPartition.Start = problemData.TrainingPartition.Start;
    95100      newProblemData.TrainingPartition.End = problemData.TrainingPartition.End;
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer.cs

    r17180 r17456  
    2020#endregion
    2121
     22using System.Collections.Generic;
     23using System.Linq;
     24using HEAL.Attic;
     25using HeuristicLab.Analysis;
    2226using HeuristicLab.Common;
    2327using HeuristicLab.Core;
     28using HeuristicLab.Data;
    2429using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     30using HeuristicLab.Optimization;
    2531using HeuristicLab.Parameters;
    26 using HEAL.Attic;
    2732
    2833namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
     
    3843    private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter";
    3944    private const string EstimationLimitsParameterName = "EstimationLimits";
     45    private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
     46    private const string ValidationPartitionParameterName = "ValidationPartition";
     47    private const string AnalyzeTestErrorParameterName = "Analyze Test Error";
    4048
    4149    #region parameter properties
     
    5563      get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
    5664    }
     65    public ILookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
     66      get { return (ILookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
     67    }
     68    public IValueLookupParameter<IntRange> ValidationPartitionParameter {
     69      get { return (IValueLookupParameter<IntRange>)Parameters[ValidationPartitionParameterName]; }
     70    }
     71    public IFixedValueParameter<BoolValue> AnalyzeTestErrorParameter {
     72      get { return (IFixedValueParameter<BoolValue>)Parameters[AnalyzeTestErrorParameterName]; }
     73    }
     74    public bool AnalyzeTestError {
     75      get { return AnalyzeTestErrorParameter.Value.Value; }
     76      set { AnalyzeTestErrorParameter.Value.Value = value; }
     77    }
    5778    #endregion
    5879
     
    6687      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree."));
    6788      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic classification model."));
     89      Parameters.Add(new LookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "Maximal length of the symbolic expression.") { Hidden = true });
     90      Parameters.Add(new ValueLookupParameter<IntRange>(ValidationPartitionParameterName, "The validation partition."));
     91      Parameters.Add(new FixedValueParameter<BoolValue>(AnalyzeTestErrorParameterName, "Flag whether the test error should be displayed in the Pareto-Front", new BoolValue(false)));
     92
    6893    }
    6994    public override IDeepCloneable Clone(Cloner cloner) {
     
    87112      return model.CreateClassificationSolution((IClassificationProblemData)ProblemDataParameter.ActualValue.Clone());
    88113    }
     114
     115    public override IOperation Apply() {
     116      var operation = base.Apply();
     117      var paretoFront = TrainingBestSolutionsParameter.ActualValue;
     118
     119      IResult result;
     120      ScatterPlot qualityToTreeSize;
     121      if (!ResultCollection.TryGetValue("Pareto Front Analysis", out result)) {
     122        qualityToTreeSize = new ScatterPlot("Quality vs Tree Size", "");
     123        qualityToTreeSize.VisualProperties.XAxisMinimumAuto = false;
     124        qualityToTreeSize.VisualProperties.XAxisMaximumAuto = false;
     125        qualityToTreeSize.VisualProperties.YAxisMinimumAuto = false;
     126        qualityToTreeSize.VisualProperties.YAxisMaximumAuto = false;
     127
     128        qualityToTreeSize.VisualProperties.XAxisMinimumFixedValue = 0;
     129        qualityToTreeSize.VisualProperties.XAxisMaximumFixedValue = MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value;
     130        qualityToTreeSize.VisualProperties.YAxisMinimumFixedValue = 0;
     131        qualityToTreeSize.VisualProperties.YAxisMaximumFixedValue = 1;
     132        ResultCollection.Add(new Result("Pareto Front Analysis", qualityToTreeSize));
     133      } else {
     134        qualityToTreeSize = (ScatterPlot)result.Value;
     135      }
     136
     137      int previousTreeLength = -1;
     138      var sizeParetoFront = new LinkedList<ISymbolicClassificationSolution>();
     139      foreach (var solution in paretoFront.OrderBy(s => s.Model.SymbolicExpressionTree.Length)) {
     140        int treeLength = solution.Model.SymbolicExpressionTree.Length;
     141        if (!sizeParetoFront.Any()) sizeParetoFront.AddLast(solution);
     142        if (solution.TrainingAccuracy > sizeParetoFront.Last.Value.TrainingAccuracy) {
     143          if (treeLength == previousTreeLength)
     144            sizeParetoFront.RemoveLast();
     145          sizeParetoFront.AddLast(solution);
     146        }
     147        previousTreeLength = treeLength;
     148      }
     149
     150      qualityToTreeSize.Rows.Clear();
     151      var trainingRow = new ScatterPlotDataRow("Training Accuracy", "", sizeParetoFront.Select(x => new Point2D<double>(x.Model.SymbolicExpressionTree.Length, x.TrainingAccuracy, x)));
     152      trainingRow.VisualProperties.PointSize = 8;
     153      qualityToTreeSize.Rows.Add(trainingRow);
     154
     155      if (AnalyzeTestError) {
     156        var testRow = new ScatterPlotDataRow("Test Accuracy", "",
     157          sizeParetoFront.Select(x => new Point2D<double>(x.Model.SymbolicExpressionTree.Length, x.TestAccuracy, x)));
     158        testRow.VisualProperties.PointSize = 8;
     159        qualityToTreeSize.Rows.Add(testRow);
     160      }
     161
     162      var validationPartition = ValidationPartitionParameter.ActualValue;
     163      if (validationPartition.Size != 0) {
     164        var problemData = ProblemDataParameter.ActualValue;
     165        var validationIndizes = Enumerable.Range(validationPartition.Start, validationPartition.Size).ToList();
     166        var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, validationIndizes).ToList();
     167        OnlineCalculatorError error;
     168        var validationRow = new ScatterPlotDataRow("Validation Accuracy", "",
     169          sizeParetoFront.Select(x => new Point2D<double>(x.Model.SymbolicExpressionTree.Length,
     170          OnlineAccuracyCalculator.Calculate(targetValues, x.GetEstimatedClassValues(validationIndizes), out error))));
     171        validationRow.VisualProperties.PointSize = 7;
     172        qualityToTreeSize.Rows.Add(validationRow);
     173      }
     174
     175      return operation;
     176    }
    89177  }
    90178}
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views

  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs

    r17180 r17456  
    3838    }
    3939
     40    protected override void SetEnabledStateOfControls() {
     41      base.SetEnabledStateOfControls();
     42
     43      var tree = Content?.Model?.SymbolicExpressionTree;
     44      btnOptimizeConstants.Enabled = tree != null && SymbolicRegressionConstantOptimizationEvaluator.CanOptimizeConstants(tree);
     45    }
     46
    4047    protected override void UpdateModel(ISymbolicExpressionTree tree) {
    4148      var model = new SymbolicRegressionModel(Content.ProblemData.TargetVariable, tree, Content.Model.Interpreter, Content.Model.LowerEstimationLimit, Content.Model.UpperEstimationLimit);
     
    4653    protected override ISymbolicExpressionTree OptimizeConstants(ISymbolicExpressionTree tree, IProgress progress) {
    4754      const int constOptIterations = 50;
    48       const int maxRepetitions = 1000;
     55      const int maxRepetitions = 100;
     56      const double minimumImprovement = 1e-10;
    4957      var regressionProblemData = Content.ProblemData;
    5058      var model = Content.Model;
    5159      progress.CanBeStopped = true;
    52       var prevResult = 0.0;
     60      double prevResult = 0.0, improvement = 0.0;
    5361      var result = 0.0;
    5462      int reps = 0;
     
    5967          applyLinearScaling: true, maxIterations: constOptIterations, updateVariableWeights: true, lowerEstimationLimit: model.LowerEstimationLimit, upperEstimationLimit: model.UpperEstimationLimit,
    6068          iterationCallback: (args, func, obj) => {
    61             double newProgressValue = progress.ProgressValue + 1.0 / (constOptIterations + 2); // (maxIterations + 2) iterations are reported
     69            double newProgressValue = progress.ProgressValue + (1.0 / (constOptIterations + 2) / maxRepetitions); // (constOptIterations + 2) iterations are reported
    6270            progress.ProgressValue = Math.Min(newProgressValue, 1.0);
    6371          });
    6472        reps++;
    65       } while (prevResult < result && reps < maxRepetitions &&
     73        improvement = result - prevResult;
     74      } while (improvement > minimumImprovement && reps < maxRepetitions &&
    6675               progress.ProgressState != ProgressState.StopRequested &&
    6776               progress.ProgressState != ProgressState.CancelRequested);
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views

  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.Designer.cs

    r17180 r17456  
    5757      this.grpViewHost = new System.Windows.Forms.GroupBox();
    5858      this.treeChart = new HeuristicLab.Problems.DataAnalysis.Symbolic.Views.InteractiveSymbolicExpressionTreeChart();
     59      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    5960      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
    6061      this.splitContainer.Panel1.SuspendLayout();
     
    148149      this.btnSimplify.Text = "Simplify";
    149150      this.btnSimplify.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
     151      this.toolTip.SetToolTip(this.btnSimplify, "Simplifies the model structure based on mathematical simplification rules.");
    150152      this.btnSimplify.UseVisualStyleBackColor = true;
    151153      this.btnSimplify.Click += new System.EventHandler(this.btnSimplify_Click);
     
    162164      this.btnOptimizeConstants.Text = "Optimize";
    163165      this.btnOptimizeConstants.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
     166      this.toolTip.SetToolTip(this.btnOptimizeConstants, "Optimizes the numerical constants of the model. \r\nIf the algorithm converges, opt" +
     167        "imization is stopped.");
    164168      this.btnOptimizeConstants.UseVisualStyleBackColor = true;
    165169      this.btnOptimizeConstants.Click += new System.EventHandler(this.btnOptimizeConstants_Click);
     
    226230    protected System.Windows.Forms.Button btnOptimizeConstants;
    227231    private System.Windows.Forms.Label treeStatusValue;
     232    private System.Windows.Forms.ToolTip toolTip;
    228233  }
    229234}
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r17180 r17456  
    168168    private void Content_Changed(object sender, EventArgs e) {
    169169      UpdateView();
     170      SetEnabledStateOfControls();
    170171    }
    171172
     
    192193
    193194      progress.Start("Calculate Impact and Replacement Values ...");
     195      cancellationTokenSource = new CancellationTokenSource();
    194196      progress.CanBeStopped = true;
    195       cancellationTokenSource = new CancellationTokenSource();
    196       var impactAndReplacementValues = await Task.Run(() => CalculateImpactAndReplacementValues(tree));
    197197      try {
    198         await Task.Delay(500, cancellationTokenSource.Token); // wait for progressbar to finish animation
    199       } catch (OperationCanceledException) { }
    200       var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2);
    201       foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) {
    202         foldedNodes[pair.Key] = MakeConstantTreeNode(pair.Value);
    203       }
    204       nodeImpacts = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1);
    205       progress.Finish();
     198        var impactAndReplacementValues = await Task.Run(() => CalculateImpactAndReplacementValues(tree));
     199        try {
     200          await Task.Delay(300, cancellationTokenSource.Token); // wait for progressbar to finish animation
     201        } catch (OperationCanceledException) { }
     202
     203        var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2);
     204        foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) {
     205          foldedNodes[pair.Key] = MakeConstantTreeNode(pair.Value);
     206        }
     207
     208        nodeImpacts = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1);
     209      } finally {
     210        progress.Finish();
     211      }
     212
    206213      progress.CanBeStopped = false;
    207214      PaintNodeImpacts();
     
    313320    private async void btnOptimizeConstants_Click(object sender, EventArgs e) {
    314321      progress.Start("Optimizing Constants ...");
    315       var tree = (ISymbolicExpressionTree)Content.Model.SymbolicExpressionTree.Clone();
    316       var newTree = await Task.Run(() => OptimizeConstants(tree, progress));
    317       await Task.Delay(500); // wait for progressbar to finish animation
    318       UpdateModel(newTree); // UpdateModel calls Progress.Finish (via Content_Changed)
     322      cancellationTokenSource = new CancellationTokenSource();
     323      progress.CanBeStopped = true;
     324      try {
     325        var tree = (ISymbolicExpressionTree)Content.Model.SymbolicExpressionTree.Clone();
     326
     327        var newTree = await Task.Run(() => OptimizeConstants(tree, progress));
     328        try {
     329          await Task.Delay(300, cancellationTokenSource.Token); // wait for progressbar to finish animation
     330        } catch (OperationCanceledException) { }
     331        UpdateModel(newTree); // triggers progress.Finish after calculating the node impacts when model is changed
     332      } catch {
     333        progress.Finish();
     334      }
    319335    }
    320336  }
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/ArithmeticExpressionGrammar.cs

    r17180 r17456  
    2121
    2222using System.Collections.Generic;
     23using HEAL.Attic;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    26 using HEAL.Attic;
    2727using HeuristicLab.PluginInfrastructure;
    2828
     
    3131  [StorableType("FCBA02B7-5D29-42F5-A64C-A60AD8EA475D")]
    3232  [Item("ArithmeticExpressionGrammar", "Represents a grammar for functional expressions using only arithmetic operations.")]
    33   public class ArithmeticExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
     33  public class ArithmeticExpressionGrammar : DataAnalysisGrammar, ISymbolicDataAnalysisGrammar {
    3434
    3535    [StorableConstructor]
     
    5656      var factorVariableSymbol = new FactorVariable();
    5757
    58       var allSymbols = new List<Symbol>() { add, sub, mul, div, constant, variableSymbol, binFactorVariableSymbol, factorVariableSymbol};
     58      var allSymbols = new List<Symbol>() { add, sub, mul, div, constant, variableSymbol, binFactorVariableSymbol, factorVariableSymbol };
    5959      var functionSymbols = new List<Symbol>() { add, sub, mul, div };
    6060
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/FullFunctionalExpressionGrammar.cs

    r17180 r17456  
    2222using System.Collections.Generic;
    2323using System.Linq;
     24using HEAL.Attic;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    27 using HEAL.Attic;
    2828
    2929namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    3030  [StorableType("44B0829C-1CB5-4BE9-9514-BBA54FAB2912")]
    3131  [Item("FullFunctionalExpressionGrammar", "Represents a grammar for functional expressions using all available functions.")]
    32   public class FullFunctionalExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
     32  public class FullFunctionalExpressionGrammar : DataAnalysisGrammar, ISymbolicDataAnalysisGrammar {
    3333    [StorableConstructor]
    3434    protected FullFunctionalExpressionGrammar(StorableConstructorFlag _) : base(_) { }
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs

    r17455 r17456  
    2222using System.Collections.Generic;
    2323using System.Linq;
     24using HEAL.Attic;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    27 using HEAL.Attic;
    2828namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    2929  [StorableType("36A22322-0627-4E25-A468-F2A788AF6D46")]
    3030  [Item("TypeCoherentExpressionGrammar", "Represents a grammar for functional expressions in which special syntactic constraints are enforced so that boolean and real-valued expressions are not mixed.")]
    31   public class TypeCoherentExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
     31  public class TypeCoherentExpressionGrammar : DataAnalysisGrammar, ISymbolicDataAnalysisGrammar {
    3232    private const string ArithmeticFunctionsName = "Arithmetic Functions";
    3333    private const string TrigonometricFunctionsName = "Trigonometric Functions";
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r17455 r17456  
    160160    <Compile Include="Formatters\SymbolicDataAnalysisExpressionMathematicaFormatter.cs" />
    161161    <Compile Include="Formatters\SymbolicDataAnalysisExpressionCSharpFormatter.cs" />
     162    <Compile Include="Grammars\DataAnalysisGrammar.cs" />
    162163    <Compile Include="Hashing\HashExtensions.cs" />
    163164    <Compile Include="Hashing\HashUtil.cs" />
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisGrammar.cs

    r17180 r17456  
    2020#endregion
    2121
     22using HEAL.Attic;
    2223using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    23 using HEAL.Attic;
    2424
    2525namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    2626  [StorableType("5b0720d7-b1f0-4c2f-893e-cd2549e20e9e")]
    2727  public interface ISymbolicDataAnalysisGrammar : ISymbolicExpressionGrammar {
     28    void ConfigureVariableSymbols(IDataAnalysisProblemData problemData);
    2829  }
    2930}
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeBatchInterpreter.cs

    r16768 r17456  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 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
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
     
    181202
    182203    [ThreadStatic]
    183     private Dictionary<string, double[]> cachedData;
     204    private static Dictionary<string, double[]> cachedData;
    184205
    185206    [ThreadStatic]
    186     private IDataset dataset;
     207    private static IDataset cachedDataset;
    187208
    188209    private void InitCache(IDataset dataset) {
    189       this.dataset = dataset;
     210      cachedDataset = dataset;
    190211      cachedData = new Dictionary<string, double[]>();
    191212      foreach (var v in dataset.DoubleVariables) {
     
    196217    public void InitializeState() {
    197218      cachedData = null;
    198       dataset = null;
     219      cachedDataset = null;
    199220      EvaluatedSolutions = 0;
    200221    }
    201222
    202223    private double[] GetValues(ISymbolicExpressionTree tree, IDataset dataset, int[] rows) {
    203       if (cachedData == null || this.dataset != dataset) {
     224      if (cachedData == null || cachedDataset != dataset) {
    204225        InitCache(dataset);
    205226      }
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeNativeInterpreter.cs

    r17180 r17456  
    9999
    100100    [ThreadStatic]
    101     private IDataset dataset;
     101    private static IDataset cachedDataset;
    102102
    103103    private static readonly HashSet<byte> supportedOpCodes = new HashSet<byte>() {
     
    127127      if (!rows.Any()) return Enumerable.Empty<double>();
    128128
    129       if (cachedData == null || this.dataset != dataset) {
     129      if (cachedData == null || cachedDataset != dataset) {
    130130        InitCache(dataset);
    131131      }
     
    152152
    153153    private void InitCache(IDataset dataset) {
    154       this.dataset = dataset;
     154      cachedDataset = dataset;
    155155
    156156      // free handles to old data
     
    178178        cachedData = null;
    179179      }
    180       dataset = null;
     180      cachedDataset = null;
    181181      EvaluatedSolutions = 0;
    182182    }
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs

    r17455 r17456  
    2424using System.Drawing;
    2525using System.Linq;
     26using HEAL.Attic;
    2627using HeuristicLab.Common;
    2728using HeuristicLab.Common.Resources;
     
    3132using HeuristicLab.Optimization;
    3233using HeuristicLab.Parameters;
    33 using HEAL.Attic;
    3434using HeuristicLab.PluginInfrastructure;
    3535using HeuristicLab.Problems.Instances;
     
    212212    protected virtual void UpdateGrammar() {
    213213      var problemData = ProblemData;
    214       var ds = problemData.Dataset;
    215214      var grammar = SymbolicExpressionTreeGrammar;
     215
    216216      grammar.MaximumFunctionArguments = MaximumFunctionArguments.Value;
    217217      grammar.MaximumFunctionDefinitions = MaximumFunctionDefinitions.Value;
    218       foreach (var varSymbol in grammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.VariableBase>()) {
    219         if (!varSymbol.Fixed) {
    220           varSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => ds.VariableHasType<double>(x));
    221           varSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => ds.VariableHasType<double>(x));
    222         }
    223       }
    224       foreach (var factorSymbol in grammar.Symbols.OfType<BinaryFactorVariable>()) {
    225         if (!factorSymbol.Fixed) {
    226           factorSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => ds.VariableHasType<string>(x));
    227           factorSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => ds.VariableHasType<string>(x));
    228           factorSymbol.VariableValues = factorSymbol.VariableNames
    229             .ToDictionary(varName => varName, varName => ds.GetStringValues(varName).Distinct().ToList());
    230         }
    231       }
    232       foreach (var factorSymbol in grammar.Symbols.OfType<FactorVariable>()) {
    233         if (!factorSymbol.Fixed) {
    234           factorSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => ds.VariableHasType<string>(x));
    235           factorSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => ds.VariableHasType<string>(x));
    236           factorSymbol.VariableValues = factorSymbol.VariableNames
    237             .ToDictionary(varName => varName,
    238             varName => ds.GetStringValues(varName).Distinct()
    239             .Select((n, i) => Tuple.Create(n, i))
    240             .ToDictionary(tup => tup.Item1, tup => tup.Item2));
    241         }
    242       }
     218
     219      grammar.ConfigureVariableSymbols(problemData);
    243220    }
    244221
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Views

  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.cs

    r17276 r17456  
    2525using System.Threading;
    2626using System.Threading.Tasks;
     27using System.Windows.Forms;
    2728using HeuristicLab.Common;
    2829using HeuristicLab.Data;
     
    4041    private CancellationTokenSource cancellationToken = new CancellationTokenSource();
    4142    private List<Tuple<string, double>> rawVariableImpacts = new List<Tuple<string, double>>();
    42     private bool attachedToProgress = false;
    4343
    4444    public new IClassificationSolution Content {
     
    8787      }
    8888    }
    89     protected override void OnHidden(EventArgs e) {
    90       base.OnHidden(e);
     89    protected override void OnVisibleChanged(EventArgs e) {
     90      base.OnVisibleChanged(e);
     91      if (!this.Visible) {
     92        cancellationToken.Cancel();
     93      }
     94    }
     95
     96    protected override void OnClosed(FormClosedEventArgs e) {
     97      base.OnClosed(e);
    9198      cancellationToken.Cancel();
    92 
    93       if (attachedToProgress) {
    94         Progress.Hide(this);
    95         attachedToProgress = false;
    96       }
    9799    }
    98100
     
    133135      variableImpactsArrayView.Caption = Content.Name + " Variable Impacts";
    134136      progress = Progress.Show(this, "Calculating variable impacts for " + Content.Name);
    135       attachedToProgress = true;
    136137      cancellationToken = new CancellationTokenSource();
    137138
     
    145146          .ToList();
    146147
    147         List<Tuple<string, double>> impacts = null;
    148         await Task.Run(() => { impacts = CalculateVariableImpacts(originalVariableOrdering, Content.Model, problemData, Content.EstimatedClassValues, dataPartition, replMethod, factorReplMethod, cancellationToken.Token, progress); });
    149         if (impacts == null) { return; }
     148        var impacts = await Task.Run(() => CalculateVariableImpacts(originalVariableOrdering, Content.Model, problemData, Content.EstimatedClassValues, dataPartition, replMethod, factorReplMethod, cancellationToken.Token, progress));
    150149
    151150        rawVariableImpacts.AddRange(impacts);
    152151        UpdateOrdering();
     152      } catch (OperationCanceledException) {
    153153      } finally {
    154         if (attachedToProgress) {
    155           Progress.Hide(this);
    156           attachedToProgress = false;
    157         }
     154        Progress.Hide(this);
    158155      }
    159156    }
     
    180177      var clonedModel = (IClassificationModel)model.Clone();
    181178      foreach (var variableName in originalVariableOrdering) {
    182         if (cancellationToken.Token.IsCancellationRequested) { return null; }
     179        token.ThrowIfCancellationRequested();
    183180        progress.ProgressValue = (double)++i / count;
    184181        progress.Message = string.Format("Calculating impact for variable {0} ({1} of {2})", variableName, i, count);
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs

    r17416 r17456  
    2525using System.Threading;
    2626using System.Threading.Tasks;
     27using System.Windows.Forms;
    2728using HeuristicLab.Common;
    2829using HeuristicLab.Data;
     
    4041    private CancellationTokenSource cancellationToken = new CancellationTokenSource();
    4142    private List<Tuple<string, double>> rawVariableImpacts = new List<Tuple<string, double>>();
    42     private bool attachedToProgress = false;
    4343
    4444    public new IRegressionSolution Content {
     
    8888    }
    8989
    90     protected override void OnHidden(EventArgs e) {
    91       base.OnHidden(e);
     90    protected override void OnVisibleChanged(EventArgs e) {
     91      base.OnVisibleChanged(e);
     92      if (!this.Visible) {
     93        cancellationToken.Cancel();
     94      }
     95    }
     96
     97    protected override void OnClosed(FormClosedEventArgs e) {
     98      base.OnClosed(e);
    9299      cancellationToken.Cancel();
    93 
    94       if (attachedToProgress) {
    95         Progress.Hide(this);
    96         attachedToProgress = false;
    97       }
    98100    }
    99101
     
    132134      variableImpactsArrayView.Caption = Content.Name + " Variable Impacts";
    133135      var progress = Progress.Show(this, "Calculating variable impacts for " + Content.Name);
    134       attachedToProgress = true;
    135136      cancellationToken = new CancellationTokenSource();
    136137
     
    144145          .ToList();
    145146
    146         List<Tuple<string, double>> impacts = null;
    147         await Task.Run(() => { impacts = CalculateVariableImpacts(originalVariableOrdering, Content.Model, problemData, Content.EstimatedValues, dataPartition, replMethod, factorReplMethod, cancellationToken.Token, progress); });
    148         if (impacts == null) { return; }
     147        var impacts = await Task.Run(() => CalculateVariableImpacts(originalVariableOrdering, Content.Model, problemData, Content.EstimatedValues, dataPartition, replMethod, factorReplMethod, cancellationToken.Token, progress));
    149148
    150149        rawVariableImpacts.AddRange(impacts);
    151150        UpdateOrdering();
     151      } catch (OperationCanceledException) {
    152152      } finally {
    153         if (attachedToProgress) {
    154           Progress.Hide(this);
    155           attachedToProgress = false;
    156         }
     153        Progress.Hide(this);
    157154      }
    158155    }
     
    179176
    180177      foreach (var variableName in originalVariableOrdering) {
    181         if (cancellationToken.Token.IsCancellationRequested) { return null; }
     178        token.ThrowIfCancellationRequested();
    182179        progress.ProgressValue = (double)++i / count;
    183180        progress.Message = string.Format("Calculating impact for variable {0} ({1} of {2})", variableName, i, count);
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4

  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionVariableImpactsCalculator.cs

    r17180 r17456  
    2626using System.Collections.Generic;
    2727using System.Linq;
     28using HEAL.Attic;
    2829using HeuristicLab.Common;
    2930using HeuristicLab.Core;
    3031using HeuristicLab.Data;
    3132using HeuristicLab.Parameters;
    32 using HEAL.Attic;
    3333using HeuristicLab.Random;
    3434
     
    173173
    174174      IList originalValues = null;
    175       IList replacementValues = GetReplacementValues(modifiableDataset, variableName, model, rows, targetValues, out originalValues, replacementMethod, factorReplacementMethod);
    176 
    177       double newValue = CalculateQualityForReplacement(model, modifiableDataset, variableName, originalValues, rows, replacementValues, targetValues);
     175      IList replacementValues = GetReplacementValues(modifiableDataset, variableName, model, problemData.AllowedInputVariables, rows, targetValues, out originalValues, replacementMethod, factorReplacementMethod);
     176
     177      double newValue = CalculateQualityForReplacement(model, modifiableDataset, problemData.AllowedInputVariables, variableName, originalValues, rows, replacementValues, targetValues);
    178178      double impact = quality - newValue;
    179179
     
    184184      string variableName,
    185185      IClassificationModel model,
     186      IEnumerable<string> allowedInputVariables,
    186187      IEnumerable<int> rows,
    187188      IEnumerable<double> targetValues,
     
    196197      } else if (modifiableDataset.VariableHasType<string>(variableName)) {
    197198        originalValues = modifiableDataset.GetReadOnlyStringValues(variableName).ToList();
    198         replacementValues = GetReplacementValuesForString(model, modifiableDataset, variableName, rows, (List<string>)originalValues, targetValues, factorReplacementMethod);
     199        replacementValues = GetReplacementValuesForString(model, modifiableDataset, allowedInputVariables, variableName, rows, (List<string>)originalValues, targetValues, factorReplacementMethod);
    199200      } else {
    200201        throw new NotSupportedException("Variable not supported");
     
    254255    private static IList GetReplacementValuesForString(IClassificationModel model,
    255256      ModifiableDataset modifiableDataset,
     257      IEnumerable<string> allowedInputVariables,
    256258      string variableName,
    257259      IEnumerable<int> rows,
     
    270272            List<string> curReplacementValues = Enumerable.Repeat(repl, modifiableDataset.Rows).ToList();
    271273            //fholzing: this result could be used later on (theoretically), but is neglected for better readability/method consistency
    272             var newValue = CalculateQualityForReplacement(model, modifiableDataset, variableName, originalValues, rows, curReplacementValues, targetValues);
     274            var newValue = CalculateQualityForReplacement(model, modifiableDataset, allowedInputVariables, variableName, originalValues, rows, curReplacementValues, targetValues);
    273275            var curQuality = newValue;
    274276
     
    308310      IClassificationModel model,
    309311      ModifiableDataset modifiableDataset,
     312      IEnumerable<string> allowedInputVariables,
    310313      string variableName,
    311314      IList originalValues,
     
    317320      var discModel = model as IDiscriminantFunctionClassificationModel;
    318321      if (discModel != null) {
    319         var problemData = new ClassificationProblemData(modifiableDataset, modifiableDataset.VariableNames, model.TargetVariable);
     322        var problemData = new ClassificationProblemData(modifiableDataset, allowedInputVariables, model.TargetVariable);
    320323        discModel.RecalculateModelParameters(problemData, rows);
    321324      }
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationModel.cs

    r17180 r17456  
    7474      classValues = (double[])original.classValues.Clone();
    7575      thresholds = (double[])original.thresholds.Clone();
     76      thresholdCalculator = (IDiscriminantFunctionThresholdCalculator)original.thresholdCalculator.Clone();
    7677    }
    7778
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.ExternalEvaluation.GP/3.5/ExternalEvaluationExpressionGrammar.cs

    r17180 r17456  
    2121
    2222using System.Collections.Generic;
     23using HEAL.Attic;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    25 using HEAL.Attic;
     26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2627using HeuristicLab.Problems.DataAnalysis.Symbolic;
    27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2828
    2929namespace HeuristicLab.Problems.ExternalEvaluation.GP {
    3030  [StorableType("747A7784-EF15-4CEF-A621-79A9071A69F5")]
    3131  [Item("ExternalEvaluationExpressionGrammar", "Represents a grammar for functional expressions using all available functions.")]
    32   public class ExternalEvaluationExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
     32  public class ExternalEvaluationExpressionGrammar : DataAnalysisGrammar {
    3333    [Storable]
    3434    private HeuristicLab.Problems.DataAnalysis.Symbolic.Variable variableSymbol;
     
    4545    }
    4646
    47     private void Initialize() {     
     47    private void Initialize() {
    4848      var add = new Addition();
    4949      var sub = new Subtraction();
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.GrammaticalEvolution

  • branches/3040_VectorBasedGP/HeuristicLab.Problems.GrammaticalEvolution/3.4/SymbolicRegression/GESymbolicExpressionGrammar.cs

    r17180 r17456  
    2525using System.Collections.Generic;
    2626using System.Linq;
     27using HEAL.Attic;
    2728using HeuristicLab.Common;
    2829using HeuristicLab.Core;
    2930using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    30 using HEAL.Attic;
    3131using HeuristicLab.Problems.DataAnalysis.Symbolic;
    3232using HeuristicLab.Random;
     
    3535  [StorableType("73D43A23-02FF-4BD8-9834-55D8A90E0FCE")]
    3636  [Item("GESymbolicExpressionGrammar", "Represents a grammar for functional expressions for grammatical evolution.")]
    37   public class GESymbolicExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
     37  public class GESymbolicExpressionGrammar : DataAnalysisGrammar, ISymbolicDataAnalysisGrammar {
    3838    [StorableConstructor]
    3939    protected GESymbolicExpressionGrammar(StorableConstructorFlag _) : base(_) { }
  • branches/3040_VectorBasedGP/HeuristicLab.Scripting.Views/3.3/HeuristicLab.Scripting.Views-3.3.csproj

    r16658 r17456  
    9797    <Compile Include="CSharpScriptView.Designer.cs">
    9898      <DependentUpon>CSharpScriptView.cs</DependentUpon>
     99    </Compile>
     100    <Compile Include="CompilerErrorDialog.cs">
     101      <SubType>Form</SubType>
     102    </Compile>
     103    <Compile Include="CompilerErrorDialog.Designer.cs">
     104      <DependentUpon>CompilerErrorDialog.cs</DependentUpon>
    99105    </Compile>
    100106    <Compile Include="ExecutableScriptView.cs">
  • branches/3040_VectorBasedGP/HeuristicLab.Scripting.Views/3.3/ScriptView.Designer.cs

    r17180 r17456  
    184184      this.errorListView.UseCompatibleStateImageBehavior = false;
    185185      this.errorListView.View = System.Windows.Forms.View.Details;
     186      this.errorListView.MouseClick += new System.Windows.Forms.MouseEventHandler(this.errorListView_MouseClick);
    186187      this.errorListView.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.errorListView_MouseDoubleClick);
    187188      //
  • branches/3040_VectorBasedGP/HeuristicLab.Scripting.Views/3.3/ScriptView.cs

    r17180 r17456  
    209209    }
    210210
     211    private void errorListView_MouseClick(object sender, MouseEventArgs e) {
     212      if (e.Button != MouseButtons.Left) return;
     213
     214      var item = errorListView.SelectedItems[0];
     215      var message = (CompilerError)item.Tag;
     216
     217      codeEditor.ScrollToPosition(message.Line, message.Column);
     218      codeEditor.Focus();
     219    }
     220
    211221    private void errorListView_MouseDoubleClick(object sender, MouseEventArgs e) {
    212       if (e.Button == MouseButtons.Left) {
    213         var item = errorListView.SelectedItems[0];
    214         var message = (CompilerError)item.Tag;
    215         codeEditor.ScrollToPosition(message.Line, message.Column);
    216         codeEditor.Focus();
    217       }
     222      if (e.Button != MouseButtons.Left) return;
     223
     224      var item = errorListView.SelectedItems[0];
     225      var message = (CompilerError)item.Tag;
     226
     227      using (var dialog = new CompilerErrorDialog(message)) {
     228        dialog.ShowDialog(this);
     229      };
    218230    }
    219231    #endregion
  • branches/3040_VectorBasedGP/HeuristicLab.Services.Hive

  • branches/3040_VectorBasedGP/HeuristicLab.Services.Hive/3.3/HiveService.cs

    r17180 r17456  
    665665            bool oldIsAllowedToCalculate = slave.IsAllowedToCalculate;
    666666            Guid? oldParentResourceId = slave.ParentResourceId;
     667            bool? oldIsDisposable = slave.IsDisposable;
    667668            slaveInfo.CopyToEntity(slave);
    668669            slave.IsAllowedToCalculate = oldIsAllowedToCalculate;
    669670            slave.ParentResourceId = oldParentResourceId;
     671            slave.IsDisposable = oldIsDisposable;
    670672            slave.LastHeartbeat = DateTime.Now;
    671673            slave.SlaveState = DA.SlaveState.Idle;
  • branches/3040_VectorBasedGP/HeuristicLab.Tests

  • branches/3040_VectorBasedGP/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GaussianProcessRegressionSampleTest.cs

    r17180 r17456  
    6868      gpr.Problem = regProblem;
    6969
    70       gpr.CovarianceFunction = new CovarianceSquaredExponentialIso();
    71       gpr.MeanFunction = new MeanConst();
     70      gpr.CovarianceFunction = gpr.CovarianceFunctionParameter.ValidValues.OfType<CovarianceSquaredExponentialIso>().First();
     71      gpr.MeanFunction = gpr.MeanFunctionParameter.ValidValues.OfType<MeanConst>().First();
    7272      gpr.MinimizationIterations = 20;
    7373      gpr.Seed = 0;
Note: See TracChangeset for help on using the changeset viewer.