forked from tsai/mathnet-numerics
549 changed files with 17198 additions and 11432 deletions
@ -0,0 +1,124 @@ |
|||||
|
|
||||
|
Microsoft Visual Studio Solution File, Format Version 12.00 |
||||
|
# Visual Studio 2013 |
||||
|
VisualStudioVersion = 12.0.21005.1 |
||||
|
MinimumVisualStudioVersion = 10.0.40219.1 |
||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{5A0892FF-82CE-40FC-BCE1-73810C615F52}" |
||||
|
ProjectSection(SolutionItems) = preProject |
||||
|
src\NativeProviders\Common\lapack_common.h = src\NativeProviders\Common\lapack_common.h |
||||
|
src\NativeProviders\Common\resource.h = src\NativeProviders\Common\resource.h |
||||
|
src\NativeProviders\Common\resource.rc = src\NativeProviders\Common\resource.rc |
||||
|
src\NativeProviders\Common\WindowsDLL.cpp = src\NativeProviders\Common\WindowsDLL.cpp |
||||
|
src\NativeProviders\Common\wrapper_common.h = src\NativeProviders\Common\wrapper_common.h |
||||
|
EndProjectSection |
||||
|
EndProject |
||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MKL", "src\NativeProviders\Windows\MKL\MKLWrapper.vcxproj", "{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}" |
||||
|
EndProject |
||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ATLAS", "src\NativeProviders\Windows\ATLAS\ATLASWrapper.vcxproj", "{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}" |
||||
|
EndProject |
||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Numerics", "src\Numerics\Numerics.csproj", "{B7CAE5F4-A23F-4438-B5BE-41226618B695}" |
||||
|
EndProject |
||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests-MKL", "src\UnitTests\UnitTests-MKL.csproj", "{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}" |
||||
|
EndProject |
||||
|
Global |
||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
||||
|
Debug|Any CPU = Debug|Any CPU |
||||
|
Debug|Mixed Platforms = Debug|Mixed Platforms |
||||
|
Debug|Win32 = Debug|Win32 |
||||
|
Debug|x64 = Debug|x64 |
||||
|
Release|Any CPU = Release|Any CPU |
||||
|
Release|Mixed Platforms = Release|Mixed Platforms |
||||
|
Release|Win32 = Release|Win32 |
||||
|
Release|x64 = Release|x64 |
||||
|
Release-Signed|Any CPU = Release-Signed|Any CPU |
||||
|
Release-Signed|Mixed Platforms = Release-Signed|Mixed Platforms |
||||
|
Release-Signed|Win32 = Release-Signed|Win32 |
||||
|
Release-Signed|x64 = Release-Signed|x64 |
||||
|
EndGlobalSection |
||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|Any CPU.ActiveCfg = Debug|Win32 |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|Mixed Platforms.Build.0 = Debug|Win32 |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|Win32.ActiveCfg = Debug|Win32 |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|Win32.Build.0 = Debug|Win32 |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|x64.ActiveCfg = Debug|x64 |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|x64.Build.0 = Debug|x64 |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Release|Any CPU.ActiveCfg = Release|Win32 |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Release|Mixed Platforms.ActiveCfg = Release|Win32 |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Release|Mixed Platforms.Build.0 = Release|Win32 |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Release|Win32.ActiveCfg = Release|Win32 |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Release|Win32.Build.0 = Release|Win32 |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Release|x64.ActiveCfg = Release|x64 |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Release|x64.Build.0 = Release|x64 |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Release-Signed|Any CPU.ActiveCfg = Release|Win32 |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Release-Signed|Mixed Platforms.ActiveCfg = Release|Win32 |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Release-Signed|Mixed Platforms.Build.0 = Release|Win32 |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Release-Signed|Win32.ActiveCfg = Release|Win32 |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Release-Signed|Win32.Build.0 = Release|Win32 |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Release-Signed|x64.ActiveCfg = Release|x64 |
||||
|
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Release-Signed|x64.Build.0 = Release|x64 |
||||
|
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Debug|Any CPU.ActiveCfg = Debug|Win32 |
||||
|
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 |
||||
|
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Debug|Mixed Platforms.Build.0 = Debug|Win32 |
||||
|
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Debug|Win32.ActiveCfg = Debug|Win32 |
||||
|
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Debug|x64.ActiveCfg = Debug|x64 |
||||
|
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Release|Any CPU.ActiveCfg = Release|Win32 |
||||
|
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Release|Mixed Platforms.ActiveCfg = Release|Win32 |
||||
|
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Release|Win32.ActiveCfg = Release|Win32 |
||||
|
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Release|x64.ActiveCfg = Release|x64 |
||||
|
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Release-Signed|Any CPU.ActiveCfg = Release|Win32 |
||||
|
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Release-Signed|Mixed Platforms.ActiveCfg = Release|Win32 |
||||
|
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Release-Signed|Mixed Platforms.Build.0 = Release|Win32 |
||||
|
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Release-Signed|Win32.ActiveCfg = Release|Win32 |
||||
|
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Release-Signed|Win32.Build.0 = Release|Win32 |
||||
|
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Release-Signed|x64.ActiveCfg = Release|x64 |
||||
|
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Release-Signed|x64.Build.0 = Release|x64 |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Debug|Win32.ActiveCfg = Debug|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Debug|Win32.Build.0 = Debug|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Debug|x64.ActiveCfg = Debug|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Debug|x64.Build.0 = Debug|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Release|Mixed Platforms.Build.0 = Release|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Release|Win32.ActiveCfg = Release|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Release|Win32.Build.0 = Release|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Release|x64.ActiveCfg = Release|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Release|x64.Build.0 = Release|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Release-Signed|Any CPU.ActiveCfg = Release-Signed|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Release-Signed|Any CPU.Build.0 = Release-Signed|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Release-Signed|Mixed Platforms.ActiveCfg = Release-Signed|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Release-Signed|Mixed Platforms.Build.0 = Release-Signed|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Release-Signed|Win32.ActiveCfg = Release-Signed|Any CPU |
||||
|
{B7CAE5F4-A23F-4438-B5BE-41226618B695}.Release-Signed|x64.ActiveCfg = Release-Signed|Any CPU |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Debug|Win32.ActiveCfg = Debug|x86 |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Debug|Win32.Build.0 = Debug|x86 |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Debug|x64.ActiveCfg = Debug|x64 |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Debug|x64.Build.0 = Debug|x64 |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release|Mixed Platforms.Build.0 = Release|Any CPU |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release|Win32.ActiveCfg = Release|x86 |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release|Win32.Build.0 = Release|x86 |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release|x64.ActiveCfg = Release|x64 |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release|x64.Build.0 = Release|x64 |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release-Signed|Any CPU.ActiveCfg = Release|Any CPU |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release-Signed|Any CPU.Build.0 = Release|Any CPU |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release-Signed|Mixed Platforms.ActiveCfg = Release|Any CPU |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release-Signed|Mixed Platforms.Build.0 = Release|Any CPU |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release-Signed|Win32.ActiveCfg = Release|Any CPU |
||||
|
{3515A344-AB5F-41C7-A14C-04A79B3FFAB1}.Release-Signed|x64.ActiveCfg = Release|Any CPU |
||||
|
EndGlobalSection |
||||
|
GlobalSection(SolutionProperties) = preSolution |
||||
|
HideSolutionNode = FALSE |
||||
|
EndGlobalSection |
||||
|
EndGlobal |
||||
@ -0,0 +1,43 @@ |
|||||
|
|
||||
|
Microsoft Visual Studio Solution File, Format Version 12.00 |
||||
|
# Visual Studio 2013 |
||||
|
VisualStudioVersion = 12.0.21005.1 |
||||
|
MinimumVisualStudioVersion = 10.0.40219.1 |
||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Readme", "Readme", "{C2F37492-38AE-4186-8A7F-17B0B080942C}" |
||||
|
ProjectSection(SolutionItems) = preProject |
||||
|
CONTRIBUTING.md = CONTRIBUTING.md |
||||
|
CONTRIBUTORS.md = CONTRIBUTORS.md |
||||
|
LICENSE.md = LICENSE.md |
||||
|
MAINTAINING.md = MAINTAINING.md |
||||
|
README.md = README.md |
||||
|
RELEASENOTES.md = RELEASENOTES.md |
||||
|
EndProjectSection |
||||
|
EndProject |
||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Numerics-Net35", "src\Numerics\Numerics-Net35.csproj", "{E54E712D-EB6B-4FBF-B29A-6BB95E719BAC}" |
||||
|
EndProject |
||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests-Net35", "src\UnitTests\UnitTests-Net35.csproj", "{9014A0CE-725D-4718-918C-923C0CA19FEE}" |
||||
|
EndProject |
||||
|
Global |
||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
||||
|
Debug|Any CPU = Debug|Any CPU |
||||
|
Release|Any CPU = Release|Any CPU |
||||
|
Release-Signed|Any CPU = Release-Signed|Any CPU |
||||
|
EndGlobalSection |
||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
||||
|
{E54E712D-EB6B-4FBF-B29A-6BB95E719BAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
|
{E54E712D-EB6B-4FBF-B29A-6BB95E719BAC}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
|
{E54E712D-EB6B-4FBF-B29A-6BB95E719BAC}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
|
{E54E712D-EB6B-4FBF-B29A-6BB95E719BAC}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
|
{E54E712D-EB6B-4FBF-B29A-6BB95E719BAC}.Release-Signed|Any CPU.ActiveCfg = Release-Signed|Any CPU |
||||
|
{E54E712D-EB6B-4FBF-B29A-6BB95E719BAC}.Release-Signed|Any CPU.Build.0 = Release-Signed|Any CPU |
||||
|
{9014A0CE-725D-4718-918C-923C0CA19FEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
|
{9014A0CE-725D-4718-918C-923C0CA19FEE}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
|
{9014A0CE-725D-4718-918C-923C0CA19FEE}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
|
{9014A0CE-725D-4718-918C-923C0CA19FEE}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
|
{9014A0CE-725D-4718-918C-923C0CA19FEE}.Release-Signed|Any CPU.ActiveCfg = Release|Any CPU |
||||
|
{9014A0CE-725D-4718-918C-923C0CA19FEE}.Release-Signed|Any CPU.Build.0 = Release|Any CPU |
||||
|
EndGlobalSection |
||||
|
GlobalSection(SolutionProperties) = preSolution |
||||
|
HideSolutionNode = FALSE |
||||
|
EndGlobalSection |
||||
|
EndGlobal |
||||
@ -0,0 +1,71 @@ |
|||||
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> |
||||
|
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=Full_0020Cleanup_0020_0028Math_002ENET_0029/@EntryIndexedValue"><?xml version="1.0" encoding="utf-16"?><Profile name="Full Cleanup (Math.NET)"><CSArrangeThisQualifier>True</CSArrangeThisQualifier><CSRemoveCodeRedundancies>True</CSRemoveCodeRedundancies><CSUseAutoProperty>True</CSUseAutoProperty><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSUpdateFileHeader>True</CSUpdateFileHeader><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSShortenReferences>True</CSShortenReferences><CSReformatCode>True</CSReformatCode><XMLReformatCode>True</XMLReformatCode><CssAlphabetizeProperties>True</CssAlphabetizeProperties><CssReformatCode>True</CssReformatCode><JsReformatCode>True</JsReformatCode><JsInsertSemicolon>True</JsInsertSemicolon><VBFormatDocComments>True</VBFormatDocComments><VBReformatCode>True</VBReformatCode><VBShortenReferences>True</VBShortenReferences><VBOptimizeImports>True</VBOptimizeImports><HtmlReformatCode>True</HtmlReformatCode><AspOptimizeRegisterDirectives>True</AspOptimizeRegisterDirectives><CSReorderTypeMembers>True</CSReorderTypeMembers><CSUseVar><BehavourStyle>CAN_CHANGE_BOTH</BehavourStyle><LocalVariableStyle>IMPLICIT_WHEN_INITIALIZER_HAS_TYPE</LocalVariableStyle><ForeachVariableStyle>ALWAYS_EXPLICIT</ForeachVariableStyle></CSUseVar></Profile></s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/CodeCleanup/RecentlyUsedProfile/@EntryValue">Full Cleanup (Math.NET)</s:String> |
||||
|
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_LINQ_QUERY/@EntryValue">False</s:Boolean> |
||||
|
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_ARGUMENT/@EntryValue">False</s:Boolean> |
||||
|
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_ARRAY_AND_OBJECT_INITIALIZER/@EntryValue">False</s:Boolean> |
||||
|
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_EXPRESSION/@EntryValue">False</s:Boolean> |
||||
|
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_EXTENDS_LIST/@EntryValue">False</s:Boolean> |
||||
|
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_PARAMETER/@EntryValue">False</s:Boolean> |
||||
|
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTLINE_TYPE_PARAMETER_CONSTRAINS/@EntryValue">False</s:Boolean> |
||||
|
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTLINE_TYPE_PARAMETER_LIST/@EntryValue">False</s:Boolean> |
||||
|
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/EXPLICIT_PRIVATE_MODIFIER/@EntryValue">False</s:Boolean> |
||||
|
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_ANONYMOUS_METHOD_BLOCK/@EntryValue">False</s:Boolean> |
||||
|
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_EMBRACED_INITIALIZER_BLOCK/@EntryValue">False</s:Boolean> |
||||
|
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/LINE_FEED_AT_FILE_END/@EntryValue">True</s:Boolean> |
||||
|
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_FIELD_ATTRIBUTE_ON_SAME_LINE/@EntryValue">False</s:Boolean> |
||||
|
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_ACCESSOR_ATTRIBUTE_ON_SAME_LINE/@EntryValue">False</s:Boolean> |
||||
|
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_BEFORE_BINARY_OPSIGN/@EntryValue">True</s:Boolean> |
||||
|
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LINES/@EntryValue">False</s:Boolean> |
||||
|
<s:String x:Key="/Default/CodeStyle/FileHeader/FileHeaderText/@EntryValue"><copyright file="$FILENAME$" company="Math.NET">
 |
||||
|
Math.NET Numerics, part of the Math.NET Project
 |
||||
|
http://numerics.mathdotnet.com
 |
||||
|
http://github.com/mathnet/mathnet-numerics
 |
||||
|
http://mathnetnumerics.codeplex.com
 |
||||
|

 |
||||
|
Copyright (c) 2009-$CURRENT_YEAR$ Math.NET
 |
||||
|

 |
||||
|
Permission is hereby granted, free of charge, to any person
 |
||||
|
obtaining a copy of this software and associated documentation
 |
||||
|
files (the "Software"), to deal in the Software without
 |
||||
|
restriction, including without limitation the rights to use,
 |
||||
|
copy, modify, merge, publish, distribute, sublicense, and/or sell
 |
||||
|
copies of the Software, and to permit persons to whom the
 |
||||
|
Software is furnished to do so, subject to the following
 |
||||
|
conditions:
 |
||||
|

 |
||||
|
The above copyright notice and this permission notice shall be
 |
||||
|
included in all copies or substantial portions of the Software.
 |
||||
|

 |
||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 |
||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 |
||||
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 |
||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 |
||||
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 |
||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 |
||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 |
||||
|
OTHER DEALINGS IN THE SOFTWARE.
 |
||||
|
</copyright></s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CDF/@EntryIndexedValue">CDF</s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DFT/@EntryIndexedValue">DFT</s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FFT/@EntryIndexedValue">FFT</s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ILU/@EntryIndexedValue">ILU</s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ILUTP/@EntryIndexedValue">ILUTP</s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=LU/@EntryIndexedValue">LU</s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MAE/@EntryIndexedValue">MAE</s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MC/@EntryIndexedValue">MC</s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MCMC/@EntryIndexedValue">MCMC</s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MILU/@EntryIndexedValue">MILU</s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MSE/@EntryIndexedValue">MSE</s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=PDF/@EntryIndexedValue">PDF</s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=QR/@EntryIndexedValue">QR</s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SAD/@EntryIndexedValue">SAD</s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SAS/@EntryIndexedValue">SAS</s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SPSS/@EntryIndexedValue">SPSS</s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SSD/@EntryIndexedValue">SSD</s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SVD/@EntryIndexedValue">SVD</s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TFQMR/@EntryIndexedValue">TFQMR</s:String> |
||||
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WH/@EntryIndexedValue">WH</s:String> |
||||
|
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean> |
||||
|
<s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue"><data /></s:String> |
||||
|
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue"><data><IncludeFilters /><ExcludeFilters /></data></s:String></wpf:ResourceDictionary> |
||||
@ -0,0 +1,2 @@ |
|||||
|
repositories.config text |
||||
|
* -text |
||||
Binary file not shown.
@ -0,0 +1,24 @@ |
|||||
|
<?xml version="1.0"?> |
||||
|
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"> |
||||
|
<metadata> |
||||
|
<id>TaskParallelLibrary</id> |
||||
|
<version>1.0.2856.0</version> |
||||
|
<title>Task Parallel Library for .NET 3.5</title> |
||||
|
<authors>Microsoft Corporation</authors> |
||||
|
<owners>Microsoft Corporation</owners> |
||||
|
<licenseUrl>http://go.microsoft.com/fwlink/?LinkID=186234</licenseUrl> |
||||
|
<projectUrl>http://msdn.microsoft.com/en-us/library/dd460717.aspx</projectUrl> |
||||
|
<iconUrl>http://i.msdn.microsoft.com/ee402630.NET_lg.png</iconUrl> |
||||
|
<requireLicenseAcceptance>true</requireLicenseAcceptance> |
||||
|
<description>The package includes: |
||||
|
* Task<T> for executing asynchronous operations. |
||||
|
* Concurrent Collections such as ConcurrentStack, ConcurentQueue ad ConcurrentDictionary. |
||||
|
* PLINQ for writing parallel queries. |
||||
|
* additional Threading operations such as Barrier,SpinLock and SpinWait.</description> |
||||
|
<summary>A complete and official Microsoft backport of the Task Parallel Library (TPL) for .NET 3.5.</summary> |
||||
|
<releaseNotes>This backport was shipped with the Reactive Extensions (Rx) library up until v1.0.2856.0. It can be downloaded from http://www.microsoft.com/download/en/details.aspx?id=24940 .</releaseNotes> |
||||
|
<copyright /> |
||||
|
<language /> |
||||
|
<tags>tpl plinq pfx task parallel extensions .net35 backport</tags> |
||||
|
</metadata> |
||||
|
</package> |
||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,11 @@ |
|||||
|
The files below can be distributed as described in the MICROSOFT REACTIVE EXTENSTIONS FOR JAVASCRIPT AND .NET LIBRARIES License. |
||||
|
|
||||
|
System.Observable.dll |
||||
|
System.CoreEx.dll |
||||
|
System.Reactive.dll |
||||
|
System.Interactive.dll |
||||
|
System.Threading.dll |
||||
|
System.Linq.Async.dll |
||||
|
System.Reactive.Testing.dll |
||||
|
System.Reactive.ClientProfile.dll |
||||
|
System.Reactive.ExtendedProfile.dll |
||||
@ -0,0 +1,145 @@ |
|||||
|
// <copyright file="TriangularDistribution.cs" company="Math.NET">
|
||||
|
// Math.NET Numerics, part of the Math.NET Project
|
||||
|
// http://numerics.mathdotnet.com
|
||||
|
// http://github.com/mathnet/mathnet-numerics
|
||||
|
// http://mathnetnumerics.codeplex.com
|
||||
|
// Copyright (c) 2009-2010 Math.NET
|
||||
|
// Permission is hereby granted, free of charge, to any person
|
||||
|
// obtaining a copy of this software and associated documentation
|
||||
|
// files (the "Software"), to deal in the Software without
|
||||
|
// restriction, including without limitation the rights to use,
|
||||
|
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
|
// copies of the Software, and to permit persons to whom the
|
||||
|
// Software is furnished to do so, subject to the following
|
||||
|
// conditions:
|
||||
|
// The above copyright notice and this permission notice shall be
|
||||
|
// included in all copies or substantial portions of the Software.
|
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
using System; |
||||
|
using MathNet.Numerics.Distributions; |
||||
|
|
||||
|
namespace Examples.ContinuousDistributionsExamples |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// ContinuousUniform distribution example
|
||||
|
/// </summary>
|
||||
|
public class TriangularDistribution : IExample |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Gets the name of this example
|
||||
|
/// </summary>
|
||||
|
/// <seealso cref="http://reference.wolfram.com/mathematica/ref/TriangularDistribution.html"/>
|
||||
|
public string Name |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
return "Triangular distribution"; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the description of this example
|
||||
|
/// </summary>
|
||||
|
public string Description |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
return "Triangular distribution properties and samples generating examples"; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Run example
|
||||
|
/// </summary>
|
||||
|
/// <a href="https://en.wikipedia.org/wiki/Triangular_distribution">Triangular distribution</a>
|
||||
|
public void Run() |
||||
|
{ |
||||
|
// 1. Initialize
|
||||
|
var triangular = new Triangular(0, 1, 0.3); |
||||
|
Console.WriteLine(@"1. Initialize the new instance of the Triangular distribution class with parameters Lower = {0}, Upper = {1}, Mode = {2}", triangular.LowerBound, triangular.UpperBound, triangular.Mode); |
||||
|
Console.WriteLine(); |
||||
|
|
||||
|
// 2. Distributuion properties:
|
||||
|
Console.WriteLine(@"2. {0} distributuion properties:", triangular); |
||||
|
|
||||
|
// Cumulative distribution function
|
||||
|
Console.WriteLine(@"{0} - Сumulative distribution at location '0.3'", triangular.CumulativeDistribution(0.3).ToString(" #0.00000;-#0.00000")); |
||||
|
|
||||
|
// Probability density
|
||||
|
Console.WriteLine(@"{0} - Probability density at location '0.3'", triangular.Density(0.3).ToString(" #0.00000;-#0.00000")); |
||||
|
|
||||
|
// Log probability density
|
||||
|
Console.WriteLine(@"{0} - Log probability density at location '0.3'", triangular.DensityLn(0.3).ToString(" #0.00000;-#0.00000")); |
||||
|
|
||||
|
// Entropy
|
||||
|
Console.WriteLine(@"{0} - Entropy", triangular.Entropy.ToString(" #0.00000;-#0.00000")); |
||||
|
|
||||
|
// Largest element in the domain
|
||||
|
Console.WriteLine(@"{0} - Largest element in the domain", triangular.Maximum.ToString(" #0.00000;-#0.00000")); |
||||
|
|
||||
|
// Smallest element in the domain
|
||||
|
Console.WriteLine(@"{0} - Smallest element in the domain", triangular.Minimum.ToString(" #0.00000;-#0.00000")); |
||||
|
|
||||
|
// Mean
|
||||
|
Console.WriteLine(@"{0} - Mean", triangular.Mean.ToString(" #0.00000;-#0.00000")); |
||||
|
|
||||
|
// Median
|
||||
|
Console.WriteLine(@"{0} - Median", triangular.Median.ToString(" #0.00000;-#0.00000")); |
||||
|
|
||||
|
// Mode
|
||||
|
Console.WriteLine(@"{0} - Mode", triangular.Mode.ToString(" #0.00000;-#0.00000")); |
||||
|
|
||||
|
// Variance
|
||||
|
Console.WriteLine(@"{0} - Variance", triangular.Variance.ToString(" #0.00000;-#0.00000")); |
||||
|
|
||||
|
// Standard deviation
|
||||
|
Console.WriteLine(@"{0} - Standard deviation", triangular.StdDev.ToString(" #0.00000;-#0.00000")); |
||||
|
|
||||
|
// Skewness
|
||||
|
Console.WriteLine(@"{0} - Skewness", triangular.Skewness.ToString(" #0.00000;-#0.00000")); |
||||
|
Console.WriteLine(); |
||||
|
|
||||
|
// 10 samples
|
||||
|
Console.WriteLine(@"3. Generate 10 samples of the Triangular distribution"); |
||||
|
for (var i = 0; i < 10; i++) |
||||
|
{ |
||||
|
Console.Write(triangular.Sample().ToString("N05") + @" "); |
||||
|
} |
||||
|
|
||||
|
Console.WriteLine(); |
||||
|
Console.WriteLine(); |
||||
|
|
||||
|
// 10000 samples with starting parameters
|
||||
|
Console.WriteLine(@"4. Generate 100000 samples of the Triangular({0}, {1}, {2}) distribution and display histogram", triangular.LowerBound, triangular.UpperBound, triangular.Mode); |
||||
|
var data = new double[100000]; |
||||
|
for (var i = 0; i < data.Length; i++) |
||||
|
{ |
||||
|
data[i] = triangular.Sample(); |
||||
|
} |
||||
|
|
||||
|
ConsoleHelper.DisplayHistogram(data); |
||||
|
Console.WriteLine(); |
||||
|
|
||||
|
// 10000 with different parameters
|
||||
|
triangular.UpperBound = 10; |
||||
|
triangular.Mode = 8; |
||||
|
triangular.LowerBound = 2; |
||||
|
Console.WriteLine(@"4. Generate 100000 samples of the Triangular({0}, {1}, {2}) distribution and display histogram", triangular.LowerBound, triangular.UpperBound, triangular.Mode); |
||||
|
for (var i = 0; i < data.Length; i++) |
||||
|
{ |
||||
|
data[i] = triangular.Sample(); |
||||
|
} |
||||
|
|
||||
|
ConsoleHelper.DisplayHistogram(data); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,53 +0,0 @@ |
|||||
|
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00 |
|
||||
# Visual Studio 2012 |
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{5A0892FF-82CE-40FC-BCE1-73810C615F52}" |
|
||||
ProjectSection(SolutionItems) = preProject |
|
||||
..\Common\lapack_common.h = ..\Common\lapack_common.h |
|
||||
..\Common\resource.h = ..\Common\resource.h |
|
||||
..\Common\resource.rc = ..\Common\resource.rc |
|
||||
..\Common\WindowsDLL.cpp = ..\Common\WindowsDLL.cpp |
|
||||
..\Common\wrapper_common.h = ..\Common\wrapper_common.h |
|
||||
EndProjectSection |
|
||||
EndProject |
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MKLWrapper", "MKL\MKLWrapper.vcxproj", "{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}" |
|
||||
EndProject |
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ATLASWrapper", "ATLASWrapper\ATLASWrapper.vcxproj", "{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}" |
|
||||
EndProject |
|
||||
Global |
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
|
||||
Debug|Mixed Platforms = Debug|Mixed Platforms |
|
||||
Debug|Win32 = Debug|Win32 |
|
||||
Debug|x64 = Debug|x64 |
|
||||
Release|Mixed Platforms = Release|Mixed Platforms |
|
||||
Release|Win32 = Release|Win32 |
|
||||
Release|x64 = Release|x64 |
|
||||
EndGlobalSection |
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
|
||||
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 |
|
||||
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|Mixed Platforms.Build.0 = Debug|Win32 |
|
||||
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|Win32.ActiveCfg = Debug|Win32 |
|
||||
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|Win32.Build.0 = Debug|Win32 |
|
||||
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|x64.ActiveCfg = Debug|x64 |
|
||||
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Debug|x64.Build.0 = Debug|x64 |
|
||||
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Release|Mixed Platforms.ActiveCfg = Release|Win32 |
|
||||
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Release|Mixed Platforms.Build.0 = Release|Win32 |
|
||||
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Release|Win32.ActiveCfg = Release|Win32 |
|
||||
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Release|Win32.Build.0 = Release|Win32 |
|
||||
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Release|x64.ActiveCfg = Release|x64 |
|
||||
{C0B0DBA9-7FB0-4C87-BDB1-3EED19DC2B8F}.Release|x64.Build.0 = Release|x64 |
|
||||
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 |
|
||||
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Debug|Mixed Platforms.Build.0 = Debug|Win32 |
|
||||
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Debug|Win32.ActiveCfg = Debug|Win32 |
|
||||
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Debug|Win32.Build.0 = Debug|Win32 |
|
||||
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Debug|x64.ActiveCfg = Debug|Win32 |
|
||||
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Release|Mixed Platforms.ActiveCfg = Release|Win32 |
|
||||
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Release|Mixed Platforms.Build.0 = Release|Win32 |
|
||||
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Release|Win32.ActiveCfg = Release|Win32 |
|
||||
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Release|Win32.Build.0 = Release|Win32 |
|
||||
{2362B8AC-C52B-45E4-A1BF-C682A4DB4220}.Release|x64.ActiveCfg = Release|x64 |
|
||||
EndGlobalSection |
|
||||
GlobalSection(SolutionProperties) = preSolution |
|
||||
HideSolutionNode = FALSE |
|
||||
EndGlobalSection |
|
||||
EndGlobal |
|
||||
@ -0,0 +1,134 @@ |
|||||
|
#if PORTABLE
|
||||
|
namespace MathNet.Numerics |
||||
|
{ |
||||
|
using System; |
||||
|
|
||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)] |
||||
|
public class SerializableAttribute : Attribute |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] |
||||
|
public class SpecialNameAttribute : Attribute |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
|
#endif
|
||||
|
|
||||
|
#if (PORTABLE || NET35)
|
||||
|
namespace MathNet.Numerics |
||||
|
{ |
||||
|
using System; |
||||
|
|
||||
|
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method, AllowMultiple = false, Inherited = false)] |
||||
|
public class TargetedPatchingOptOutAttribute : Attribute |
||||
|
{ |
||||
|
public string Reason { get; private set; } |
||||
|
|
||||
|
public TargetedPatchingOptOutAttribute(string reason) |
||||
|
{ |
||||
|
Reason = reason; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
#endif
|
||||
|
|
||||
|
#if NET35
|
||||
|
namespace MathNet.Numerics |
||||
|
{ |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
internal static class ObjectComparer |
||||
|
{ |
||||
|
internal static int Compare<T>(T a, T b) |
||||
|
{ |
||||
|
if (ReferenceEquals(a, null)) return -1; |
||||
|
if (ReferenceEquals(b, null)) return 1; |
||||
|
if (Equals(a, b)) return 0; |
||||
|
return Comparer<T>.Default.Compare(a, b); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public class Tuple<T1, T2> : IComparable, IComparable<Tuple<T1, T2>> |
||||
|
{ |
||||
|
public T1 Item1 { get; set; } |
||||
|
public T2 Item2 { get; set; } |
||||
|
|
||||
|
public Tuple(T1 item1, T2 item2) |
||||
|
{ |
||||
|
Item1 = item1; |
||||
|
Item2 = item2; |
||||
|
} |
||||
|
|
||||
|
public int CompareTo(object obj) |
||||
|
{ |
||||
|
if (obj == null) return 1; |
||||
|
var other = obj as Tuple<T1, T2>; |
||||
|
if (other == null) throw new ArgumentException(); |
||||
|
return CompareTo(other); |
||||
|
} |
||||
|
|
||||
|
public int CompareTo(Tuple<T1, T2> other) |
||||
|
{ |
||||
|
if (other == null) return 1; |
||||
|
int a = ObjectComparer.Compare(Item1, other.Item1); |
||||
|
return a != 0 ? a : ObjectComparer.Compare(Item2, other.Item2); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public class Tuple<T1, T2, T3> : IComparable, IComparable<Tuple<T1, T2, T3>> |
||||
|
{ |
||||
|
public T1 Item1 { get; set; } |
||||
|
public T2 Item2 { get; set; } |
||||
|
public T3 Item3 { get; set; } |
||||
|
|
||||
|
public Tuple(T1 item1, T2 item2, T3 item3) |
||||
|
{ |
||||
|
Item1 = item1; |
||||
|
Item2 = item2; |
||||
|
Item3 = item3; |
||||
|
} |
||||
|
|
||||
|
public int CompareTo(object obj) |
||||
|
{ |
||||
|
if (obj == null) return 1; |
||||
|
var other = obj as Tuple<T1, T2, T3>; |
||||
|
if (other == null) throw new ArgumentException(); |
||||
|
return CompareTo(other); |
||||
|
} |
||||
|
|
||||
|
public int CompareTo(Tuple<T1, T2, T3> other) |
||||
|
{ |
||||
|
if (other == null) return 1; |
||||
|
int a = ObjectComparer.Compare(Item1, other.Item1); |
||||
|
if (a != 0) return a; |
||||
|
int b = ObjectComparer.Compare(Item2, other.Item2); |
||||
|
return b != 0 ? b : ObjectComparer.Compare(Item3, other.Item3); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static class EnumerableExtensions |
||||
|
{ |
||||
|
public static IEnumerable<T> Zip<TA, TB, T>(this IEnumerable<TA> seqA, IEnumerable<TB> seqB, Func<TA, TB, T> func) |
||||
|
{ |
||||
|
if (seqA == null) throw new ArgumentNullException("seqA"); |
||||
|
if (seqB == null) throw new ArgumentNullException("seqB"); |
||||
|
|
||||
|
return Zip35Deferred(seqA, seqB, func); |
||||
|
} |
||||
|
|
||||
|
private static IEnumerable<T> Zip35Deferred<A, B, T>(IEnumerable<A> seqA, IEnumerable<B> seqB, Func<A, B, T> func) |
||||
|
{ |
||||
|
using (var iteratorA = seqA.GetEnumerator()) |
||||
|
using (var iteratorB = seqB.GetEnumerator()) |
||||
|
{ |
||||
|
while (iteratorA.MoveNext() && iteratorB.MoveNext()) |
||||
|
{ |
||||
|
yield return func(iteratorA.Current, iteratorB.Current); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
#endif
|
||||
@ -0,0 +1,420 @@ |
|||||
|
// <copyright file="Triangular.cs" company="Math.NET">
|
||||
|
// Math.NET Numerics, part of the Math.NET Project
|
||||
|
// http://numerics.mathdotnet.com
|
||||
|
// http://github.com/mathnet/mathnet-numerics
|
||||
|
// http://mathnetnumerics.codeplex.com
|
||||
|
//
|
||||
|
// Copyright (c) 2009-2013 Math.NET
|
||||
|
//
|
||||
|
// Permission is hereby granted, free of charge, to any person
|
||||
|
// obtaining a copy of this software and associated documentation
|
||||
|
// files (the "Software"), to deal in the Software without
|
||||
|
// restriction, including without limitation the rights to use,
|
||||
|
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
|
// copies of the Software, and to permit persons to whom the
|
||||
|
// Software is furnished to do so, subject to the following
|
||||
|
// conditions:
|
||||
|
//
|
||||
|
// The above copyright notice and this permission notice shall be
|
||||
|
// included in all copies or substantial portions of the Software.
|
||||
|
//
|
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using MathNet.Numerics.Properties; |
||||
|
using MathNet.Numerics.Random; |
||||
|
|
||||
|
namespace MathNet.Numerics.Distributions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Triangular distribution.
|
||||
|
/// For details, see <a href="https://en.wikipedia.org/wiki/Triangular_distribution">Wikipedia - Triangular distribution</a>.
|
||||
|
/// </summary>
|
||||
|
/// <remarks><para>The distribution will use the <see cref="System.Random"/> by default.
|
||||
|
/// Users can get/set the random number generator by using the <see cref="RandomSource"/> property.</para>
|
||||
|
/// <para>The statistics classes will check whether all the incoming parameters are in the allowed range. This might involve heavy computation. Optionally, by setting Control.CheckDistributionParameters
|
||||
|
/// to <c>false</c>, all parameter checks can be turned off.</para></remarks>
|
||||
|
public class Triangular : IContinuousDistribution |
||||
|
{ |
||||
|
System.Random _random; |
||||
|
|
||||
|
double _lower; |
||||
|
double _upper; |
||||
|
double _mode; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the Triangular class with the given lower bound, upper bound and mode.
|
||||
|
/// </summary>
|
||||
|
/// <param name="lower">Lower bound. Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="upper">Upper bound. Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="mode">Mode (most frequent value). Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <exception cref="ArgumentException">If the upper bound is smaller than the mode or if the mode is smaller than the lower bound.</exception>
|
||||
|
public Triangular(double lower, double upper, double mode) |
||||
|
{ |
||||
|
_random = SystemRandomSource.Default; |
||||
|
SetParameters(lower, upper, mode); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the Triangular class with the given lower bound, upper bound and mode.
|
||||
|
/// </summary>
|
||||
|
/// <param name="lower">Lower bound. Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="upper">Upper bound. Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="mode">Mode (most frequent value). Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="randomSource">The random number generator which is used to draw random samples.</param>
|
||||
|
/// <exception cref="ArgumentException">If the upper bound is smaller than the mode or if the mode is smaller than the lower bound.</exception>
|
||||
|
public Triangular(double lower, double upper, double mode, System.Random randomSource) |
||||
|
{ |
||||
|
_random = randomSource ?? SystemRandomSource.Default; |
||||
|
SetParameters(lower, upper, mode); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// A string representation of the distribution.
|
||||
|
/// </summary>
|
||||
|
/// <returns>a string representation of the distribution.</returns>
|
||||
|
public override string ToString() |
||||
|
{ |
||||
|
return "Triangular(Lower = " + _lower + ", Upper = " + _upper + ", Mode = " + _mode + ")"; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Sets the parameters of the distribution after checking their validity.
|
||||
|
/// </summary>
|
||||
|
/// <param name="lower">Lower bound. Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="upper">Upper bound. Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="mode">Mode (most frequent value). Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
|
||||
|
void SetParameters(double lower, double upper, double mode) |
||||
|
{ |
||||
|
if (upper < mode || mode < lower || Double.IsNaN(upper) || Double.IsNaN(lower) || Double.IsNaN(mode)) |
||||
|
{ |
||||
|
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters); |
||||
|
} |
||||
|
|
||||
|
_lower = lower; |
||||
|
_upper = upper; |
||||
|
_mode = mode; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the lower bound of the distribution.
|
||||
|
/// </summary>
|
||||
|
public double LowerBound |
||||
|
{ |
||||
|
get { return _lower; } |
||||
|
set { SetParameters(value, _upper, _mode); } |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the upper bound of the distribution.
|
||||
|
/// </summary>
|
||||
|
public double UpperBound |
||||
|
{ |
||||
|
get { return _upper; } |
||||
|
set { SetParameters(_lower, value, _mode); } |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the random number generator which is used to draw random samples.
|
||||
|
/// </summary>
|
||||
|
public System.Random RandomSource |
||||
|
{ |
||||
|
get { return _random; } |
||||
|
set { _random = value ?? SystemRandomSource.Default; } |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the mean of the distribution.
|
||||
|
/// </summary>
|
||||
|
public double Mean |
||||
|
{ |
||||
|
get { return (_lower + _upper + _mode) / 3.0; } |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the variance of the distribution.
|
||||
|
/// </summary>
|
||||
|
public double Variance |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
var a = _lower; |
||||
|
var b = _upper; |
||||
|
var c = _mode; |
||||
|
return (a * a + b * b + c * c - a * b - a * c - b * c) / 18.0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the standard deviation of the distribution.
|
||||
|
/// </summary>
|
||||
|
public double StdDev |
||||
|
{ |
||||
|
get { return Math.Sqrt(Variance); } |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the entropy of the distribution.
|
||||
|
/// </summary>
|
||||
|
/// <value></value>
|
||||
|
public double Entropy |
||||
|
{ |
||||
|
get { return 0.5 + Math.Log((_upper - _lower) / 2); } |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the skewness of the distribution.
|
||||
|
/// </summary>
|
||||
|
public double Skewness |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
var a = _lower; |
||||
|
var b = _upper; |
||||
|
var c = _mode; |
||||
|
var q = Math.Sqrt(2) * (a + b - 2 * c) * (2 * a - b - c) * (a - 2 * b + c); |
||||
|
var d = 5 * Math.Pow(a * a + b * b + c * c - a * b - a * c - b * c, 3.0 / 2); |
||||
|
return q / d; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets or sets the mode of the distribution.
|
||||
|
/// </summary>
|
||||
|
public double Mode |
||||
|
{ |
||||
|
get { return _mode; } |
||||
|
set { SetParameters(_lower, _upper, value); } |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the median of the distribution.
|
||||
|
/// </summary>
|
||||
|
/// <value></value>
|
||||
|
public double Median |
||||
|
{ |
||||
|
get |
||||
|
{ |
||||
|
var a = _lower; |
||||
|
var b = _upper; |
||||
|
var c = _mode; |
||||
|
return c >= (a + b) / 2 |
||||
|
? a + Math.Sqrt((b - a) * (c - a) / 2) |
||||
|
: b - Math.Sqrt((b - a) * (b - c) / 2); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the minimum of the distribution.
|
||||
|
/// </summary>
|
||||
|
public double Minimum |
||||
|
{ |
||||
|
get { return _lower; } |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the maximum of the distribution.
|
||||
|
/// </summary>
|
||||
|
public double Maximum |
||||
|
{ |
||||
|
get { return _upper; } |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
|
||||
|
/// </summary>
|
||||
|
/// <param name="x">The location at which to compute the density.</param>
|
||||
|
/// <returns>the density at <paramref name="x"/>.</returns>
|
||||
|
/// <seealso cref="PDF"/>
|
||||
|
public double Density(double x) |
||||
|
{ |
||||
|
return PDF(_lower, _upper, _mode, x); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
|
||||
|
/// </summary>
|
||||
|
/// <param name="x">The location at which to compute the log density.</param>
|
||||
|
/// <returns>the log density at <paramref name="x"/>.</returns>
|
||||
|
/// <seealso cref="PDFLn"/>
|
||||
|
public double DensityLn(double x) |
||||
|
{ |
||||
|
return PDFLn(_lower, _upper, _mode, x); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X ≤ x).
|
||||
|
/// </summary>
|
||||
|
/// <param name="x">The location at which to compute the cumulative distribution function.</param>
|
||||
|
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>
|
||||
|
/// <seealso cref="CDF"/>
|
||||
|
public double CumulativeDistribution(double x) |
||||
|
{ |
||||
|
return CDF(_lower, _upper, _mode, x); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Computes the inverse of the cumulative distribution function (InvCDF) for the distribution
|
||||
|
/// at the given probability. This is also known as the quantile or percent point function.
|
||||
|
/// </summary>
|
||||
|
/// <param name="p">The location at which to compute the inverse cumulative density.</param>
|
||||
|
/// <returns>the inverse cumulative density at <paramref name="p"/>.</returns>
|
||||
|
/// <seealso cref="InvCDF"/>
|
||||
|
public double InverseCumulativeDistribution(double p) |
||||
|
{ |
||||
|
return InvCDF(_lower, _upper, _mode, p); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Generates a sample from the <c>Triangular</c> distribution.
|
||||
|
/// </summary>
|
||||
|
/// <returns>a sample from the distribution.</returns>
|
||||
|
public double Sample() |
||||
|
{ |
||||
|
return Sample(_random, _lower, _upper, _mode); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Generates a sequence of samples from the <c>Triangular</c> distribution.
|
||||
|
/// </summary>
|
||||
|
/// <returns>a sequence of samples from the distribution.</returns>
|
||||
|
public IEnumerable<double> Samples() |
||||
|
{ |
||||
|
return Samples(_random, _lower, _upper, _mode); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
|
||||
|
/// </summary>
|
||||
|
/// <param name="lower">Lower bound. Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="upper">Upper bound. Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="mode">Mode (most frequent value). Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="x">The location at which to compute the density.</param>
|
||||
|
/// <returns>the density at <paramref name="x"/>.</returns>
|
||||
|
/// <seealso cref="Density"/>
|
||||
|
public static double PDF(double lower, double upper, double mode, double x) |
||||
|
{ |
||||
|
if (upper < mode) throw new ArgumentOutOfRangeException("upper", Resources.InvalidDistributionParameters); |
||||
|
if (mode < lower) throw new ArgumentOutOfRangeException("lower", Resources.InvalidDistributionParameters); // TODO: Is "lower" the appropriate argument here?
|
||||
|
|
||||
|
var a = lower; |
||||
|
var b = upper; |
||||
|
var c = mode; |
||||
|
|
||||
|
if (a <= x && x <= c) return 2 * (x - a) / ((b - a) * (c - a)); |
||||
|
if (c < x & x <= b) return 2 * (b - x) / ((b - a) * (b - c)); |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x).
|
||||
|
/// </summary>
|
||||
|
/// <param name="lower">Lower bound. Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="upper">Upper bound. Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="mode">Mode (most frequent value). Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="x">The location at which to compute the density.</param>
|
||||
|
/// <returns>the log density at <paramref name="x"/>.</returns>
|
||||
|
/// <seealso cref="DensityLn"/>
|
||||
|
public static double PDFLn(double lower, double upper, double mode, double x) |
||||
|
{ |
||||
|
return Math.Log(PDF(lower, upper, mode, x)); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X ≤ x).
|
||||
|
/// </summary>
|
||||
|
/// <param name="x">The location at which to compute the cumulative distribution function.</param>
|
||||
|
/// <param name="lower">Lower bound. Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="upper">Upper bound. Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="mode">Mode (most frequent value). Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <returns>the cumulative distribution at location <paramref name="x"/>.</returns>
|
||||
|
/// <seealso cref="CumulativeDistribution"/>
|
||||
|
public static double CDF(double lower, double upper, double mode, double x) |
||||
|
{ |
||||
|
if (upper < mode) throw new ArgumentOutOfRangeException("upper", Resources.InvalidDistributionParameters); |
||||
|
if (mode < lower) throw new ArgumentOutOfRangeException("lower", Resources.InvalidDistributionParameters); // TODO: Is "lower" the appropriate argument here?
|
||||
|
|
||||
|
var a = lower; |
||||
|
var b = upper; |
||||
|
var c = mode; |
||||
|
|
||||
|
if (x < a) return 0; |
||||
|
if (a <= x && x <= c) return (x - a) * (x - a) / ((b - a) * (c - a)); |
||||
|
if (c < x & x <= b) return 1 - (b - x) * (b - x) / ((b - a) * (b - c)); |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Computes the inverse of the cumulative distribution function (InvCDF) for the distribution
|
||||
|
/// at the given probability. This is also known as the quantile or percent point function.
|
||||
|
/// </summary>
|
||||
|
/// <param name="p">The location at which to compute the inverse cumulative density.</param>
|
||||
|
/// <param name="lower">Lower bound. Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="upper">Upper bound. Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="mode">Mode (most frequent value). Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <returns>the inverse cumulative density at <paramref name="p"/>.</returns>
|
||||
|
/// <seealso cref="InverseCumulativeDistribution"/>
|
||||
|
public static double InvCDF(double lower, double upper, double mode, double p) |
||||
|
{ |
||||
|
if (upper < mode) throw new ArgumentOutOfRangeException("upper", Resources.InvalidDistributionParameters); |
||||
|
if (mode < lower) throw new ArgumentOutOfRangeException("lower", Resources.InvalidDistributionParameters); // TODO: Is "lower" the appropriate argument here?
|
||||
|
|
||||
|
var a = lower; |
||||
|
var b = upper; |
||||
|
var c = mode; |
||||
|
|
||||
|
if (p <= 0) return lower; |
||||
|
// Taken from http://www.ntrand.com/triangular-distribution/
|
||||
|
if (p < (c - a) / (b - a)) return a + Math.Sqrt(p * (c - a) * (b - a)); |
||||
|
if (p < 1) return b - Math.Sqrt((1 - p) * (b - c) * (b - a)); |
||||
|
return upper; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Generates a sample from the <c>Triangular</c> distribution.
|
||||
|
/// </summary>
|
||||
|
/// <param name="rnd">The random number generator to use.</param>
|
||||
|
/// <param name="lower">Lower bound. Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="upper">Upper bound. Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="mode">Mode (most frequent value). Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <returns>a sample from the distribution.</returns>
|
||||
|
public double Sample(System.Random rnd, double lower, double upper, double mode) |
||||
|
{ |
||||
|
var a = lower; |
||||
|
var b = upper; |
||||
|
var c = mode; |
||||
|
var u = rnd.NextDouble(); |
||||
|
|
||||
|
return u < (c - a) / (b - a) |
||||
|
? a + Math.Sqrt(u * (b - a) * (c - a)) |
||||
|
: b - Math.Sqrt((1 - u) * (b - a) * (b - c)); ; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Generates a sequence of samples from the <c>Triangular</c> distribution.
|
||||
|
/// </summary>
|
||||
|
/// <param name="rnd">The random number generator to use.</param>
|
||||
|
/// <param name="lower">Lower bound. Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="upper">Upper bound. Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <param name="mode">Mode (most frequent value). Range: lower ≤ mode ≤ upper</param>
|
||||
|
/// <returns>a sequence of samples from the distribution.</returns>
|
||||
|
public IEnumerable<double> Samples(System.Random rnd, double lower, double upper, double mode) |
||||
|
{ |
||||
|
while (true) |
||||
|
{ |
||||
|
yield return Sample(rnd, lower, upper, mode); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,611 @@ |
|||||
|
// <copyright file="Euclid.cs" company="Math.NET">
|
||||
|
// Math.NET Numerics, part of the Math.NET Project
|
||||
|
// http://numerics.mathdotnet.com
|
||||
|
// http://github.com/mathnet/mathnet-numerics
|
||||
|
// http://mathnetnumerics.codeplex.com
|
||||
|
//
|
||||
|
// Copyright (c) 2009-2013 Math.NET
|
||||
|
//
|
||||
|
// Permission is hereby granted, free of charge, to any person
|
||||
|
// obtaining a copy of this software and associated documentation
|
||||
|
// files (the "Software"), to deal in the Software without
|
||||
|
// restriction, including without limitation the rights to use,
|
||||
|
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
|
// copies of the Software, and to permit persons to whom the
|
||||
|
// Software is furnished to do so, subject to the following
|
||||
|
// conditions:
|
||||
|
//
|
||||
|
// The above copyright notice and this permission notice shall be
|
||||
|
// included in all copies or substantial portions of the Software.
|
||||
|
//
|
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
|
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
#if !NOSYSNUMERICS
|
||||
|
using System.Numerics; |
||||
|
#endif
|
||||
|
|
||||
|
namespace MathNet.Numerics |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Integer number theory functions.
|
||||
|
/// </summary>
|
||||
|
public static class Euclid |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Canonical Modulus. The result has the sign of the divisor.
|
||||
|
/// </summary>
|
||||
|
public static double Modulus(double dividend, double divisor) |
||||
|
{ |
||||
|
return ((dividend%divisor) + divisor)%divisor; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Canonical Modulus. The result has the sign of the divisor.
|
||||
|
/// </summary>
|
||||
|
public static int Modulus(int dividend, int divisor) |
||||
|
{ |
||||
|
return ((dividend%divisor) + divisor)%divisor; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Canonical Modulus. The result has the sign of the divisor.
|
||||
|
/// </summary>
|
||||
|
public static long Modulus(long dividend, long divisor) |
||||
|
{ |
||||
|
return ((dividend%divisor) + divisor)%divisor; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Remainder (% operator). The result has the sign of the dividend.
|
||||
|
/// </summary>
|
||||
|
public static double Remainder(double dividend, double divisor) |
||||
|
{ |
||||
|
return dividend%divisor; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Remainder (% operator). The result has the sign of the dividend.
|
||||
|
/// </summary>
|
||||
|
public static int Remainder(int dividend, int divisor) |
||||
|
{ |
||||
|
return dividend%divisor; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Remainder (% operator). The result has the sign of the dividend.
|
||||
|
/// </summary>
|
||||
|
public static long Remainder(long dividend, long divisor) |
||||
|
{ |
||||
|
return dividend%divisor; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Find out whether the provided 32 bit integer is an even number.
|
||||
|
/// </summary>
|
||||
|
/// <param name="number">The number to very whether it's even.</param>
|
||||
|
/// <returns>True if and only if it is an even number.</returns>
|
||||
|
public static bool IsEven(this int number) |
||||
|
{ |
||||
|
return (number & 0x1) == 0x0; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Find out whether the provided 64 bit integer is an even number.
|
||||
|
/// </summary>
|
||||
|
/// <param name="number">The number to very whether it's even.</param>
|
||||
|
/// <returns>True if and only if it is an even number.</returns>
|
||||
|
public static bool IsEven(this long number) |
||||
|
{ |
||||
|
return (number & 0x1) == 0x0; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Find out whether the provided 32 bit integer is an odd number.
|
||||
|
/// </summary>
|
||||
|
/// <param name="number">The number to very whether it's odd.</param>
|
||||
|
/// <returns>True if and only if it is an odd number.</returns>
|
||||
|
public static bool IsOdd(this int number) |
||||
|
{ |
||||
|
return (number & 0x1) == 0x1; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Find out whether the provided 64 bit integer is an odd number.
|
||||
|
/// </summary>
|
||||
|
/// <param name="number">The number to very whether it's odd.</param>
|
||||
|
/// <returns>True if and only if it is an odd number.</returns>
|
||||
|
public static bool IsOdd(this long number) |
||||
|
{ |
||||
|
return (number & 0x1) == 0x1; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Find out whether the provided 32 bit integer is a perfect power of two.
|
||||
|
/// </summary>
|
||||
|
/// <param name="number">The number to very whether it's a power of two.</param>
|
||||
|
/// <returns>True if and only if it is a power of two.</returns>
|
||||
|
public static bool IsPowerOfTwo(this int number) |
||||
|
{ |
||||
|
return number > 0 && (number & (number - 1)) == 0x0; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Find out whether the provided 64 bit integer is a perfect power of two.
|
||||
|
/// </summary>
|
||||
|
/// <param name="number">The number to very whether it's a power of two.</param>
|
||||
|
/// <returns>True if and only if it is a power of two.</returns>
|
||||
|
public static bool IsPowerOfTwo(this long number) |
||||
|
{ |
||||
|
return number > 0 && (number & (number - 1)) == 0x0; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Find out whether the provided 32 bit integer is a perfect square, i.e. a square of an integer.
|
||||
|
/// </summary>
|
||||
|
/// <param name="number">The number to very whether it's a perfect square.</param>
|
||||
|
/// <returns>True if and only if it is a perfect square.</returns>
|
||||
|
public static bool IsPerfectSquare(this int number) |
||||
|
{ |
||||
|
if (number < 0) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
int lastHexDigit = number & 0xF; |
||||
|
if (lastHexDigit > 9) |
||||
|
{ |
||||
|
return false; // return immediately in 6 cases out of 16.
|
||||
|
} |
||||
|
|
||||
|
if (lastHexDigit == 0 || lastHexDigit == 1 || lastHexDigit == 4 || lastHexDigit == 9) |
||||
|
{ |
||||
|
int t = (int)Math.Floor(Math.Sqrt(number) + 0.5); |
||||
|
return (t * t) == number; |
||||
|
} |
||||
|
|
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Find out whether the provided 64 bit integer is a perfect square, i.e. a square of an integer.
|
||||
|
/// </summary>
|
||||
|
/// <param name="number">The number to very whether it's a perfect square.</param>
|
||||
|
/// <returns>True if and only if it is a perfect square.</returns>
|
||||
|
public static bool IsPerfectSquare(this long number) |
||||
|
{ |
||||
|
if (number < 0) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
int lastHexDigit = (int)(number & 0xF); |
||||
|
if (lastHexDigit > 9) |
||||
|
{ |
||||
|
return false; // return immediately in 6 cases out of 16.
|
||||
|
} |
||||
|
|
||||
|
if (lastHexDigit == 0 || lastHexDigit == 1 || lastHexDigit == 4 || lastHexDigit == 9) |
||||
|
{ |
||||
|
long t = (long)Math.Floor(Math.Sqrt(number) + 0.5); |
||||
|
return (t * t) == number; |
||||
|
} |
||||
|
|
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Raises 2 to the provided integer exponent (0 <= exponent < 31).
|
||||
|
/// </summary>
|
||||
|
/// <param name="exponent">The exponent to raise 2 up to.</param>
|
||||
|
/// <returns>2 ^ exponent.</returns>
|
||||
|
/// <exception cref="ArgumentOutOfRangeException"/>
|
||||
|
public static int PowerOfTwo(this int exponent) |
||||
|
{ |
||||
|
if (exponent < 0 || exponent >= 31) |
||||
|
{ |
||||
|
throw new ArgumentOutOfRangeException("exponent"); |
||||
|
} |
||||
|
|
||||
|
return 1 << exponent; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Raises 2 to the provided integer exponent (0 <= exponent < 63).
|
||||
|
/// </summary>
|
||||
|
/// <param name="exponent">The exponent to raise 2 up to.</param>
|
||||
|
/// <returns>2 ^ exponent.</returns>
|
||||
|
/// <exception cref="ArgumentOutOfRangeException"/>
|
||||
|
public static long PowerOfTwo(this long exponent) |
||||
|
{ |
||||
|
if (exponent < 0 || exponent >= 63) |
||||
|
{ |
||||
|
throw new ArgumentOutOfRangeException("exponent"); |
||||
|
} |
||||
|
|
||||
|
return ((long)1) << (int)exponent; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Find the closest perfect power of two that is larger or equal to the provided
|
||||
|
/// 32 bit integer.
|
||||
|
/// </summary>
|
||||
|
/// <param name="number">The number of which to find the closest upper power of two.</param>
|
||||
|
/// <returns>A power of two.</returns>
|
||||
|
/// <exception cref="ArgumentOutOfRangeException"/>
|
||||
|
public static int CeilingToPowerOfTwo(this int number) |
||||
|
{ |
||||
|
if (number == Int32.MinValue) |
||||
|
{ |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
const int maxPowerOfTwo = 0x40000000; |
||||
|
if (number > maxPowerOfTwo) |
||||
|
{ |
||||
|
throw new ArgumentOutOfRangeException("number"); |
||||
|
} |
||||
|
|
||||
|
number--; |
||||
|
number |= number >> 1; |
||||
|
number |= number >> 2; |
||||
|
number |= number >> 4; |
||||
|
number |= number >> 8; |
||||
|
number |= number >> 16; |
||||
|
return number + 1; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Find the closest perfect power of two that is larger or equal to the provided
|
||||
|
/// 64 bit integer.
|
||||
|
/// </summary>
|
||||
|
/// <param name="number">The number of which to find the closest upper power of two.</param>
|
||||
|
/// <returns>A power of two.</returns>
|
||||
|
/// <exception cref="ArgumentOutOfRangeException"/>
|
||||
|
public static long CeilingToPowerOfTwo(this long number) |
||||
|
{ |
||||
|
if (number == Int64.MinValue) |
||||
|
{ |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
const long maxPowerOfTwo = 0x4000000000000000; |
||||
|
if (number > maxPowerOfTwo) |
||||
|
{ |
||||
|
throw new ArgumentOutOfRangeException("number"); |
||||
|
} |
||||
|
|
||||
|
number--; |
||||
|
number |= number >> 1; |
||||
|
number |= number >> 2; |
||||
|
number |= number >> 4; |
||||
|
number |= number >> 8; |
||||
|
number |= number >> 16; |
||||
|
number |= number >> 32; |
||||
|
return number + 1; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns the greatest common divisor (<c>gcd</c>) of two integers using Euclid's algorithm.
|
||||
|
/// </summary>
|
||||
|
/// <param name="a">First Integer: a.</param>
|
||||
|
/// <param name="b">Second Integer: b.</param>
|
||||
|
/// <returns>Greatest common divisor <c>gcd</c>(a,b)</returns>
|
||||
|
public static long GreatestCommonDivisor(long a, long b) |
||||
|
{ |
||||
|
while (b != 0) |
||||
|
{ |
||||
|
var remainder = a%b; |
||||
|
a = b; |
||||
|
b = remainder; |
||||
|
} |
||||
|
|
||||
|
return Math.Abs(a); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns the greatest common divisor (<c>gcd</c>) of a set of integers using Euclid's
|
||||
|
/// algorithm.
|
||||
|
/// </summary>
|
||||
|
/// <param name="integers">List of Integers.</param>
|
||||
|
/// <returns>Greatest common divisor <c>gcd</c>(list of integers)</returns>
|
||||
|
public static long GreatestCommonDivisor(IList<long> integers) |
||||
|
{ |
||||
|
if (null == integers) |
||||
|
{ |
||||
|
throw new ArgumentNullException("integers"); |
||||
|
} |
||||
|
|
||||
|
if (integers.Count == 0) |
||||
|
{ |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
var gcd = Math.Abs(integers[0]); |
||||
|
|
||||
|
for (var i = 1; (i < integers.Count) && (gcd > 1); i++) |
||||
|
{ |
||||
|
gcd = GreatestCommonDivisor(gcd, integers[i]); |
||||
|
} |
||||
|
|
||||
|
return gcd; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns the greatest common divisor (<c>gcd</c>) of a set of integers using Euclid's algorithm.
|
||||
|
/// </summary>
|
||||
|
/// <param name="integers">List of Integers.</param>
|
||||
|
/// <returns>Greatest common divisor <c>gcd</c>(list of integers)</returns>
|
||||
|
public static long GreatestCommonDivisor(params long[] integers) |
||||
|
{ |
||||
|
return GreatestCommonDivisor((IList<long>)integers); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Computes the extended greatest common divisor, such that a*x + b*y = <c>gcd</c>(a,b).
|
||||
|
/// </summary>
|
||||
|
/// <param name="a">First Integer: a.</param>
|
||||
|
/// <param name="b">Second Integer: b.</param>
|
||||
|
/// <param name="x">Resulting x, such that a*x + b*y = <c>gcd</c>(a,b).</param>
|
||||
|
/// <param name="y">Resulting y, such that a*x + b*y = <c>gcd</c>(a,b)</param>
|
||||
|
/// <returns>Greatest common divisor <c>gcd</c>(a,b)</returns>
|
||||
|
/// <example>
|
||||
|
/// <code>
|
||||
|
/// long x,y,d;
|
||||
|
/// d = Fn.GreatestCommonDivisor(45,18,out x, out y);
|
||||
|
/// -> d == 9 && x == 1 && y == -2
|
||||
|
/// </code>
|
||||
|
/// The <c>gcd</c> of 45 and 18 is 9: 18 = 2*9, 45 = 5*9. 9 = 1*45 -2*18, therefore x=1 and y=-2.
|
||||
|
/// </example>
|
||||
|
public static long ExtendedGreatestCommonDivisor(long a, long b, out long x, out long y) |
||||
|
{ |
||||
|
long mp = 1, np = 0, m = 0, n = 1; |
||||
|
|
||||
|
while (b != 0) |
||||
|
{ |
||||
|
long rem; |
||||
|
#if PORTABLE
|
||||
|
rem = a % b; |
||||
|
var quot = a / b; |
||||
|
#else
|
||||
|
long quot = Math.DivRem(a, b, out rem); |
||||
|
#endif
|
||||
|
a = b; |
||||
|
b = rem; |
||||
|
|
||||
|
var tmp = m; |
||||
|
m = mp - (quot*m); |
||||
|
mp = tmp; |
||||
|
|
||||
|
tmp = n; |
||||
|
n = np - (quot*n); |
||||
|
np = tmp; |
||||
|
} |
||||
|
|
||||
|
if (a >= 0) |
||||
|
{ |
||||
|
x = mp; |
||||
|
y = np; |
||||
|
return a; |
||||
|
} |
||||
|
|
||||
|
x = -mp; |
||||
|
y = -np; |
||||
|
return -a; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns the least common multiple (<c>lcm</c>) of two integers using Euclid's algorithm.
|
||||
|
/// </summary>
|
||||
|
/// <param name="a">First Integer: a.</param>
|
||||
|
/// <param name="b">Second Integer: b.</param>
|
||||
|
/// <returns>Least common multiple <c>lcm</c>(a,b)</returns>
|
||||
|
public static long LeastCommonMultiple(long a, long b) |
||||
|
{ |
||||
|
if ((a == 0) || (b == 0)) |
||||
|
{ |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
return Math.Abs((a/GreatestCommonDivisor(a, b))*b); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns the least common multiple (<c>lcm</c>) of a set of integers using Euclid's algorithm.
|
||||
|
/// </summary>
|
||||
|
/// <param name="integers">List of Integers.</param>
|
||||
|
/// <returns>Least common multiple <c>lcm</c>(list of integers)</returns>
|
||||
|
public static long LeastCommonMultiple(IList<long> integers) |
||||
|
{ |
||||
|
if (null == integers) |
||||
|
{ |
||||
|
throw new ArgumentNullException("integers"); |
||||
|
} |
||||
|
|
||||
|
if (integers.Count == 0) |
||||
|
{ |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
var lcm = Math.Abs(integers[0]); |
||||
|
|
||||
|
for (var i = 1; i < integers.Count; i++) |
||||
|
{ |
||||
|
lcm = LeastCommonMultiple(lcm, integers[i]); |
||||
|
} |
||||
|
|
||||
|
return lcm; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns the least common multiple (<c>lcm</c>) of a set of integers using Euclid's algorithm.
|
||||
|
/// </summary>
|
||||
|
/// <param name="integers">List of Integers.</param>
|
||||
|
/// <returns>Least common multiple <c>lcm</c>(list of integers)</returns>
|
||||
|
public static long LeastCommonMultiple(params long[] integers) |
||||
|
{ |
||||
|
return LeastCommonMultiple((IList<long>)integers); |
||||
|
} |
||||
|
|
||||
|
#if !NOSYSNUMERICS
|
||||
|
/// <summary>
|
||||
|
/// Returns the greatest common divisor (<c>gcd</c>) of two big integers.
|
||||
|
/// </summary>
|
||||
|
/// <param name="a">First Integer: a.</param>
|
||||
|
/// <param name="b">Second Integer: b.</param>
|
||||
|
/// <returns>Greatest common divisor <c>gcd</c>(a,b)</returns>
|
||||
|
public static BigInteger GreatestCommonDivisor(BigInteger a, BigInteger b) |
||||
|
{ |
||||
|
return BigInteger.GreatestCommonDivisor(a, b); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns the greatest common divisor (<c>gcd</c>) of a set of big integers.
|
||||
|
/// </summary>
|
||||
|
/// <param name="integers">List of Integers.</param>
|
||||
|
/// <returns>Greatest common divisor <c>gcd</c>(list of integers)</returns>
|
||||
|
public static BigInteger GreatestCommonDivisor(IList<BigInteger> integers) |
||||
|
{ |
||||
|
if (null == integers) |
||||
|
{ |
||||
|
throw new ArgumentNullException("integers"); |
||||
|
} |
||||
|
|
||||
|
if (integers.Count == 0) |
||||
|
{ |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
var gcd = BigInteger.Abs(integers[0]); |
||||
|
|
||||
|
for (int i = 1; (i < integers.Count) && (gcd > BigInteger.One); i++) |
||||
|
{ |
||||
|
gcd = GreatestCommonDivisor(gcd, integers[i]); |
||||
|
} |
||||
|
|
||||
|
return gcd; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns the greatest common divisor (<c>gcd</c>) of a set of big integers.
|
||||
|
/// </summary>
|
||||
|
/// <param name="integers">List of Integers.</param>
|
||||
|
/// <returns>Greatest common divisor <c>gcd</c>(list of integers)</returns>
|
||||
|
public static BigInteger GreatestCommonDivisor(params BigInteger[] integers) |
||||
|
{ |
||||
|
return GreatestCommonDivisor((IList<BigInteger>)integers); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Computes the extended greatest common divisor, such that a*x + b*y = <c>gcd</c>(a,b).
|
||||
|
/// </summary>
|
||||
|
/// <param name="a">First Integer: a.</param>
|
||||
|
/// <param name="b">Second Integer: b.</param>
|
||||
|
/// <param name="x">Resulting x, such that a*x + b*y = <c>gcd</c>(a,b).</param>
|
||||
|
/// <param name="y">Resulting y, such that a*x + b*y = <c>gcd</c>(a,b)</param>
|
||||
|
/// <returns>Greatest common divisor <c>gcd</c>(a,b)</returns>
|
||||
|
/// <example>
|
||||
|
/// <code>
|
||||
|
/// long x,y,d;
|
||||
|
/// d = Fn.GreatestCommonDivisor(45,18,out x, out y);
|
||||
|
/// -> d == 9 && x == 1 && y == -2
|
||||
|
/// </code>
|
||||
|
/// The <c>gcd</c> of 45 and 18 is 9: 18 = 2*9, 45 = 5*9. 9 = 1*45 -2*18, therefore x=1 and y=-2.
|
||||
|
/// </example>
|
||||
|
public static BigInteger ExtendedGreatestCommonDivisor(BigInteger a, BigInteger b, out BigInteger x, out BigInteger y) |
||||
|
{ |
||||
|
BigInteger mp = BigInteger.One, np = BigInteger.Zero, m = BigInteger.Zero, n = BigInteger.One; |
||||
|
|
||||
|
while (!b.IsZero) |
||||
|
{ |
||||
|
BigInteger rem; |
||||
|
BigInteger quot = BigInteger.DivRem(a, b, out rem); |
||||
|
a = b; |
||||
|
b = rem; |
||||
|
|
||||
|
BigInteger tmp = m; |
||||
|
m = mp - (quot*m); |
||||
|
mp = tmp; |
||||
|
|
||||
|
tmp = n; |
||||
|
n = np - (quot*n); |
||||
|
np = tmp; |
||||
|
} |
||||
|
|
||||
|
if (a >= BigInteger.Zero) |
||||
|
{ |
||||
|
x = mp; |
||||
|
y = np; |
||||
|
return a; |
||||
|
} |
||||
|
|
||||
|
x = -mp; |
||||
|
y = -np; |
||||
|
return -a; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns the least common multiple (<c>lcm</c>) of two big integers.
|
||||
|
/// </summary>
|
||||
|
/// <param name="a">First Integer: a.</param>
|
||||
|
/// <param name="b">Second Integer: b.</param>
|
||||
|
/// <returns>Least common multiple <c>lcm</c>(a,b)</returns>
|
||||
|
public static BigInteger LeastCommonMultiple(BigInteger a, BigInteger b) |
||||
|
{ |
||||
|
if (a.IsZero || b.IsZero) |
||||
|
{ |
||||
|
return BigInteger.Zero; |
||||
|
} |
||||
|
|
||||
|
return BigInteger.Abs((a/BigInteger.GreatestCommonDivisor(a, b))*b); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns the least common multiple (<c>lcm</c>) of a set of big integers.
|
||||
|
/// </summary>
|
||||
|
/// <param name="integers">List of Integers.</param>
|
||||
|
/// <returns>Least common multiple <c>lcm</c>(list of integers)</returns>
|
||||
|
public static BigInteger LeastCommonMultiple(IList<BigInteger> integers) |
||||
|
{ |
||||
|
if (null == integers) |
||||
|
{ |
||||
|
throw new ArgumentNullException("integers"); |
||||
|
} |
||||
|
|
||||
|
if (integers.Count == 0) |
||||
|
{ |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
var lcm = BigInteger.Abs(integers[0]); |
||||
|
|
||||
|
for (int i = 1; i < integers.Count; i++) |
||||
|
{ |
||||
|
lcm = LeastCommonMultiple(lcm, integers[i]); |
||||
|
} |
||||
|
|
||||
|
return lcm; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns the least common multiple (<c>lcm</c>) of a set of big integers.
|
||||
|
/// </summary>
|
||||
|
/// <param name="integers">List of Integers.</param>
|
||||
|
/// <returns>Least common multiple <c>lcm</c>(list of integers)</returns>
|
||||
|
public static BigInteger LeastCommonMultiple(params BigInteger[] integers) |
||||
|
{ |
||||
|
return LeastCommonMultiple((IList<BigInteger>)integers); |
||||
|
} |
||||
|
#endif
|
||||
|
} |
||||
|
} |
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue