public void EncodeFullDateTimeTest(int w, double r, Object input, int[] expectedOutput) { CortexNetworkContext ctx = new CortexNetworkContext(); var now = DateTimeOffset.Now; Dictionary <string, Dictionary <string, object> > encoderSettings = getFullEncoderSettings(); var encoder = new DateTimeEncoder(encoderSettings, DateTimeEncoder.Precision.Days); var result = encoder.Encode(DateTimeOffset.Parse(input.ToString())); // This is a limitation for 2D drawing only. if ((result.Length % 2) != 0) { throw new ArgumentException("Only odd number of bits is allowed. Please set Offset pproperty of all encoders to odd value."); } Debug.WriteLine(NeoCortexApi.Helpers.StringifyVector(result)); int[,] twoDimenArray = ArrayUtils.Make2DArray <int>(result, (int)Math.Sqrt(result.Length), (int)Math.Sqrt(result.Length)); var twoDimArray = ArrayUtils.Transpose(twoDimenArray); NeoCortexUtils.DrawBitmap(twoDimArray, 1024, 1024, $"FullDateTime_out_{input.ToString().Replace("/", "-").Replace(":", "-")}_32x32-N-{encoderSettings["DateTimeEncoder"]["N"]}-W-{encoderSettings["DateTimeEncoder"]["W"]}.png", Color.Yellow, Color.Black); // Assert.IsTrue(result.SequenceEqual(expectedOutput)); }
public void EncodeDateTimeTest(int w, double r, Object input, int[] expectedOutput) { CortexNetworkContext ctx = new CortexNetworkContext(); var now = DateTimeOffset.Now; Dictionary <string, Dictionary <string, object> > encoderSettings = new Dictionary <string, Dictionary <string, object> >(); encoderSettings.Add("DateTimeEncoder", new Dictionary <string, object>() { { "W", 21 }, { "N", 1024 }, { "MinVal", now.AddYears(-10) }, { "MaxVal", now }, { "Periodic", false }, { "Name", "DateTimeEncoder" }, { "ClipInput", false }, { "Padding", 5 }, }); var encoder = new DateTimeEncoder(encoderSettings, DateTimeEncoder.Precision.Days); var result = encoder.Encode(DateTimeOffset.Parse(input.ToString())); Debug.WriteLine(NeoCortexApi.Helpers.StringifyVector(result)); //Debug.WriteLine(NeoCortexApi.Helpers.StringifyVector(expectedOutput)); int[,] twoDimenArray = ArrayUtils.Make2DArray <int>(result, 32, 32); var twoDimArray = ArrayUtils.Transpose(twoDimenArray); NeoCortexUtils.DrawBitmap(twoDimArray, 1024, 1024, $"DateTime_out_{input.ToString().Replace("/", "-").Replace(":", "-")}_32x32-N-{encoderSettings["DateTimeEncoder"]["N"]}-W-{encoderSettings["DateTimeEncoder"]["W"]}.png"); // Assert.IsTrue(result.SequenceEqual(expectedOutput)); }
private static void execFullDateTimeEncodingTest(string prefix, object input) { var now = DateTimeOffset.Now; Dictionary <string, Dictionary <string, object> > encoderSettings = getFullEncoderSettings(); encoderSettings["DayOfWeekEncoder"]["ClipInput"] = false; var encoder = new DateTimeEncoder(encoderSettings, DateTimeEncoder.Precision.Days); var result = encoder.Encode(DateTimeOffset.Parse(input.ToString(), CultureInfo.InvariantCulture)); // This is a limitation for 2D drawing only. if ((result.Length % 2) != 0) { throw new ArgumentException("Only odd number of bits is allowed. Please set Offset pproperty of all encoders to odd value."); } Debug.WriteLine(NeoCortexApi.Helpers.StringifyVector(result)); int[,] twoDimenArray = ArrayUtils.Make2DArray <int>(result, (int)Math.Sqrt(result.Length), (int)Math.Sqrt(result.Length)); var twoDimArray = ArrayUtils.Transpose(twoDimenArray); NeoCortexUtils.DrawBitmap(twoDimArray, 1024, 1024, $"{prefix}_out_{input.ToString().Replace("/", "-").Replace(":", "-")}_32x32-N-{encoderSettings["DateTimeEncoder"]["N"]}-W-{encoderSettings["DateTimeEncoder"]["W"]}.png", Color.Yellow, Color.Black); }
public void EncodeTimeOnlyTest(Object input, int[] expectedOutput) { CortexNetworkContext ctx = new CortexNetworkContext(); Dictionary <string, object> encoderSettings = getDefaultSettings(); DateTimeEncoder encoder = new DateTimeEncoder(encoderSettings); var result = encoder.EncodeTimeOnly(input); foreach (var item in result) { Debug.Write(item + ","); } Assert.IsTrue(result.SequenceEqual(expectedOutput)); }
public void CreateSdrAsBitmapTest() { Object[] d1 = new Object[] { "05/02/2020 22:58:06", "06/04/2020 01:28:07", "07/09/2019 21:15:07", "08/01/2017 11:27:07" }; this.DateTimeEncoderTest(d1); Object[] inputs = { "05/02/2020 22:58:07", "06/04/2020 01:28:07", "07/09/2019 21:15:07", "08/01/2018 11:27:07" }; foreach (var input in inputs) { var outFolder = @"EncoderOutputImages\DateTimeEncoderOutput"; Directory.CreateDirectory(outFolder); var now = DateTimeOffset.Now; Dictionary <string, Dictionary <string, object> > encoderSettings = new Dictionary <string, Dictionary <string, object> >(); encoderSettings.Add("DateTimeEncoder", new Dictionary <string, object>() { { "W", 21 }, { "N", 1024 }, { "MinVal", now.AddYears(-10) }, { "MaxVal", now }, { "Periodic", false }, { "Name", "DateTimeEncoder" }, { "ClipInput", false }, { "Padding", 5 }, }); var encoder = new DateTimeEncoder(encoderSettings, DateTimeEncoder.Precision.Days); var result = encoder.Encode(DateTimeOffset.Parse(input.ToString())); Debug.WriteLine($"Input = {input}"); Debug.WriteLine($"SDRs Generated = {NeoCortexApi.Helpers.StringifyVector(result)}"); Debug.WriteLine($"SDR As Indices = {NeoCortexApi.Helpers.StringifyVector(ArrayUtils.IndexWhere(result, k => k == 1))}"); int[,] twoDimenArray = ArrayUtils.Make2DArray <int>(result, 32, 32); var twoDimArray = ArrayUtils.Transpose(twoDimenArray); NeoCortexUtils.DrawBitmap(twoDimArray, 1024, 1024, $"{outFolder}\\{input.ToString().Replace("/", "-").Replace(":", "-")}_32x32-N-{encoderSettings["DateTimeEncoder"]["N"]}-W-{encoderSettings["DateTimeEncoder"]["W"]}.png"); } }
public string GenerateToken(List <Claim> claims) { try { StringBuilder sb = new StringBuilder(); foreach (var item in claims) { sb.Append(item.Value + "|"); } //Generate raw token var strRawToken = sb.ToString() + DateTimeEncoder.EncryptTimeStamp(DateTime.Now.AddSeconds(_option.Expirty)); //Encrypt token and return return(Encryptor.EncryptAES(strRawToken, _option.CommonCSNTokenKey, _option.CommonCSNTokenIV).Replace('+', '-').Replace('/', '_').Replace('=', '.')); } catch (System.Exception ex) { throw ex; } }
public void InitTest4() { Dictionary <string, object> encoderSettings = getDefaultSettings(); // We change here value of Name property. encoderSettings["Name"] = "hello"; // We add here new property. encoderSettings.Add("TestProp1", "hello"); var encoder = new DateTimeEncoder(); // Settings can also be passed by invoking Initialize(sett) encoder.Initialize(encoderSettings); // Property can also be set this way. encoder["abc"] = "1"; Assert.IsTrue((string)encoder["TestProp1"] == "hello"); Assert.IsTrue((string)encoder["Name"] == "hello"); Assert.IsTrue((string)encoder["abc"] == "1"); }
public void DateTimeEncoderTest(Object[] inputs) { var outFolder = @"..\..\..\..\ScalarEncoderResults"; var now = DateTimeOffset.Now; Dictionary <string, Dictionary <string, object> > encoderSettings = new Dictionary <string, Dictionary <string, object> >(); encoderSettings.Add("DateTimeEncoder", new Dictionary <string, object>() { { "W", 7 }, { "N", 20 }, { "MinVal", now.AddYears(-10) }, { "MaxVal", now }, { "Periodic", false }, { "Name", "DateTimeEncoder" }, { "ClipInput", false }, { "Padding", 5 }, }); var encoder = new DateTimeEncoder(encoderSettings, DateTimeEncoder.Precision.Days); Dictionary <Object, int[]> sdrs = new Dictionary <Object, int[]>(); foreach (Object input in inputs) { int[] result = encoder.Encode(DateTimeOffset.Parse(input.ToString())); int[,] twoDimenArray = ArrayUtils.Make2DArray <int>(result, 32, 32); var twoDimArray = ArrayUtils.Transpose(twoDimenArray); NeoCortexUtils.DrawBitmap(twoDimArray, 1024, 1024, $"{outFolder}\\{input.ToString().Replace("/", "-").Replace(":", "-")}_32x32-N-{encoderSettings["DateTimeEncoder"]["N"]}-W-{encoderSettings["DateTimeEncoder"]["W"]}.png"); Console.WriteLine($"Input = {input}"); Console.WriteLine($"SDRs Generated = {NeoCortexApi.Helpers.StringifyVector(result)}"); Console.WriteLine($"SDR As Text = {NeoCortexApi.Helpers.StringifyVector(ArrayUtils.IndexWhere(result, k => k == 1))}"); sdrs.Add(input, result); } // <summary> /// Calculate all required results. /// 1. Overlap and Union of the Binary arrays of two scalar values /// It cross compares the binary arrays of any of the two scalar values User enters. /// 2. Creates bitmaps of the overlaping and non-overlaping regions of the two binary arrays selected by the User. /// </summary> int[] result1 = encoder.Encode(DateTimeOffset.Parse(inputs[0].ToString())); Console.WriteLine($"Input 000 = {inputs[0]}"); Console.WriteLine($"Input 33 = {inputs[3]}"); int[] result2 = encoder.Encode(DateTimeOffset.Parse(inputs[3].ToString())); SimilarityResult1(result1, result2, sdrs, outFolder, inputs[0], inputs[3]); }