func TestSVM(t *testing.T) { data := []Data(nil) for i := 0.0; i < 5.0; i += 0.1 { data = append( data, &mydata{ value: []gotypes.Value{ gotypes.WrapReal(i), }, class: -1.0, }, ) } for i := 5.0; i <= 10.0; i += 0.1 { data = append( data, &mydata{ value: []gotypes.Value{ gotypes.WrapReal(i), }, class: 1.0, }, ) } Alpha := float32(0.5) C := float32(0.5) svm := NewSVMClassifer(data, &herpKern{}, Alpha, C) if svm == nil { t.FailNow() } }
func parseColumn(text string, theType gotypes.Type) (result gotypes.Value, retType gotypes.Type, err error) { if theType == gotypes.Unknown { if result, retType, err = parseColumn(text, gotypes.Real); err == nil { /* Empty */ } else if result, retType, err = parseColumn(text, gotypes.Integer); err == nil { /* Empty */ } else if result, retType, err = parseColumn(text, gotypes.Boolean); err == nil { /* Empty */ } else if result, retType, err = parseColumn(text, gotypes.Text); err == nil { /* Empty */ } else { panic("Something went seriously wrong") } } else { var ( real float64 integer int64 boolean bool ) retType = theType switch theType { case gotypes.Real: if real, err = strconv.ParseFloat(strings.TrimSpace(text), 64); err != nil { break } else { result = gotypes.WrapReal(real) } case gotypes.Integer: if integer, err = strconv.ParseInt(strings.TrimSpace(text), 10, 64); err != nil { break } else { result = gotypes.WrapInteger(integer) } case gotypes.Boolean: if boolean, err = strconv.ParseBool(strings.TrimSpace(text)); err != nil { break } else { result = gotypes.WrapBoolean(boolean) } case gotypes.Text: result = gotypes.WrapText(text) default: panic(fmt.Sprintf("%s: %d\n", "Unknown type", theType)) } } return }
func init() { features := 8 jump := 1000 var wg sync.WaitGroup LargeData = make([]classify.Data, LargeK) for i := 0; i < LargeK; i += jump { wg.Add(1) go func(i int) { start := i end := gomath.MinInt(LargeK, i+jump) for start < end { vArray := make([]gotypes.Value, features) LargeData[start] = &mydata{value: vArray, class: 0} for k := range vArray { vArray[k] = gotypes.WrapReal(rand.Float64()) } start++ } wg.Done() }(i) } wg.Wait() }
func createValue(text string) gotypes.Value { val, _ := strconv.ParseFloat(text, 64) return gotypes.WrapReal(val) }