Changeset 7099
- Timestamp:
- 11/29/11 19:52:22 (13 years ago)
- Location:
- branches/HeuristicLab.TimeSeries
- Files:
-
- 4 deleted
- 14 edited
- 18 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TimeSeries/HeuristicLab 3.3.sln
r7097 r7099 81 81 {E10F395F-C8A6-48AD-B470-9AA7A1F43809} = {E10F395F-C8A6-48AD-B470-9AA7A1F43809} 82 82 {B7A64A60-B538-479F-9C47-A3180C458F6C} = {B7A64A60-B538-479F-9C47-A3180C458F6C} 83 {07486E68-1517-4B9D-A58D-A38E99AE71AB} = {07486E68-1517-4B9D-A58D-A38E99AE71AB} 83 84 {4AE3FC69-C575-42D2-BC46-0FAD5850EFC5} = {4AE3FC69-C575-42D2-BC46-0FAD5850EFC5} 84 85 {56F9106A-079F-4C61-92F6-86A84C2D84B7} = {56F9106A-079F-4C61-92F6-86A84C2D84B7} … … 92 93 {70DFD984-B1D9-46FE-8EB7-4DE92D71A9FC} = {70DFD984-B1D9-46FE-8EB7-4DE92D71A9FC} 93 94 {06D4A186-9319-48A0-BADE-A2058D462EEA} = {06D4A186-9319-48A0-BADE-A2058D462EEA} 95 {5B9B9E8C-2706-43C2-80B8-A08341E431F7} = {5B9B9E8C-2706-43C2-80B8-A08341E431F7} 94 96 {997F018D-AEA2-4F21-9301-82FAF6A5612D} = {997F018D-AEA2-4F21-9301-82FAF6A5612D} 95 97 {D767C38D-8014-46B0-9A32-03A3AECCE34A} = {D767C38D-8014-46B0-9A32-03A3AECCE34A} … … 114 116 {66D249C3-A01D-42A8-82A2-919BC8EC3D83} = {66D249C3-A01D-42A8-82A2-919BC8EC3D83} 115 117 {E4CFB0C3-0589-4893-B38E-8BEDF885C765} = {E4CFB0C3-0589-4893-B38E-8BEDF885C765} 118 {E6CB1FC5-78EC-4EB8-BF12-35303C36F962} = {E6CB1FC5-78EC-4EB8-BF12-35303C36F962} 116 119 {79271BC8-4446-40E2-BB89-9BE4E17174FE} = {79271BC8-4446-40E2-BB89-9BE4E17174FE} 120 {02766ECC-D0F5-4115-9ECA-47409167B638} = {02766ECC-D0F5-4115-9ECA-47409167B638} 117 121 {7A2531CE-3F7C-4F13-BCCA-ED6DC27A7086} = {7A2531CE-3F7C-4F13-BCCA-ED6DC27A7086} 118 122 {102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B} = {102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B} … … 316 320 EndProject 317 321 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Algorithms.Benchmarks.Views-3.3", "HeuristicLab.Algorithms.Benchmarks.Views\3.3\HeuristicLab.Algorithms.Benchmarks.Views-3.3.csproj", "{3C906172-E044-4DF0-B4FD-AA21192D5D3E}" 322 EndProject 323 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4", "HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4.csproj", "{07486E68-1517-4B9D-A58D-A38E99AE71AB}" 324 EndProject 325 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views-3.4", "HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views-3.4.csproj", "{E6CB1FC5-78EC-4EB8-BF12-35303C36F962}" 318 326 EndProject 319 327 Global … … 1524 1532 {3C906172-E044-4DF0-B4FD-AA21192D5D3E}.Release|x86.ActiveCfg = Release|x86 1525 1533 {3C906172-E044-4DF0-B4FD-AA21192D5D3E}.Release|x86.Build.0 = Release|x86 1534 {07486E68-1517-4B9D-A58D-A38E99AE71AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 1535 {07486E68-1517-4B9D-A58D-A38E99AE71AB}.Debug|Any CPU.Build.0 = Debug|Any CPU 1536 {07486E68-1517-4B9D-A58D-A38E99AE71AB}.Debug|x64.ActiveCfg = Debug|x64 1537 {07486E68-1517-4B9D-A58D-A38E99AE71AB}.Debug|x64.Build.0 = Debug|x64 1538 {07486E68-1517-4B9D-A58D-A38E99AE71AB}.Debug|x86.ActiveCfg = Debug|x86 1539 {07486E68-1517-4B9D-A58D-A38E99AE71AB}.Debug|x86.Build.0 = Debug|x86 1540 {07486E68-1517-4B9D-A58D-A38E99AE71AB}.Release|Any CPU.ActiveCfg = Release|Any CPU 1541 {07486E68-1517-4B9D-A58D-A38E99AE71AB}.Release|Any CPU.Build.0 = Release|Any CPU 1542 {07486E68-1517-4B9D-A58D-A38E99AE71AB}.Release|x64.ActiveCfg = Release|x64 1543 {07486E68-1517-4B9D-A58D-A38E99AE71AB}.Release|x64.Build.0 = Release|x64 1544 {07486E68-1517-4B9D-A58D-A38E99AE71AB}.Release|x86.ActiveCfg = Release|x86 1545 {07486E68-1517-4B9D-A58D-A38E99AE71AB}.Release|x86.Build.0 = Release|x86 1546 {E6CB1FC5-78EC-4EB8-BF12-35303C36F962}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 1547 {E6CB1FC5-78EC-4EB8-BF12-35303C36F962}.Debug|Any CPU.Build.0 = Debug|Any CPU 1548 {E6CB1FC5-78EC-4EB8-BF12-35303C36F962}.Debug|x64.ActiveCfg = Debug|x64 1549 {E6CB1FC5-78EC-4EB8-BF12-35303C36F962}.Debug|x64.Build.0 = Debug|x64 1550 {E6CB1FC5-78EC-4EB8-BF12-35303C36F962}.Debug|x86.ActiveCfg = Debug|x86 1551 {E6CB1FC5-78EC-4EB8-BF12-35303C36F962}.Debug|x86.Build.0 = Debug|x86 1552 {E6CB1FC5-78EC-4EB8-BF12-35303C36F962}.Release|Any CPU.ActiveCfg = Release|Any CPU 1553 {E6CB1FC5-78EC-4EB8-BF12-35303C36F962}.Release|Any CPU.Build.0 = Release|Any CPU 1554 {E6CB1FC5-78EC-4EB8-BF12-35303C36F962}.Release|x64.ActiveCfg = Release|x64 1555 {E6CB1FC5-78EC-4EB8-BF12-35303C36F962}.Release|x64.Build.0 = Release|x64 1556 {E6CB1FC5-78EC-4EB8-BF12-35303C36F962}.Release|x86.ActiveCfg = Release|x86 1557 {E6CB1FC5-78EC-4EB8-BF12-35303C36F962}.Release|x86.Build.0 = Release|x86 1526 1558 EndGlobalSection 1527 1559 GlobalSection(SolutionProperties) = preSolution -
branches/HeuristicLab.TimeSeries/HeuristicLab.Algorithms.DataAnalysis/3.4/HeuristicLab.Algorithms.DataAnalysis-3.4.csproj
r7097 r7099 144 144 </Compile> 145 145 <Compile Include="Linear\AlglibUtil.cs" /> 146 <Compile Include="Linear\LinearTimeSeriesPrognosis.cs" /> 146 147 <Compile Include="Linear\LinearDiscriminantAnalysis.cs" /> 147 148 <Compile Include="Linear\LinearRegression.cs"> … … 247 248 <Private>False</Private> 248 249 </ProjectReference> 250 <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4.csproj"> 251 <Project>{07486E68-1517-4B9D-A58D-A38E99AE71AB}</Project> 252 <Name>HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4</Name> 253 <Private>False</Private> 254 </ProjectReference> 249 255 <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj"> 250 256 <Project>{3D28463F-EC96-4D82-AFEE-38BE91A0CA00}</Project> -
branches/HeuristicLab.TimeSeries/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/AlglibUtil.cs
r7097 r7099 27 27 public static class AlglibUtil { 28 28 public static double[,] PrepareInputMatrix(Dataset dataset, IEnumerable<string> variables, IEnumerable<int> rows) { 29 List<string> variablesList = variables.ToList(); 29 return PrepareInputMatrix(dataset, variables, rows, new int[] { 0 }); 30 } 31 32 public static double[,] PrepareInputMatrix(Dataset dataset, IEnumerable<string> variables, IEnumerable<int> rows, IEnumerable<int> lags) { 33 int maxLag = lags.Max(); 34 35 // drop last variable (target variable) 36 List<string> inputVariablesList = variables 37 .Reverse() 38 .Skip(1) 39 .Reverse() 40 .ToList(); 41 string targetVariable = variables.Last(); 30 42 List<int> rowsList = rows.ToList(); 31 32 double[,] matrix = new double[ rowsList.Count, variablesList.Count];43 int nRows = rowsList.Count - maxLag; 44 double[,] matrix = new double[nRows, inputVariablesList.Count * lags.Count() + 1]; 33 45 34 46 int col = 0; 35 foreach (string column in variables) { 36 var values = dataset.GetDoubleValues(column, rows); 37 int row = 0; 38 foreach (var value in values) { 39 matrix[row, col] = value; 40 row++; 47 int row = 0; 48 // input variables 49 foreach (int lag in lags) { 50 foreach (string column in inputVariablesList) { 51 var values = dataset.GetDoubleValues(column, rows.Select(x => x - lag).Take(nRows)); 52 row = 0; 53 foreach (var value in values) { 54 if (row >= 0) { 55 matrix[row, col] = value; 56 } 57 row++; 58 } 59 col++; 41 60 } 42 col++;43 61 } 44 62 // target variable 63 row = 0; 64 foreach (var value in dataset.GetDoubleValues(targetVariable, rows).Take(nRows)) { 65 matrix[row, col] = value; 66 row++; 67 } 45 68 return matrix; 46 69 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorRegression.cs
r7097 r7099 143 143 parameter.Probability = false; 144 144 145 146 145 SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(dataset, targetVariable, allowedInputVariables, rows); 147 146 SVM.RangeTransform rangeTransform = SVM.RangeTransform.Compute(problem); -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionErrorCharacteristicsCurveView.cs
r7097 r7099 67 67 } 68 68 69 var laggedVariables = Content.Model.SymbolicExpressionTree.IterateNodesPostfix() 70 .OfType<LaggedVariableTreeNode>() 71 .Select(n => n.Lag) 72 .Where(l => l < 0); 73 if (laggedVariables.Any()) throw new NotSupportedException("The symbolic regression solution contains lagged variables."); 74 69 75 //check inputVariables used in the symbolic regression model 70 76 var usedVariables = -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views-3.4.csproj
r6807 r7099 41 41 <DebugType>full</DebugType> 42 42 <Optimize>false</Optimize> 43 <OutputPath> bin\Debug\</OutputPath>43 <OutputPath>../../bin/</OutputPath> 44 44 <DefineConstants>DEBUG;TRACE</DefineConstants> 45 45 <ErrorReport>prompt</ErrorReport> … … 58 58 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' "> 59 59 <DebugSymbols>true</DebugSymbols> 60 <OutputPath> bin\x64\Debug\</OutputPath>60 <OutputPath>../../bin/</OutputPath> 61 61 <DefineConstants>DEBUG;TRACE</DefineConstants> 62 62 <DebugType>full</DebugType> … … 66 66 </PropertyGroup> 67 67 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> 68 <OutputPath> bin\x64\Release\</OutputPath>68 <OutputPath>../../bin/</OutputPath> 69 69 <DefineConstants>TRACE</DefineConstants> 70 70 <Optimize>true</Optimize> … … 76 76 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> 77 77 <DebugSymbols>true</DebugSymbols> 78 <OutputPath> bin\x86\Debug\</OutputPath>78 <OutputPath>../../bin/</OutputPath> 79 79 <DefineConstants>DEBUG;TRACE</DefineConstants> 80 80 <DebugType>full</DebugType> … … 84 84 </PropertyGroup> 85 85 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> 86 <OutputPath> bin\x86\Release\</OutputPath>86 <OutputPath>../../bin/</OutputPath> 87 87 <DefineConstants>TRACE</DefineConstants> 88 88 <Optimize>true</Optimize> … … 110 110 </ItemGroup> 111 111 <ItemGroup> 112 <Compile Include=" HeuristicLabProblemsDataAnalysisSymbolicTimeSeriesPrognosisViewsPlugin.cs" />112 <Compile Include="Plugin.cs" /> 113 113 <Compile Include="SymbolicTimeSeriesPrognosisSolutionErrorCharacteristicsCurveView.cs"> 114 114 <SubType>UserControl</SubType> … … 124 124 </Compile> 125 125 <None Include="HeuristicLab.snk" /> 126 <None Include="HeuristicLabProblemsDataAnalysisSymbolicTimeSeriesPrognosisViewsPlugin.cs.frame" /> 127 <None Include="Properties\AssemblyInfo.frame" /> 126 <None Include="Plugin.cs.frame" /> 128 127 <Compile Include="InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs"> 129 128 <SubType>UserControl</SubType> … … 133 132 </Compile> 134 133 <Compile Include="Properties\AssemblyInfo.cs" /> 134 <None Include="Properties\AssemblyInfo.cs.frame" /> 135 135 </ItemGroup> 136 136 <ItemGroup> … … 256 256 257 257 call PreBuildEvent.cmd 258 SubWCRev "%25ProjectDir%25\" "%25ProjectDir%25\HeuristicLabProblemsDataAnalysisSymbolicTimeSeriesPrognosisViewsPlugin.cs.frame" "%25ProjectDir%25\HeuristicLabProblemsDataAnalysisSymbolicTimeSeriesPrognosisViewsPlugin.cs"</PreBuildEvent>258 </PreBuildEvent> 259 259 </PropertyGroup> 260 260 </Project> -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4.csproj
r6802 r7099 41 41 <DebugType>full</DebugType> 42 42 <Optimize>false</Optimize> 43 <OutputPath> bin\Debug\</OutputPath>43 <OutputPath>../../bin/</OutputPath> 44 44 <DefineConstants>DEBUG;TRACE</DefineConstants> 45 45 <ErrorReport>prompt</ErrorReport> … … 50 50 <DebugType>pdbonly</DebugType> 51 51 <Optimize>true</Optimize> 52 <OutputPath> bin\Release\</OutputPath>52 <OutputPath>../../bin/</OutputPath> 53 53 <DefineConstants>TRACE</DefineConstants> 54 54 <ErrorReport>prompt</ErrorReport> … … 58 58 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' "> 59 59 <DebugSymbols>true</DebugSymbols> 60 <OutputPath> bin\x64\Debug\</OutputPath>60 <OutputPath>../../bin/</OutputPath> 61 61 <DefineConstants>DEBUG;TRACE</DefineConstants> 62 62 <DebugType>full</DebugType> … … 66 66 </PropertyGroup> 67 67 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> 68 <OutputPath> bin\x64\Release\</OutputPath>68 <OutputPath>../../bin/</OutputPath> 69 69 <DefineConstants>TRACE</DefineConstants> 70 70 <Optimize>true</Optimize> … … 76 76 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> 77 77 <DebugSymbols>true</DebugSymbols> 78 <OutputPath> bin\x86\Debug\</OutputPath>78 <OutputPath>../../bin/</OutputPath> 79 79 <DefineConstants>DEBUG;TRACE</DefineConstants> 80 80 <DebugType>full</DebugType> … … 84 84 </PropertyGroup> 85 85 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> 86 <OutputPath> bin\x86\Release\</OutputPath>86 <OutputPath>../../bin/</OutputPath> 87 87 <DefineConstants>TRACE</DefineConstants> 88 88 <Optimize>true</Optimize> … … 93 93 </PropertyGroup> 94 94 <ItemGroup> 95 <Reference Include="ALGLIB-3.1.0, Version=3.1.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 96 <Reference Include="HeuristicLab.ALGLIB-3.1.0, Version=3.1.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 95 97 <Reference Include="System" /> 96 98 <Reference Include="System.Core"> … … 108 110 </ItemGroup> 109 111 <ItemGroup> 110 <Compile Include="HeuristicLabProblemsDataAnalysisSymbolicTimeSeriesPrognosisPlugin.cs" />111 112 <Compile Include="Interfaces\ISymbolicTimeSeriesPrognosisEvaluator.cs" /> 112 113 <Compile Include="Interfaces\ISymbolicTimeSeriesPrognosisModel.cs" /> 113 114 <Compile Include="Interfaces\ISymbolicTimeSeriesPrognosisSingleObjectiveEvaluator.cs" /> 114 115 <Compile Include="Interfaces\ISymbolicTimeSeriesPrognosisSolution.cs" /> 116 <Compile Include="Plugin.cs" /> 115 117 <Compile Include="SingleObjective\SymbolicTimeSeriesPrognosisSingleObjectiveEvaluator.cs" /> 116 118 <Compile Include="SingleObjective\SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator.cs" /> … … 123 125 <Compile Include="SymbolicTimeSeriesPrognosisSolution.cs" /> 124 126 <None Include="HeuristicLab.snk" /> 125 <None Include="HeuristicLabProblemsDataAnalysisSymbolicTimeSeriesPrognosisPlugin.cs.frame" /> 126 <None Include="Properties\AssemblyInfo.frame" /> 127 <None Include="Plugin.cs.frame" /> 127 128 <Compile Include="Properties\AssemblyInfo.cs" /> 129 <None Include="Properties\AssemblyInfo.cs.frame" /> 128 130 </ItemGroup> 129 131 <ItemGroup> … … 151 153 <Project>{06D4A186-9319-48A0-BADE-A2058D462EEA}</Project> 152 154 <Name>HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4</Name> 153 </ProjectReference>154 <ProjectReference Include="..\..\HeuristicLab.ExtLibs\HeuristicLab.ALGLIB\3.1.0\ALGLIB-3.1.0\ALGLIB-3.1.0.csproj">155 <Project>{FC841674-62A7-4055-BE91-E41944B6C606}</Project>156 <Name>ALGLIB-3.1.0</Name>157 </ProjectReference>158 <ProjectReference Include="..\..\HeuristicLab.ExtLibs\HeuristicLab.ALGLIB\3.1.0\HeuristicLab.ALGLIB-3.1.0\HeuristicLab.ALGLIB-3.1.0.csproj">159 <Project>{DE69A359-A5B8-4D3D-BA8D-D5780D7F96D6}</Project>160 <Name>HeuristicLab.ALGLIB-3.1.0 %28HeuristicLab.ExtLibs\HeuristicLab.ALGLIB\HeuristicLab.ALGLIB-3.1.0\HeuristicLab.ALGLIB-3.1.0%29</Name>161 155 </ProjectReference> 162 156 <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj"> … … 222 216 223 217 call PreBuildEvent.cmd 224 SubWCRev "%25ProjectDir%25\" "%25ProjectDir%25\HeuristicLabProblemsDataAnalysisSymbolicTimeSeriesPrognosisPlugin.cs.frame" "%25ProjectDir%25\HeuristicLabProblemsDataAnalysisSymbolicTimeSeriesPrognosisPlugin.cs"</PreBuildEvent>218 </PreBuildEvent> 225 219 </PropertyGroup> 226 220 </Project> -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveProblem.cs
r6802 r7099 62 62 MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength; 63 63 64 SymbolicExpressionTreeGrammarParameter.ValueChanged += (o, e) => ConfigureGrammarSymbols(); 65 66 ConfigureGrammarSymbols(); 67 64 68 InitializeOperators(); 65 69 UpdateEstimationLimits(); 70 } 71 72 private void ConfigureGrammarSymbols() { 73 var grammar = SymbolicExpressionTreeGrammar as TypeCoherentExpressionGrammar; 74 if (grammar != null) grammar.ConfigureAsDefaultTimeSeriesPrognosisGrammar(); 66 75 } 67 76 -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SymbolicTimeSeriesPrognosisModel.cs
r6802 r7099 86 86 if (startNode.GetSubtree(0).Symbol is Addition) { 87 87 var addNode = startNode.GetSubtree(0); 88 if (addNode.Subtree sCount == 2 && addNode.GetSubtree(0).Symbol is Multiplication && addNode.GetSubtree(1).Symbol is Constant) {88 if (addNode.SubtreeCount == 2 && addNode.GetSubtree(0).Symbol is Multiplication && addNode.GetSubtree(1).Symbol is Constant) { 89 89 alphaTreeNode = addNode.GetSubtree(1) as ConstantTreeNode; 90 90 var mulNode = addNode.GetSubtree(0); 91 if (mulNode.Subtree sCount == 2 && mulNode.GetSubtree(1).Symbol is Constant) {91 if (mulNode.SubtreeCount == 2 && mulNode.GetSubtree(1).Symbol is Constant) { 92 92 betaTreeNode = mulNode.GetSubtree(1) as ConstantTreeNode; 93 93 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs
r7097 r7099 194 194 Symbols.Where(s => s.Name == TimeSeriesSymbolsName).First().Enabled = false; 195 195 } 196 197 public void ConfigureAsDefaultTimeSeriesPrognosisGrammar() { 198 Symbols.Where(s => s is Variable).First().Enabled = false; 199 Symbols.Where(s => s.Name == TrigonometricFunctionsName).First().Enabled = false; 200 Symbols.Where(s => s.Name == PowerFunctionsName).First().Enabled = false; 201 Symbols.Where(s => s.Name == ConditionalSymbolsName).First().Enabled = false; 202 } 196 203 } 197 204 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj
r7097 r7099 122 122 <DependentUpon>ClassificationEnsembleSolutionModelView.cs</DependentUpon> 123 123 </Compile> 124 <Compile Include="Solution Views\TimeSeriesPrognosisSolutionView.cs"> 125 <SubType>UserControl</SubType> 126 </Compile> 127 <Compile Include="Solution Views\TimeSeriesPrognosisSolutionView.Designer.cs"> 128 <DependentUpon>TimeSeriesPrognosisSolutionView.cs</DependentUpon> 129 </Compile> 130 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView.cs"> 131 <SubType>UserControl</SubType> 132 </Compile> 133 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView.Designer.cs"> 134 <DependentUpon>TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView.cs</DependentUpon> 135 </Compile> 136 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionLineChartView.cs"> 137 <SubType>UserControl</SubType> 138 </Compile> 139 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionLineChartView.Designer.cs"> 140 <DependentUpon>TimeSeriesPrognosisSolutionLineChartView.cs</DependentUpon> 141 </Compile> 142 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionPrognosedValuesView.cs"> 143 <SubType>UserControl</SubType> 144 </Compile> 145 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionPrognosedValuesView.Designer.cs"> 146 <DependentUpon>TimeSeriesPrognosisSolutionPrognosedValuesView.cs</DependentUpon> 147 </Compile> 148 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionScatterPlotView.cs"> 149 <SubType>UserControl</SubType> 150 </Compile> 151 <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionScatterPlotView.Designer.cs"> 152 <DependentUpon>TimeSeriesPrognosisSolutionScatterPlotView.cs</DependentUpon> 153 </Compile> 124 154 <Compile Include="DataAnalysisSolutionEvaluationView.cs"> 125 155 <SubType>UserControl</SubType> -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r7097 r7099 129 129 </Compile> 130 130 <Compile Include="Implementation\Regression\RegressionEnsembleSolution.cs" /> 131 <Compile Include="Implementation\TimeSeriesPrognosis\TimeSeriesPrognosisProblem.cs" /> 132 <Compile Include="Implementation\TimeSeriesPrognosis\TimeSeriesPrognosisProblemData.cs" /> 133 <Compile Include="Implementation\TimeSeriesPrognosis\TimeSeriesPrognosisSolution.cs" /> 134 <Compile Include="Implementation\TimeSeriesPrognosis\TimeSeriesPrognosisSolutionBase.cs" /> 131 135 <Compile Include="Interfaces\Classification\IClassificationEnsembleModel.cs"> 132 136 <SubType>Code</SubType> … … 142 146 <Compile Include="Implementation\Regression\RegressionSolutionBase.cs" /> 143 147 <Compile Include="OnlineCalculators\NormalizedGiniCalculator.cs" /> 148 <Compile Include="Interfaces\TimeSeriesPrognosis\IOnlineTimeSeriesCalculator.cs" /> 149 <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisModel.cs" /> 150 <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisProblem.cs" /> 151 <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisProblemData.cs" /> 152 <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisSolution.cs" /> 153 <Compile Include="OnlineCalculators\OnlineDirectionalSymmetryCalculator.cs" /> 144 154 <Compile Include="OnlineCalculators\OnlineMeanAbsoluteErrorCalculator.cs" /> 145 155 <Compile Include="OnlineCalculators\OnlineLinearScalingParameterCalculator.cs" /> … … 178 188 <Compile Include="Implementation\Regression\RegressionSolution.cs" /> 179 189 <Compile Include="Plugin.cs" /> 190 <Compile Include="OnlineCalculators\OnlineTheilsUStatisticCalculator.cs" /> 191 <Compile Include="OnlineCalculators\OnlineWeightedDirectionalSymmetryCalculator.cs" /> 180 192 <Compile Include="TableFileParser.cs" /> 181 193 <Compile Include="Implementation\Classification\ThresholdCalculators\AccuracyMaximizationThresholdCalculator.cs" /> -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionBase.cs
r6802 r7099 40 40 private const string TrainingNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (training)"; 41 41 private const string TestNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (test)"; 42 private const string TrainingDirectionalSymmetryResultName = " Directional symmetry (training)";43 private const string TestDirectionalSymmetryResultName = " Directional symmetry (test)";44 private const string TrainingWeightedDirectionalSymmetryResultName = " Weighted directional symmetry (training)";45 private const string TestWeightedDirectionalSymmetryResultName = " Weighted directional symmetry (test)";46 private const string TrainingTheilsUStatisticResultName = " Theil's U (training)";47 private const string TestTheilsUStatisticResultName = " Theil's U (test)";42 private const string TrainingDirectionalSymmetryResultName = "Average directional symmetry (training)"; 43 private const string TestDirectionalSymmetryResultName = "Average directional symmetry (test)"; 44 private const string TrainingWeightedDirectionalSymmetryResultName = "Average weighted directional symmetry (training)"; 45 private const string TestWeightedDirectionalSymmetryResultName = "Average weighted directional symmetry (test)"; 46 private const string TrainingTheilsUStatisticResultName = "Average Theil's U (training)"; 47 private const string TestTheilsUStatisticResultName = "Average Theil's U (test)"; 48 48 49 49 public new ITimeSeriesPrognosisModel Model { … … 146 146 Add(new Result(TrainingNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the training partition", new DoubleValue())); 147 147 Add(new Result(TestNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the test partition", new DoubleValue())); 148 Add(new Result(TrainingDirectionalSymmetryResultName, "The directional symmetry of the output of the model on the training partition", new DoubleValue()));149 Add(new Result(TestDirectionalSymmetryResultName, "The directional symmetry of the output of the model on the test partition", new DoubleValue()));150 Add(new Result(TrainingWeightedDirectionalSymmetryResultName, "The weighted directional symmetry of the outputof the model on the training partition", new DoubleValue()));151 Add(new Result(TestWeightedDirectionalSymmetryResultName, "The weighted directional symmetry of the outputof the model on the test partition", new DoubleValue()));152 Add(new Result(TrainingTheilsUStatisticResultName, "The Theil's U statistic of the outputof the model on the training partition", new DoubleValue()));153 Add(new Result(TestTheilsUStatisticResultName, "The Theil's U statistic of the outputof the model on the test partition", new DoubleValue()));148 Add(new Result(TrainingDirectionalSymmetryResultName, "The average directional symmetry of the forecasts of the model on the training partition", new PercentValue())); 149 Add(new Result(TestDirectionalSymmetryResultName, "The average directional symmetry of the forecasts of the model on the test partition", new PercentValue())); 150 Add(new Result(TrainingWeightedDirectionalSymmetryResultName, "The average weighted directional symmetry of the forecasts of the model on the training partition", new DoubleValue())); 151 Add(new Result(TestWeightedDirectionalSymmetryResultName, "The average weighted directional symmetry of the forecasts of the model on the test partition", new DoubleValue())); 152 Add(new Result(TrainingTheilsUStatisticResultName, "The average Theil's U statistic of the forecasts of the model on the training partition", new DoubleValue())); 153 Add(new Result(TestTheilsUStatisticResultName, "The average Theil's U statistic of the forecasts of the model on the test partition", new DoubleValue())); 154 154 } 155 155 … … 166 166 167 167 OnlineCalculatorError errorState; 168 double trainingMse = OnlineMeanSquaredErrorCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);168 double trainingMse = OnlineMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 169 169 TrainingMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingMse : double.NaN; 170 double testMse = OnlineMeanSquaredErrorCalculator.Calculate( estimatedTestValues, originalTestValues, out errorState);170 double testMse = OnlineMeanSquaredErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 171 171 TestMeanSquaredError = errorState == OnlineCalculatorError.None ? testMse : double.NaN; 172 172 173 double trainingMae = OnlineMeanAbsoluteErrorCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);173 double trainingMae = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 174 174 TrainingMeanAbsoluteError = errorState == OnlineCalculatorError.None ? trainingMae : double.NaN; 175 double testMae = OnlineMeanAbsoluteErrorCalculator.Calculate( estimatedTestValues, originalTestValues, out errorState);175 double testMae = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 176 176 TestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMae : double.NaN; 177 177 178 double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);178 double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 179 179 TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR2 : double.NaN; 180 double testR2 = OnlinePearsonsRSquaredCalculator.Calculate( estimatedTestValues, originalTestValues, out errorState);180 double testR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 181 181 TestRSquared = errorState == OnlineCalculatorError.None ? testR2 : double.NaN; 182 182 183 double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);183 double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 184 184 TrainingRelativeError = errorState == OnlineCalculatorError.None ? trainingRelError : double.NaN; 185 double testRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate( estimatedTestValues, originalTestValues, out errorState);185 double testRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 186 186 TestRelativeError = errorState == OnlineCalculatorError.None ? testRelError : double.NaN; 187 187 188 double trainingNmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);188 double trainingNmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 189 189 TrainingNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingNmse : double.NaN; 190 double testNmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate( estimatedTestValues, originalTestValues, out errorState);190 double testNmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 191 191 TestNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? testNmse : double.NaN; 192 192 193 double trainingDirectionalSymmetry = OnlineDirectionalSymmetryCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState); 193 var startTrainingValues = originalTrainingValues; 194 // each continuation is only one element long 195 var actualContinuationsTraining = from x in originalTrainingValues.Skip(1) 196 select Enumerable.Repeat(x, 1); 197 // each forecast is only one elemnt long 198 // disregards the first estimated value (we could include this again by extending the list of original values by one step to the left 199 // this is the easier way 200 var predictedContinuationsTraining = from x in estimatedTrainingValues.Skip(1) 201 select Enumerable.Repeat(x, 1); 202 203 var startTestValues = originalTestValues; 204 var actualContinuationsTest = from x in originalTestValues.Skip(1) 205 select Enumerable.Repeat(x, 1); 206 var predictedContinuationsTest = from x in estimatedTestValues.Skip(1) 207 select Enumerable.Repeat(x, 1); 208 209 double trainingDirectionalSymmetry = OnlineDirectionalSymmetryCalculator.Calculate(startTrainingValues, actualContinuationsTraining, predictedContinuationsTraining, out errorState); 194 210 TrainingDirectionalSymmetry = errorState == OnlineCalculatorError.None ? trainingDirectionalSymmetry : double.NaN; 195 double testDirectionalSymmetry = OnlineDirectionalSymmetryCalculator.Calculate( estimatedTestValues, originalTestValues, out errorState);211 double testDirectionalSymmetry = OnlineDirectionalSymmetryCalculator.Calculate(startTestValues, actualContinuationsTest, predictedContinuationsTest, out errorState); 196 212 TestDirectionalSymmetry = errorState == OnlineCalculatorError.None ? testDirectionalSymmetry : double.NaN; 197 213 198 double trainingWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);214 double trainingWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate(startTrainingValues, actualContinuationsTraining, predictedContinuationsTraining, out errorState); 199 215 TrainingWeightedDirectionalSymmetry = errorState == OnlineCalculatorError.None ? trainingWeightedDirectionalSymmetry : double.NaN; 200 double testWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate( estimatedTestValues, originalTestValues, out errorState);216 double testWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate(startTestValues, actualContinuationsTest, predictedContinuationsTest, out errorState); 201 217 TestWeightedDirectionalSymmetry = errorState == OnlineCalculatorError.None ? testWeightedDirectionalSymmetry : double.NaN; 202 218 203 double trainingTheilsU = OnlineTheilsUStatisticCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);219 double trainingTheilsU = OnlineTheilsUStatisticCalculator.Calculate(startTrainingValues, actualContinuationsTraining, predictedContinuationsTraining, out errorState); 204 220 TrainingTheilsUStatistic = errorState == OnlineCalculatorError.None ? trainingTheilsU : double.NaN; 205 double testTheilsU = OnlineTheilsUStatisticCalculator.Calculate( estimatedTestValues, originalTestValues, out errorState);221 double testTheilsU = OnlineTheilsUStatisticCalculator.Calculate(startTestValues, actualContinuationsTest, predictedContinuationsTest, out errorState); 206 222 TestTheilsUStatistic = errorState == OnlineCalculatorError.None ? testTheilsU : double.NaN; 207 208 209 223 } 210 224 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineDirectionalSymmetryCalculator.cs
r6802 r7099 22 22 using System; 23 23 using System.Collections.Generic; 24 using HeuristicLab.Common; 24 25 25 26 26 27 namespace HeuristicLab.Problems.DataAnalysis { 27 public class OnlineDirectionalSymmetryCalculator : IOnlineCalculator { 28 private double prevEstimated; 29 private double prevOriginal; 28 public class OnlineDirectionalSymmetryCalculator : IOnlineTimeSeriesCalculator { 30 29 private int n; 31 30 private int nCorrect; … … 33 32 public double DirectionalSymmetry { 34 33 get { 35 if (n < =1) return 0.0;36 return (double)nCorrect / (n - 1) * 100.0;34 if (n < 1) return 0.0; 35 return (double)nCorrect / n; 37 36 } 38 37 } … … 51 50 } 52 51 53 public void Add(double original, double estimated) {54 if (double.IsNaN( estimated) || double.IsInfinity(estimated) || double.IsNaN(original) || double.IsInfinity(original) || (errorState & OnlineCalculatorError.InvalidValueAdded) > 0) {52 public void Add(double startValue, IEnumerable<double> actualContinuation, IEnumerable<double> predictedContinuation) { 53 if (double.IsNaN(startValue) || (errorState & OnlineCalculatorError.InvalidValueAdded) > 0) { 55 54 errorState = errorState | OnlineCalculatorError.InvalidValueAdded; 56 } else if (n == 0) {57 prevOriginal = original;58 prevEstimated = estimated;59 n++;60 55 } else { 61 if ((original - prevOriginal) * (estimated - prevEstimated) >= 0.0) { 62 nCorrect++; 56 var actualEnumerator = actualContinuation.GetEnumerator(); 57 var predictedEnumerator = predictedContinuation.GetEnumerator(); 58 double prevActual = startValue; 59 double prevPredicted = startValue; 60 while (actualEnumerator.MoveNext() & predictedEnumerator.MoveNext() & errorState != OnlineCalculatorError.InvalidValueAdded) { 61 double actual = actualEnumerator.Current; 62 double predicted = predictedEnumerator.Current; 63 if (double.IsNaN(actual) || double.IsNaN(predicted)) { 64 errorState = errorState | OnlineCalculatorError.InvalidValueAdded; 65 } else { 66 // count a prediction correct if the trend (positive/negative/no change) is predicted correctly 67 if ((actual - prevActual) * (predicted - prevPredicted) > 0.0 || 68 (actual - prevActual).IsAlmost(predicted - prevPredicted) 69 ) { 70 nCorrect++; 71 } 72 n++; 73 } 63 74 } 64 n++; 65 errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded); // n >= 1 66 prevOriginal = original; 67 prevEstimated = estimated; 75 // check if both enumerators are at the end to make sure both enumerations have the same length 76 if (actualEnumerator.MoveNext() || predictedEnumerator.MoveNext()) { 77 errorState = errorState | OnlineCalculatorError.InvalidValueAdded; 78 } else { 79 errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded); // n >= 1 80 } 68 81 } 69 82 } … … 72 85 n = 0; 73 86 nCorrect = 0; 74 prevOriginal = double.NaN;75 prevEstimated = double.NaN;76 87 errorState = OnlineCalculatorError.InsufficientElementsAdded; 77 88 } 78 89 79 90 80 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineCalculatorError errorState) { 81 IEnumerator<double> firstEnumerator = first.GetEnumerator(); 82 IEnumerator<double> secondEnumerator = second.GetEnumerator(); 91 public static double Calculate(IEnumerable<double> startValues, IEnumerable<IEnumerable<double>> actualContinuations, IEnumerable<IEnumerable<double>> predictedContinuations, out OnlineCalculatorError errorState) { 92 IEnumerator<double> startValueEnumerator = startValues.GetEnumerator(); 93 IEnumerator<IEnumerable<double>> actualContinuationsEnumerator = actualContinuations.GetEnumerator(); 94 IEnumerator<IEnumerable<double>> predictedContinuationsEnumerator = predictedContinuations.GetEnumerator(); 83 95 OnlineDirectionalSymmetryCalculator dsCalculator = new OnlineDirectionalSymmetryCalculator(); 84 96 85 // add first element of time series as a reference point 86 firstEnumerator.MoveNext(); 87 secondEnumerator.MoveNext(); 88 dsCalculator.Add(firstEnumerator.Current, secondEnumerator.Current); 89 90 // always move forward both enumerators (do not use short-circuit evaluation!) 91 while (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) { 92 double estimated = secondEnumerator.Current; 93 double original = firstEnumerator.Current; 94 dsCalculator.Add(original, estimated); 97 // always move forward all enumerators (do not use short-circuit evaluation!) 98 while (startValueEnumerator.MoveNext() & actualContinuationsEnumerator.MoveNext() & predictedContinuationsEnumerator.MoveNext()) { 99 dsCalculator.Add(startValueEnumerator.Current, actualContinuationsEnumerator.Current, predictedContinuationsEnumerator.Current); 95 100 if (dsCalculator.ErrorState != OnlineCalculatorError.None) break; 96 101 } 97 102 98 // check if bothenumerators are at the end to make sure both enumerations have the same length103 // check if all enumerators are at the end to make sure both enumerations have the same length 99 104 if (dsCalculator.ErrorState == OnlineCalculatorError.None && 100 (s econdEnumerator.MoveNext() || firstEnumerator.MoveNext())) {101 throw new ArgumentException("Number of elements in first and second enumerationdoesn't match.");105 (startValueEnumerator.MoveNext() || actualContinuationsEnumerator.MoveNext() || predictedContinuationsEnumerator.MoveNext())) { 106 throw new ArgumentException("Number of elements in startValues, actualContinuations and estimatedValues predictedContinuations doesn't match."); 102 107 } else { 103 108 errorState = dsCalculator.ErrorState; -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineTheilsUStatisticCalculator.cs
r6802 r7099 22 22 using System; 23 23 using System.Collections.Generic; 24 using HeuristicLab.Common; 24 25 25 26 namespace HeuristicLab.Problems.DataAnalysis { 26 public class OnlineTheilsUStatisticCalculator : IOnline Calculator {27 public class OnlineTheilsUStatisticCalculator : IOnlineTimeSeriesCalculator { 27 28 private OnlineMeanAndVarianceCalculator squaredErrorMeanCalculator; 28 29 private OnlineMeanAndVarianceCalculator unbiasedEstimatorMeanCalculator; 29 private double prevOriginal;30 private int n;31 30 32 31 public double TheilsUStatistic { … … 52 51 } 53 52 54 public void Add(double original, double estimated) {55 if (double.IsNaN( estimated) || double.IsInfinity(estimated) || double.IsNaN(original) || double.IsInfinity(original) || (errorState & OnlineCalculatorError.InvalidValueAdded) > 0) {53 public void Add(double startValue, IEnumerable<double> actualContinuation, IEnumerable<double> predictedContinuation) { 54 if (double.IsNaN(startValue) || (errorState & OnlineCalculatorError.InvalidValueAdded) > 0) { 56 55 errorState = errorState | OnlineCalculatorError.InvalidValueAdded; 57 } else if (n == 0) {58 prevOriginal = original;59 n++;60 56 } else { 61 // error of predicted change 62 double errorEstimatedChange = (estimated - original); 63 squaredErrorMeanCalculator.Add(errorEstimatedChange * errorEstimatedChange); 57 var actualEnumerator = actualContinuation.GetEnumerator(); 58 var predictedEnumerator = predictedContinuation.GetEnumerator(); 59 while (actualEnumerator.MoveNext() & predictedEnumerator.MoveNext() & ErrorState != OnlineCalculatorError.InvalidValueAdded) { 60 double actual = actualEnumerator.Current; 61 double predicted = predictedEnumerator.Current; 62 if (double.IsNaN(actual) || double.IsNaN(predicted)) { 63 errorState = errorState | OnlineCalculatorError.InvalidValueAdded; 64 } else { 65 // error of predicted change 66 double errorPredictedChange = (predicted - startValue) - (actual - startValue); 67 squaredErrorMeanCalculator.Add(errorPredictedChange * errorPredictedChange); 64 68 65 double errorNoChange = (original - prevOriginal); 66 unbiasedEstimatorMeanCalculator.Add(errorNoChange * errorNoChange); 67 errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded); // n >= 1 69 double errorNoChange = (actual - startValue); 70 unbiasedEstimatorMeanCalculator.Add(errorNoChange * errorNoChange); 71 } 72 } 73 // check if both enumerators are at the end to make sure both enumerations have the same length 74 if (actualEnumerator.MoveNext() || predictedEnumerator.MoveNext()) { 75 errorState = errorState | OnlineCalculatorError.InvalidValueAdded; 76 } else { 77 errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded); // n >= 1 78 } 68 79 } 69 80 } 70 81 71 72 82 public void Reset() { 73 prevOriginal = double.NaN;74 n = 0;75 83 squaredErrorMeanCalculator.Reset(); 76 84 unbiasedEstimatorMeanCalculator.Reset(); … … 80 88 #endregion 81 89 82 public static double Calculate(IEnumerable<double> estimatedValues, IEnumerable<double> originalValues, out OnlineCalculatorError errorState) { 83 IEnumerator<double> originalValuesEnumerator = originalValues.GetEnumerator(); 84 IEnumerator<double> estimatedValuesEnumerator = estimatedValues.GetEnumerator(); 90 public static double Calculate(IEnumerable<double> startValues, IEnumerable<IEnumerable<double>> actualContinuations, IEnumerable<IEnumerable<double>> predictedContinuations, out OnlineCalculatorError errorState) { 91 IEnumerator<double> startValueEnumerator = startValues.GetEnumerator(); 92 IEnumerator<IEnumerable<double>> actualContinuationsEnumerator = actualContinuations.GetEnumerator(); 93 IEnumerator<IEnumerable<double>> predictedContinuationsEnumerator = predictedContinuations.GetEnumerator(); 85 94 OnlineTheilsUStatisticCalculator calculator = new OnlineTheilsUStatisticCalculator(); 86 95 87 // add first element of time series as a reference point 88 originalValuesEnumerator.MoveNext(); 89 estimatedValuesEnumerator.MoveNext(); 90 calculator.Add(originalValuesEnumerator.Current, estimatedValuesEnumerator.Current); 91 92 // always move forward both enumerators (do not use short-circuit evaluation!) 93 while (originalValuesEnumerator.MoveNext() & estimatedValuesEnumerator.MoveNext()) { 94 double estimated = estimatedValuesEnumerator.Current; 95 double original = originalValuesEnumerator.Current; 96 calculator.Add(original, estimated); 96 // always move forward all enumerators (do not use short-circuit evaluation!) 97 while (startValueEnumerator.MoveNext() & actualContinuationsEnumerator.MoveNext() & predictedContinuationsEnumerator.MoveNext()) { 98 calculator.Add(startValueEnumerator.Current, actualContinuationsEnumerator.Current, predictedContinuationsEnumerator.Current); 97 99 if (calculator.ErrorState != OnlineCalculatorError.None) break; 98 100 } 99 101 100 // check if bothenumerators are at the end to make sure both enumerations have the same length102 // check if all enumerators are at the end to make sure both enumerations have the same length 101 103 if (calculator.ErrorState == OnlineCalculatorError.None && 102 ( estimatedValuesEnumerator.MoveNext() || originalValuesEnumerator.MoveNext())) {103 throw new ArgumentException("Number of elements in first and second enumerationdoesn't match.");104 (startValueEnumerator.MoveNext() || actualContinuationsEnumerator.MoveNext() || predictedContinuationsEnumerator.MoveNext())) { 105 throw new ArgumentException("Number of elements in startValues, actualContinuations and estimatedValues predictedContinuations doesn't match."); 104 106 } else { 105 107 errorState = calculator.ErrorState; -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineWeightedDirectionalSymmetryCalculator.cs
r6802 r7099 22 22 using System; 23 23 using System.Collections.Generic; 24 using HeuristicLab.Common; 24 25 25 26 26 27 namespace HeuristicLab.Problems.DataAnalysis { 27 public class OnlineWeightedDirectionalSymmetryCalculator : IOnline Calculator {28 public class OnlineWeightedDirectionalSymmetryCalculator : IOnlineTimeSeriesCalculator { 28 29 private double prevEstimated; 29 30 private double prevOriginal; … … 52 53 } 53 54 54 public void Add(double original, double estimated) {55 if (double.IsNaN( estimated) || double.IsInfinity(estimated) || double.IsNaN(original) || double.IsInfinity(original) || (errorState & OnlineCalculatorError.InvalidValueAdded) > 0) {55 public void Add(double startValue, IEnumerable<double> actualContinuation, IEnumerable<double> predictedContinuation) { 56 if (double.IsNaN(startValue) || (errorState & OnlineCalculatorError.InvalidValueAdded) > 0) { 56 57 errorState = errorState | OnlineCalculatorError.InvalidValueAdded; 57 } else if (n == 0) {58 prevOriginal = original;59 prevEstimated = estimated;60 n++;61 58 } else { 62 double err = Math.Abs(original - estimated); 63 if ((original - prevOriginal) * (estimated - prevEstimated) >= 0.0) { 64 correctSum += err; 59 var actualEnumerator = actualContinuation.GetEnumerator(); 60 var predictedEnumerator = predictedContinuation.GetEnumerator(); 61 while (actualEnumerator.MoveNext() & predictedEnumerator.MoveNext() & errorState != OnlineCalculatorError.InvalidValueAdded) { 62 double actual = actualEnumerator.Current; 63 double predicted = predictedEnumerator.Current; 64 if (double.IsNaN(actual) || double.IsNaN(predicted)) { 65 errorState = errorState | OnlineCalculatorError.InvalidValueAdded; 66 } else { 67 double err = Math.Abs(actual - predicted); 68 // count as correct only if the trend (positive/negative/no change) is predicted correctly 69 if ((actual - startValue) * (predicted - startValue) > 0.0 || 70 (actual - startValue).IsAlmost(predicted - startValue)) { 71 correctSum += err; 72 } else { 73 incorrectSum += err; 74 } 75 n++; 76 } 77 } 78 // check if both enumerators are at the end to make sure both enumerations have the same length 79 if (actualEnumerator.MoveNext() || predictedEnumerator.MoveNext()) { 80 errorState = errorState | OnlineCalculatorError.InvalidValueAdded; 65 81 } else { 66 incorrectSum += err;82 errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded); // n >= 1 67 83 } 68 n++;69 errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded); // n >= 170 prevOriginal = original;71 prevEstimated = estimated;72 84 } 73 85 } … … 83 95 84 96 85 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineCalculatorError errorState) { 86 IEnumerator<double> firstEnumerator = first.GetEnumerator(); 87 IEnumerator<double> secondEnumerator = second.GetEnumerator(); 88 OnlineDirectionalSymmetryCalculator dsCalculator = new OnlineDirectionalSymmetryCalculator(); 89 90 // add first element of time series as a reference point 91 firstEnumerator.MoveNext(); 92 secondEnumerator.MoveNext(); 93 dsCalculator.Add(firstEnumerator.Current, secondEnumerator.Current); 97 public static double Calculate(IEnumerable<double> startValues, IEnumerable<IEnumerable<double>> actualContinuations, IEnumerable<IEnumerable<double>> predictedContinuations, out OnlineCalculatorError errorState) { 98 IEnumerator<double> startValueEnumerator = startValues.GetEnumerator(); 99 IEnumerator<IEnumerable<double>> actualContinuationsEnumerator = actualContinuations.GetEnumerator(); 100 IEnumerator<IEnumerable<double>> predictedContinuationsEnumerator = predictedContinuations.GetEnumerator(); 101 OnlineWeightedDirectionalSymmetryCalculator calculator = new OnlineWeightedDirectionalSymmetryCalculator(); 94 102 95 // always move forward both enumerators (do not use short-circuit evaluation!) 96 while (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) { 97 double estimated = secondEnumerator.Current; 98 double original = firstEnumerator.Current; 99 dsCalculator.Add(original, estimated); 100 if (dsCalculator.ErrorState != OnlineCalculatorError.None) break; 103 // always move forward all enumerators (do not use short-circuit evaluation!) 104 while (startValueEnumerator.MoveNext() & actualContinuationsEnumerator.MoveNext() & predictedContinuationsEnumerator.MoveNext()) { 105 calculator.Add(startValueEnumerator.Current, actualContinuationsEnumerator.Current, predictedContinuationsEnumerator.Current); 106 if (calculator.ErrorState != OnlineCalculatorError.None) break; 101 107 } 102 108 103 // check if bothenumerators are at the end to make sure both enumerations have the same length104 if ( dsCalculator.ErrorState == OnlineCalculatorError.None &&105 (s econdEnumerator.MoveNext() || firstEnumerator.MoveNext())) {106 throw new ArgumentException("Number of elements in first and second enumerationdoesn't match.");109 // check if all enumerators are at the end to make sure both enumerations have the same length 110 if (calculator.ErrorState == OnlineCalculatorError.None && 111 (startValueEnumerator.MoveNext() || actualContinuationsEnumerator.MoveNext() || predictedContinuationsEnumerator.MoveNext())) { 112 throw new ArgumentException("Number of elements in startValues, actualContinuations and estimatedValues predictedContinuations doesn't match."); 107 113 } else { 108 errorState = dsCalculator.ErrorState;109 return dsCalculator.DirectionalSymmetry;114 errorState = calculator.ErrorState; 115 return calculator.WeightedDirectionalSymmetry; 110 116 } 111 117 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis-3.4/StatisticCalculatorsTest.cs
r7097 r7099 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 139 140 } 140 141 } 142 143 [TestMethod] 144 public void CalculateDirectionalSymmetryTest() { 145 // delta: +0.01, +1, -0.01, -2, -0.01, -1, +0.01, +2 146 var original = new double[] 147 { 148 0, 149 0.01, 150 1.01, 151 1, 152 -1, 153 -1.01, 154 -2.01, 155 -2, 156 0 157 }; 158 // delta to original(t-1): +1, +0, -1, -0, -1, +0.01, +0.01, +2 159 var estimated = new double[] 160 { 161 -1, 162 1, 163 0.01, 164 0.01, 165 1, 166 -1, 167 -1.02, 168 -2.02, 169 0 170 }; 171 172 // one-step forecast 173 var startValues = original; 174 var actualContinuations = from x in original.Skip(1) 175 select Enumerable.Repeat(x, 1); 176 var predictedContinuations = from x in estimated.Skip(1) 177 select Enumerable.Repeat(x, 1); 178 double expected = 0.5; // half of the predicted deltas are correct 179 OnlineCalculatorError errorState; 180 double actual = OnlineDirectionalSymmetryCalculator.Calculate(startValues, actualContinuations, predictedContinuations, out errorState); 181 Assert.AreEqual(expected, actual, 1E-9); 182 } 183 184 [TestMethod] 185 public void CalculateMultiStepDirectionalSymmetryTest() { 186 // delta: +0.01, +1, -0.01, -2, -0.01, -1, +0.01, +2 187 var original = new double[] { 0, 0.01, 1.01, 1, -1, -1.01, -2.01, -2, 0 }; 188 { 189 var estimated = new double[][] 190 { 191 new double[] {0.01, 1.01, 1, -1, -1.01}, 192 new double[] {1.01, 1, -1, -1.01, -2.01}, 193 new double[] {1, -1, -1.01, -2.01, -2}, 194 new double[] {-1, -1.01, -2.01, -2, 0} 195 }; 196 197 // 5-step forecast 198 var startValues = original.Take(4); 199 var actualContinuations = from i in Enumerable.Range(1, original.Count() - 5) 200 select original.Skip(i).Take(5); 201 var predictedContinuations = estimated; 202 double expected = 1; // predictions are 100% correct 203 OnlineCalculatorError errorState; 204 double actual = OnlineDirectionalSymmetryCalculator.Calculate(startValues, actualContinuations, 205 predictedContinuations, out errorState); 206 Assert.AreEqual(expected, actual, 1E-9); 207 } 208 { 209 // only the direction is relevant 210 var estimated = new double[][] 211 { 212 new double[] {0.01, 0.01, 0.01, -0.01, -0.01}, // start=0, original deltas: 0.01, 1.01, 1.00, -1.00, -1.01 213 new double[] {0.02, 0.02, 0.00, 0.00, 0.00}, // start=0.01, original deltas: 1.00, 0.90, -1.01, -1.02, -2.02, 214 new double[] { 1.00, 1.00, 1.00, 1.00, 1.00}, // start=1.01, original deltas: -0.01, -2.01, -2.02, -3.02, -3.01 215 new double[] { 0.90, 0.90, 0.90, 0.90, 0.90} // start=1, original deltas: -2.00, -0.01, -3.01, -3.00, -1.00 216 }; 217 218 // 5-step forecast 219 var startValues = original.Take(4); 220 var actualContinuations = from i in Enumerable.Range(1, original.Count() - 5) 221 select original.Skip(i).Take(5); 222 var predictedContinuations = estimated; 223 double expected = 1; // half of the predicted deltas are correct 224 OnlineCalculatorError errorState; 225 double actual = OnlineDirectionalSymmetryCalculator.Calculate(startValues, actualContinuations, 226 predictedContinuations, out errorState); 227 Assert.AreEqual(expected, actual, 1E-9); 228 } 229 { 230 // also check incorrectly predicted directions 231 var estimated = new double[][] 232 { 233 new double[] {0.01, 0.01, 0.01, +0.01, +0.01}, // start=0, original deltas: 0.01, 1.01, 1.00, -1.00, -1.01 234 new double[] {0.02, 0.00, 0.02, 0.00, 0.00}, // start=0.01, original deltas: 1.00, 0.90, -1.01, -1.02, -2.02, 235 new double[] { 1.02, 1.00, 1.02, 1.00, 1.02}, // start=1.01, original deltas: -0.01, -2.01, -2.02, -3.02, -3.01 236 new double[] { 0.90, 0.90, 0.90, 0.90, 0.90} // start=1, original deltas: -2.00, -0.01, -3.01, -3.00, -1.00 237 }; 238 239 // 5-step forecast 240 var startValues = original.Take(4); 241 var actualContinuations = from i in Enumerable.Range(1, original.Count() - 5) 242 select original.Skip(i).Take(5); 243 var predictedContinuations = estimated; 244 double expected = (20 - 7) / 20.0; // half of the predicted deltas are correct 245 OnlineCalculatorError errorState; 246 double actual = OnlineDirectionalSymmetryCalculator.Calculate(startValues, actualContinuations, 247 predictedContinuations, out errorState); 248 Assert.AreEqual(expected, actual, 1E-9); 249 } 250 } 251 252 253 [TestMethod] 254 public void CalculateWeightedDirectionalSymmetryTest() { 255 var original = new double[] { 0, 0.01, 1.01, 1, -1, -1.01, -2.01, -2, 0 }; // +0.01, +1, -0.01, -2, -0.01, -1, +0.01, +2 256 var estimated = new double[] { 1, 2, 2, 1, 1, 0, 0.01, 0.02, 2.02 }; // delta to original: +2, +1.99, -0.01, 0, +1, -1.02, +2.01, +4.02 257 // one-step forecast 258 var startValues = original; 259 var actualContinuations = from x in original.Skip(1) 260 select Enumerable.Repeat(x, 1); 261 var predictedContinuations = from x in estimated.Skip(1) 262 select Enumerable.Repeat(x, 1); 263 // absolute errors = 1.99, 0.99, 0, 2, 1.01, 2.02, 2.02, 2.02 264 // sum of absolute errors for correctly predicted deltas = 2.97 265 // sum of absolute errors for incorrectly predicted deltas = 3.03 266 double expected = 5.03 / 7.02; 267 OnlineCalculatorError errorState; 268 double actual = OnlineWeightedDirectionalSymmetryCalculator.Calculate(startValues, actualContinuations, predictedContinuations, out errorState); 269 Assert.AreEqual(expected, actual, 1E-9); 270 } 271 272 [TestMethod] 273 public void CalculateTheilsUTest() { 274 var original = new double[] { 0, 0.01, 1.01, 1, -1, -1.01, -2.01, -2, 0 }; 275 var estimated = new double[] { 1, 1.01, 0.01, 2, 0, -0.01, -1.01, -3, 1 }; 276 // one-step forecast 277 var startValues = original; 278 var actualContinuations = from x in original.Skip(1) 279 select Enumerable.Repeat(x, 1); 280 var predictedContinuations = from x in estimated.Skip(1) 281 select Enumerable.Repeat(x, 1); 282 // Sum of squared errors of model y(t+1) = y(t) = 10.0004 283 // Sum of squared errors of predicted values = 8 284 double expected = Math.Sqrt(8 / 10.0004); 285 OnlineCalculatorError errorState; 286 double actual = OnlineTheilsUStatisticCalculator.Calculate(startValues, actualContinuations, predictedContinuations, out errorState); 287 Assert.AreEqual(expected, actual, 1E-9); 288 } 289 290 [TestMethod] 291 public void CalculateMultiStepTheilsUTest() { 292 var original = new double[] { 0, 0.01, 1.01, 1, -1, -1.01, -2.01, -2, 0 }; 293 { 294 // prefect prediction 295 var estimated = new double[][] 296 { 297 new double[] {0.01, 1.01, 1, -1, -1.01}, 298 new double[] {1.01, 1, -1, -1.01, -2.01}, 299 new double[] {1, -1, -1.01, -2.01, -2}, 300 new double[] {-1, -1.01, -2.01, -2, 0} 301 }; 302 // 5-step forecast 303 var startValues = original.Take(4); 304 var actualContinuations = from i in Enumerable.Range(1, original.Count() - 5) 305 select original.Skip(i).Take(5); 306 var predictedContinuations = estimated; 307 308 double expected = 0; 309 OnlineCalculatorError errorState; 310 double actual = OnlineTheilsUStatisticCalculator.Calculate(startValues, actualContinuations, 311 predictedContinuations, out errorState); 312 Assert.AreEqual(expected, actual, 1E-9); 313 } 314 { 315 // naive prediction 316 var estimated = new double[][] 317 { 318 new double[] {0, 0, 0, 0, 0}, 319 new double[] {0.01, 0.01, 0.01, 0.01, 0.01}, 320 new double[] {1.01, 1.01, 1.01, 1.01, 1.01}, 321 new double[] {1, 1, 1, 1, 1} 322 }; 323 // 5-step forecast 324 var startValues = original.Take(4); 325 var actualContinuations = from i in Enumerable.Range(1, original.Count() - 5) 326 select original.Skip(i).Take(5); 327 var predictedContinuations = estimated; 328 329 double expected = 1; 330 OnlineCalculatorError errorState; 331 double actual = OnlineTheilsUStatisticCalculator.Calculate(startValues, actualContinuations, 332 predictedContinuations, out errorState); 333 Assert.AreEqual(expected, actual, 1E-9); 334 } 335 { 336 // realistic prediction 337 var estimated = new double[][] 338 { 339 new double[] {0.005, 0.5, 0.5, -0.5, -0.5}, // start = 0 340 new double[] {0.60, 0.5, -0.5, -0.5, -1}, // start = 0.01 341 new double[] {-0.005, 0, 0, -0.5, -1}, // start = 1.01 342 new double[] {-0, 0, -0.5, -1, 0.5} // start = 1 343 }; 344 // 5-step forecast 345 var startValues = original.Take(4); 346 var actualContinuations = from i in Enumerable.Range(1, original.Count() - 5) 347 select original.Skip(i).Take(5); 348 var predictedContinuations = estimated; 349 350 double expected = 0.47558387; 351 OnlineCalculatorError errorState; 352 double actual = OnlineTheilsUStatisticCalculator.Calculate(startValues, actualContinuations, 353 predictedContinuations, out errorState); 354 Assert.AreEqual(expected, actual, 1E-6); 355 } 356 } 357 358 [TestMethod] 359 public void CalculateAccuracyTest() { 360 var original = new double[] { 1, 1, 0, 0 }; 361 var estimated = new double[] { 1, 0, 1, 0 }; 362 double expected = 0.5; 363 OnlineCalculatorError errorState; 364 double actual = OnlineAccuracyCalculator.Calculate(original, estimated, out errorState); 365 Assert.AreEqual(expected, actual, 1E-9); 366 } 367 368 [TestMethod] 369 public void CalculateMeanAbsolutePercentageErrorTest() { 370 var original = new double[] { 1, 2, 3, 1, 5 }; 371 var estimated = new double[] { 2, 1, 3, 1, 0 }; 372 double expected = 0.5; 373 OnlineCalculatorError errorState; 374 double actual = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(original, estimated, out errorState); 375 Assert.AreEqual(expected, actual, 1E-9); 376 Assert.AreEqual(OnlineCalculatorError.None, errorState); 377 378 // if the original contains zero values the result is not defined 379 var original2 = new double[] { 1, 2, 0, 0, 0 }; 380 OnlineMeanAbsolutePercentageErrorCalculator.Calculate(original2, estimated, out errorState); 381 Assert.AreEqual(OnlineCalculatorError.InvalidValueAdded, errorState); 382 } 141 383 } 142 384 }
Note: See TracChangeset
for help on using the changeset viewer.