Exemplo n.º 1
0
        /// <summary>
        ///   Computes the model's baseline survival function. This method
        ///   simply calls the <see cref="UnivariateContinuousDistribution.ComplementaryDistributionFunction"/>
        ///   of the <see cref="BaselineHazard"/> function.
        /// </summary>
        ///
        /// <param name="time">The event time.</param>
        ///
        /// <returns>The baseline survival function at the given time.</returns>
        ///
        public double Survival(double time)
        {
            if (BaselineHazard == null)
            {
                throw new InvalidOperationException();
            }

            return(BaselineHazard.ComplementaryDistributionFunction(time));
        }
Exemplo n.º 2
0
        /// <summary>
        ///   Computes the model output for the given time.
        /// </summary>
        ///
        /// <param name="time">The event time.</param>
        ///
        /// <returns>The probabilities of the event occurring at the given time.</returns>
        ///
        public double Compute(double time)
        {
            if (BaselineHazard == null)
            {
                throw new InvalidOperationException();
            }

            return(BaselineHazard.CumulativeHazardFunction(time));
        }
        /// <summary>
        /// Predicts a class label for the given input vector, returning the
        /// log-likelihood that the input vector belongs to its predicted class.
        /// </summary>
        ///
        /// <param name="time">The event times.</param>
        ///
        public double LogLikelihood(double time)
        {
            if (BaselineHazard == null)
            {
                throw new InvalidOperationException();
            }

            return(BaselineHazard.LogCumulativeHazardFunction(time));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Predicts a class label vector for the given input vector, returning the
        /// log-likelihood that the input vector belongs to its predicted class.
        /// </summary>
        /// <param name="input">The input vector.</param>
        public override double LogLikelihood(Tuple <double[], double> input)
        {
            double sum = Intercept;

            for (int i = 0; i < Coefficients.Length; i++)
            {
                sum += Coefficients[i] * input.Item1[i];
            }
            double h0 = BaselineHazard.LogCumulativeHazardFunction(input.Item2);

            return(h0 + sum);
        }
        /// <summary>
        /// Predicts a class label vector for the given input vectors, returning the
        /// log-likelihood that the input vector belongs to its predicted class.
        /// </summary>
        ///
        /// <param name="input">The input vector.</param>
        /// <param name="result">An array where the log-likelihoods will be stored,
        /// avoiding unnecessary memory allocations.</param>
        ///
        public override double[] LogLikelihood(Tuple <double[], double>[] input, double[] result)
        {
#pragma warning disable 612, 618
            for (int j = 0; j < input.Length; j++)
            {
                double sum = Intercept;
                for (int i = 0; i < Coefficients.Length; i++)
                {
                    sum += Coefficients[i] * (input[j].Item1[i] - Offsets[i]);
                }
                double h0 = BaselineHazard.LogCumulativeHazardFunction(input[j].Item2);
                result[j] = h0 + sum;
            }
            return(result);

#pragma warning restore 612, 618
        }
Exemplo n.º 6
0
        /// <summary>
        ///   Computes the model output for the given input vector.
        /// </summary>
        ///
        /// <param name="input">The input vector.</param>
        /// <param name="time">The event time.</param>
        ///
        /// <returns>The probabilities of the event occurring at
        /// the given time for the given observation.</returns>
        ///
        public double Compute(double[] input, double time)
        {
            if (BaselineHazard == null)
            {
                throw new InvalidOperationException();
            }

            double sum = 0;

            for (int i = 0; i < Coefficients.Length; i++)
            {
                sum += Coefficients[i] * (input[i] - Offsets[i]);
            }
            double exp = Math.Exp(sum);

            double h0 = BaselineHazard.CumulativeHazardFunction(time);

            return(h0 * exp);
        }