Ignore:
Timestamp:
02/16/17 12:15:11 (3 years ago)
Author:
mkommend
Message:

#2205: Worked on optimization networks for integrated machine learning.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.MachineLearning/FeatureSelectionOrchestrator.cs

    r14631 r14675  
    9393
    9494    private void FeatureSelectionEvaluationPort_MessageReceived(IMessage evaluationMessage, CancellationToken token) {
     95      var problemData = (IRegressionProblemData)RegressionProblemData.Clone();
    9596      var binaryVector = (BinaryVector)evaluationMessage["BinaryVector"];
    96       var problemData = (IRegressionProblemData)RegressionProblemData.Clone();
     97      binaryVector.ElementNames = problemData.InputVariables.CheckedItems.Select(variable => variable.Value.Value);
    9798
    9899      var allowedVariables = problemData.InputVariables.CheckedItems.Zip(binaryVector,
    99100        (variable, allowed) => new { VariableName = variable.Value, Allowed = allowed });
     101
    100102      foreach (var allowedVariable in allowedVariables)
    101103        problemData.InputVariables.SetItemCheckedState(allowedVariable.VariableName, allowedVariable.Allowed);
     
    113115
    114116      var regressionSolution = results.Select(r => r.Value).OfType<IRegressionSolution>().First();
     117
     118      UpdatedResults(binaryVector, regressionSolution);
     119
     120
    115121      double quality = regressionSolution.TestMeanAbsoluteError;
    116122      evaluationMessage["Quality"] = new DoubleValue(quality);
     123    }
     124
     125    private void UpdatedResults(BinaryVector binaryVector, IRegressionSolution solution) {
     126      if (!Results.ContainsKey("Best Solution Vector")) {
     127        Results.Add(new Result("Best Solution Vector", typeof(BinaryVector)));
     128        //Results.Add(new Result("Best Solution Variables", typeof(DoubleArray)));
     129        Results.Add(new Result("Best Symbolic Solution", typeof(IRegressionSolution)));
     130      }
     131
     132      var previousBestVector = (BinaryVector)Results["Best Solution Vector"].Value;
     133
     134      //check if better vector has been found
     135      if (previousBestVector != null && binaryVector.SequenceEqual(previousBestVector))
     136        return;
     137
     138      Results["Best Solution Vector"].Value = binaryVector;
     139      Results["Best Symbolic Solution"].Value = solution;
     140
     141      //var variableNames = solution.ProblemData.AllowedInputVariables;
     142      //alglib.linearmodel lm = BuildModel(best, problemData);
     143
     144      //double[] coefficients = null;
     145      //int nFeatures = -1;
     146      //alglib.lrunpack(lm, out coefficients, out nFeatures);
     147
     148      //var doubleArray = new DoubleArray(coefficients.ToArray());
     149      //doubleArray.ElementNames = variableNames;
     150      //Results["Best Solution Variables"].Value = doubleArray;
     151
     152
    117153    }
    118154
Note: See TracChangeset for help on using the changeset viewer.