예제 #1
0
        public void SaveAsCode(TextWriter writer, RoleMappedSchema schema)
        {
            Host.CheckValue(writer, nameof(writer));
            Host.CheckValue(schema, nameof(schema));

            var weights = Weight;

            LinearPredictorUtils.SaveAsCode(writer, ref weights, Bias, schema);
        }
예제 #2
0
        /// <summary>
        /// Output the text model to a given writer
        /// </summary>
        public void SaveAsCode(TextWriter writer, RoleMappedSchema schema)
        {
            Host.CheckValue(writer, nameof(writer));
            Host.CheckValueOrNull(schema);

            for (int i = 0; i < _biases.Length; i++)
            {
                LinearPredictorUtils.SaveAsCode(writer,
                                                ref _weights[i],
                                                _biases[i],
                                                schema,
                                                "score[" + i.ToString() + "]");
            }

            writer.WriteLine(string.Format("var softmax = MathUtils.SoftMax(scores, {0});", _numClasses));
            for (int c = 0; c < _biases.Length; c++)
            {
                writer.WriteLine("output[{0}] = Math.Exp(scores[{0}] - softmax);", c);
            }
        }