Example #1
0
        /// <summary>
        /// Writes this layer as XML
        /// </summary>
        /// <param name="writer">The XML writer</param>
        public void WriteTo(XmlWriter writer)
        {
            writer.WriteStartElement("layer");
            writer.WriteAttributeString("input-size", InputSize.ToString());
            writer.WriteAttributeString("output-size", OutputSize.ToString());
            writer.WriteAttributeString("activation", Activation.ToString());
            writer.WriteAttributeString("weight-init", WeightInitialisation.ToString());
            writer.WriteAttributeString("regularisation", Regularisation.ToString());
            writer.WriteAttributeString("weight-update", WeightUpdate.ToString());
            writer.WriteAttributeString("trainer", LayerTrainer.ToString());
            writer.WriteAttributeString("lambda", Lambda.ToString());
            writer.WriteAttributeString("momentum", Momentum.ToString());
            writer.WriteAttributeString("decay-rate", DecayRate.ToString());
            writer.WriteAttributeString("decay-rate2", DecayRate2.ToString());
            writer.WriteAttributeString("dropout", Dropout.ToString());
            if (Bias != null)
            {
                Bias.WriteTo("bias", writer);
            }
            if (Weight != null)
            {
                writer.WriteStartElement("weight");
                foreach (var item in Weight)
                {
                    item.WriteTo("row", writer);
                }
                writer.WriteEndElement();
            }

            writer.WriteEndElement();
        }
Example #2
0
        private static void WeightUpdateExample()
        {
            string userId     = "";
            string userSecret = "";

            var choice = AskFor <int>("Enter 1 to enter custom profile info, or 0 to use the last searched for info: ");

            if (choice == 1)
            {
                userId     = AskFor <string>("Enter a User Token to look for: ");
                userSecret = AskFor <string>("Enter a User Secret to look for: ");
            }
            else
            {
                userId     = searchUserKey;
                userSecret = searchUserSecret;
            }

            if (weightUpdate == null)
            {
                weightUpdate = new WeightUpdate(consumerKey, consumerSecret);
            }

            var weight  = AskFor <double>("Weight (pounds): ");
            var height  = AskFor <double>("Height (feet) [5'11\" = 5.9167]: ");
            var goal    = AskFor <double>("Goal Weight (pounds): ");
            var comment = AskFor <string>("Comment: ");

            var response = weightUpdate.GetResponseSynchronously(new WeightUpdateRequest()
            {
                UserToken        = userId,
                UserSecret       = userSecret,
                CurrentWeight_KG = weight * 0.45359237,
                CurrentHeight_CM = height * 30.48,
                GoalWeight_KG    = goal * 0.45359237,
                Comment          = comment,
                UpdateDate       = DateTime.UtcNow,
            });

            if (response != null && response.IsSuccess)
            {
                Console.WriteLine("Successfully reported weight.");
            }
            else
            {
                Console.WriteLine("Problem reporting weight.");
            }
        }
Example #3
0
        // Constructor
        public Neuron(int Number_Of_Connections, int Seed)
        {
            for (int i = 0; i < Number_Of_Connections; i++)
            {
                Weights.Add(Random_GaussianDist(Seed + i, 0, 1));
                Inputs.Add(0);
                WeightUpdate.Add(0);
                PreviousWeightUpdate.Add(0);
            }

            // Add additional value to represent bias
            Weights.Add(0.1);
            Inputs.Add(0);
            WeightUpdate.Add(0);
            PreviousWeightUpdate.Add(0);
        }
        public IActionResult Patch([FromBody] WeightUpdate value, [FromRoute] string id, [FromQuery(Name = "update_mask")] string updateMask)
        {
            if (!Guid.TryParse(id, out Guid parsedId))
            {
                return(BadRequest("Expected the ID to be a UUID / GUID"));
            }
            // Arrange
            if (string.IsNullOrWhiteSpace(updateMask))
            {
                return(BadRequest("update_mask is required. Fields to be updated must be supplied using their JSON property names. Acceptable field names are: " + this.GetJsonPropertyNameFieldsAsCsv(typeof(WeightUpdate))));
            }

            var updateMaskList = updateMask.Split(',').ToList();

            var weightMeasurement = value.MapTo();

            if (weightMeasurement == null)
            {
                return(BadRequest("Unable to process the request."));
            }
            else if (weightMeasurement.Unit == WeightMeasurement.Units.None && updateMaskList.Contains("unit", StringComparer.InvariantCultureIgnoreCase))
            {
                return(BadRequest("Unable to process the request. Units were not properly defined. Acceptable values are: " + Enum <WeightMeasurement.Units> .GetValuesAsCSV()));
            }
            else
            {
                weightMeasurement.Id = parsedId;
            }

            // Act
            if (!_bizLogic.Exists(weightMeasurement.Id))
            {
                return(NotFound("ID not found."));
            }

            var bizResult = _bizLogic.Update(weightMeasurement, updateMaskList);

            // Response
            if (bizResult.Outcome == MetrikOutcome.Ok)
            {
                WeightUpdated responseResult = WeightUpdated.MapFrom(bizResult.Artifact);
                return(Ok(responseResult));
            }

            return(ParseMetrikResultIntoActionResult(bizResult));
        }
        public IActionResult Put([FromBody] WeightUpdate value, [FromRoute] string id)
        {
            if (!Guid.TryParse(id, out Guid parsedId))
            {
                return(BadRequest("Expected the ID to be a UUID / GUID"));
            }
            // Arrange
            var weightMeasurement = value.MapTo();

            if (weightMeasurement == null)
            {
                return(BadRequest("Unable to process the request."));
            }
            else if (weightMeasurement.Unit == WeightMeasurement.Units.None)
            {
                return(BadRequest("Unable to process the request. Units were not properly defined. Acceptable values are: " + Enum <WeightMeasurement.Units> .GetValuesAsCSV()));
            }
            else
            {
                weightMeasurement.Id = parsedId;
            }

            var updateMask = this.GetJsonPropertyNameFields(typeof(WeightUpdate));

            // Act
            if (!_bizLogic.Exists(weightMeasurement.Id))
            {
                return(NotFound("ID not found."));
            }

            var bizResult = _bizLogic.Update(weightMeasurement, updateMask);

            // Response
            if (bizResult.Outcome == MetrikOutcome.Ok)
            {
                WeightUpdated responseResult = WeightUpdated.MapFrom(bizResult.Artifact);
                return(Ok(responseResult));
            }

            return(ParseMetrikResultIntoActionResult(bizResult));
        }
Example #6
0
 private void UpdateWeight(string weight)
 {
     WeightUpdate?.Invoke(weight);
 }