/* ComputeContinu Given an attribute A and the target attribute T which contain N classes in C, compute the information gain of A. The result of Gini partitions value, Gini Index, and Gini Gain is saved in ContinuPart, Index, and Gain. */ func (gini *Gini) ComputeContinu(A *[]float64, T *[]string, C *[]string) { gini.IsContinu = true // make a copy of attribute and target. A2 := make([]float64, len(*A)) copy(A2, *A) T2 := make([]string, len(*T)) copy(T2, *T) gini.SortedIndex = numerus.Floats64IndirectSort(A2, true) if DEBUG >= 1 { fmt.Println("[gini] attr sorted :", A2) } // sort the target attribute using sorted index. tekstus.StringsSortByIndex(&T2, gini.SortedIndex) // create partition gini.createContinuPartition(&A2) // create holder for gini index and gini gain gini.Index = make([]float64, len(gini.ContinuPart)) gini.Gain = make([]float64, len(gini.ContinuPart)) gini.MinIndexValue = 1.0 // compute gini index for all samples gini.Value = gini.compute(&T2, C) gini.computeContinuGain(&A2, &T2, C) }
// // ComputeContinuFloat Given an attribute A and the target attribute T which contain // N classes in C, compute the information gain of A. // // The result of Gini partitions value, Gini Index, and Gini Gain is saved in // ContinuPart, Index, and Gain. // // Algorithm, // (0) Sort the attribute. // (1) Sort the target attribute using sorted index. // (2) Create continu partition. // (3) Create temporary space for gini index and gini gain. // (4) Compute gini index for all target. // func (gini *Gini) ComputeContinuFloat(A, T, C *[]float64) { gini.IsContinu = true gini.SortedIndex = numerus.Floats64IndirectSort(*A, true) if DEBUG >= 1 { fmt.Println("[gini] attr sorted :", A) } // (1) numerus.Floats64SortByIndex(T, gini.SortedIndex) // (2) gini.createContinuPartition(A) // (3) gini.Index = make([]float64, len(gini.ContinuPart)) gini.Gain = make([]float64, len(gini.ContinuPart)) gini.MinIndexValue = 1.0 // (4) gini.Value = gini.computeFloat(T, C) gini.computeContinuGainFloat(A, T, C) }