func (jr *Jazzrobot) Load(filename string) error { patterns, _ := loadPatternSlice(filename) //chrom := []string{"C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"} //chords := make(map[string][]float64) k := len(patterns) * 12 for _, pattern := range patterns { for noteValue := 0; noteValue < 12; noteValue++ { weights := make([]float64, 12) for noteIndex, patternEntry := range pattern.Notes { w := pattern.Weights[noteIndex] newNoteValue := (noteValue + patternEntry) % 12 weights[newNoteValue] = pattern.Weights[noteIndex] * w } id := fmt.Sprintf("%d", len(jr.chordMap)) root := noteValue noteWeights := weights patternId := pattern.Name patternNotes := pattern.Notes jr.chordMap[id] = noteset.New(id, root, noteWeights, patternId, patternNotes) jr.mainModel.AddCentroid(data.New(weights, k, id)) //chordName := fmt.Sprintf("%s %s", noteName, pattern.Name) //chords[chordName] = chord } } /* csvfile, err := os.Open(filename) if err != nil { return err } defer csvfile.Close() reader := csv.NewReader(csvfile) rawCSVdata, err := reader.ReadAll() if err != nil { return err } k := len(rawCSVdata) for _, v := range rawCSVdata { attributes := make([]float64, 0) var tag string for i := range v { if i == 0 { tag = v[i] continue } attr, _ := strconv.ParseFloat(v[i], 64) attributes = append(attributes, attr) } jr.mainModel.AddCentroid(data.New(attributes, k, tag)) }*/ jr.mainModel.UpdateCentroids() log.Printf("Loaded [%d, %d] number of chords\n", len(jr.chordMap), len(jr.mainModel.Centroids)) return nil }
func (model *Model) Classify(attributes []float64) (*data.Data, error) { dataItem := data.New(attributes, len(model.Centroids), "") dataItem.UpdateClassification(model.Centroids) return dataItem, nil }