create parallel computing for the Canopy evaluation

This commit is contained in:
この中二病に爆焔を! 2024-01-25 09:03:01 +08:00
parent 7ffb5bd1ab
commit 55ff139f93
2 changed files with 45 additions and 0 deletions

View File

@ -8,9 +8,13 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\sciBASIC#\Data\BinaryData\BinaryData\binarydata-netcore5.vbproj" />
<ProjectReference Include="..\..\..\..\sciBASIC#\Data\BinaryData\msgpack\msgpack-netcore5.vbproj" />
<ProjectReference Include="..\..\..\..\sciBASIC#\Data_science\DataMining\DataMining\DataMining.NET5.vbproj" />
<ProjectReference Include="..\..\..\..\sciBASIC#\Data_science\Mathematica\Math\Math\Math.NET5.vbproj" />
<ProjectReference Include="..\..\..\..\sciBASIC#\Microsoft.VisualBasic.Core\src\Core.vbproj" />
<ProjectReference Include="..\..\..\..\sciBASIC#\mime\application%json\JSON-netcore5.vbproj" />
<ProjectReference Include="..\..\..\..\sciBASIC#\www\Microsoft.VisualBasic.NETProtocol\network-netcore5.vbproj" />
<ProjectReference Include="..\..\computing\batch\batch.vbproj" />
<ProjectReference Include="..\..\computing\Parallel\parallel-netcore5.vbproj" />
</ItemGroup>

View File

@ -1,3 +1,44 @@
Imports System.Runtime.CompilerServices
Imports batch
Imports Microsoft.VisualBasic.DataMining.Clustering
Imports Microsoft.VisualBasic.DataMining.KMeans
Imports Parallel.IpcStream
Public Module VectorMath
''' <summary>
''' a global parameters for the parallel computing
''' </summary>
Dim par As Argument
Public Sub SetEnvironment(par As Argument)
VectorMath.par = par
End Sub
Public Sub SetThreads(n_threads As Integer)
If par Is Nothing Then
par = New Argument(n_threads)
Else
par.n_threads = n_threads
End If
End Sub
''' <summary>
''' this function calculate the average distance between each points of
''' the given data vectors, result could be used for:
'''
''' 1. calculate the T2 threshold for <see cref="CanopyBuilder"/>
''' 2.
''' </summary>
''' <param name="points"></param>
''' <returns></returns>
<Extension>
Public Function AverageDistance(points As IEnumerable(Of ClusterEntity)) As Double
Dim alldata As ClusterEntity() = points.ToArray
Dim pool As SocketRef = SocketRef.WriteBuffer(alldata)
Dim task As New Func(Of ClusterEntity, ClusterEntity(), Double)(AddressOf CanopyBuilder.TotalDistance)
Dim dist = Host.ParallelFor(Of ClusterEntity, Double)(par, task, alldata, pool).ToArray
Return CanopyBuilder.AverageDistance(alldata.Length, parts:=dist)
End Function
End Module