crf

package
v0.58.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2024 License: BSD-3-Clause, BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

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

View Source
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

View Source
var (
	// ErrNoInput will tell you when no input is given.
	ErrNoInput = errors.New("rf: input samples is empty")
)

Functions

This section 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

func New(nstage, ntree, percentboot, nfeature int, tprate, tnrate float64) (crf *Runtime)

New create and return new input for cascaded random-forest.

func (*Runtime) AddForest

func (crf *Runtime) AddForest(forest *rf.Runtime)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL