Skip to content

Commit

Permalink
SDR Reconstruction
Browse files Browse the repository at this point in the history
  • Loading branch information
sahithkumar1999 committed May 23, 2024
1 parent 7e68920 commit ff27ef0
Show file tree
Hide file tree
Showing 7 changed files with 1,287 additions and 11 deletions.
55 changes: 55 additions & 0 deletions source/NeoCortexApi/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -581,5 +581,60 @@ public static List<Cell> GetDistalConnectedCells(Cell cell, IList<Cell> populati

return connectedCells;
}



public static string StringifyDictionarybykeys(Dictionary<int, double> dictionary)
{
if (dictionary == null)
{
return "null";
}

StringBuilder result = new StringBuilder();
foreach (var key in dictionary.Keys)
{
// Access the value using the key and append it to the result
result.Append($"{dictionary[key]},");
}

// Remove the trailing separator
if (result.Length > 0)
{
result.Length--; // Remove the last character
}

return result.ToString();
}



/// <summary>
/// Thresholds a collection of Reconstruced Permanence values based on a given threshold.
/// </summary>
/// <param name="values">The collection of probability values to be thresholded.</param>
/// <param name="threshold">The threshold value used for thresholding.</param>
/// <returns>A list of binary values (0 or 1) representing the thresholded probabilities.</returns>


public static List<int> ThresholdingProbabilities(IEnumerable<double> values, double threshold)
{
if (values == null)
{
return null;
}

List<int> resultList = new List<int>();

foreach (var numericValue in values)
{
int thresholdedValue = (numericValue >= threshold) ? 1 : 0;

resultList.Add(thresholdedValue);
}

return resultList;
}

}
}
4 changes: 2 additions & 2 deletions source/NeoCortexApi/SPSdrReconstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public SPSdrReconstructor(Connections mem)
/// <exception cref="ArgumentNullException"></exception>
public Dictionary<int, double> Reconstruct(int[] activeMiniColumns)
{
if(activeMiniColumns == null)
if (activeMiniColumns == null)
{
throw new ArgumentNullException(nameof(activeMiniColumns));
}

var cols = _mem.GetColumnList(activeMiniColumns);

Dictionary<int, double> result = new Dictionary<int, double>();

//
Expand Down
319 changes: 318 additions & 1 deletion source/NeoCortexUtils/NeoCortexUtils.cs

Large diffs are not rendered by default.

Loading

0 comments on commit ff27ef0

Please sign in to comment.