Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2538


Ignore:
Timestamp:
12/03/09 12:53:07 (15 years ago)
Author:
gkronber
Message:

Fixed #811

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.LinearRegression/3.2/LinearRegressionOperator.cs

    r2445 r2538  
    7171    private IFunctionTree CreateModel(double[] coefficients, List<string> allowedVariables, int minTimeOffset, int maxTimeOffset) {
    7272      IFunctionTree root = new Addition().GetTreeNode();
    73       IFunctionTree actNode = root;
     73
    7474      int timeOffsetRange = (maxTimeOffset - minTimeOffset + 1);
    7575
    76       Queue<IFunctionTree> nodes = new Queue<IFunctionTree>();
    7776      for (int i = 0; i < allowedVariables.Count; i++) {
    7877        for (int timeOffset = minTimeOffset; timeOffset <= maxTimeOffset; timeOffset++) {
     
    8180          vNode.Weight = coefficients[(i * timeOffsetRange) + (timeOffset - minTimeOffset)];
    8281          vNode.SampleOffset = timeOffset;
    83           nodes.Enqueue(vNode);
     82          root.AddSubTree(vNode);
    8483        }
    8584      }
     
    8786
    8887      cNode.Value = coefficients[coefficients.Length - 1];
    89       nodes.Enqueue(cNode);
    90 
    91       IFunctionTree newTree;
    92       while (nodes.Count != 1) {
    93         newTree = new Addition().GetTreeNode();
    94         newTree.AddSubTree(nodes.Dequeue());
    95         newTree.AddSubTree(nodes.Dequeue());
    96         nodes.Enqueue(newTree);
    97       }
    98 
    99       return nodes.Dequeue();
     88      root.AddSubTree(cNode);
     89      return root;
    10090    }
    10191
     
    10898      double[,] dataset = new double[n, p];
    10999      for (int row = 0; row < n; row++) {
    110         for (int column = 0; column < p-1; column++) {
     100        for (int column = 0; column < p - 1; column++) {
    111101          dataset[row, column] = inputMatrix[row, column];
    112102        }
    113         dataset[row, p-1] = targetVector[row];
     103        dataset[row, p - 1] = targetVector[row];
    114104      }
    115       alglib.linreg.lrbuild(ref dataset, n, p-1, ref retVal, ref lm, ref ar);
     105      alglib.linreg.lrbuild(ref dataset, n, p - 1, ref retVal, ref lm, ref ar);
    116106      if (retVal != 1) throw new ArgumentException("Error in calculation of linear regression model");
    117107      Console.Out.WriteLine("ALGLIB Linear Regression: Estimated generalization RMS = {0}", ar.cvrmserror);
     
    119109      double[] coefficients = new double[p];
    120110      for (int i = 0; i < p; i++) {
    121         coefficients[i] = lm.w[i+4];
     111        coefficients[i] = lm.w[i + 4];
    122112      }
    123113      return coefficients;
Note: See TracChangeset for help on using the changeset viewer.