Example #1
0
 public void Test_LDA_Performance200k_10() {
     int errorCode = 0; 
     try {
         LDA lda = new LDA();
         ILArray<double> X = ILMath.horzcat(ILMath.randn(2,200000)*2.0,ILMath.randn(2,200000)*-2.0);  
         ILLogicalArray labels = ILMath.tological(ILMath.horzcat(ILMath.ones(1,100000), ILMath.zeros(1,100000))); 
         labels = labels.Concat( ILMath.tological( ILMath.zeros(1,100000).Concat( ILMath.ones(1,100000),1)),0);  
         ILPerformer timer = new ILPerformer(); 
         timer.Tic();  LDA.Hyperplane C; 
         for (int i = 0; i < 10; i ++) {
            C = lda.TrainLDA(X,labels,0.4);  
         }
         timer.Toc();
         Info("Test_LDA_Performance2: data: 2x200000 run 10 times in: " + timer.Duration + "ms"); 
         Success();
     }catch(Exception e) {
         Error(errorCode,e.Message);
     }
 }
Example #2
0
        //public void Test_SimpleAsyncAlgorithmSample() {
        //    int errorCode = 0; 
        //    try {
        //        SimpleAsyncSample sampleAlg = new SimpleAsyncSample(null, 2.0,50,ILMath.randn(3,2)); 
        //        sampleAlg.RunAsync(); 
        //        while (sampleAlg.State == ILAlgorithmRunningState.Running) {
        //            Info(sampleAlg.Progress * 100 + "\r"); 
        //            System.Threading.Thread.Sleep(300); 
        //        }
        //        Info(sampleAlg.Result.result.ToString()); 
        //        //sampleAlg.Result; 
        //        Success();
        //    } catch(Exception e) {
        //        Error(errorCode,e.Message);
        //    }
        //}

        
        public void Test_LDA() {
            int errorCode = 0; 
            try {
                LDA lda = new LDA();
                lda.StateChanged += new ILAlgorithmStateChangedEventHandler(lda_StateChanged);
                lda.ProgressChanged += new ILAlgorithmStateChangedEventHandler(lda_ProgressChanged);
                ILArray<double> X = new ILArray<double>(new double[]{-2,-2,-3,-3,2,2,3,3},2,4); 
                ILLogicalArray labels = new ILLogicalArray (new byte[8]{0,1,0,1,1,0,1,0},2,4); 
                LDA.Hyperplane C = lda.TrainLDA(X,labels,0.4); 
                if (Object.ReferenceEquals(C,null))
                    throw new Exception ("LDA: result is null!"); 
                if (!(C.w is ILArray<double>) || C.w.Dimensions[0] != 2)
                    throw new Exception("LDA: Results C[0] should be ILArray<double> 2x1");
                if (!(C.b is ILArray<double>) || !C.b.IsScalar)
                    throw new Exception("LDA: Results C[1] should be ILArray<double> 2x1");
                if (ILMath.abs(C.w[0] - -9.3750) > 1e-8)
                    throw new Exception("LDA: invalid result: C.w(1) should be : -9.3750");
                if (ILMath.abs(C.w[1] - -9.3750) > 1e-8)
                    throw new Exception("LDA: invalid result: C.w(2) should be : -9.3750");
                if (ILMath.abs(C.b.GetValue(0)) > 1e-8)
                    throw new Exception("LDA: invalid result: C.b should be : 0.0!");
                Success();
            } catch(Exception e) {
                Error(errorCode,e.Message);
            }
        }
Example #3
0
 public void Test_LDA_Performance2000_var(int rep) {
     int errorCode = 0; 
     try {
         LDA lda = new LDA();
         ILArray<double> X = ILMath.horzcat(ILMath.randn(2,2000)*2.0,ILMath.randn(2,2000)*-2.0);  
         ILLogicalArray labels = ILMath.tological(ILMath.horzcat(ILMath.ones(1,2000), ILMath.zeros(1,2000))); 
         labels = labels.Concat( ILMath.tological( ILMath.zeros(1,2000).Concat( ILMath.ones(1,2000),1)),0);  
         ILPerformer timer = new ILPerformer(); 
         LDA.Hyperplane C; 
         int oldRefMin = ILNumerics.Settings.ILSettings.MinimumRefDimensions; 
         ILNumerics.Settings.ILSettings.MinimumRefDimensions = 2;
         timer.Tic();  
         for (int i = 0; i < rep; i ++) {
            C = lda.TrainLDA(X,labels,0.4);  
         }
         timer.Toc();
         Info("Test_LDA_Performance: with reference - data: 2x2000 run " + rep.ToString() + " times in: " + timer.Duration + "ms"); 
         ILNumerics.Settings.ILSettings.MinimumRefDimensions = 3; 
         timer.Tic();  
         for (int i = 0; i < rep; i ++) {
            C = lda.TrainLDA(X,labels,0.4);  
         }
         timer.Toc();
         ILNumerics.Settings.ILSettings.MinimumRefDimensions = oldRefMin; 
         Info("Test_LDA_Performance: without reference - data: 2x2000 run " + rep.ToString() + " times in: " + timer.Duration + "ms"); 
         Success();
     }catch(Exception e) {
         Error(errorCode,e.Message);
     }
 }