public double[][] GetNormalizedBinaryCodes(IActivationFunction function, int binaryLength) { byte[][] codes = BinaryOutputUtil.GetAllBinaryCodes(binaryLength); int length = codes.GetLength(0); double[][] fCodes = new double[length][]; for (int i = 0; i < length; i++) { fCodes[i] = Array.ConvertAll(codes[i], s => (double)s); NormalizeUtils.NormalizeOneDesiredOutputInPlace(function, fCodes[i]); } return(fCodes); }
/// <summary>Performs RDF normalization on the given JSON-LD input.</summary> /// <remarks>Performs RDF normalization on the given JSON-LD input.</remarks> /// <param name="input">the expanded JSON-LD object to normalize.</param> /// <param name="options">the normalization options.</param> /// <param name="callback">(err, normalized) called once the operation completes.</param> /// <exception cref="JSONLDProcessingError">JSONLDProcessingError</exception> /// <exception cref="JsonLD.Core.JsonLdError"></exception> public virtual object Normalize(RDFDataset dataset) { // create quads and map bnodes to their associated quads IList<RDFDataset.Quad> quads = new List<RDFDataset.Quad>(); IDictionary<string,IDictionary<string,object>> bnodes = new Dictionary<string,IDictionary<string,object>>(); foreach (string graphName in dataset.Keys) { var eachGraphName = graphName; IList<RDFDataset.Quad> triples = (IList<RDFDataset.Quad>)dataset[eachGraphName]; if ("@default".Equals(eachGraphName)) { eachGraphName = null; } foreach (RDFDataset.Quad quad in triples) { if (eachGraphName != null) { if (eachGraphName.IndexOf("_:") == 0) { IDictionary<string, object> tmp = new Dictionary<string, object>(); tmp["type"] = "blank node"; tmp["value"] = eachGraphName; quad["name"] = tmp; } else { IDictionary<string, object> tmp = new Dictionary<string, object>(); tmp["type"] = "IRI"; tmp["value"] = eachGraphName; quad["name"] = tmp; } } quads.Add(quad); string[] attrs = new string[] { "subject", "object", "name" }; foreach (string attr in attrs) { if (quad.ContainsKey(attr) && (string)((IDictionary<string,object>)quad[attr])["type"] == "blank node") { string id = (string)((IDictionary<string,object>)quad[attr])["value"]; if (!bnodes.ContainsKey(id)) { bnodes[id] = new Dictionary<string,object> { {"quads", new List<RDFDataset.Quad>()} }; } ((IList<RDFDataset.Quad>)bnodes[id]["quads"]).Add(quad); } } } } // mapping complete, start canonical naming NormalizeUtils normalizeUtils = new NormalizeUtils(quads, bnodes, new UniqueNamer ("_:c14n"), opts); return normalizeUtils.HashBlankNodes(bnodes.Keys); }