Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/09/16 15:34:33 (8 years ago)
Author:
gkronber
Message:

#2650 added new symbol FactorVariable (renamed previous symbol to BinaryFactorVariable)
Work in progress.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs

    r14243 r14249  
    205205          ConstantTreeNode constantTreeNode = node as ConstantTreeNode;
    206206          VariableTreeNode variableTreeNode = node as VariableTreeNode;
    207           BinaryFactorVariableTreeNode factorVariableTreeNode = node as BinaryFactorVariableTreeNode;
     207          BinaryFactorVariableTreeNode binFactorVarTreeNode = node as BinaryFactorVariableTreeNode;
     208          FactorVariableTreeNode factorVarTreeNode = node as FactorVariableTreeNode;
    208209          if (constantTreeNode != null)
    209210            c[i++] = constantTreeNode.Value;
    210211          else if (updateVariableWeights && variableTreeNode != null)
    211212            c[i++] = variableTreeNode.Weight;
    212           else if (updateVariableWeights && factorVariableTreeNode != null)
    213             c[i++] = factorVariableTreeNode.Weight;
     213          else if (updateVariableWeights && binFactorVarTreeNode != null)
     214            c[i++] = binFactorVarTreeNode.Weight;
     215          else if (factorVarTreeNode != null) {
     216            foreach (var w in factorVarTreeNode.Weights) c[i++] = w;
     217          }
    214218        }
    215219      }
     
    248252        alglib.lsfitfit(state, function_cx_1_func, function_cx_1_grad, null, null);
    249253        alglib.lsfitresults(state, out info, out c, out rep);
    250       }
    251       catch (ArithmeticException) {
     254      } catch (ArithmeticException) {
    252255        return originalQuality;
    253       }
    254       catch (alglib.alglibexception) {
     256      } catch (alglib.alglibexception) {
    255257        return originalQuality;
    256258      }
     
    273275        ConstantTreeNode constantTreeNode = node as ConstantTreeNode;
    274276        VariableTreeNode variableTreeNode = node as VariableTreeNode;
    275         BinaryFactorVariableTreeNode factorVarTreeNode = node as BinaryFactorVariableTreeNode;
     277        BinaryFactorVariableTreeNode binFactorVarTreeNode = node as BinaryFactorVariableTreeNode;
     278        FactorVariableTreeNode factorVarTreeNode = node as FactorVariableTreeNode;
    276279        if (constantTreeNode != null)
    277280          constantTreeNode.Value = constants[i++];
    278281        else if (updateVariableWeights && variableTreeNode != null)
    279282          variableTreeNode.Weight = constants[i++];
    280         else if (updateVariableWeights && factorVarTreeNode != null)
    281           factorVarTreeNode.Weight = constants[i++];
     283        else if (updateVariableWeights && binFactorVarTreeNode != null)
     284          binFactorVarTreeNode.Weight = constants[i++];
     285        else if (factorVarTreeNode != null) {
     286          foreach (var w in factorVarTreeNode.Weights) constants[i++] = w;
     287        }
    282288      }
    283289    }
     
    321327          term = par;
    322328        }
     329        return true;
     330      }
     331      if (node.Symbol is FactorVariable) {
     332        var factorVarNode = node as FactorVariableTreeNode;
     333        var products = new List<Term>();
     334        foreach (var variableValue in factorVarNode.Symbol.GetVariableValues(factorVarNode.VariableName)) {
     335          var par = new AutoDiff.Variable();
     336          parameters.Add(par);
     337          variableNames.Add(factorVarNode.VariableName);
     338          categoricalVariableValues.Add(variableValue);
     339
     340          var wVar = new AutoDiff.Variable();
     341          variables.Add(wVar);
     342
     343          products.Add(AutoDiff.TermBuilder.Product(wVar, par));
     344        }
     345        term = AutoDiff.TermBuilder.Sum(products);
    323346        return true;
    324347      }
     
    494517         !(n.Symbol is Variable) &&
    495518         !(n.Symbol is BinaryFactorVariable) &&
     519         !(n.Symbol is FactorVariable) &&
    496520         !(n.Symbol is Constant) &&
    497521         !(n.Symbol is Addition) &&
Note: See TracChangeset for help on using the changeset viewer.