├── .build.ps1
├── .gitignore
├── COPYING
├── COPYING.LESSER
├── LICENSE.txt
├── README.md
├── scripts
├── PSMath.Format.ps1xml
├── PSMath.psd1
└── PSMath.psm1
├── source
├── Horker.Math.sln
├── Horker.Math
│ ├── ArrayMethods
│ │ ├── ArrayMethodsHelper.cs
│ │ ├── Typed
│ │ │ ├── Additional.cs
│ │ │ ├── Elementwise.cs
│ │ │ ├── Linq.cs
│ │ │ └── Matrix.cs
│ │ └── Untyped
│ │ │ ├── Additional.cs
│ │ │ ├── Matrix.cs
│ │ │ ├── Measures.cs
│ │ │ ├── Tools.cs
│ │ │ └── Vector.cs
│ ├── Collections
│ │ ├── DataFrame
│ │ │ ├── DataFrame.cs
│ │ │ ├── DataFrameColumn.cs
│ │ │ ├── DataFrameColumnBase.cs
│ │ │ ├── DataFrameColumnFactory.cs
│ │ │ ├── DataFrameColumnInfo.cs
│ │ │ ├── DataFrameGroup.cs
│ │ │ ├── DataFrameType.cs
│ │ │ ├── KeyComparers.cs
│ │ │ └── NewMathDataFrame.cs
│ │ ├── DataTable
│ │ │ ├── DataTableExtensionMethods.cs
│ │ │ └── DataTablePSMethods.cs
│ │ ├── Matrix
│ │ │ ├── Matrix.cs
│ │ │ ├── MatrixCmdlets.cs
│ │ │ └── New-Math.Matrix.cs
│ │ └── Slice
│ │ │ ├── Get-Math.Slice.cs
│ │ │ └── Slice.cs
│ ├── Conversions
│ │ ├── ConversionCmdlets.cs
│ │ └── Converter.cs
│ ├── Horker.Math.csproj
│ ├── Math
│ │ ├── DataSummary.cs
│ │ └── MathCmdlets.cs
│ ├── PSObject
│ │ ├── AdditionalPSObjectMethods.cs
│ │ ├── ConvertFrom-PSObject.BinaryFormat.cs
│ │ ├── ConvertTo-PSObject.BinaryFormat.cs
│ │ ├── Export-PSObject.BinaryFormat.cs
│ │ ├── Get-PSObject.Summary.cs
│ │ ├── Get-PSObject.TypeInformation.cs
│ │ ├── Import-PSObject.BinaryFormat.cs
│ │ ├── New-PSObject.OneHot.cs
│ │ ├── New-PSObject.TruthTable.cs
│ │ └── ObjectListCmdletBase.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Sequence
│ │ └── SequenceCmdlets.cs
│ ├── Statistics
│ │ ├── Analyses
│ │ │ └── InvokeDescriptiveAnalysis.cs
│ │ ├── Distributions
│ │ │ └── Distributions.cs
│ │ ├── KalmanFilter2D.cs
│ │ ├── Regressions
│ │ │ ├── InvokeGeneralizedLinearRegression.cs
│ │ │ ├── InvokeLinearRegression.cs
│ │ │ ├── InvokeLogisticRegression.cs
│ │ │ └── InvokeStepwiseLogisticRegression.cs
│ │ └── Tests
│ │ │ ├── InvokeBinomialTest.cs
│ │ │ ├── InvokeChiSquareTest.cs
│ │ │ ├── InvokeFTest.cs
│ │ │ ├── InvokeFisherExactTest.cs
│ │ │ ├── InvokeKolmogorovSmirnovTest.cs
│ │ │ ├── InvokeLeveneTest.cs
│ │ │ ├── InvokeMannWhitneyWilcoxonTest.cs
│ │ │ ├── InvokeOneWayAnova.cs
│ │ │ ├── InvokePairedTTest.cs
│ │ │ ├── InvokeShapiroWilkTest.cs
│ │ │ ├── InvokeSignTest.cs
│ │ │ ├── InvokeTTest.cs
│ │ │ ├── InvokeTwoSampleKolmogorovSmirnovTest.cs
│ │ │ ├── InvokeTwoSampleSignTest.cs
│ │ │ ├── InvokeTwoSampleTTest.cs
│ │ │ ├── InvokeTwoSampleWilcoxonSignedRankTest.cs
│ │ │ ├── InvokeTwoWayAnova.cs
│ │ │ ├── InvokeWilcoxonSignedRankTest.cs
│ │ │ └── TestHelper.cs
│ └── packages.config
└── Tests
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── TestArrayMethods.cs
│ ├── TestDataFrame.cs
│ ├── TestDataFrameColumn.cs
│ ├── TestDataTableMethods.cs
│ ├── TestNewMathMatrix.cs
│ ├── TestNewMathSequence.cs
│ ├── Tests.csproj
│ └── packages.config
└── tools
└── Publish.ps1
/.build.ps1:
--------------------------------------------------------------------------------
1 | task . Compile, Build, ImportDebug
2 |
3 | Set-StrictMode -Version 4
4 |
5 | ############################################################
6 |
7 | $SOURCE_PATH = "$PSScriptRoot\source\Horker.Math"
8 | $SCRIPT_PATH = "$PSScriptRoot\scripts"
9 |
10 | $MODULE_PATH = "$PSScriptRoot\psmath"
11 | $MODULE_PATH_DEBUG = "$PSScriptRoot\debug\psmath"
12 |
13 | $SOLUTION_FILE = "$PSScriptRoot\source\Horker.Math.sln"
14 |
15 | $OBJECT_FILES = @(
16 | "Accord.dll"
17 | "Accord.Math.Core.dll"
18 | "Accord.Math.dll"
19 | "Accord.Statistics.dll"
20 | "Horker.Math.dll"
21 | "Horker.Math.pdb"
22 | )
23 |
24 | #$HELP_INPUT = "$SOURCE_PATH\bin\Release\Horker.Math.dll"
25 | #$HELP_INTERM = "$SOURCE_PATH\bin\Release\Horker.Data.dll-Help.xml"
26 | #$HELP_OUTPUT = "$MODULE_PATH\Horker.Data.dll-Help.xml"
27 | #$HELPGEN = "$PSScriptRoot\vendor\XmlDoc2CmdletDoc.0.2.10\tools\XmlDoc2CmdletDoc.exe"
28 |
29 | ############################################################
30 |
31 | function New-Folder2 {
32 | param(
33 | [string]$Path
34 | )
35 |
36 | try {
37 | $null = New-Item -Type Directory $Path -EA Stop
38 | Write-Host -ForegroundColor DarkCyan "$Path created"
39 | }
40 | catch {
41 | Write-Host -ForegroundColor DarkYellow $_
42 | }
43 | }
44 |
45 | function Copy-Item2 {
46 | param(
47 | [string]$Source,
48 | [string]$Dest
49 | )
50 |
51 | try {
52 | Copy-Item $Source $Dest -EA Stop
53 | Write-Host -ForegroundColor DarkCyan "Copy from $Source to $Dest done"
54 | }
55 | catch {
56 | Write-Host -ForegroundColor DarkYellow $_
57 | }
58 | }
59 |
60 | function Remove-Item2 {
61 | param(
62 | [string]$Path
63 | )
64 |
65 | try {
66 | Remove-Item $Path -EA Stop
67 | Write-Host -ForegroundColor DarkCyan "$Path removed"
68 | }
69 | catch {
70 | Write-Host -ForegroundColor DarkYellow $_
71 | }
72 | }
73 |
74 | ############################################################
75 |
76 | task Compile {
77 | msbuild $SOLUTION_FILE /p:Configuration=Debug /nologo /v:minimal
78 | msbuild $SOLUTION_FILE /p:Configuration=Release /nologo /v:minimal
79 | }
80 |
81 | task Build {
82 | . {
83 | $ErrorActionPreference = "Continue"
84 |
85 | function Copy-ObjectFiles {
86 | param(
87 | [string]$targetPath,
88 | [string]$objectPath
89 | )
90 | New-Folder2 $targetPath
91 |
92 | Copy-Item2 "$SCRIPT_PATH\*" $targetPath
93 | $OBJECT_FILES | foreach {
94 | $path = Join-Path $objectPath $_
95 | Copy-Item2 $path $targetPath
96 | }
97 | }
98 |
99 | Copy-ObjectFiles $MODULE_PATH "$SOURCE_PATH\bin\Release"
100 | Copy-ObjectFiles $MODULE_PATH_DEBUG "$SOURCE_PATH\bin\Debug"
101 | }
102 | }
103 |
104 | #task BuildHelp `
105 | # -Inputs $HELP_INPUT `
106 | # -Outputs $HELP_OUTPUT `
107 | #{
108 | # . $HELPGEN $HELP_INPUT
109 | #
110 | # Copy-Item $HELP_INTERM $MODULE_PATH
111 | #}
112 |
113 | task Test Build, ImportDebug, {
114 | Invoke-Pester "$PSScriptRoot\tests"
115 | }
116 |
117 | task ImportDebug {
118 | Import-Module $MODULE_PATH_DEBUG -Force
119 | }
120 |
121 | task Clean {
122 | Remove-Item2 "$MODULE_PATH\*" -Force -Recurse -EA Continue
123 | Remove-Item2 "$MODULE_PATH_DEBUG\*" -Force -Recurse -EA Continue
124 | }
125 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | psmath/
2 | debug/
3 |
4 | .vs/
5 | bin/
6 | obj/
7 | packages/
8 | *.user
9 |
10 | private/
11 | vendor/
12 |
--------------------------------------------------------------------------------
/COPYING.LESSER:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | PowerShell Math and Statistics Library
2 |
3 | Copyright 2018 horker
4 |
5 | This program is free software: you can redistribute it and/or modify it under
6 | the terms of the GNU Lesser General Public License as published by the Free
7 | Software Foundation, either version 2.1 of the License, or (at your option) any
8 | later version.
9 |
10 | This program is distributed in the hope that it will be useful, but WITHOUT ANY
11 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12 | PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 | details.
14 |
15 | You should have received a copy of the GNU General Public License along with
16 | this program. If not, see .
17 |
--------------------------------------------------------------------------------
/scripts/PSMath.Format.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Accord.Statistics.Analysis.LogisticRegressionAnalysis
7 |
8 | Accord.Statistics.Analysis.LogisticRegressionAnalysis
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | (($_.Coefficients | Format-Table Name, Value, OddsRatio, StandardError, Wald, LikelihoodRatio | Out-String) -Replace "(\r?\n)+", "`n" ) +
17 | (($_ | Format-List NumberOfSamples, LogLikelihood, Deviance, @{ l = "AIC"; e = { $_.Deviance + 2 * ($_.Inputs.Count + 1) } } | Out-String) -Replace "(\r?\n)+", "`n" -Replace "(\r?\n)$", "")
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | Horker.Math.Matrix
28 |
29 | Horker.Math.Matrix
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | $_.AsString()
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/scripts/PSMath.psd1:
--------------------------------------------------------------------------------
1 | #
2 | # Module manifest for module 'PSMath'
3 | #
4 | # Generated by: horker
5 | #
6 | # Generated on: 2017/12/03
7 | #
8 |
9 | @{
10 |
11 | # Script module or binary module file associated with this manifest.
12 | RootModule = 'PSMath.psm1'
13 |
14 | # Version number of this module.
15 | ModuleVersion = '0.1.1'
16 |
17 | # Supported PSEditions
18 | # CompatiblePSEditions = ''
19 |
20 | # ID used to uniquely identify this module
21 | GUID = 'e356c4e7-b682-4008-938b-0b81db760c4b'
22 |
23 | # Author of this module
24 | Author = 'horker'
25 |
26 | # Company or vendor of this module
27 | CompanyName = ''
28 |
29 | # Copyright statement for this module
30 | Copyright = '(c) 2018 horker. All rights reserved.'
31 |
32 | # Description of the functionality provided by this module
33 | Description = @"
34 | PowerShell Math and Statistics Library is a collection of math and statistics classes and cmdlets for PowerShell. It is built on top of Accord.NET (http://accord-framework.net/).
35 |
36 | This is a work in progress, but already usable for many use cases.
37 |
38 | For more details, see https://github.com/horker/psmath
39 | "@
40 |
41 | # Minimum version of the Windows PowerShell engine required by this module
42 | # PowerShellVersion = ''
43 |
44 | # Name of the Windows PowerShell host required by this module
45 | # PowerShellHostName = ''
46 |
47 | # Minimum version of the Windows PowerShell host required by this module
48 | # PowerShellHostVersion = ''
49 |
50 | # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
51 | DotNetFrameworkVersion = '4.5.2'
52 |
53 | # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
54 | # CLRVersion = ''
55 |
56 | # Processor architecture (None, X86, Amd64) required by this module
57 | # ProcessorArchitecture = ''
58 |
59 | # Modules that must be imported into the global environment prior to importing this module
60 | # RequiredModules = @()
61 |
62 | # Assemblies that must be loaded prior to importing this module
63 | RequiredAssemblies = @(
64 | "Accord.dll"
65 | "Accord.Math.Core.dll"
66 | "Accord.Math.dll"
67 | "Accord.Statistics.dll"
68 | )
69 |
70 | # Script files (.ps1) that are run in the caller's environment prior to importing this module.
71 | # ScriptsToProcess = @()
72 |
73 | # Type files (.ps1xml) to be loaded when importing this module
74 | # TypesToProcess = @()
75 |
76 | # Format files (.ps1xml) to be loaded when importing this module
77 | FormatsToProcess = @(
78 | "PSMath.Format.ps1xml"
79 | )
80 |
81 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
82 | NestedModules = @(
83 | "Horker.Math.dll"
84 | )
85 |
86 | # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
87 | FunctionsToExport = @()
88 |
89 | # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
90 | CmdletsToExport = "*"
91 |
92 | # Variables to export from this module
93 | VariablesToExport = @()
94 |
95 | # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
96 | AliasesToExport = "*"
97 |
98 | # DSC resources to export from this module
99 | # DscResourcesToExport = @()
100 |
101 | # List of all modules packaged with this module
102 | # ModuleList = @()
103 |
104 | # List of all files packaged with this module
105 | # FileList = @()
106 |
107 | # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
108 | PrivateData = @{
109 |
110 | PSData = @{
111 |
112 | # Tags applied to this module. These help with module discovery in online galleries.
113 | Tags = @(
114 | 'Accord', 'Accord.NET',
115 | 'math', 'statistics', 'statistical',
116 | 'sin', 'cos', 'exp', 'pow', 'sqrt', 'pi', 'matrix',
117 | 'mean', 'variance', 'standard', 'deviation',
118 | 'normal', 'chi', 'squire', 'f', 't', 'distribution',
119 | 'binomial', 'fisher', 'anova',
120 | 'hypothesis', 'testing',
121 | 'linear', 'logistic', 'regression'
122 | )
123 |
124 | # A URL to the license for this module.
125 | LicenseUri = 'https://opensource.org/licenses/LGPL-2.1'
126 |
127 | # A URL to the main website for this project.
128 | ProjectUri = 'https://github.com/horker/psmath'
129 |
130 | # A URL to an icon representing this module.
131 | # IconUri = ''
132 |
133 | # ReleaseNotes of this module
134 | ReleaseNotes = @"
135 | v0.1.1
136 | Fix several issues
137 |
138 | v0.1.0
139 | First release
140 | "@
141 |
142 | } # End of PSData hashtable
143 |
144 | } # End of PrivateData hashtable
145 |
146 | # HelpInfo URI of this module
147 | # HelpInfoURI = ''
148 |
149 | # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
150 | # DefaultCommandPrefix = ''
151 |
152 | }
153 |
--------------------------------------------------------------------------------
/scripts/PSMath.psm1:
--------------------------------------------------------------------------------
1 | Set-StrictMode -Version Latest
2 |
3 | $METHOD_LIST_1D = @(
4 | [PSCustomObject]@{
5 | ClassInfo = "Horker.Math.ArrayMethods.Typed.Linq[{0}]"
6 | TargetClass = "Object", "Double", "Single", "Int64", "Int32", "Int16", "Byte", "SByte"
7 | MethodNames = @(
8 | "Aggregate"
9 | "All"
10 | "Any"
11 | "AsEnumerable"
12 | "Concat"
13 | "Contains"
14 | "DefaultIfEmpty"
15 | "Distinct"
16 | "ElementAt"
17 | "ElementAtOrDefault"
18 | "Except"
19 | "First"
20 | "FirstOrDefault"
21 | #"GroupBy"
22 | "GroupJoin"
23 | "Intersect"
24 | "Join"
25 | "Last"
26 | "LastOrDefault"
27 | "LongCount"
28 | "Max"
29 | "Min"
30 | "OrderBy"
31 | "OrderByDescending"
32 | "Reverse"
33 | "Select"
34 | "SelectMany"
35 | "SequenceEqual"
36 | "Single"
37 | "SingleOrDefault"
38 | "Skip"
39 | "SkipWhile"
40 | "Sum"
41 | "Take"
42 | "TakeWhile"
43 | "ToDictionary"
44 | "ToList"
45 | "ToLookup"
46 | "Union"
47 | "Where"
48 | "Zip"
49 | )
50 | }
51 |
52 | [PSCustomObject]@{
53 | ClassInfo = "Horker.Math.ArrayMethods.Untyped.Additional"
54 | TargetClass = "Object", "Double", "Single", "Int64", "Int32", "Int16", "Byte", "SByte"
55 | MethodNames = @(
56 | "Clip"
57 | "DropNa"
58 | "DropNaN"
59 | "Histogram"
60 | "Summary"
61 | )
62 | }
63 |
64 | [PSCustomObject]@{
65 | ClassInfo = "Horker.Math.ArrayMethods.Typed.Additional[{0}]"
66 | TargetClass = "Object", "Double", "Single", "Int64", "Int32", "Int16", "Byte", "SByte"
67 | MethodNames = @(
68 | "Split"
69 | "Shuffle"
70 | "Slice"
71 | "Concatenate"
72 | )
73 | }
74 |
75 | [PSCustomObject]@{
76 | ClassInfo = "Horker.Math.ArrayMethods.Measures"
77 | TargetClass = "Object", "Double", "Single", "Int64", "Int32", "Int16", "Byte", "SByte"
78 | MethodNames = @(
79 | "ContraHarmonicMean"
80 | "Entropy"
81 | "ExponentialWeightedMean"
82 | "ExponentialWeightedVariance"
83 | "GeometricMean"
84 | "Kurtosis"
85 | "LogGeometricMean"
86 | "LowerQuartile"
87 | "Mean"
88 | "Median"
89 | "Mode"
90 | "Quantile"
91 | "Quantiles"
92 | "Quartiles"
93 | "Skewness"
94 | "StandardDeviation"
95 | "StdDev"
96 | "StandardError"
97 | "TruncatedMean"
98 | "UpperQuartile"
99 | "Variance"
100 | "Var"
101 | )
102 | }
103 |
104 | [PSCustomObject]@{
105 | ClassInfo = "Horker.Math.ArrayMethods.Tools"
106 | TargetClass = "Object", "Double", "Single", "Int64", "Int32", "Int16", "Byte", "SByte"
107 | MethodNames = @(
108 | "Center"
109 | "Rank"
110 | "Standardize"
111 | "Ties"
112 | )
113 | }
114 |
115 | [PSCustomObject]@{
116 | ClassInfo = "Horker.Math.ArrayMethods.Vector"
117 | TargetClass = "Object", "Double", "Single", "Int64", "Int32", "Int16", "Byte", "SByte"
118 | MethodNames = @(
119 | "Sample"
120 | "Scale"
121 | "Sort"
122 | )
123 | }
124 |
125 | [PSCustomObject]@{
126 | ClassInfo = "Horker.Math.ArrayMethods.Typed.Matrix[{0}]"
127 | TargetClass = "Object", "Double", "Single", "Int64", "Int32", "Int16", "Byte", "SByte"
128 | MethodNames = @(
129 | "Clear"
130 | "Copy"
131 | "DistinctCount"
132 | "Expand"
133 | "Find"
134 | "First"
135 | "Get"
136 | "IsEqual"
137 | "IsSorted"
138 | "OneHot"
139 | "Swap"
140 | )
141 | }
142 |
143 | [PSCustomObject]@{
144 | ClassInfo = "Horker.Math.ArrayMethods.Untyped.Matrix"
145 | TargetClass = "Object", "Double", "Single", "Int64", "Int32", "Int16", "Byte", "SByte"
146 | MethodNames = @(
147 | "ArgMax"
148 | "ArgMin"
149 | "ArgSort"
150 | "Bottom"
151 | "Cartesian"
152 | "Cross"
153 | "CumulativeSum"
154 | "HasInfinity"
155 | "HasNaN"
156 | "Kronecker"
157 | "Normalize"
158 | "Null"
159 | "Outer"
160 | "Product"
161 | "Stack"
162 | "Top"
163 | "Trim"
164 | )
165 | }
166 |
167 | [PSCustomObject]@{
168 | ClassInfo = "Horker.Math.ArrayMethods.Typed.ElementwiseObject"
169 | TargetClass = "Object"
170 | MethodNames = @(
171 | "ElementAdd"
172 | "ElementSubtract"
173 | "ElementMultiply"
174 | "ElementDivide"
175 | "ElementReminder"
176 | "ElementNegate"
177 | )
178 | }
179 |
180 | [PSCustomObject]@{
181 | ClassInfo = "Horker.Math.ArrayMethods.Typed.ElementwiseDouble"
182 | TargetClass = "Double"
183 | MethodNames = @(
184 | "ElementAdd"
185 | "ElementSubtract"
186 | "ElementMultiply"
187 | "ElementDivide"
188 | "ElementReminder"
189 | "ElementNegate"
190 | )
191 | }
192 |
193 | [PSCustomObject]@{
194 | ClassInfo = "Horker.Math.ArrayMethods.Typed.ElementwiseSingle"
195 | TargetClass = "Single"
196 | MethodNames = @(
197 | "ElementAdd"
198 | "ElementSubtract"
199 | "ElementMultiply"
200 | "ElementDivide"
201 | "ElementReminder"
202 | "ElementNegate"
203 | )
204 | }
205 |
206 | [PSCustomObject]@{
207 | ClassInfo = "Horker.Math.ArrayMethods.Typed.ElementwiseInt64"
208 | TargetClass = "Int64"
209 | MethodNames = @(
210 | "ElementAdd"
211 | "ElementSubtract"
212 | "ElementMultiply"
213 | "ElementDivide"
214 | "ElementReminder"
215 | "ElementNegate"
216 | )
217 | }
218 |
219 | [PSCustomObject]@{
220 | ClassInfo = "Horker.Math.ArrayMethods.Typed.ElementwiseInt32"
221 | TargetClass = "Int32"
222 | MethodNames = @(
223 | "ElementAdd"
224 | "ElementSubtract"
225 | "ElementMultiply"
226 | "ElementDivide"
227 | "ElementReminder"
228 | "ElementNegate"
229 | )
230 | }
231 |
232 | [PSCustomObject]@{
233 | ClassInfo = "Horker.Math.ArrayMethods.Typed.ElementwiseInt16"
234 | TargetClass = "Int16"
235 | MethodNames = @(
236 | "ElementAdd"
237 | "ElementSubtract"
238 | "ElementMultiply"
239 | "ElementDivide"
240 | "ElementReminder"
241 | "ElementNegate"
242 | )
243 | }
244 |
245 | [PSCustomObject]@{
246 | ClassInfo = "Horker.Math.ArrayMethods.Typed.ElementwiseByte"
247 | TargetClass = "Byte"
248 | MethodNames = @(
249 | "ElementAdd"
250 | "ElementSubtract"
251 | "ElementMultiply"
252 | "ElementDivide"
253 | "ElementReminder"
254 | "ElementNegate"
255 | )
256 | }
257 |
258 | [PSCustomObject]@{
259 | ClassInfo = "Horker.Math.ArrayMethods.Typed.ElementwiseSByte"
260 | TargetClass = "SByte"
261 | MethodNames = @(
262 | "ElementAdd"
263 | "ElementSubtract"
264 | "ElementMultiply"
265 | "ElementDivide"
266 | "ElementReminder"
267 | "ElementNegate"
268 | )
269 | }
270 | )
271 |
272 | # Methods for two-dimentional arrays
273 | $METHOD_LIST_2D = @(
274 | [PSCustomObject]@{
275 | ClassInfo = "Horker.Math.ArrayMethods.Typed.Additional[{0}]"
276 | TargetClass = "Object", "Double", "Single", "Int64", "Int32", "Int16", "Byte", "SByte"
277 | MethodNames = @(
278 | "Concatenate2"
279 | )
280 | }
281 | )
282 |
283 | # Methods for System.Data.DataTable
284 | $METHOD_LIST = @(
285 | [PSCustomObject]@{
286 | ClassInfo = "Horker.Math.DataTablePSMethods"
287 | TargetClass = "System.Data.DataTable"
288 | MethodNames = @(
289 | "ExpandToOneHot"
290 | "GetColumn"
291 | )
292 | }
293 | )
294 |
295 | foreach ($l in $METHOD_LIST_1D) {
296 | $targets = $l.TargetClass
297 | foreach ($t in $targets) {
298 | $ci = Invoke-Expression "[$($l.ClassInfo -f $t)]"
299 | foreach ($m in $l.MethodNames) {
300 | $mi = $ci.GetMethod($m)
301 | Update-TypeData -TypeName "$t[]" -MemberName $m -MemberType CodeMethod -Value $mi -Force
302 | }
303 | }
304 | }
305 |
306 | foreach ($l in $METHOD_LIST_2D) {
307 | $targets = $l.TargetClass
308 | foreach ($t in $targets) {
309 | $ci = Invoke-Expression "[$($l.ClassInfo -f $t)]"
310 | foreach ($m in $l.MethodNames) {
311 | $mi = $ci.GetMethod($m)
312 | $name = $m -replace "\d+$", "" # Remove trailing digits
313 | Update-TypeData -TypeName "$t[][]" -MemberName $name -MemberType CodeMethod -Value $mi -Force
314 | }
315 | }
316 | }
317 |
318 | foreach ($l in $METHOD_LIST) {
319 | $targets = $l.TargetClass
320 | foreach ($t in $targets) {
321 | $ci = Invoke-Expression "[$($l.ClassInfo -f $t)]"
322 | foreach ($m in $l.MethodNames) {
323 | $mi = $ci.GetMethod($m)
324 | Update-TypeData -TypeName "$t" -MemberName $m -MemberType CodeMethod -Value $mi -Force
325 | }
326 | }
327 | }
328 |
--------------------------------------------------------------------------------
/source/Horker.Math.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27130.2010
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{9E4D2A29-5617-4807-BC37-5AE6938E0195}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Horker.Math", "Horker.Math\Horker.Math.csproj", "{F4C2900E-ADFE-4612-A40C-19393FC2CEFF}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {9E4D2A29-5617-4807-BC37-5AE6938E0195}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {9E4D2A29-5617-4807-BC37-5AE6938E0195}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {9E4D2A29-5617-4807-BC37-5AE6938E0195}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {9E4D2A29-5617-4807-BC37-5AE6938E0195}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {F4C2900E-ADFE-4612-A40C-19393FC2CEFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {F4C2900E-ADFE-4612-A40C-19393FC2CEFF}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {F4C2900E-ADFE-4612-A40C-19393FC2CEFF}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {F4C2900E-ADFE-4612-A40C-19393FC2CEFF}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {B9E873E5-7212-4F40-AB65-221CF93A53C5}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/source/Horker.Math/ArrayMethods/ArrayMethodsHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Management.Automation;
4 |
5 | namespace Horker.Math.ArrayMethods
6 | {
7 | internal class Helper
8 | {
9 | internal static object[] GetObjectArray(PSObject values)
10 | {
11 | var array = values.BaseObject;
12 | if (array is object[])
13 | return array as object[];
14 | else if (array is double[])
15 | return (array as double[]).Select(x => (object)x).ToArray();
16 | else if (array is float[])
17 | return (array as float[]).Select(x => (object)x).ToArray();
18 | else if (array is Int64[])
19 | return (array as Int64[]).Select(x => (object)x).ToArray();
20 | else if (array is Int32[])
21 | return (array as Int32[]).Select(x => (object)x).ToArray();
22 | else if (array is Int16[])
23 | return (array as Int16[]).Select(x => (object)x).ToArray();
24 | else if (array is Byte[])
25 | return (array as Byte[]).Select(x => (object)x).ToArray();
26 | else if (array is SByte[])
27 | return (array as SByte[]).Select(x => (object)x).ToArray();
28 |
29 | throw new ArgumentException("Failed to convert to object[]");
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/source/Horker.Math/ArrayMethods/Typed/Elementwise.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Management.Automation;
5 | using Accord.Math;
6 | using Accord.Math.Random;
7 |
8 | namespace Horker.Math.ArrayMethods.Typed
9 | {
10 | public class ElementwiseObject
11 | {
12 | public static Double[] ElementAdd(PSObject values, Double other)
13 | { return Converter.ToDoubleArray(values).Select(x => x + other).ToArray(); }
14 |
15 | public static Double[] ElementSubtract(PSObject values, Double other)
16 | { return Converter.ToDoubleArray(values).Select(x => x - other).ToArray(); }
17 |
18 | public static Double[] ElementMultiply(PSObject values, Double other)
19 | { return Converter.ToDoubleArray(values).Select(x => x * other).ToArray(); }
20 |
21 | public static Double[] ElementDivide(PSObject values, Double other)
22 | { return Converter.ToDoubleArray(values).Select(x => x / other).ToArray(); }
23 |
24 | public static Double[] ElementReminder(PSObject values, Double other)
25 | { return Converter.ToDoubleArray(values).Select(x => x % other).ToArray(); }
26 |
27 | public static Double[] ElementNegate(PSObject values)
28 | { return Converter.ToDoubleArray(values).Select(x => -x).ToArray(); }
29 | }
30 |
31 | public class ElementwiseDouble
32 | {
33 | public static Double[] ElementAdd(PSObject values, Double other)
34 | { return (values.BaseObject as Double[]).Select(x => x + other).ToArray(); }
35 |
36 | public static Double[] ElementSubtract(PSObject values, Double other)
37 | { return (values.BaseObject as Double[]).Select(x => x - other).ToArray(); }
38 |
39 | public static Double[] ElementMultiply(PSObject values, Double other)
40 | { return (values.BaseObject as Double[]).Select(x => x * other).ToArray(); }
41 |
42 | public static Double[] ElementDivide(PSObject values, Double other)
43 | { return (values.BaseObject as Double[]).Select(x => x / other).ToArray(); }
44 |
45 | public static Double[] ElementReminder(PSObject values, Double other)
46 | { return (values.BaseObject as Double[]).Select(x => x % other).ToArray(); }
47 |
48 | public static Double[] ElementNegate(PSObject values)
49 | { return (values.BaseObject as Double[]).Select(x => -x).ToArray(); }
50 | }
51 |
52 | public class ElementwiseSingle
53 | {
54 | public static Single[] ElementAdd(PSObject values, Single other)
55 | { return (values.BaseObject as Single[]).Select(x => x + other).ToArray(); }
56 |
57 | public static Single[] ElementSubtract(PSObject values, Single other)
58 | { return (values.BaseObject as Single[]).Select(x => x - other).ToArray(); }
59 |
60 | public static Single[] ElementMultiply(PSObject values, Single other)
61 | { return (values.BaseObject as Single[]).Select(x => x * other).ToArray(); }
62 |
63 | public static Single[] ElementDivide(PSObject values, Single other)
64 | { return (values.BaseObject as Single[]).Select(x => x / other).ToArray(); }
65 |
66 | public static Single[] ElementReminder(PSObject values, Single other)
67 | { return (values.BaseObject as Single[]).Select(x => x % other).ToArray(); }
68 |
69 | public static Single[] ElementNegate(PSObject values)
70 | { return (values.BaseObject as Single[]).Select(x => -x).ToArray(); }
71 | }
72 |
73 | public class ElementwiseInt64
74 | {
75 | public static Int64[] ElementAdd(PSObject values, Int64 other)
76 | { return (values.BaseObject as Int64[]).Select(x => x + other).ToArray(); }
77 |
78 | public static Int64[] ElementSubtract(PSObject values, Int64 other)
79 | { return (values.BaseObject as Int64[]).Select(x => x - other).ToArray(); }
80 |
81 | public static Int64[] ElementMultiply(PSObject values, Int64 other)
82 | { return (values.BaseObject as Int64[]).Select(x => x * other).ToArray(); }
83 |
84 | public static Int64[] ElementDivide(PSObject values, Int64 other)
85 | { return (values.BaseObject as Int64[]).Select(x => x / other).ToArray(); }
86 |
87 | public static Int64[] ElementReminder(PSObject values, Int64 other)
88 | { return (values.BaseObject as Int64[]).Select(x => x % other).ToArray(); }
89 |
90 | public static Int64[] ElementNegate(PSObject values)
91 | { return (values.BaseObject as Int64[]).Select(x => -x).ToArray(); }
92 | }
93 |
94 | public class ElementwiseInt32
95 | {
96 | public static Int32[] ElementAdd(PSObject values, Int32 other)
97 | { return (values.BaseObject as Int32[]).Select(x => x + other).ToArray(); }
98 |
99 | public static Int32[] ElementSubtract(PSObject values, Int32 other)
100 | { return (values.BaseObject as Int32[]).Select(x => x - other).ToArray(); }
101 |
102 | public static Int32[] ElementMultiply(PSObject values, Int32 other)
103 | { return (values.BaseObject as Int32[]).Select(x => x * other).ToArray(); }
104 |
105 | public static Int32[] ElementDivide(PSObject values, Int32 other)
106 | { return (values.BaseObject as Int32[]).Select(x => x / other).ToArray(); }
107 |
108 | public static Int32[] ElementReminder(PSObject values, Int32 other)
109 | { return (values.BaseObject as Int32[]).Select(x => x % other).ToArray(); }
110 |
111 | public static Int32[] ElementNegate(PSObject values)
112 | { return (values.BaseObject as Int32[]).Select(x => -x).ToArray(); }
113 | }
114 |
115 | public class ElementwiseInt16
116 | {
117 | public static Int16[] ElementAdd(PSObject values, Int16 other)
118 | { return (values.BaseObject as Int16[]).Select(x => (Int16)(x + other)).ToArray(); }
119 |
120 | public static Int16[] ElementSubtract(PSObject values, Int16 other)
121 | { return (values.BaseObject as Int16[]).Select(x => (Int16)(x - other)).ToArray(); }
122 |
123 | public static Int16[] ElementMultiply(PSObject values, Int16 other)
124 | { return (values.BaseObject as Int16[]).Select(x => (Int16)(x * other)).ToArray(); }
125 |
126 | public static Int16[] ElementDivide(PSObject values, Int16 other)
127 | { return (values.BaseObject as Int16[]).Select(x => (Int16)(x / other)).ToArray(); }
128 |
129 | public static Int16[] ElementReminder(PSObject values, Int16 other)
130 | { return (values.BaseObject as Int16[]).Select(x => (Int16)(x % other)).ToArray(); }
131 |
132 | public static Int16[] ElementNegate(PSObject values)
133 | { return (values.BaseObject as Int16[]).Select(x => (Int16)(-x)).ToArray(); }
134 | }
135 |
136 | public class ElementwiseByte
137 | {
138 | public static Byte[] ElementAdd(PSObject values, Byte other)
139 | { return (values.BaseObject as Byte[]).Select(x => (Byte)(x + other)).ToArray(); }
140 |
141 | public static Byte[] ElementSubtract(PSObject values, Byte other)
142 | { return (values.BaseObject as Byte[]).Select(x => (Byte)(x - other)).ToArray(); }
143 |
144 | public static Byte[] ElementMultiply(PSObject values, Byte other)
145 | { return (values.BaseObject as Byte[]).Select(x => (Byte)(x * other)).ToArray(); }
146 |
147 | public static Byte[] ElementDivide(PSObject values, Byte other)
148 | { return (values.BaseObject as Byte[]).Select(x => (Byte)(x / other)).ToArray(); }
149 |
150 | public static Byte[] ElementReminder(PSObject values, Byte other)
151 | { return (values.BaseObject as Byte[]).Select(x => (Byte)(x % other)).ToArray(); }
152 |
153 | public static Byte[] ElementNegate(PSObject values)
154 | { return (values.BaseObject as Byte[]).Select(x => (Byte)(-x)).ToArray(); }
155 | }
156 |
157 | public class ElementwiseSByte
158 | {
159 | public static SByte[] ElementAdd(PSObject values, SByte other)
160 | { return (values.BaseObject as SByte[]).Select(x => (SByte)(x + other)).ToArray(); }
161 |
162 | public static SByte[] ElementSubtract(PSObject values, SByte other)
163 | { return (values.BaseObject as SByte[]).Select(x => (SByte)(x - other)).ToArray(); }
164 |
165 | public static SByte[] ElementMultiply(PSObject values, SByte other)
166 | { return (values.BaseObject as SByte[]).Select(x => (SByte)(x * other)).ToArray(); }
167 |
168 | public static SByte[] ElementDivide(PSObject values, SByte other)
169 | { return (values.BaseObject as SByte[]).Select(x => (SByte)(x / other)).ToArray(); }
170 |
171 | public static SByte[] ElementReminder(PSObject values, SByte other)
172 | { return (values.BaseObject as SByte[]).Select(x => (SByte)(x % other)).ToArray(); }
173 |
174 | public static SByte[] ElementNegate(PSObject values)
175 | { return (values.BaseObject as SByte[]).Select(x => (SByte)(-x)).ToArray(); }
176 | }
177 | }
178 |
--------------------------------------------------------------------------------
/source/Horker.Math/ArrayMethods/Typed/Matrix.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Management.Automation;
5 | using Accord.Math;
6 | using Accord.Math.Random;
7 |
8 | namespace Horker.Math.ArrayMethods.Typed
9 | {
10 | public class Matrix
11 | {
12 | public static void Clear(
13 | PSObject values
14 | )
15 | {
16 | var array = (T[])values.BaseObject;
17 | Accord.Math.Matrix.Clear(array);
18 | }
19 |
20 | /*
21 | public static T[] Concatenate(
22 | PSObject a,
23 | T[] b
24 | )
25 | {
26 | var array = (T[])a.BaseObject;
27 | return Accord.Math.Matrix.Concatenate(b);
28 | }
29 | */
30 |
31 | public static T[] Copy(
32 | PSObject vector
33 | )
34 | {
35 | var array = (T[])vector.BaseObject;
36 | var result = new T[array.Length];
37 | Array.Copy(array, result, array.Length);
38 | return result;
39 | }
40 |
41 | public static int DistinctCount(
42 | PSObject values
43 | )
44 | {
45 | var array = (T[])values.BaseObject;
46 | return Accord.Math.Matrix.DistinctCount(array);
47 | }
48 |
49 | public static T[] Expand(
50 | PSObject vector,
51 | int[] count
52 | )
53 | {
54 | var array = (T[])vector.BaseObject;
55 | return Accord.Math.Matrix.Expand(array, count);
56 | }
57 |
58 | public static int[] Find(
59 | PSObject data,
60 | Func func,
61 | bool firstOnly = false
62 | )
63 | {
64 | var array = (T[])data.BaseObject;
65 | return Accord.Math.Matrix.Find(array, func, firstOnly);
66 | }
67 |
68 | public static T[] First(
69 | PSObject values,
70 | int count
71 | )
72 | {
73 | var array = (T[])values.BaseObject;
74 | return Accord.Math.Matrix.First(array, count);
75 | }
76 |
77 | public static T[] Get(
78 | PSObject source,
79 | int startRow,
80 | int endRow
81 | )
82 | {
83 | var array = (T[])source.BaseObject;
84 | return Accord.Math.Matrix.Get(array, startRow, endRow);
85 | }
86 |
87 | public static bool IsEqual(
88 | PSObject a,
89 | PSObject b
90 | )
91 | {
92 | return Accord.Math.Matrix.IsEqual(a, b);;
93 | }
94 |
95 | public static bool IsSorted(
96 | PSObject values,
97 | Accord.Math.Comparers.ComparerDirection direction = Accord.Math.Comparers.ComparerDirection.Ascending
98 | )
99 | {
100 | var array = Converter.ToDoubleArray(values);
101 | return Accord.Math.Matrix.IsSorted(array, direction);
102 | }
103 |
104 | public static Matrix OneHot(PSObject values, int? columns = null)
105 | {
106 | var array = (T[])values.BaseObject;
107 |
108 | if (columns.HasValue)
109 | return Accord.Math.Matrix.OneHot(array.Apply(x => Convert.ToInt32(x)), columns.Value);
110 | else
111 | return Accord.Math.Matrix.OneHot(array.Apply(x => Convert.ToInt32(x)));
112 | }
113 |
114 | public static void Swap(
115 | PSObject values,
116 | int a,
117 | int b
118 | )
119 | {
120 | var array = (T[])values.BaseObject;
121 | Accord.Math.Matrix.Swap(array, a, b);
122 | }
123 | }
124 | }
--------------------------------------------------------------------------------
/source/Horker.Math/ArrayMethods/Untyped/Additional.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Management.Automation;
5 | using Accord.Math;
6 | using Accord.Math.Random;
7 |
8 | namespace Horker.Math.ArrayMethods.Untyped
9 | {
10 | public class HistogramBin
11 | {
12 | public double Lower;
13 | public double Upper;
14 | public int Count;
15 | }
16 |
17 | public class Additional
18 | {
19 | public static double[] Clip(PSObject values, double min, double? max = null)
20 | {
21 | var array = Converter.ToDoubleArray(values);
22 |
23 | if (max.HasValue)
24 | return array.Select(x => x < min ? min : (x > max.Value ? max.Value : x)).ToArray();
25 | else
26 | return array.Select(x => x > min ? min : x).ToArray();
27 | }
28 |
29 | public static object[] DropNa(PSObject values)
30 | {
31 | var array = Helper.GetObjectArray(values);
32 |
33 | var result = new List