last ...
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,107 @@
|
|||||||
|
|
||||||
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\Constants\ConfigurationNodeNames.cs
|
||||||
|
|
||||||
|
namespace xAiService.Constants
|
||||||
|
{
|
||||||
|
public partial struct ConfigurationNodeNames
|
||||||
|
{
|
||||||
|
public const string AI_SERVICE_NODE = "AIServiceConfiguration";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\DI\XDIHelperExtension.cs
|
||||||
|
|
||||||
|
namespace xAiService.DI
|
||||||
|
{
|
||||||
|
public static partial class XDIHelperExtension
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
|
||||||
|
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\Modules\xAiService\Helpers\VectorHelper.cs
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
|
||||||
|
namespace xAiService.Helpers
|
||||||
|
{
|
||||||
|
public static class VectorHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Normalize a Vector ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="vector"></param>
|
||||||
|
public static void Normalize(float[] vector)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (vector.IsNull() || !vector.HasChild())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
float sum = 0f;
|
||||||
|
foreach (var value in vector)
|
||||||
|
{
|
||||||
|
sum += value * value;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
float norm = MathF.Sqrt(sum);
|
||||||
|
if (norm <= 1e-9f)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = 0; i < vector.Length; i++)
|
||||||
|
{
|
||||||
|
vector[i] /= norm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Similarity Check ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="a"></param>
|
||||||
|
/// <param name="b"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static float CosineSimilarity(float[] a, float[] b)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
if (a.IsNull() || b.IsNull())
|
||||||
|
{
|
||||||
|
return 0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (a.Length != b.Length)
|
||||||
|
{
|
||||||
|
return 0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
float dot = 0f;
|
||||||
|
float normA = 0f;
|
||||||
|
float normB = 0f;
|
||||||
|
for (int i = 0; i < a.Length; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
dot += a[i] * b[i];
|
||||||
|
normA += a[i] * a[i];
|
||||||
|
normB += b[i] * b[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
float denominator = MathF.Sqrt(normA) * MathF.Sqrt(normB);
|
||||||
|
if (denominator <= 1e-9f)
|
||||||
|
{
|
||||||
|
return 0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = dot / denominator;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+1
-1
Submodule xAiApi updated: 9afa413c6f...ed8a66f432
Reference in New Issue
Block a user