Documentation ¶
Index ¶
- func GetCoalitionValue(coalition map[Touchpoint]struct{}, allContributions []ContributionSet) big.Float
- func GetFirstTouchpointValue(touchpoint Touchpoint, allContributions []Contribution) big.Float
- func GetLastTouchpointValue(touchpoint Touchpoint, allContributions []Contribution) big.Float
- func GetLinearValue(touchpoint Touchpoint, allContributions []ContributionSet) big.Float
- func GetRepeatedLinearValue(touchpoint Touchpoint, allContributions []Contribution) big.Float
- func GetShapleyValue(touchpoint Touchpoint, allContributions []ContributionSet) big.Float
- func GetTotalValue(contributions []ContributionSet) big.Float
- type Contribution
- type ContributionSet
- type Touchpoint
- type Touchpoints
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCoalitionValue ¶
func GetCoalitionValue(coalition map[Touchpoint]struct{}, allContributions []ContributionSet) big.Float
GetCoalitionValue returns the total value a given coalition achieved over a list of contributions.
Example (Multiple) ¶
contributions := []ContributionSet{ ContributionSet{ Touchpoints: map[Touchpoint]struct{}{ Touchpoint{"Touchpoint 1"}: struct{}{}, }, Value: *new(big.Float).SetFloat64(100.), }, ContributionSet{ Touchpoints: map[Touchpoint]struct{}{ Touchpoint{"Touchpoint 1"}: struct{}{}, Touchpoint{"Touchpoint 2"}: struct{}{}, }, Value: *new(big.Float).SetFloat64(200.), }, ContributionSet{ Touchpoints: map[Touchpoint]struct{}{ Touchpoint{"Touchpoint 1"}: struct{}{}, Touchpoint{"Touchpoint 3"}: struct{}{}, Touchpoint{"Touchpoint 1"}: struct{}{}, }, Value: *new(big.Float).SetFloat64(300.), }, } coalition := map[Touchpoint]struct{}{ Touchpoint{"Touchpoint 1"}: struct{}{}, Touchpoint{"Touchpoint 3"}: struct{}{}, } coalitionValue := GetCoalitionValue(coalition, contributions) fmt.Println(coalitionValue.String())
Output: 400
Example (Singleton) ¶
contributions := []ContributionSet{ ContributionSet{ Touchpoints: map[Touchpoint]struct{}{ Touchpoint{"Touchpoint 1"}: struct{}{}, }, Value: *new(big.Float).SetFloat64(100.), }, ContributionSet{ Touchpoints: map[Touchpoint]struct{}{ Touchpoint{"Touchpoint 1"}: struct{}{}, Touchpoint{"Touchpoint 2"}: struct{}{}, }, Value: *new(big.Float).SetFloat64(200.), }, ContributionSet{ Touchpoints: map[Touchpoint]struct{}{ Touchpoint{"Touchpoint 2"}: struct{}{}, Touchpoint{"Touchpoint 3"}: struct{}{}, Touchpoint{"Touchpoint 1"}: struct{}{}, }, Value: *new(big.Float).SetFloat64(300.), }, } coalition := map[Touchpoint]struct{}{ Touchpoint{"Touchpoint 1"}: struct{}{}, } coalitionValue := GetCoalitionValue(coalition, contributions) fmt.Println(coalitionValue.String())
Output: 100
func GetFirstTouchpointValue ¶
func GetFirstTouchpointValue(touchpoint Touchpoint, allContributions []Contribution) big.Float
GetFirstTouchpointValue returns summed value of all contributions where the given touchpoints happened to be first in its list of contributors.
Example ¶
contributions := []Contribution{ Contribution{ Touchpoints: []Touchpoint{ Touchpoint{"Touchpoint 1"}, }, Value: *new(big.Float).SetFloat64(100.), }, Contribution{ Touchpoints: []Touchpoint{ Touchpoint{"Touchpoint 1"}, Touchpoint{"Touchpoint 2"}, }, Value: *new(big.Float).SetFloat64(200.), }, Contribution{ Touchpoints: []Touchpoint{ Touchpoint{"Touchpoint 1"}, Touchpoint{"Touchpoint 3"}, Touchpoint{"Touchpoint 1"}, }, Value: *new(big.Float).SetFloat64(300.), }, } touchpoint := Touchpoint{"Touchpoint 1"} firstTouchpointValue := GetFirstTouchpointValue(touchpoint, contributions) fmt.Println(firstTouchpointValue.String())
Output: 600
func GetLastTouchpointValue ¶
func GetLastTouchpointValue(touchpoint Touchpoint, allContributions []Contribution) big.Float
GetLastTouchpointValue returns summed value of all contributions where the given touchpoints happened to be last in its list of contributors.
Example ¶
contributions := []Contribution{ Contribution{ Touchpoints: []Touchpoint{ Touchpoint{"Touchpoint 1"}, }, Value: *new(big.Float).SetFloat64(100.), }, Contribution{ Touchpoints: []Touchpoint{ Touchpoint{"Touchpoint 1"}, Touchpoint{"Touchpoint 2"}, }, Value: *new(big.Float).SetFloat64(200.), }, Contribution{ Touchpoints: []Touchpoint{ Touchpoint{"Touchpoint 1"}, Touchpoint{"Touchpoint 3"}, Touchpoint{"Touchpoint 1"}, }, Value: *new(big.Float).SetFloat64(300.), }, } touchpoint := Touchpoint{"Touchpoint 1"} lastTouchpointValue := GetLastTouchpointValue(touchpoint, contributions) fmt.Println(lastTouchpointValue.String())
Output: 400
func GetLinearValue ¶
func GetLinearValue(touchpoint Touchpoint, allContributions []ContributionSet) big.Float
GetLinearValue returns the linear value (ignoring repetition) of a given touchpoint summed over all contributions. The linear value without repititions for Contribution objecs can best be calculated by first transformating them to ContributionSet objects with the Set() method and then applying this function.
Example ¶
contributions := []ContributionSet{ ContributionSet{ Touchpoints: map[Touchpoint]struct{}{ Touchpoint{"Touchpoint 1"}: struct{}{}, }, Value: *new(big.Float).SetFloat64(100.), }, ContributionSet{ Touchpoints: map[Touchpoint]struct{}{ Touchpoint{"Touchpoint 1"}: struct{}{}, Touchpoint{"Touchpoint 2"}: struct{}{}, }, Value: *new(big.Float).SetFloat64(200.), }, ContributionSet{ Touchpoints: map[Touchpoint]struct{}{ Touchpoint{"Touchpoint 1"}: struct{}{}, Touchpoint{"Touchpoint 3"}: struct{}{}, }, Value: *new(big.Float).SetFloat64(300.), }, } touchpoint := Touchpoint{"Touchpoint 1"} linearValue := GetLinearValue(touchpoint, contributions) fmt.Println(linearValue.String())
Output: 350
func GetRepeatedLinearValue ¶
func GetRepeatedLinearValue(touchpoint Touchpoint, allContributions []Contribution) big.Float
GetRepeatedLinearValue returns the linear value (with repition) of a given touchpoint summed over all contributions.
Example ¶
contributions := []Contribution{ Contribution{ Touchpoints: []Touchpoint{ Touchpoint{"Touchpoint 1"}, }, Value: *new(big.Float).SetFloat64(100.), }, Contribution{ Touchpoints: []Touchpoint{ Touchpoint{"Touchpoint 1"}, Touchpoint{"Touchpoint 2"}, }, Value: *new(big.Float).SetFloat64(200.), }, Contribution{ Touchpoints: []Touchpoint{ Touchpoint{"Touchpoint 1"}, Touchpoint{"Touchpoint 3"}, Touchpoint{"Touchpoint 1"}, }, Value: *new(big.Float).SetFloat64(300.), }, } touchpoint := Touchpoint{"Touchpoint 1"} linearValue := GetRepeatedLinearValue(touchpoint, contributions) fmt.Println(linearValue.String())
Output: 400
func GetShapleyValue ¶
func GetShapleyValue(touchpoint Touchpoint, allContributions []ContributionSet) big.Float
GetShapleyValue returns the (unordered) Shapley value of a given touchpoint over all provided contributions. For a concise introduction to Shapley values, see https://christophm.github.io/interpretable-ml-book/shapley.html
Example ¶
contributions := []ContributionSet{ ContributionSet{ Touchpoints: map[Touchpoint]struct{}{ Touchpoint{"Touchpoint 1"}: struct{}{}, }, Value: *new(big.Float).SetFloat64(100.), }, ContributionSet{ Touchpoints: map[Touchpoint]struct{}{ Touchpoint{"Touchpoint 1"}: struct{}{}, Touchpoint{"Touchpoint 2"}: struct{}{}, }, Value: *new(big.Float).SetFloat64(200.), }, ContributionSet{ Touchpoints: map[Touchpoint]struct{}{ Touchpoint{"Touchpoint 1"}: struct{}{}, Touchpoint{"Touchpoint 3"}: struct{}{}, Touchpoint{"Touchpoint 1"}: struct{}{}, }, Value: *new(big.Float).SetFloat64(300.), }, } touchpoint := Touchpoint{"Touchpoint 1"} shapleyValue := GetShapleyValue(touchpoint, contributions) fmt.Println(shapleyValue.String())
Output: 350
func GetTotalValue ¶
func GetTotalValue(contributions []ContributionSet) big.Float
GetTotalValue returns the summed value over all contributions.
Example ¶
contributions := []ContributionSet{ ContributionSet{ Touchpoints: map[Touchpoint]struct{}{ Touchpoint{"Touchpoint 1"}: struct{}{}, Touchpoint{"Touchpoint 2"}: struct{}{}, }, Value: *new(big.Float).SetFloat64(100.), }, ContributionSet{ Touchpoints: map[Touchpoint]struct{}{ Touchpoint{"Touchpoint 1"}: struct{}{}, Touchpoint{"Touchpoint 3"}: struct{}{}, Touchpoint{"Touchpoint 1"}: struct{}{}, }, Value: *new(big.Float).SetFloat64(200.), }, } totalValue := GetTotalValue(contributions) fmt.Println(totalValue.String())
Output: 300
Types ¶
type Contribution ¶
type Contribution struct { Touchpoints Touchpoints Value big.Float }
A Contribution consists of an ordered list of touchpoints together with their combined value.
func (Contribution) Set ¶
func (contribution Contribution) Set() ContributionSet
func (Contribution) String ¶
func (contribution Contribution) String() string
type ContributionSet ¶
type ContributionSet struct { Touchpoints map[Touchpoint]struct{} Value big.Float }
A ContributionSet consists of an unordered set of touchpoints together with their combined value.
func (ContributionSet) String ¶
func (contribution ContributionSet) String() string
type Touchpoint ¶
type Touchpoint struct {
Name string // name of the touchpoint
}
A Touchpoint represents a contributing entity in a ContributionSet.
type Touchpoints ¶
type Touchpoints []Touchpoint
Touchpoints represents a list of touchpoints. It implements the sort.Interface interface.
func GetAllTouchpoints ¶
func GetAllTouchpoints(contributions []ContributionSet) Touchpoints
GetAllTouchpoints returns a list (without repetition) all touchpoints encountered in contributions.
Example ¶
contributions := []ContributionSet{ ContributionSet{ Touchpoints: map[Touchpoint]struct{}{ Touchpoint{"Touchpoint 1"}: struct{}{}, Touchpoint{"Touchpoint 2"}: struct{}{}, }, Value: *new(big.Float).SetFloat64(100.), }, ContributionSet{ Touchpoints: map[Touchpoint]struct{}{ Touchpoint{"Touchpoint 1"}: struct{}{}, Touchpoint{"Touchpoint 3"}: struct{}{}, Touchpoint{"Touchpoint 1"}: struct{}{}, }, Value: *new(big.Float).SetFloat64(200.), }, } allTouchpoints := GetAllTouchpoints(contributions) fmt.Println(allTouchpoints)
Output: [{Touchpoint 1} {Touchpoint 2} {Touchpoint 3}]
func (Touchpoints) Len ¶
func (touchpoints Touchpoints) Len() int
Len returns the length of Touchpoints.
func (Touchpoints) Less ¶
func (touchpoints Touchpoints) Less(i, j int) bool
Less provides a strict order on Touchpoints.
func (Touchpoints) String ¶
func (touchpoints Touchpoints) String() string
String provides a string represenation of Touchpoints.
func (Touchpoints) Swap ¶
func (touchpoints Touchpoints) Swap(i, j int)
Swap swaps the order of two elements of Touchpoints.