Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/05/16 08:25:08 (8 years ago)
Author:
gkronber
Message:

#2581:

  • added unit tests for the number of different expressions
  • fixed problems in Automaton and constraintHandler that lead to duplicate expressions
  • added possibility for MCTS to handle dead-ends in the search tree (when it is not possible to construct a valid new expression)
  • added statistics on function and gradient evaluations
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/MctsSymbolicRegression/ExpressionEvaluator.cs

    r13650 r13651  
    2828  internal class ExpressionEvaluator {
    2929    // manages it's own vector buffers
    30     private readonly List<double[]> vectorBuffers = new List<double[]>();
    31     private readonly List<double[]> scalarBuffers = new List<double[]>(); // scalars are vectors of length 1 (to allow mixing scalars and vectors on the same stack)
     30    private readonly double[][] vectorBuffers;
     31    private readonly double[][] scalarBuffers; // scalars are vectors of length 1 (to allow mixing scalars and vectors on the same stack)
     32    private int lastVecBufIdx;
     33    private int lastScalarBufIdx;
    3234
    3335
    3436    private double[] GetVectorBuffer() {
    35       var v = vectorBuffers[vectorBuffers.Count - 1];
    36       vectorBuffers.RemoveAt(vectorBuffers.Count - 1);
    37       return v;
     37      return vectorBuffers[--lastVecBufIdx];
    3838    }
    3939    private double[] GetScalarBuffer() {
    40       var v = scalarBuffers[scalarBuffers.Count - 1];
    41       scalarBuffers.RemoveAt(scalarBuffers.Count - 1);
    42       return v;
     40      return scalarBuffers[--lastScalarBufIdx];
    4341    }
    4442
    4543    private void ReleaseBuffer(double[] buf) {
    46       (buf.Length == 1 ? scalarBuffers : vectorBuffers).Add(buf);
     44      if (buf.Length == 1) {
     45        scalarBuffers[lastScalarBufIdx++] = buf;
     46      } else {
     47        vectorBuffers[lastVecBufIdx++] = buf;
     48      }
    4749    }
    4850
     
    7375
    7476      // preallocate buffers
     77      vectorBuffers = new double[MaxStackSize * (1 + MaxParams)][];
     78      scalarBuffers = new double[MaxStackSize * (1 + MaxParams)][];
    7579      for (int i = 0; i < MaxStackSize; i++) {
    7680        ReleaseBuffer(new double[vLen]);
     
    9498      short arg;
    9599      // checked at the end to make sure we do not leak buffers
    96       int initialScalarCount = scalarBuffers.Count;
    97       int initialVectorCount = vectorBuffers.Count;
     100      int initialScalarCount = lastScalarBufIdx;
     101      int initialVectorCount = lastVecBufIdx;
    98102
    99103      while (true) {
     
    179183
    180184                var f = 1.0 / (maxFx * consts[curParamIdx]);
    181                 // adjust c so that maxFx*c = 1
     185                // adjust c so that maxFx*c = 1 TODO: this is not ideal as enforce positive argument to exp()
    182186                consts[curParamIdx] *= f;
    183187
     
    211215            }
    212216            ReleaseBuffer(r);
    213             Contract.Assert(vectorBuffers.Count == initialVectorCount);
    214             Contract.Assert(scalarBuffers.Count == initialScalarCount);
     217            Contract.Assert(lastVecBufIdx == initialVectorCount);
     218            Contract.Assert(lastScalarBufIdx == initialScalarCount);
    215219            return;
    216220        }
     
    232236
    233237      // checked at the end to make sure we do not leak buffers
    234       int initialScalarCount = scalarBuffers.Count;
    235       int initialVectorCount = vectorBuffers.Count;
     238      int initialScalarCount = lastScalarBufIdx;
     239      int initialVectorCount = lastVecBufIdx;
    236240
    237241      while (true) {
     
    400404            }
    401405
    402             Contract.Assert(vectorBuffers.Count == initialVectorCount);
    403             Contract.Assert(scalarBuffers.Count == initialScalarCount);
     406            Contract.Assert(lastVecBufIdx == initialVectorCount);
     407            Contract.Assert(lastScalarBufIdx == initialScalarCount);
    404408            return; // break loop
    405409        }
Note: See TracChangeset for help on using the changeset viewer.