Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/27/18 17:34:41 (7 years ago)
Author:
jzenisek
Message:

#2719: added proxy ensemble model

Location:
branches/2719_HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis/3.4
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/2719_HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis/3.4/Datastream.cs

    r14710 r15867  
    3939
    4040    protected const string ProblemDataParameterName = "ProblemData";
     41    protected const string DataSourceAddressParameterName = "DataSourceAdress";
    4142    protected const string InitialSlidingWindowParameterName = "InitialSlidingWindowParameter";
    4243    protected const string SlidingWindowSizeParameterName = "SlidingWindowSize";
     
    4546    protected const string FitnessPartitionParameterName = "FitnessPartition";
    4647    protected const string SlidingWindowSonarRatioParameterName = "SlidingWindowSonarRatio";
     48    protected const string SlidingWindowEvaluationSchemeParameterName = "SlidingWindowEvaluationScheme";
    4749
    4850    #region parameter properites
    4951
    50     public IValueParameter<RegressionProblemData> ProblemDataParameter {
    51       get { return (IValueParameter<RegressionProblemData>) Parameters[ProblemDataParameterName]; } 
    52     }
    53 
    54     public IValueParameter<IntRange> InitialSlidingWindowParameter {
    55       get { return (IValueParameter<IntRange>) Parameters[InitialSlidingWindowParameterName]; }
    56     }
    57 
    58     public IValueParameter<IntValue> SlidingWindowSizeParameter {
    59       get { return (IValueParameter<IntValue>) Parameters[SlidingWindowSizeParameterName]; }
    60     }
    61 
    62     public IValueParameter<IntValue> SlidingWindowStepWidthParameter {
    63       get { return (IValueParameter<IntValue>) Parameters[SlidingWindowStepWidthParameterName]; }
    64     }
    65 
    66     public IValueParameter<IntValue> SlidingWindowMovementDelayParameter {
    67       get { return (IValueParameter<IntValue>) Parameters[SlidingWindowMovementDelayParameterName]; }
    68     }
    69 
    70     public IValueParameter<DoubleValue> SlidingWindowSonarRatioParameter {
    71       get { return (IValueParameter<DoubleValue>) Parameters[SlidingWindowSonarRatioParameterName]; }
     52    public enum EvaluationScheme { none, equal, linear, quadratic, cubic, exponential }
     53
     54    public IValueParameter<RegressionProblemData> ProblemDataParameter
     55    {
     56      get { return (IValueParameter<RegressionProblemData>)Parameters[ProblemDataParameterName]; }
     57    }
     58
     59    public IValueParameter<StringValue> DataSourceAddressParameter
     60    {
     61      get { return (IValueParameter<StringValue>)Parameters[DataSourceAddressParameterName]; }
     62    }
     63
     64    public IValueParameter<IntRange> InitialSlidingWindowParameter
     65    {
     66      get { return (IValueParameter<IntRange>)Parameters[InitialSlidingWindowParameterName]; }
     67    }
     68
     69    public IValueParameter<IntValue> SlidingWindowSizeParameter
     70    {
     71      get { return (IValueParameter<IntValue>)Parameters[SlidingWindowSizeParameterName]; }
     72    }
     73
     74    public IValueParameter<IntValue> SlidingWindowStepWidthParameter
     75    {
     76      get { return (IValueParameter<IntValue>)Parameters[SlidingWindowStepWidthParameterName]; }
     77    }
     78
     79    public IValueParameter<IntValue> SlidingWindowMovementDelayParameter
     80    {
     81      get { return (IValueParameter<IntValue>)Parameters[SlidingWindowMovementDelayParameterName]; }
     82    }
     83
     84    public IValueParameter<DoubleValue> SlidingWindowSonarRatioParameter
     85    {
     86      get { return (IValueParameter<DoubleValue>)Parameters[SlidingWindowSonarRatioParameterName]; }
     87    }
     88
     89    public IValueParameter<EnumValue<EvaluationScheme>> SlidingWindowEvaluationSchemeParameter
     90    {
     91      get
     92      {
     93        return (IValueParameter<EnumValue<EvaluationScheme>>)Parameters[SlidingWindowEvaluationSchemeParameterName];
     94      }
    7295    }
    7396
     
    80103    #region properties
    81104
    82     public RegressionProblemData ProblemData {
     105    public RegressionProblemData ProblemData
     106    {
    83107      get { return ProblemDataParameter.Value; }
    84       set {
    85         if(value == null) throw new ArgumentNullException("ProblemData", "The provided value for problemData is null.");
     108      set
     109      {
     110        if (value == null) throw new ArgumentNullException("ProblemData", "The provided value for problemData is null.");
    86111        ProblemDataParameter.Value = value;
    87112        //OnProblemDataChanged();
    88113      }
    89114    }
    90    
    91 
    92     public IntRange InitialSlidingWindow {
     115
     116    public StringValue DataSourceAddress
     117    {
     118      get { return DataSourceAddressParameter.Value; }
     119      set { DataSourceAddressParameter.Value = value; }
     120    }
     121
     122    public IntRange InitialSlidingWindow
     123    {
    93124      get { return InitialSlidingWindowParameter.Value; }
    94125      set { InitialSlidingWindowParameter.Value = value; }
    95126    }
    96127
    97     public IntValue SlidingWindowSize {
     128    public IntValue SlidingWindowSize
     129    {
    98130      get { return SlidingWindowSizeParameter.Value; }
    99131      set { SlidingWindowSizeParameter.Value = value; }
    100132    }
    101133
    102     public IntValue SlidingWindowStepWidth {
     134    public IntValue SlidingWindowStepWidth
     135    {
    103136      get { return SlidingWindowStepWidthParameter.Value; }
    104137      set { SlidingWindowStepWidthParameter.Value = value; }
    105138    }
    106139
    107     public IntValue SlidingWindowMovementDelay {
     140    public IntValue SlidingWindowMovementDelay
     141    {
    108142      get { return SlidingWindowMovementDelayParameter.Value; }
    109143      set { SlidingWindowMovementDelayParameter.Value = value; }
    110144    }
    111145
    112     public DoubleValue SlidingWindowSonarRatio {
     146    public DoubleValue SlidingWindowSonarRatio
     147    {
    113148      get { return SlidingWindowSonarRatioParameter.Value; }
    114149      set { SlidingWindowSonarRatioParameter.Value = value; }
    115150    }
    116151
     152    public EnumValue<EvaluationScheme> SlidingWindowEvaluationScheme
     153    {
     154      get { return SlidingWindowEvaluationSchemeParameter.Value; }
     155      set { SlidingWindowEvaluationSchemeParameter.Value = value; }
     156    }
     157
     158
    117159    #endregion
    118160
     
    121163    public IntRange FitnessPartition { get; set; }
    122164
    123     public bool UpdateAvailable {
    124       get { return false; }
    125     }
    126 
    127     public bool SlidingWindowMovementPossible {
    128       get {
     165    public bool UpdateAvailable
     166    {
     167      get { return !String.IsNullOrWhiteSpace(DataSourceAddress.Value); }
     168    }
     169
     170    public bool SlidingWindowMovementPossible
     171    {
     172      get
     173      {
    129174        return ProblemData != null && ProblemData.Dataset != null &&
    130175               (
     
    135180    }
    136181
    137     public bool SlidingWindowEvaluationPossible {
    138       get {
     182    public bool SlidingWindowEvaluationPossible
     183    {
     184      get
     185      {
    139186        //return ProblemData != null && ProblemData.Dataset != null && ProblemData.Dataset.Rows > 0 && FitnessPartition.Size > 0;
    140187        return FitnessPartition.Size > 0;
     
    149196        FitnessPartition.Start += SlidingWindowStepWidth.Value;
    150197        FitnessPartition.End += SlidingWindowStepWidth.Value;
    151       } else { 
     198      } else {
    152199        FitnessPartition.End += SlidingWindowStepWidth.Value;
    153200        FitnessPartition.Start += FitnessPartition.End - SlidingWindowSize.Value;
    154       } 
     201      }
    155202
    156203      //if (FitnessPartition.Size > SlidingWindowSize.Value) {
     
    191238    public Datastream() : base() {
    192239      Parameters.Add(new ValueParameter<RegressionProblemData>(ProblemDataParameterName, "ProblemData for analysis with selected ensembles.", null));
     240      Parameters.Add(new FixedValueParameter<StringValue>(DataSourceAddressParameterName, "Source address of data stream", new StringValue("")));
    193241      Parameters.Add(new FixedValueParameter<IntRange>(InitialSlidingWindowParameterName, "Initial sliding window boundaries", new IntRange(0, 100)));
    194242      Parameters.Add(new FixedValueParameter<IntValue>(SlidingWindowSizeParameterName, "Sliding window size", new IntValue(100)));
     
    196244      Parameters.Add(new FixedValueParameter<IntValue>(SlidingWindowMovementDelayParameterName, "Sliding window movement delay interval (milliseconds)", new IntValue(0)));
    197245      Parameters.Add(new FixedValueParameter<DoubleValue>(SlidingWindowSonarRatioParameterName, "Sliding window sonar ratio", new DoubleValue(0.25)));
     246      Parameters.Add(new FixedValueParameter<EnumValue<EvaluationScheme>>(SlidingWindowEvaluationSchemeParameterName, "Sliding window evaluation scheme", new EnumValue<EvaluationScheme>(EvaluationScheme.none)));
    198247      RegisterParameterEvents();
    199248      InitializeState();
     
    201250    #endregion
    202251
    203     public void InitializeState(){
     252    public void InitializeState() {
    204253      if (ProblemData == null || ProblemData.Dataset == null || ProblemData.Dataset.Rows == 0) {
    205254        FitnessPartition = new IntRange(0, 0);
     
    216265        FitnessPartition = new IntRange(0, 0);
    217266      } else {
    218         if(FitnessPartition == null) FitnessPartition = (IntRange)InitialSlidingWindow.Clone();
     267        if (FitnessPartition == null) FitnessPartition = (IntRange)InitialSlidingWindow.Clone();
    219268        if (FitnessPartition.End > ProblemData.Dataset.Rows) {
    220269          FitnessPartition.End = ProblemData.Dataset.Rows;
     
    258307    // TODO
    259308    public IEnumerable<IParameterizedItem> ExecutionContextItems { get; }
    260    
     309
    261310  }
    262311}
  • branches/2719_HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis/3.4/DatastreamAnalysisOptimizer.cs

    r14710 r15867  
    7474    }
    7575
    76     private double lastStateValue;
     76    //private double lastStateValue;
    7777    private double pR2Sum;
    7878    private int detectionCount;
     
    108108
    109109    [Storable]
    110     private IItemList<RatedEnsembleModel> ensembles;
    111 
    112     public IItemList<RatedEnsembleModel> Ensembles {
     110    private IItemList<ProxyEnsembleModel> ensembles;
     111
     112    public IItemList<ProxyEnsembleModel> Ensembles {
    113113      get { return ensembles; }
    114114      set {
    115115        if (value == null || value == ensembles)
    116116          return;
    117         if (!(value is IRatedEnsembleModel)) throw new ArgumentException("Invaid ensemble model type");
     117        if (!(value is IProxyEnsembleModel)) throw new ArgumentException("Invaid ensemble model type");
    118118        DeregisterEnsembleEvents();
    119119        ensembles = value;
     
    214214    protected void SetupResults() {
    215215      evaluationCount = 0;
    216       lastStateValue = 0.0;
     216      //lastStateValue = 0.0;
    217217      pR2Sum = 0.0;
    218218      exclusivitySum = 0.0;
     
    267267      log = new Log();
    268268      results = new ResultCollection();
    269       ensembles = new ItemList<RatedEnsembleModel>();
     269      ensembles = new ItemList<ProxyEnsembleModel>();
    270270      datastream = new Datastream();
    271271      runsCounter = 0;
     
    287287      log = cloner.Clone(original.log);
    288288      results = cloner.Clone(original.results);
    289       ensembles = (ItemList<RatedEnsembleModel>) original.Ensembles.Clone(cloner);
     289      ensembles = (ItemList<ProxyEnsembleModel>) original.Ensembles.Clone(cloner);
    290290      datastream = (Datastream) original.Datastream.Clone(cloner);
    291291      runsCounter = original.runsCounter;
     
    322322    }
    323323
    324     public override void Start() {
     324    public override void Start(CancellationToken cancellationToken) {
     325      base.Start(cancellationToken);
    325326      if (ensembles == null || datastream == null) return;
    326       base.Start();
    327       cancellationTokenSource = new CancellationTokenSource();
     327
     328      cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
    328329      stopPending = false;
    329330
     
    450451        // play and evaluate initial window
    451452        PlayDatastream();
    452         lastStateValue = Datastream.ProblemData.Dataset.GetDoubleValue("h", replayedIndex);
     453        //lastStateValue = Datastream.ProblemData.Dataset.GetDoubleValue("h", replayedIndex);
    453454        if (Datastream.SlidingWindowEvaluationPossible) Evaluate();
    454455        replayedIndex = Datastream.FitnessPartition.End;
     
    490491      }
    491492    }
    492    
     493
     494    private void Smoothen(double[] estimatedValuesPerRow) {
     495      if (Datastream.SlidingWindowEvaluationScheme.Value == Datastream.EvaluationScheme.equal) {
     496        var avg = estimatedValuesPerRow.Average();
     497        for (int i = 0; i < estimatedValuesPerRow.Length; i++) {
     498          estimatedValuesPerRow[i] = avg;
     499        }
     500      }
     501    }
     502
    493503    private void Evaluate() {
    494504      evaluationCount++;
     
    512522      var curDetectionCount = 0;
    513523      var changeDetectionCount = 0;
    514       double curStateValue = 0.0;
     524      //double curStateValue = 0.0;
     525
    515526      foreach (var ensemble in Ensembles) {
    516527
    517528        var sonarEstimatedValuesPerModelPerRow = ensemble.Model.Models.Select(x => x.GetEstimatedValues(datastream.ProblemData.Dataset, sonarRows).ToArray());
    518529        var sonarEstimatedValuesPerRow = Enumerable.Range(0, sonarSize).Select(r => sonarEstimatedValuesPerModelPerRow.Select(m => m[r]).Average()).ToArray();
    519 
     530       
    520531        var estimatedValuesPerModelPerRow = ensemble.Model.Models.Select(x => x.GetEstimatedValues(datastream.ProblemData.Dataset, rows).ToArray());
    521532        var estimatedValuesPerRow = Enumerable.Range(0, Datastream.FitnessPartition.Size).Select(r => estimatedValuesPerModelPerRow.Select(e => e[r]).Average()).ToArray(); // per row
     
    550561        int replayCount = estimatedValuesPerRow.Length - replayAmount;
    551562
     563        Smoothen(estimatedValuesPerRow);
     564
    552565        for (int i = replayedIndex; i < Datastream.FitnessPartition.End; i++) {
    553566          //ResultsTargets.Rows[ensemble.Name].Values.Add(averageEstimatedValue);
     
    594607      }
    595608
    596       double replCount = 0.0;
    597       double accCount = 0.0;
    598       for (int i = replayedIndex; i < Datastream.FitnessPartition.End; i++) {
    599         replCount++;
    600         curStateValue = problemData.Dataset.GetDoubleValue("h", i);
    601         if (curStateValue <= 0.5 && winningEnsembleIdx == 0 && winningEnsemblePR2 > ensembles[winningEnsembleIdx].QualityThreshold.Start) {
    602           accCount++;
    603         } else if (curStateValue > 0.5 && winningEnsembleIdx == 1 && winningEnsemblePR2 > ensembles[winningEnsembleIdx].QualityThreshold.Start) {
    604           accCount++;
    605         }
    606       }
    607       accuracySum += accCount / replCount;
    608       ResultsDetectionAccuracy = accuracySum / evaluationCount;
     609      //double replCount = 0.0;
     610      //double accCount = 0.0;
     611      //for (int i = replayedIndex; i < Datastream.FitnessPartition.End; i++) {
     612      //  replCount++;
     613      //  //curStateValue = problemData.Dataset.GetDoubleValue("h", i);
     614      //  if (curStateValue <= 0.5 && winningEnsembleIdx == 0 && winningEnsemblePR2 > ensembles[winningEnsembleIdx].QualityThreshold.Start) {
     615      //    accCount++;
     616      //  } else if (curStateValue > 0.5 && winningEnsembleIdx == 1 && winningEnsemblePR2 > ensembles[winningEnsembleIdx].QualityThreshold.Start) {
     617      //    accCount++;
     618      //  }
     619      //}
     620      //accuracySum += accCount / replCount;
     621      //ResultsDetectionAccuracy = accuracySum / evaluationCount;
     622
     623
     624
    609625
    610626      //if (accCount / replCount > 1.0) {
     
    621637      //}
    622638
    623       lastStateValue = curStateValue;
     639      //lastStateValue = curStateValue;
    624640
    625641      // detection of state change
     
    650666    private bool accDiscount = false;
    651667
    652     private double CalulateEnsembleConfidenceCM1(RatedEnsembleModel ensemble, IEnumerable<double[]> estimatedValuesPerModelPerRow, IEnumerable<double> realValues) {
     668    private double CalulateEnsembleConfidenceCM1(ProxyEnsembleModel ensemble, IEnumerable<double[]> estimatedValuesPerModelPerRow, IEnumerable<double> realValues) {
    653669      int noModels = estimatedValuesPerModelPerRow.Count();
    654670      int votes = 0;
     
    717733
    718734    protected virtual void RegisterEnsembleEvents() {
    719       ensembles.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<RatedEnsembleModel>>(Ensembles_ItemsChanged);
    720       ensembles.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<RatedEnsembleModel>>(Ensembles_ItemsChanged);
    721       ensembles.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<RatedEnsembleModel>>(Ensembles_ItemsChanged);
    722       ensembles.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<RatedEnsembleModel>>(Ensembles_ItemsChanged);
    723       ensembles.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<RatedEnsembleModel>>(Ensembles_Reset);
     735      ensembles.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<ProxyEnsembleModel>>(Ensembles_ItemsChanged);
     736      ensembles.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<ProxyEnsembleModel>>(Ensembles_ItemsChanged);
     737      ensembles.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<ProxyEnsembleModel>>(Ensembles_ItemsChanged);
     738      ensembles.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<ProxyEnsembleModel>>(Ensembles_ItemsChanged);
     739      ensembles.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<ProxyEnsembleModel>>(Ensembles_Reset);
    724740    }
    725741
    726742    protected virtual void DeregisterEnsembleEvents() {
    727       ensembles.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<RatedEnsembleModel>>(Ensembles_ItemsChanged);
    728       ensembles.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<RatedEnsembleModel>>(Ensembles_ItemsChanged);
    729       ensembles.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<RatedEnsembleModel>>(Ensembles_ItemsChanged);
    730       ensembles.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<RatedEnsembleModel>>(Ensembles_ItemsChanged);
    731       ensembles.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<RatedEnsembleModel>>(Ensembles_Reset);
     743      ensembles.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<ProxyEnsembleModel>>(Ensembles_ItemsChanged);
     744      ensembles.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<ProxyEnsembleModel>>(Ensembles_ItemsChanged);
     745      ensembles.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<ProxyEnsembleModel>>(Ensembles_ItemsChanged);
     746      ensembles.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<ProxyEnsembleModel>>(Ensembles_ItemsChanged);
     747      ensembles.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<ProxyEnsembleModel>>(Ensembles_Reset);
    732748    }
    733749    #endregion
  • branches/2719_HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis/3.4/HeuristicLab.DatastreamAnalysis.csproj

    r14710 r15867  
    1818    <DebugType>full</DebugType>
    1919    <Optimize>false</Optimize>
    20     <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
     20    <OutputPath>..\..\..\..\trunk\bin\</OutputPath>
    2121    <DefineConstants>DEBUG;TRACE</DefineConstants>
    2222    <ErrorReport>prompt</ErrorReport>
     
    110110    <Compile Include="IAnalysisBase.cs" />
    111111    <Compile Include="IDatastream.cs" />
    112     <Compile Include="IRatedEnsembleModel.cs" />
     112    <Compile Include="IProxyEnsembleModel.cs" />
    113113    <Compile Include="Plugin.cs" />
    114114    <Compile Include="Properties\AssemblyInfo.cs" />
    115     <Compile Include="RatedEnsembleModel.cs" />
     115    <Compile Include="ProxyEnsembleModel.cs" />
    116116  </ItemGroup>
    117117  <ItemGroup>
  • branches/2719_HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis/3.4/HeuristicLab.DatastreamAnalysis.csproj.user

    r14536 r15867  
    33  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
    44    <StartAction>Program</StartAction>
    5     <StartProgram>C:\dev\workspaces\hl-core\trunk\sources\bin\HeuristicLab 3.3.exe</StartProgram>
    6     <StartArguments>/hidestarter /start:Optimizer</StartArguments>
     5    <StartProgram>C:\dev\workspaces\hl-core\trunk\bin\HeuristicLab 3.3.exe</StartProgram>
     6    <StartArguments>/start:Optimizer /hideStarter</StartArguments>
    77  </PropertyGroup>
    88  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
  • branches/2719_HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis/3.4/Plugin.cs

    r15025 r15867  
    2323
    2424namespace HeuristicLab.DatastreamAnalysis {
    25   [Plugin("HeuristicLab.DatastreamAnalysis", "3.4.14.14710")]
     25  [Plugin("HeuristicLab.DatastreamAnalysis", "3.4.14.15025")]
    2626  [PluginFile("HeuristicLab.DatastreamAnalysis-3.4.dll", PluginFileType.Assembly)]
    2727  [PluginDependency("HeuristicLab.Collections", "3.3")]
  • branches/2719_HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis/3.4/Properties/AssemblyInfo.cs

    r15025 r15867  
    5454// [assembly: AssemblyVersion("1.0.*")]
    5555[assembly: AssemblyVersion("3.4.0.0")]
    56 [assembly: AssemblyFileVersion("3.4.14.14710")]
     56[assembly: AssemblyFileVersion("3.4.14.15025")]
Note: See TracChangeset for help on using the changeset viewer.