Package pycv :: Package cs :: Package ml :: Package cla :: Module thresh1d
[hide private]
[frames] | no frames]

Module thresh1d

source code

Classes [hide private]
  UAC
Univariate Additive Classifier A classifier of the form: Classify x as class y = sgn( s(x) + c sgn(x-b) ) where s(x) is a score function, (c,b) are unknown parameters.
Functions [hide private]
 
_sdSolveUAC(s, sid, y, nspc, x, bid, B, minF0, bnd2, typ) source code
 
histogram_1d(wcd, nbins, minValue=None, maxValue=None)
Compute a histogram from a (weighted) classification dataset with ishape=()
source code
 
sort_1d(cd)
Take a classification dataset with ishape=(), sort them in ascending order.
source code
 
thresh_1d(criterion, param1, wcd, sort_id=None)
Solve threshold-based 1D binary classifier.
source code
 
thresh_normal_1d(criterion, param1, stats)
Solve the class-conditional Gaussian-assumed classification with thresholding and goal.
source code
Function Details [hide private]

histogram_1d(wcd, nbins, minValue=None, maxValue=None)

source code 
Compute a histogram from a (weighted) classification dataset with ishape=()
Parameters:
  • wcd (WeightedCDataset) - a (weighted) dataset of J classes and ishape ()
  • nbins (integer) - the number of bins
  • minValue (double) - minimum value of the view, default is the smallest value in the dataset
  • maxValue (double) - maximum value of the view, default is the largest value in the dataset
Returns:
hist : array(shape=(J,nbins), dtype='double')

J histograms of J classes

bin_interval : array(shape=(nbins,2),dtype='double')

array of nbins bin intervals

sort_1d(cd)

source code 
Take a classification dataset with ishape=(), sort them in ascending order.
Parameters:
  • cd (CDataset) - a dataset of J classes and ishape ()
Returns:
sorted_id : array(shape=(cd.N,2),'int')

each tuple (j,index) represents an input value, which is identified by its class 'j' and its index 'index' in the class

thresh_1d(criterion, param1, wcd, sort_id=None)

source code 

Solve threshold-based 1D binary classifier.

The function solves the following problem: Given two sets of samples of two classes, a positive one and a negative one, a threshold-based classifier classifies a value x into a positive or a negative class: sign(x - heta). The optimal heta is chosen based on different criteria: - Minimize the classification error: lambda * p(pos)*FRR + p(neg)*FAR - Minimize the error without prior: lambda * FRR + FAR - Minimize FAR with constraint FRR <= maxFRR - Minimize FRR with constraint FAR <= maxFAR

Parameters:
  • criterion (integer from 0 to 3) - 0: minimize classification error with prior probabilities 1: minimize classification error without prior probabilities 2: minimize FAR while constraining FRR 3: minimize FRR while constraining FAR
  • param1 (double) -
    a parameter representing

    lambda if criterion < 2 maxFRR if criterion == 2 maxFAR if criterion == 3

  • wcd (WeightedCDataset(J=2,ishape=()) (in cs.ml.cla package)) - a dataset of sample values of the two classes
  • sort_id (array) - the result of calling sort_1d(wcd), if sort_id is None, sort_1d(wcd) is called
Returns:
result : array(shape=(2,),dtype='d')

an argout array representing - result[0]: the threshold - result[1]: the optimized function value at that threshold

thresh_normal_1d(criterion, param1, stats)

source code 

Solve the class-conditional Gaussian-assumed classification with thresholding and goal.

This set of functions solve the following problem:
Given two classes normally distributed, a positive one and a negative one,
a threshold-based classifier classifies a value x into a positive or a negative
class: sign(x -     heta). The optimal      heta is chosen based on different criteria:
 - Minimize the classification error: \lambda * p(pos)*FRR + p(neg)*FAR
 - Minimize the error without prior: \lambda * FRR + FAR
 - Minimize FAR with constraint FRR <= maxFRR
 - Minimize FRR with constraint FAR <= maxFAR

:Parameters:
    criterion : integer from 0 to 3
        0: minimize classification error with prior probabilities
        1: minimize classification error without prior probabilities
        2: minimize FAR while constraining FRR
        3: minimize FRR while constraining FAR
    param1 : double
        a parameter representing
            \lambda if criterion < 2
            maxFRR if criterion == 2
            maxFAR if criterion == 3
    stats : Stats2e(J=2,d=1)
        REQUIREMENT: mean of class 0 <= mean of class 1

:Returns:
    result : array(shape=(2,),dtype='d')
        an argout array representing
        - result[0]: the threshold
        - result[1]: the optimized function value at that threshold