Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Damir Dobric committed Jun 25, 2024
2 parents 66e13d9 + f51c6ce commit 20e5916
Show file tree
Hide file tree
Showing 47 changed files with 5,836 additions and 253 deletions.
1 change: 1 addition & 0 deletions .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
5.0.x
6.0.x
7.0.x
8.0.x
- name: Install dependencies
run: dotnet restore ${{env.MainSln}}
Expand Down
Binary file not shown.
542 changes: 542 additions & 0 deletions source/Documentation/Spatial Pooler SDR Reconstruction.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion source/GridCell/GridCell.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<None Remove="NumSharp" />
Expand Down
14 changes: 7 additions & 7 deletions source/HtmActorHost/HtmActorHost.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand All @@ -20,12 +20,12 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="DotNetActors" Version="1.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NeoCortexApi.Parallel\NeoCortexApi.Parallel.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion source/ImageEncoder/HtmImageEncoder.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<PackageLicenseFile>license.txt</PackageLicenseFile>
<IsPackable>true</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
Expand Down
12 changes: 9 additions & 3 deletions source/NeoCortexApi.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32014.148
Expand Down Expand Up @@ -53,9 +52,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nuget", "nuget", "{9475B9AE
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GridCell", "GridCell\GridCell.csproj", "{E102D57D-BA8F-4E21-8365-8ABAFB5D2C94}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NeoCortexApiAnomaly", "Samples\NeoCortexApiAnomaly\NeoCortexApiAnomaly.csproj", "{7F272910-3A59-4BBB-8888-9A7F695CA754}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NeoCortexApiAnomaly", "Samples\NeoCortexApiAnomaly\NeoCortexApiAnomaly.csproj", "{7F272910-3A59-4BBB-8888-9A7F695CA754}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NeocortexApiLLMSample", "NeocortexApiLLMSample\NeocortexApiLLMSample.csproj", "{8D1F778F-AF73-44CF-965E-C061C07B99A7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NeocortexApiLLMSample", "NeocortexApiLLMSample\NeocortexApiLLMSample.csproj", "{8D1F778F-AF73-44CF-965E-C061C07B99A7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApproveMultiSequenceLearning", "Samples\ApproveMultiSequenceLearning\ApproveMultiSequenceLearning.csproj", "{D56D5B70-0094-41F0-9FFD-BCAB50BA7737}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -123,6 +124,10 @@ Global
{8D1F778F-AF73-44CF-965E-C061C07B99A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D1F778F-AF73-44CF-965E-C061C07B99A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D1F778F-AF73-44CF-965E-C061C07B99A7}.Release|Any CPU.Build.0 = Release|Any CPU
{D56D5B70-0094-41F0-9FFD-BCAB50BA7737}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D56D5B70-0094-41F0-9FFD-BCAB50BA7737}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D56D5B70-0094-41F0-9FFD-BCAB50BA7737}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D56D5B70-0094-41F0-9FFD-BCAB50BA7737}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -133,6 +138,7 @@ Global
{AE2CF42C-DC7D-4F0A-8B43-84A5D81E1D72} = {99AE2313-7D07-4905-A0BB-52D304FCC2F7}
{7F272910-3A59-4BBB-8888-9A7F695CA754} = {99AE2313-7D07-4905-A0BB-52D304FCC2F7}
{8D1F778F-AF73-44CF-965E-C061C07B99A7} = {99AE2313-7D07-4905-A0BB-52D304FCC2F7}
{D56D5B70-0094-41F0-9FFD-BCAB50BA7737} = {99AE2313-7D07-4905-A0BB-52D304FCC2F7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {71185BAD-1342-4836-BCDA-6EC97118F92D}
Expand Down
87 changes: 80 additions & 7 deletions source/NeoCortexApi/Encoders/EncoderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace NeoCortexApi.Encoders
Expand Down Expand Up @@ -33,9 +35,9 @@ public abstract class EncoderBase : IHtmModule, ISerializable
protected int nInternal;

protected double rangeInternal;

protected bool encLearningEnabled;

protected List<FieldMetaType> flattenedFieldTypeList;

protected Dictionary<Dictionary<string, int>, List<FieldMetaType>> decoderFieldTypes;
Expand All @@ -50,6 +52,7 @@ public abstract class EncoderBase : IHtmModule, ISerializable
// Moved to MultiEncoder.
//protected Dictionary<EncoderTuple, List<EncoderTuple>> encoders;
protected List<String> scalarNames;
private object[] encoders;

/// <summary>
/// Default constructor.
Expand Down Expand Up @@ -87,6 +90,11 @@ public void Initialize(Dictionary<String, Object> encoderSettings)
Radius = -1.0;
Periodic = false;
ClipInput = false;
NumBits = 0;
PeriodicRadius = 0;
BucketWidth = 0;
NumBuckets = 0;


foreach (var item in encoderSettings)
{
Expand Down Expand Up @@ -132,7 +140,7 @@ public object this[string key]
}
}



