-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#9 Add part of categorical converter
- Loading branch information
1 parent
a80eb99
commit abe5686
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package ml | ||
|
||
import ( | ||
"runtime" | ||
"sync" | ||
) | ||
|
||
// CategoricalToNumericConverter converts passed struct | ||
// to categorical []float64 format where | ||
// each field is one element of the returned | ||
// slice. | ||
type CategoricalToNumericConverter[T any] struct { | ||
// dataSlice is a slice of other entities of the same type | ||
// used to convert categorical data to numeric one | ||
dataSlice []T | ||
|
||
// convertRoutinesCount represents how many routines will be working | ||
// in order to calculate given tree. | ||
convertRoutinesCount int | ||
|
||
mu sync.Mutex | ||
} | ||
|
||
// NewCategoricalConverter creates a new instance of the categorical converter | ||
func NewCategoricalConverter[T any](dataSlice []T) *CategoricalToNumericConverter[T] { | ||
return &CategoricalToNumericConverter[T]{ | ||
dataSlice: dataSlice, | ||
convertRoutinesCount: runtime.NumCPU(), // basically there is no need have more workers than cores. | ||
} | ||
} | ||
|
||
// Convert converts given struct fields into []float64 and returns it. | ||
// It converts all the fields into numeric format. | ||
func (c *CategoricalToNumericConverter[T]) Convert(obj T) []float64 { | ||
c.mu.Lock() | ||
defer c.mu.Unlock() | ||
|
||
var wg sync.WaitGroup | ||
for i := range c.convertRoutinesCount { | ||
|
||
} | ||
|
||
} |