package crf
import "git.sr.ht/~shulhan/pakakeh.go/lib/mining/classifier/crf"
Package crf implement the cascaded random forest algorithm, proposed by Baumann et.al in their paper:
Baumann, Florian, et al. "Cascaded Random Forest for Fast Object Detection." Image Analysis. Springer Berlin Heidelberg, 2013. 131-142.
Index ¶
- Constants
- Variables
- type Runtime
- func New(nstage, ntree, percentboot, nfeature int, tprate, tnrate float64) (crf *Runtime)
- func (crf *Runtime) AddForest(forest *rf.Runtime)
- func (crf *Runtime) Build(samples tabula.ClasetInterface) (e error)
- func (crf *Runtime) ClassifySetByWeight(samples tabula.ClasetInterface, sampleListID []int, ) ( predicts []string, cm *classifier.CM, probs []float64, )
- func (crf *Runtime) Initialize(samples tabula.ClasetInterface) error
Constants ¶
const ( // DefStage default number of stage DefStage = 200 // DefTPRate default threshold for true-positive rate. DefTPRate = 0.9 // DefTNRate default threshold for true-negative rate. DefTNRate = 0.7 // DefNumTree default number of tree. DefNumTree = 1 // DefPercentBoot default percentage of sample that will be used for // bootstraping a tree. DefPercentBoot = 66 // DefPerfFile default performance file output. DefPerfFile = "crf.perf" // DefStatFile default statistic file output. DefStatFile = "crf.stat" )
Variables ¶
var ( // ErrNoInput will tell you when no input is given. ErrNoInput = errors.New("rf: input samples is empty") )
Types ¶
type Runtime ¶
type Runtime struct { // Runtime embed common fields for classifier. classifier.Runtime // NStage number of stage. NStage int `json:"NStage"` // NTree number of tree in each stage. NTree int `json:"NTree"` // TPRate threshold for true positive rate per stage. TPRate float64 `json:"TPRate"` // TNRate threshold for true negative rate per stage. TNRate float64 `json:"TNRate"` // NRandomFeature number of features used to split the dataset. NRandomFeature int `json:"NRandomFeature"` // PercentBoot percentage of bootstrap. PercentBoot int `json:"PercentBoot"` // contains filtered or unexported fields }
Runtime define the cascaded random forest runtime input and output.
func New ¶
New create and return new input for cascaded random-forest.
func (*Runtime) AddForest ¶
AddForest will append new forest.
func (*Runtime) Build ¶
func (crf *Runtime) Build(samples tabula.ClasetInterface) (e error)
Build given a sample dataset, build the stage with randomforest.
func (*Runtime) ClassifySetByWeight ¶
func (crf *Runtime) ClassifySetByWeight(samples tabula.ClasetInterface, sampleListID []int, ) ( predicts []string, cm *classifier.CM, probs []float64, )
ClassifySetByWeight will classify each instance in samples by weight with respect to its single performance.
Algorithm, (1) For each instance in samples, (1.1) for each stage, (1.1.1) collect votes for instance in current stage. (1.1.2) Compute probabilities of each classes in votes.
prob_class = count_of_class / total_votes
(1.1.3) Compute total of probabilities times of stage weight.
stage_prob = prob_class * stage_weight
(1.2) Divide each class stage probabilities with
stage_prob = stage_prob / (sum_of_all_weights * number_of_tree_in_forest)
(1.3) Select class label with highest probabilities. (1.4) Save stage probabilities for positive class. (2) Compute confusion matrix.
func (*Runtime) Initialize ¶
func (crf *Runtime) Initialize(samples tabula.ClasetInterface) error
Initialize will check crf inputs and set it to default values if its invalid.
Source Files ¶
- Version
- v0.60.0 (latest)
- Published
- Feb 1, 2025
- Platform
- linux/amd64
- Imports
- 10 packages
- Last checked
- 14 minutes ago –
Tools for package owners.