From 6c1ad46c89bb4f4ff498cb61e1acbc1437e5ce79 Mon Sep 17 00:00:00 2001 From: Anton Antonov Date: Mon, 15 Jul 2013 00:03:07 -0400 Subject: [PATCH] Added handling of the SVDRank suboption. Now the thin SVD is used, before the full SVD was used. --- AVCDecisionTreeForest.m | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/AVCDecisionTreeForest.m b/AVCDecisionTreeForest.m index 180d1b41..b80e2830 100644 --- a/AVCDecisionTreeForest.m +++ b/AVCDecisionTreeForest.m @@ -211,7 +211,7 @@ Mathematica is (C) Copyright 1988-2012 Wolfram Research, Inc. (* check is the set too pure *) - If[Length[numDataRecs] > 0.1*linCombMinRecs, + If[Length[numDataRecs] > 0.1*linCombMinRecs && Length[numDataRecs] > svdRank, PRINT["AVCSplitSelection:: Dimensions[numDataRecs] = ", Dimensions[numDataRecs]]; (* find splitting directions using SVD *) @@ -220,22 +220,19 @@ Mathematica is (C) Copyright 1988-2012 Wolfram Research, Inc. AbsoluteTiming[ (* the union is needed in order to avoid singular matrices *) - numDataRecs = Union[numDataRecs[[All, numAxes]]]; - {U, S, V} = - SingularValueDecomposition[numDataRecs, Tolerance -> 0.01]; + numDataRecs = Union[numDataRecs[[All, numAxes]]]; + {U, S, V} = SingularValueDecomposition[numDataRecs, svdRank, Tolerance -> 0.01]; ] ]; (* compute the variable columns of the linear combinations *) numDataRecs = dataRecs[[All, numAxes]].V; - numAvcs = - Map[AVC[numDataRecs[[All, #]], classLabels] &, Range[Length[numAxes]]]; + numAvcs = Map[AVC[numDataRecs[[All, #]], classLabels] &, Range[svdRank]]; PRINT["AVCSplitSelection:: Length/@numAvcs = ", Length /@ numAvcs]; numRes = Table[Append[ - AVCFindBestSplitValue[numAvcs[[i]], Number, nStrata, - impFunc], {numAxes, V[[All, i]]}], {i, Length[numAxes]}]; + AVCFindBestSplitValue[numAvcs[[i]], Number, nStrata, impFunc], {numAxes, V[[All, i]]}], {i, svdRank}]; ]; ]; ]; @@ -270,8 +267,12 @@ Mathematica is (C) Copyright 1988-2012 Wolfram Research, Inc. linCombMinRecs, svdRank}, (* Options handling *) - {linCombMinRecs, - svdRank} = {"MinRecords", "SVDRank"} /. linComb /. {"MinRecords" -> 200, "SVDRank" -> 2}; + {linCombMinRecs, svdRank} = {"MinRecords", "SVDRank"} /. linComb /. {"MinRecords" -> 200, "SVDRank" -> 2}; + + Which[ + TrueQ[svdRank === All], svdRank = Count[columnTypes, Number], + ! IntegerQ[svdRank], svdRank = 0 + ]; impFunc = If[ TrueQ[ impFunc == "Entropy"], AVCEntropy, AVCGini ]; @@ -296,8 +297,7 @@ Mathematica is (C) Copyright 1988-2012 Wolfram Research, Inc. (* Recursive calling *) Which[ - (*res[[1]]<=impurityTh,{{{Length[ - data],data[[1,-1]]}}},*) + (*res[[1]]<=impurityTh,{{{Length[data],data[[1,-1]]}}},*) res[[1]] <= impurityTh || Length[data] < Theta, {SortBy[Reverse /@ Tally[data[[All, -1]]], -#[[1]] &]},