Skip to content

Commit

Permalink
LDA now also shown as simple button classfier (for gauss set)
Browse files Browse the repository at this point in the history
-> fixed a memory leak
-> fixed a few edge cases in the robust lda classifiers 
-> added a check for the tanh function to not run into overflows.
  • Loading branch information
mikerabat committed Jan 23, 2017
1 parent ba49cda commit b32887b
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 81 deletions.
8 changes: 8 additions & 0 deletions BaseIncrementalLearner.pas
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ TCustomIncrementalLearnerExampleList = class(TObject)
procedure LoadExamples; virtual; abstract;

constructor Create(const aInitPercentage : double; aStrategy : TIncrementalLearnStrategy);
destructor Destroy; override;
end;

// #############################################################
Expand Down Expand Up @@ -248,4 +249,11 @@ constructor TCustomIncrementalLearnerExampleList.Create(
inherited Create;
end;

destructor TCustomIncrementalLearnerExampleList.Destroy;
begin
fRndEng.Free;

inherited;
end;

end.
12 changes: 7 additions & 5 deletions SimpleClassifier/FischerBatchLDA.pas
Original file line number Diff line number Diff line change
Expand Up @@ -285,20 +285,22 @@ function TFisherBatchLDALearner.DoLearn(
begin
Result := nil;
eigVals := nil;

pcaU := nil;
pcaMu := nil;

numClasses := IndexOfClasses(classIdx, classLabels);
// this base classifier does not suppert reduction by now.
// todo: eventually just dismiss the eigenvectors (as proposed in the phd - the LDAonK classifier)
// todo: eventually just don't use the eigenvectors (as proposed in the phd - the LDAonK classifier)
CreateBaseLDAClassifier(pcaU, pcaMu, eigVals, ldaV, classCenters, classLabels, classIdx, numClasses);

if fProps.ClassifierType = ctFastRobust then
begin
pcaU.Free;
pcaMu.Free;
FreeAndNil(pcaU);
FreeAndNil(pcaMu);
end;

eigVals.Free;
if not Assigned(pcaMu) then
if not Assigned(pcaMu) and (fProps.ClassifierType <> ctFastRobust) then
raise ELDAException.Create('Error no pca matrix assigned');

case fProps.ClassifierType of
Expand Down
2 changes: 1 addition & 1 deletion SimpleClassifier/FischerClassifiers.pas
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ function TFischerRobustLDAClassifier.RobustAlphaTrimmedLinEQSolver(
data := X.SubMatrix;
QuickSort(data[0], sizeof(double), Length(data), DoubleSortFunc);

numNewElements := Max(fU.Width, Min(numElements - 1, Round(numElements*fProps.ReductionFactor)));
numNewElements := Min(numElements - 1, Max(fU.Width, Round(numElements*fProps.ReductionFactor)));
if numNewElements <= 0 then
break;

Expand Down
9 changes: 8 additions & 1 deletion SimpleClassifier/SVM.pas
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,14 @@ implementation

procedure TanhFunc(var value : double);
begin
value := tanh(value);
if value < -10
then
value := -1
else if value > 10
then
value := 1
else
value := tanh(value);
end;

{ TSVMLearner }
Expand Down
82 changes: 46 additions & 36 deletions TestApp/ufrmTestClassifier.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,25 @@ object frmClassifierTest: TfrmClassifierTest
Anchors = [akLeft, akTop, akRight]
Caption = 'Simple Tests'
TabOrder = 0
object Button1: TButton
object butCreateGaussSet: TButton
Left = 14
Top = 32
Width = 139
Height = 25
Caption = 'Create 2D Gauss set'
TabOrder = 0
OnClick = Button1Click
OnClick = butCreateGaussSetClick
end
object Button2: TButton
object butDecissionStump: TButton
Left = 14
Top = 72
Width = 139
Height = 25
Caption = 'Decission Stump'
TabOrder = 1
OnClick = Button2Click
OnClick = butDecissionStumpClick
end
object Button3: TButton
object butAdaBoost: TButton
Left = 161
Top = 72
Width = 153
Expand All @@ -91,9 +91,9 @@ object frmClassifierTest: TfrmClassifierTest
Font.Style = []
ParentFont = False
TabOrder = 2
OnClick = Button3Click
OnClick = butAdaBoostClick
end
object Button4: TButton
object butGentleBoost: TButton
Left = 161
Top = 32
Width = 153
Expand All @@ -106,71 +106,71 @@ object frmClassifierTest: TfrmClassifierTest
Font.Style = []
ParentFont = False
TabOrder = 3
OnClick = Button4Click
OnClick = butGentleBoostClick
end
object Button5: TButton
object butBagging: TButton
Left = 320
Top = 32
Width = 153
Height = 25
Caption = 'Bagging Decission Stump'
TabOrder = 4
OnClick = Button5Click
end
object Button10: TButton
Left = 638
Top = 72
Width = 149
Height = 25
Caption = 'Integral Image Test'
TabOrder = 5
OnClick = Button10Click
OnClick = butBaggingClick
end
object butC45: TButton
Left = 479
Top = 32
Width = 42
Height = 25
Caption = 'C4.5'
TabOrder = 6
TabOrder = 5
OnClick = butC45Click
end
object btnNaiveBayes: TButton
object butNaiveBayes: TButton
Left = 479
Top = 72
Width = 153
Width = 106
Height = 25
Caption = 'Naive Bayes'
TabOrder = 7
OnClick = btnNaiveBayesClick
TabOrder = 6
OnClick = butNaiveBayesClick
end
object Button11: TButton
object butRBF: TButton
Left = 320
Top = 72
Width = 72
Height = 25
Caption = 'RBF'
TabOrder = 8
OnClick = Button11Click
TabOrder = 7
OnClick = butRBFClick
end
object Button12: TButton
object butKMean: TButton
Left = 398
Top = 72
Width = 75
Height = 25
Caption = 'KMean'
TabOrder = 9
OnClick = Button12Click
TabOrder = 8
OnClick = butKMeanClick
end
object butNeuralNet: TButton
Left = 527
Top = 32
Width = 105
Height = 25
Caption = 'Neural Network'
TabOrder = 10
TabOrder = 9
OnClick = butNeuralNetClick
end
object butLDA: TButton
Left = 686
Top = 72
Width = 101
Height = 25
Caption = 'Classic LDA'
TabOrder = 10
OnClick = butLDAClick
end
end
object GroupBox2: TGroupBox
Left = 516
Expand Down Expand Up @@ -237,14 +237,14 @@ object frmClassifierTest: TfrmClassifierTest
Height = 16
Caption = 'FaceDB'
end
object Button7: TButton
object butImgRobustFischerLDA: TButton
Left = 16
Top = 140
Width = 257
Height = 25
Caption = 'Robust Fischer LDA - Augmented Basis'
TabOrder = 0
OnClick = Button7Click
OnClick = butImgRobustFischerLDAClick
end
object chkBlendPart: TCheckBox
Left = 168
Expand Down Expand Up @@ -287,7 +287,7 @@ object frmClassifierTest: TfrmClassifierTest
Height = 25
Caption = 'Incremental Fischer LDA'
TabOrder = 5
OnClick = Button7Click
OnClick = butImgRobustFischerLDAClick
end
object edFaceDB: TEdit
Left = 51
Expand Down Expand Up @@ -350,15 +350,25 @@ object frmClassifierTest: TfrmClassifierTest
TabOrder = 12
WordWrap = True
end
object butIntImgTest: TButton
Left = 216
Top = 428
Width = 75
Height = 25
Caption = 'Int Img Test'
TabOrder = 13
Visible = False
OnClick = butIntImgTestClick
end
end
object Button9: TButton
object butSVM: TButton
Left = 646
Top = 32
Width = 149
Height = 25
Caption = 'Support Vector Machines'
TabOrder = 2
OnClick = Button9Click
OnClick = butSVMClick
end
object sdSaveAdaBoost: TSaveDialog
DefaultExt = 'cls'
Expand Down
Loading

0 comments on commit b32887b

Please sign in to comment.