/// <summary>
/// In real cortex mode, W must be >= 21. Empirical value.
Expand All @@ -146,13 +154,30 @@ public object this[string key]

public int N { get => (int)this["N"]; set => this["N"] = (int)value; }

public int Verbosity { get => (int)this["Verbosity"]; set => this["Verbosity"] = (int)value; }

public int startIdx { get => (int)this["startIdx"]; set => this["startIdx"] = (int)value; }
public int runLength { get => (int)this["runLength"]; set => this["runLength"] = (int)value; }
public bool[] tmpOutput { get => (bool[])this["tmpOutput"]; set => this["tmpOutput"] = (bool[])value; }


public double run { get => (double)this["run"]; set => this["run"] = (double)value; }
/// <summary>
/// public double nz { get => (double)this["nz"]; set => this["nz"] = (double)value; }
/// </summary>
public double runs { get => (double)this["runs"]; set => this["runs"] = (double)value; }



public int NInternal { get => (int)this["NInternal"]; set => this["NInternal"] = (int)value; }

/// <summary>
/// Number of bits set on one, which represents single encoded value.
/// </summary>
public int W { get => (int)this["W"]; set => this["W"] = (int)value; }



public double MinVal { get => (double)this["MinVal"]; set => this["MinVal"] = (double)value; }

public double MaxVal { get => (double)this["MaxVal"]; set => this["MaxVal"] = (double)value; }
Expand All @@ -175,6 +200,12 @@ public object this[string key]
/// </summary>
public bool ClipInput { get => (bool)this["ClipInput"]; set => this["ClipInput"] = (bool)value; }

public int NumBits { get; private set; }
public double PeriodicRadius { get; private set; }
public double BucketWidth { get; private set; }
public int NumBuckets { get; private set; }
public double[] Centers { get; private set; }

public int Padding { get => (int)this["Padding"]; set => this["Padding"] = value; }

public double Range { get => (double)this["Range"]; set => this["Range"] = value; }
Expand Down Expand Up @@ -203,6 +234,7 @@ public object this[string key]
/// Returns true if the underlying encoder works on deltas
/// </summary>
public abstract bool IsDelta { get; }
public (object name, object enc, object offset) encoder { get; private set; }
#endregion

/// <summary>
Expand Down Expand Up @@ -260,6 +292,47 @@ public int[] RightVecProd(SparseObjectMatrix<int[]> matrix, int[] encoded)
}



/// <summary>
/// This method maps a value from one range to another range.
///It takes in the value, the minimum and maximum of the input range, and the minimum and maximum of the output range as parameters.
///The method then returns the corresponding value in the output range based on the input value and input-output range relationship.
/// </summary>
/// <param name="val"></param>
/// <param name="fromMin"></param>
/// <param name="fromMax"></param>
/// <param name="toMin"></param>
/// <param name="toMax"></param>
/// <returns></returns>
public static double map(double val, double fromMin, double fromMax, double toMin, double toMax)
{
return (val - fromMin) * (toMax - toMin) / (fromMax - fromMin) + toMin;
}


/// <summary>
///This method wraps an input value within a specified range, so that it always falls within the range.
/// If the input value is outside the range, it is wrapped around to the other side of the range until it falls within the range.
/// The range is defined by a minimum and maximum value.
/// </summary>
/// <param name="val"></param>
/// <param name="minVal"></param>
/// <param name="maxVal"></param>
/// <returns></returns>
public static int wrap(int val, int minVal, int maxVal)
{
int range = maxVal - minVal + 1;
while (val < minVal)
{
val += range;
}
while (val > maxVal)
{
val -= range;
}
return val;
}

/// <summary>
/// Returns the rendered similarity matrix for the whole rage of values between min and max.
/// </summary>
Expand All @@ -270,7 +343,7 @@ public string TraceSimilarities(bool traceValues = true)
Dictionary<string, int[]> sdrMap = new Dictionary<string, int[]>();
List<string> inpVals = new List<string>();
StringBuilder sb = new StringBuilder();

for (double i = this.MinVal; i < this.MaxVal; i += 1.0)
{
var sdr = this.Encode(i);
Expand All @@ -280,7 +353,7 @@ public string TraceSimilarities(bool traceValues = true)
if (traceValues)
{
sb.AppendLine($"{i.ToString("000")} - {Helpers.StringifyVector(sdr, separator: null)}");
}
}
}

sb.AppendLine();
Expand Down Expand Up @@ -319,8 +392,8 @@ public bool Equals(EncoderBase other)

public void Serialize(object obj, string name, StreamWriter sw)
{
var excludeMembers = new List<string>
{
var excludeMembers = new List<string>
{
nameof(EncoderBase.Properties),
nameof(EncoderBase.halfWidth),
nameof(EncoderBase.rangeInternal),
Expand Down
Loading

0 comments on commit 20e5916

Please sign in to comment.