github.com/jgbaldwinbrown/perf@v0.1.1/pkg/stats/deltadist.go (about)

     1  // Copyright 2015 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package stats
     6  
     7  // DeltaDist is the Dirac delta function, centered at T, with total
     8  // area 1.
     9  //
    10  // The CDF of the Dirac delta function is the Heaviside step function,
    11  // centered at T. Specifically, f(T) == 1.
    12  type DeltaDist struct {
    13  	T float64
    14  }
    15  
    16  func (d DeltaDist) PDF(x float64) float64 {
    17  	if x == d.T {
    18  		return inf
    19  	}
    20  	return 0
    21  }
    22  
    23  func (d DeltaDist) pdfEach(xs []float64) []float64 {
    24  	res := make([]float64, len(xs))
    25  	for i, x := range xs {
    26  		if x == d.T {
    27  			res[i] = inf
    28  		}
    29  	}
    30  	return res
    31  }
    32  
    33  func (d DeltaDist) CDF(x float64) float64 {
    34  	if x >= d.T {
    35  		return 1
    36  	}
    37  	return 0
    38  }
    39  
    40  func (d DeltaDist) cdfEach(xs []float64) []float64 {
    41  	res := make([]float64, len(xs))
    42  	for i, x := range xs {
    43  		res[i] = d.CDF(x)
    44  	}
    45  	return res
    46  }
    47  
    48  func (d DeltaDist) InvCDF(y float64) float64 {
    49  	if y < 0 || y > 1 {
    50  		return nan
    51  	}
    52  	return d.T
    53  }
    54  
    55  func (d DeltaDist) Bounds() (float64, float64) {
    56  	return d.T - 1, d.T + 1
    57  }