-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[+] transformation funtions implementation
- Loading branch information
Showing
10 changed files
with
269 additions
and
34 deletions.
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
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,30 @@ | ||
package transformation | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/dmitryikh/leaves/util" | ||
) | ||
|
||
type TransformLogistic struct{} | ||
|
||
func (t *TransformLogistic) Transform(rawPredictions []float64, outputPredictions []float64, startIndex int) error { | ||
if len(rawPredictions) != 1 { | ||
return fmt.Errorf("expected len(rawPredictions) = 1 (got %d)", len(rawPredictions)) | ||
} | ||
|
||
outputPredictions[startIndex] = util.Sigmoid(rawPredictions[0]) | ||
return nil | ||
} | ||
|
||
func (t *TransformLogistic) NOutputGroups() int { | ||
return 1 | ||
} | ||
|
||
func (t *TransformLogistic) Type() TransformType { | ||
return Logistic | ||
} | ||
|
||
func (t *TransformLogistic) Name() string { | ||
return Logistic.Name() | ||
} |
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,24 @@ | ||
package transformation | ||
|
||
type TransformRaw struct { | ||
NumOutputGroups int | ||
} | ||
|
||
func (t *TransformRaw) Transform(rawPredictions []float64, outputPredictions []float64, startIndex int) error { | ||
for i, v := range rawPredictions { | ||
outputPredictions[startIndex+i] = v | ||
} | ||
return nil | ||
} | ||
|
||
func (t *TransformRaw) NOutputGroups() int { | ||
return t.NumOutputGroups | ||
} | ||
|
||
func (t *TransformRaw) Type() TransformType { | ||
return Raw | ||
} | ||
|
||
func (t *TransformRaw) Name() string { | ||
return Raw.Name() | ||
} |
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,32 @@ | ||
package transformation | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/dmitryikh/leaves/util" | ||
) | ||
|
||
type TransformSoftmax struct { | ||
NClasses int | ||
} | ||
|
||
func (t *TransformSoftmax) Transform(rawPredictions []float64, outputPredictions []float64, startIndex int) error { | ||
if len(rawPredictions) != t.NClasses { | ||
return fmt.Errorf("expected len(rawPredictions) = %d (got %d)", t.NClasses, len(rawPredictions)) | ||
} | ||
|
||
util.SoftmaxFloat64Slice(rawPredictions, outputPredictions, startIndex) | ||
return nil | ||
} | ||
|
||
func (t *TransformSoftmax) NOutputGroups() int { | ||
return t.NClasses | ||
} | ||
|
||
func (t *TransformSoftmax) Type() TransformType { | ||
return Softmax | ||
} | ||
|
||
func (t *TransformSoftmax) Name() string { | ||
return Softmax.Name() | ||
} |
Oops, something went wrong.