Exemplo n.º 1
0
        private void standardDeviationClicked(object sender, EventArgs e)
        {
            string operatorType = "SD";
            Form   dlg1         = new AnalyzeForm();

            if (analyzeOption(dlg1))
            {
                for (int i = 0; i < Data.columnChoosen.Length; i++)
                {
                    if (Data.columnChoosen[i] != -1)
                    {
                        int      column = Data.columnChoosen[i];
                        double[] data;
                        int      miss, dataSize;
                        double   result;

                        createDataArr(column, out data, out miss, out dataSize);
                        Debug.WriteLine(miss);

                        result = FunctionClass.StandardDeviation(data, miss, dataSize);
                        Debug.WriteLine("deviasi standar-nya adalah " + result);
                        results.Add(result.ToString());
                    }
                }
                DialogResult dialog       = new DialogResult();
                Form         dialogResult = new ResultForm(operatorType);
                dialog = dialogResult.ShowDialog();
                results.Clear();
            }
            else
            {
                dlg1.Close();
            }
        }
Exemplo n.º 2
0
        private void regresionClicked(object sender, EventArgs e)
        {
            string operatorType = "Linear Regression";
            Form   dlg1         = new AnalyzeForm();

            if (analyzeOption(dlg1))
            {
                List <double[]> xy = new List <double[]>();
                for (int i = 0; i < Data.columnChoosen.Length; i++)
                {
                    if (Data.columnChoosen[i] != -1)
                    {
                        int      column = Data.columnChoosen[i];
                        int      miss, dataSize;
                        double[] data;

                        createDataArr(column, out data, out miss, out dataSize);
                        Debug.WriteLine(miss);
                        xy.Add(data);
                    }
                }
                double r, rPar, a, aPar, b, bPar;
                long   time, timeSeq;

                FunctionClass.LinearRegression(
                    xy[0], xy[1],
                    0, xy[0].Length < xy[1].Length?xy[0].Length:xy[1].Length,
                    out r, out b, out a, out timeSeq);
                ParallelFunctionClass.LinearRegressionPar(
                    xy[0], xy[1],
                    0, xy[0].Length < xy[1].Length ? xy[0].Length : xy[1].Length,
                    out rPar, out bPar, out aPar, out time);
                Debug.WriteLine("regresi linear-nya {2} adalah: Y = {0}X + {1}", a, b, timeSeq);
                Debug.WriteLine("regresi linearPar-nya {2} adalah: Y = {0}X + {1}", aPar, bPar, time);
                results.Add("Y = " + a + "X + " + b);

                DialogResult dialog       = new DialogResult();
                Form         dialogResult = new ResultForm(operatorType);
                dialog = dialogResult.ShowDialog();
                results.Clear();
            }
            else
            {
                dlg1.Close();
            }
        }
Exemplo n.º 3
0
        private void rangeClicked(object sender, EventArgs e)
        {
            string operatorType = "Range";
            Form   dlg1         = new AnalyzeForm();

            if (analyzeOption(dlg1))
            {
                for (int i = 0; i < Data.columnChoosen.Length; i++)
                {
                    if (Data.columnChoosen[i] != -1)
                    {
                        int      column = Data.columnChoosen[i];
                        double[] data;
                        int      miss, dataSize;
                        double   result, parRes, parRes1, parRes2;
                        long     timeSeq, timePar, timePar1, timePar2;

                        createDataArr(column, out data, out miss, out dataSize);
                        Debug.WriteLine(miss);

                        result  = FunctionClass.Range(data, miss, dataSize, out timeSeq);
                        parRes  = ParallelFunctionClass.RangeParTask1(data, miss, dataSize, out timePar);
                        parRes1 = ParallelFunctionClass.RangeParTask2(data, miss, dataSize, out timePar1);
                        Debug.WriteLine("range-nya adalah " + result + " waktu: " + timeSeq);
                        Debug.WriteLine("range_parallel (1): " + parRes + " waktu: " + timePar);
                        Debug.WriteLine("range_parallel (2): " + parRes1 + " waktu: " + timePar1);
                        results.Add(result.ToString());
                    }
                }
                DialogResult dialog       = new DialogResult();
                Form         dialogResult = new ResultForm(operatorType);
                dialog = dialogResult.ShowDialog();
                results.Clear();
            }
            else
            {
                dlg1.Close();
            }
        }
Exemplo n.º 4
0
        private void meanToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult dr = new DialogResult();
            Form dlg1 = new AnalyzeForm();
            dr = dlg1.ShowDialog();
            for (int ix = 0; ix < Data.columnChoosen.Length;ix++ )
                if(Data.columnChoosen[ix]!=-1)
                    columnChoosen.Add(Data.variableView[Data.columnChoosen[ix]].nama);
            judul = "SLR";
            if (dr == DialogResult.OK)
            {
                if (columnChoosen.Count == 2)
                    {
                        int columny = Data.columnChoosen[0];
                        int columnx = Data.columnChoosen[1];
                        try
                        {
                            CudafyModule km = CudafyTranslator.Cudafy(eArchitecture.sm_20);
                            _gpu = CudafyHost.GetDevice(eGPUType.Cuda);
                            _gpu.LoadModule(km);
                            GPGPUProperties gpprop = _gpu.GetDeviceProperties(false);
                            var sheet = reoGridControl2.CurrentWorksheet;
                            // Get the first CUDA device and load our module
                            int Ny = jumlahthread(columny);
                            int Nx = jumlahthread(columnx);
                            int N = new int();
                            if (Ny > Nx)
                                N = Ny;
                            else
                                N = Nx;
                            float[] ay = new float[Ny];
                            float[] by = new float[Ny];
                            float[] ax = new float[Nx];
                            float[] bx = new float[Nx];
                            float[] c = new float[N];

                            // fill the arrays 'a' and 'b' on the CPU
                            int jumlahDatay = jumlahdata(columny,Ny);
                            int jumlahDatax = jumlahdata(columnx,Nx);
                            ay = InitData(1, columny, Ny, ay, by);
                            by = InitData(2, columny, Ny, ay, by);
                            ax = InitData(1, columnx, Nx, ax, bx);
                            bx = InitData(2, columnx, Nx, ax, bx);

                            float temp,temp2;
                            int missingCounty = 0;
                            int missingCountx = 0;

                            for (int b = 0; b < Data.variableView[columny].missing.Count; b++)
                            {
                                for (int a = 0; a < Ny; a++)
                                {
                                    float.TryParse(Data.variableView[columny].missing[b], out temp);
                                    if (ay[a] == temp)
                                    {
                                        ay[a] = 0;
                                        missingCounty++;
                                    }
                                }
                            }
                            for (int b = 0; b < Data.variableView[columnx].missing.Count; b++)
                            {
                                for (int a = 0; a < Nx; a++)
                                {
                                    float.TryParse(Data.variableView[columnx].missing[b], out temp);
                                    if (ax[a] == temp)
                                    {
                                        ax[a] = 0;
                                        missingCountx++;
                                    }
                                }
                            }

                            if (Data.variableView[columny].missingRange.Count > 1)
                            {
                                for (int a = 0; a < Ny; a++)
                                {
                                    float.TryParse(Data.variableView[columny].missingRange[0], out temp);
                                    float.TryParse(Data.variableView[columny].missingRange[1], out temp2);
                                    if (ay[a] >= temp && ay[a] <= temp2)
                                    {
                                        ay[a] = 0;
                                        missingCounty++;
                                    }

                                }
                            }
                            if (Data.variableView[columnx].missingRange.Count > 1)
                            {
                                for (int a = 0; a < Nx; a++)
                                {
                                    float.TryParse(Data.variableView[columnx].missingRange[0], out temp);
                                    float.TryParse(Data.variableView[columnx].missingRange[1], out temp2);
                                    if (ax[a] >= temp && ax[a] <= temp2)
                                    {
                                        ax[a] = 0;
                                        missingCounty++;
                                    }

                                }
                            }

                            Debug.WriteLine("y  :  " + missingCounty + "/nx  :  " + missingCountx);

                            float[] dev_a = _gpu.CopyToDevice(ay);
                            float[] dev_b = _gpu.CopyToDevice(ax);
                            float[] dev_c = _gpu.Allocate<float>(c);
                            _gpu.Launch((N + 127) / 128, 128).multiplyVector(dev_a, dev_b, dev_c, N);
                            float[] save1 = new float[N];
                            _gpu.CopyFromDevice(dev_c, save1);
                            //_gpu.Free(dev_a);
                            //_gpu.Free(dev_b);
                            //_gpu.Free(dev_c);
                            dev_a = _gpu.CopyToDevice(by);
                            dev_b = _gpu.CopyToDevice(bx);
                            dev_c = _gpu.Allocate<float>(c);
                            _gpu.Launch((N + 127) / 128, 128).multiplyVector(dev_a, dev_b, dev_c, N);
                            float[] save2 = new float[N];
                            _gpu.CopyFromDevice(dev_c, save2);
                            //_gpu.Free(dev_a);
                            //_gpu.Free(dev_b);
                            //_gpu.Free(dev_c);
                            dev_a = _gpu.CopyToDevice(save1);
                            dev_b = _gpu.CopyToDevice(save2);
                            dev_c = _gpu.Allocate<float>(c);
                            float sumxy = jumlahan(N,dev_a,dev_b,dev_c,c);
                            //_gpu.Free(dev_a);
                            //_gpu.Free(dev_b);
                            //_gpu.Free(dev_c);
                            //results.Add(mean);
                            
                            c = new float[Nx];
                            dev_a = _gpu.CopyToDevice(ax);
                            dev_b = _gpu.CopyToDevice(bx);
                            dev_c = _gpu.Allocate<float>(c);
                            float sumx = jumlahan(Nx, dev_a, dev_b, dev_c, c);
                            //_gpu.Free(dev_a);
                            //_gpu.Free(dev_b);
                            //_gpu.Free(dev_c);
                            c = new float[Ny];
                            dev_a = _gpu.CopyToDevice(ay);
                            dev_b = _gpu.CopyToDevice(by);
                            dev_c = _gpu.Allocate<float>(c);
                            float sumy = jumlahan(Nx, dev_a, dev_b, dev_c, c);
                            //_gpu.Free(dev_a);
                            //_gpu.Free(dev_b);
                            //_gpu.Free(dev_c);
                            c = new float[N];
                            dev_a = _gpu.CopyToDevice(ax);
                            dev_b = _gpu.CopyToDevice(ax);
                            dev_c = _gpu.Allocate<float>(c);
                            _gpu.Launch((N + 127) / 128, 128).multiplyVector(dev_a, dev_b, dev_c, Nx);
                            save1 = new float[N];
                            _gpu.CopyFromDevice(dev_c, save1);
                            //_gpu.Free(dev_a);
                            //_gpu.Free(dev_b);
                            //_gpu.Free(dev_c);
                            dev_a = _gpu.CopyToDevice(bx);
                            dev_b = _gpu.CopyToDevice(bx);
                            dev_c = _gpu.Allocate<float>(c);
                            _gpu.Launch((N + 127) / 128, 128).multiplyVector(dev_a, dev_b, dev_c, Nx);
                            save2 = new float[N];
                            _gpu.CopyFromDevice(dev_c, save2);
                            //_gpu.Free(dev_a);
                            //_gpu.Free(dev_b);
                            //_gpu.Free(dev_c);
                            dev_a = _gpu.CopyToDevice(save1);
                            dev_b = _gpu.CopyToDevice(save2);
                            dev_c = _gpu.Allocate<float>(c);
                            float sumxquad = jumlahan(Nx, dev_a, dev_b, dev_c, c);
                            //_gpu.Free(dev_a);
                            //_gpu.Free(dev_b);
                            //_gpu.Free(dev_c);
                            _gpu.FreeAll();
                            
                            float jumlahData = new float();
                            if (jumlahDatax>jumlahDatay)
                                jumlahData = jumlahDatax;
                            else
                                jumlahData = jumlahDatay;

                            float beta = ((jumlahData * sumxy) - (sumx * sumy)) / ((jumlahData * sumxquad) - (sumx * sumx));
                            ab[0] = beta.ToString();

                            float alpha = (sumy / (jumlahDatay - missingCounty)) - beta * (sumx / jumlahDatax - missingCountx);
                            ab[1] = alpha.ToString();
                        }
                        catch (CudafyLanguageException cle)
                        {
                        }
                        catch (CudafyCompileException cce)
                        {
                        }
                        catch (CudafyHostException che)
                        {
                            Console.Write(che.Message);
                        }
                    }

                DialogResult dialog = new DialogResult();
                Form dialogResult = new ResultSLR();
                dialog = dialogResult.ShowDialog();
                
              //  Console.ReadLine();
            }
            else
                dlg1.Close();
        }
Exemplo n.º 5
0
        private void modusToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult dr = new DialogResult();
            Form dlg1 = new AnalyzeForm();
            dr = dlg1.ShowDialog();
            for (int ix = 0; ix < Data.columnChoosen.Length; ix++)
                if (Data.columnChoosen[ix] != -1)
                    columnChoosen.Add(Data.variableView[Data.columnChoosen[ix]].nama);
            judul = "Modus";
            if (dr == DialogResult.OK)
            {
                for (int index = 0; index < Data.columnChoosen.Length; index++)
                    if (Data.columnChoosen[index] != -1)
                    {
                        int column = Data.columnChoosen[index];
                        try
                        {
                            var sheet = reoGridControl2.CurrentWorksheet;
                            int N = jumlahdata2(column);

                            float[] a = new float[N];
                            float[] b = new float[N];

                            a = InitData2(column, N, a);

                            float temp, temp2;
                            int missingCount = 0;

                            for (int bx = 0; bx < Data.variableView[column].missing.Count; bx++)
                            {
                                for (int ax = 0; ax < N; ax++)
                                {
                                    float.TryParse(Data.variableView[column].missing[bx], out temp);
                                    if (a[ax] == temp)
                                    {
                                        a[ax] = 0;
                                        missingCount++;
                                    }
                                }
                            }

                            if (Data.variableView[column].missingRange.Count > 1)
                            {
                                for (int ax = 0; ax < N; ax++)
                                {
                                    float.TryParse(Data.variableView[column].missingRange[0], out temp);
                                    float.TryParse(Data.variableView[column].missingRange[1], out temp2);
                                    if (a[ax] >= temp && a[ax] <= temp2)
                                    {
                                        a[ax] = 0;
                                        missingCount++;
                                    }

                                }
                            }

                            Debug.WriteLine(missingCount);

                            float Modus = modus(N, a);
                            results.Add(Modus);

                        }
                        catch (CudafyLanguageException cle)
                        {
                        }
                        catch (CudafyCompileException cce)
                        {
                        }
                        catch (CudafyHostException che)
                        {
                            Console.Write(che.Message);
                        }
                    }

                DialogResult dialog = new DialogResult();
                Form dialogResult = new ResultForm();
                dialog = dialogResult.ShowDialog();

                //  Console.ReadLine();
            }
            else
                dlg1.Close();
        }
Exemplo n.º 6
0
        private void varianceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult dr = new DialogResult();
            Form dlg1 = new AnalyzeForm();
            dr = dlg1.ShowDialog();
            for (int ix = 0; ix < Data.columnChoosen.Length; ix++)
                if (Data.columnChoosen[ix] != -1)
                    columnChoosen.Add(Data.variableView[Data.columnChoosen[ix]].nama);
            judul = "Variance";
            if (dr == DialogResult.OK)
            {
                for (int index = 0; index < Data.columnChoosen.Length; index++)
                    if (Data.columnChoosen[index] != -1)
                    {
                        int column = Data.columnChoosen[index];
                        try
                        {
                            CudafyModule km = CudafyTranslator.Cudafy(eArchitecture.sm_20);
                            _gpu = CudafyHost.GetDevice(eGPUType.Cuda);
                            _gpu.LoadModule(km);
                            GPGPUProperties gpprop = _gpu.GetDeviceProperties(false);
                            var sheet = reoGridControl2.CurrentWorksheet;
                            // Get the first CUDA device and load our module
                            int N = jumlahthread(column);
                            float[] a = new float[N];
                            float[] b = new float[N];
                            float[] c = new float[N];
                            // fill the arrays 'a' and 'b' on the CPU
                            int jumlahData = jumlahdata(column,N);
                            a = InitData(1, column, N,a,b);
                            b = InitData(2, column, N,a,b);

                            float temp, temp2;
                            int missingCount = 0;

                            for (int bx = 0; bx < Data.variableView[column].missing.Count; bx++)
                            {
                                for (int ax = 0; ax < N; ax++)
                                {
                                    float.TryParse(Data.variableView[column].missing[bx], out temp);
                                    if (a[ax] == temp)
                                    {
                                        a[ax] = 0;
                                        missingCount++;
                                    }
                                }
                            }

                            if (Data.variableView[column].missingRange.Count > 1)
                            {
                                for (int ax = 0; ax < N; ax++)
                                {
                                    float.TryParse(Data.variableView[column].missingRange[0], out temp);
                                    float.TryParse(Data.variableView[column].missingRange[1], out temp2);
                                    if (a[ax] >= temp && a[ax] <= temp2)
                                    {
                                        a[ax] = 0;
                                        missingCount++;
                                    }

                                }
                            }

                            Debug.WriteLine(missingCount);
                            
                            float[] dev_a = _gpu.CopyToDevice(a);
                            float[] dev_b = _gpu.CopyToDevice(b);
                            float[] dev_c = _gpu.Allocate<float>(c);
                            int N1 = N;
                            float hasil = jumlahan(N, dev_a, dev_b, dev_c, c);
                            float mean = (hasil / (jumlahData - missingCount));
                                                        
                            _gpu.FreeAll();

                            c = new float[N1];
                            dev_a = _gpu.CopyToDevice(a);
                            dev_b = _gpu.CopyToDevice(b);
                            dev_c = _gpu.Allocate<float>(c);
                            _gpu.Launch((N1 + 127) / 128, 128).powerVector(dev_a, dev_c, mean, N1);
                            _gpu.CopyFromDevice(dev_c, c);
                            _gpu.Free(dev_a);
                            _gpu.Free(dev_c);
                            float[] d = new float[N];
                            dev_c = _gpu.Allocate<float>(d);
                            _gpu.Launch((N1 + 127) / 128, 128).powerVector(dev_b, dev_c, mean, N1);
                            _gpu.CopyFromDevice(dev_c, d);
                            _gpu.Free(dev_b);
                            _gpu.Free(dev_c);
                            _gpu.FreeAll();
                            if (jumlahData%2 != 0)
                            {
                                d[N1-1] = 0;
                            }
                            float[] f = new float[N1];
                            hasil = new float();
                            dev_a = _gpu.CopyToDevice(c);
                            dev_b = _gpu.CopyToDevice(d);
                            dev_c = _gpu.Allocate<float>(c);
                            hasil = jumlahan(N, dev_a, dev_b, dev_c, c);
                            float variance = (hasil / (jumlahData - missingCount-1));
                            results.Add(variance);
                        }
                        catch (CudafyLanguageException cle)
                        {
                        }
                        catch (CudafyCompileException cce)
                        {
                        }
                        catch (CudafyHostException che)
                        {
                            Console.Write(che.Message);
                        }
                    }

                DialogResult dialog = new DialogResult();
                Form dialogResult = new ResultForm();
                dialog = dialogResult.ShowDialog();

                //  Console.ReadLine();
            }
            else
                dlg1.Close();
        }
Exemplo n.º 7
0
        private void standardDeviasiToolStripMenuItem_Click(object sender, EventArgs e)
        {
        {
            DialogResult dr = new DialogResult();
            Form dlg1 = new AnalyzeForm();
            dr = dlg1.ShowDialog();
            for (int ix = 0; ix < Data.columnChoosen.Length; ix++)
                if (Data.columnChoosen[ix] != -1)
                    columnChoosen.Add(Data.variableView[Data.columnChoosen[ix]].nama);

            if (dr == DialogResult.OK)
            {
                for (int index = 0; index < Data.columnChoosen.Length; index++)
                    if (Data.columnChoosen[index] != -1)
                    {
                        int column = Data.columnChoosen[index];
                        computeStdv(column);
                    }

                DialogResult dialog = new DialogResult();
                Form dialogResult = new STDVForm();         
                dialog = dialogResult.ShowDialog();

                //  Console.ReadLine();
            }
            else
                dlg1.Close();
        }
        }
Exemplo n.º 8
0
        private void modusToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IDictionary<string, double> hasilmodus = new Dictionary<string, double>();
            DialogResult dr = new DialogResult();
            Form dlg1 = new AnalyzeForm();
            dr = dlg1.ShowDialog();
            for (int ix = 0; ix < Data.columnChoosen.Length;ix++ )
                if(Data.columnChoosen[ix]!=-1)
                    columnChoosen.Add(Data.variableView[Data.columnChoosen[ix]].nama);
            if (dr == DialogResult.OK)
            {
                for (int index = 0; index < Data.columnChoosen.Length;index++)
                    if (Data.columnChoosen[index] != -1)
                    {
                        int column = Data.columnChoosen[index];
                        string labelkolom = Data.variableView[Data.columnChoosen[index]].nama;
                        Console.WriteLine(column);
                        
                        try
                        {
                            var sheet=reoGridControl2.CurrentWorksheet;
                            int N = sheet.RowCount;
                            Console.WriteLine(N);

                            double[] arrayIsi = new double[N];
                            for (int i = 0; i < N; i++) {
                                var isi = sheet.GetCell(i, column);


                                if (isi != null && isi.Data != null)
                                {
                                    string s = isi.Data.ToString();
                                    double bil;
                                    try
                                    {
                                        bil = double.Parse(s);
                                    }
                                    catch (Exception c) 
                                    {
                                        bil = 0;
                                    }
                                    arrayIsi[i] = bil;

                                    /*
                                    for (int ix = 0; ix < Data.variableView[column].missing.Count; ix++)
                                    {
                                        if(bil.ToString() != Data.variableView[column].missing[ix])
                                      

                                    }*/
                                }
                            }
                            double temp, temp2;
                            IDictionary<double, int> zz = new Dictionary<double, int>();
                            for(int i = 0; i<arrayIsi.Length; i++) {
                                foreach (var terserah in Data.variableView[column].missing) // Missing Diskritisasi
                                {
                                    if (terserah != arrayIsi[i].ToString())
                                        if (zz.ContainsKey(arrayIsi[i]))
                                        {
                                            zz[arrayIsi[i]] = zz[arrayIsi[i]] + 1;
                                        }
                                        else
                                        {
                                            zz.Add(arrayIsi[i], 1);
                                        }
                                    //untuk mengeluarkan perhitungan frekuensi dari sebuah bilangan
                                }

                                if (Data.variableView[column].missingRange.Count > 0)
                                {

                                    double.TryParse(Data.variableView[column].missingRange[0], out temp);
                                    double.TryParse(Data.variableView[column].missingRange[1], out temp2);

                                    if ( arrayIsi[i] < temp || arrayIsi[i] > temp2)
                                        if (zz.ContainsKey(arrayIsi[i]))
                                        {
                                            zz[arrayIsi[i]] = zz[arrayIsi[i]] + 1;
                                        }
                                        else
                                        {
                                            zz.Add(arrayIsi[i], 1);
                                        }
                                }

                                
                            }

                            if (zz.Count == 0)
                            {
                                for (int i = 0; i < arrayIsi.Length; i++)

                                    if (zz.ContainsKey(arrayIsi[i]))
                                    {
                                        zz[arrayIsi[i]] = zz[arrayIsi[i]] + 1;
                                    }
                                    else
                                    {
                                        zz.Add(arrayIsi[i], 1);
                                    }
                            }
                            zz.Remove(0);

                            //Parallel Disini aja kali ya 
                            //Menghitung Jumlah data dan dibagi 2 di masukan ke dalam thread                                                   

                            double mode = 0;
                            
                            int ma = 0;
                            var sw = Stopwatch.StartNew();
                            foreach (KeyValuePair<double, int> pair in zz)
                            {
                                if (ma < pair.Value)
                                {
                                    ma = pair.Value;
                                    mode = pair.Key;
                                }
                                //Console.WriteLine("{0}, {1}", pair.Key, pair.Value);
                                Console.WriteLine("Sekuensial thread {0} nilainya {1}", Thread.CurrentThread.ManagedThreadId, pair);
                            }
                            Console.WriteLine("Nilai Modusnya adalah : {0}", mode);
                            Console.WriteLine("waktu seq: {0}", sw.Elapsed.TotalMilliseconds);
                            Console.WriteLine();
                            hasilmodus.Add(labelkolom, mode);

                            double labelparalel = 0;
                            float modusparalel = 0;
                            sw = Stopwatch.StartNew();
                            Parallel.ForEach(zz, isi =>
                            {
                                if (modusparalel < isi.Value)
                                {
                                    modusparalel = isi.Value;
                                    labelparalel = isi.Key;
                                }
                                Console.WriteLine("Paralel thread {0} nilainya {1}", Thread.CurrentThread.ManagedThreadId, isi);

                            });
                            results.Add(labelparalel);
                            Console.WriteLine("hasil modus paralel: {0}", labelparalel);
                            Console.WriteLine("Wktu parael: {0}", sw.Elapsed.TotalMilliseconds);
                           
                            /*int jumlahData = arrayIsi.Length / 2;
                            double[] bagian_1 = new double[jumlahData];
                            double[] bagian_2 = new double[jumlahData];
                            double[] allocate = new double[jumlahData];

                            int counter = 0;
                            foreach (double data in arrayIsi)
                            {
                                if (counter <= jumlahData)
                                {
                                    bagian_1[counter] = data;
                                }
                                else
                                {
                                    bagian_2[counter] = data;
                                }

                                counter++;
                            }



                            double[] dev_a = _gpu.CopyToDevice(bagian_1);
                            double[] dev_b = _gpu.CopyToDevice(bagian_2);
                            double[] dev_c = _gpu.Allocate<double>(allocate);

                            while (jumlahData > 1) {

                                if (jumlahData % 2 == 0)
                                {
                                    jumlahData = jumlahData / 2;
                                }
                                else {
                                    jumlahData = (jumlahData + 1) / 2;
                                }
                            }
                             */

                            //mode = zz.GroupBy(value => value.Value).OrderByDescending(group => group.Count()).First().First().Key;
                            //Console.WriteLine(mode);
                            //hasilmodus.Add(labelkolom, mode);
                            //Console.WriteLine("di atas ini");

                            /* 
                             * hapus aja
                            int[] data = new int[10000000];
                            int[] K=new int[2500];
                            IDictionary<string, int> kamus = new Dictionary<string, int>();
                            kamus.Add("1", 13);
                            kamus.Add("2", 99999668);
                            int maxValue = 0;
                            for (int i = 0; i < sheet.RowCount;i++ )
                            {
                                data[i] = Convert.ToInt32(sheet[i,0]);
                            }

                            for (int x = 0; x < data.Length; x++)
                            {
                                //K[data[x]] = K[data[x]] + 1;
                                if(kamus.ContainsKey(data[x].ToString())) {
                                    kamus[data[x].ToString()] = kamus[data[x].ToString()] + 1;
                                    //kamus.Add(data[x].ToString(), kamus[data[x].ToString()] + 1);
                                } else {
                                    //kamus[data[x].ToString()] = 1;
                                    kamus.Add(data[x].ToString(), 1);
                                }
                            }
                            //Console.WriteLine(kamus.ToString());
                            foreach (int z in kamus.Values) {
                                //Console.WriteLine(z);
                            }
                            maxValue = kamus.Values.Max();
                            
                            for (int y = 0; y < data.Length; y++)
                            {
                                if(data[y]>kamus[data[y].ToString()])
                                //(data[y]>K[data[y]])
                                {
                                    maxValue=data[y];
                                    //diubah
                                    //maxValue = kamus[data[y]];  
                                }
                            }
                             
                            
                            Debug.WriteLine(maxValue);
                            */
                        }
                        catch (CudafyLanguageException cle)
                        {
                        }
                        catch (CudafyCompileException cce)
                        {
                        }
                        catch (CudafyHostException che)
                        {
                            Console.Write(che.Message);
                        }
                    }

                DialogResult dialog = new DialogResult();
                Form dialogResult = new ResultForm();

                /*
                foreach (KeyValuePair<string, double> pair in hasilmodus)
                {
                    Console.WriteLine("Kolom {0} nilai modus {1}",
                    pair.Key,
                    pair.Value);

                }
                 */

                dialog = dialogResult.ShowDialog();

              //  Console.ReadLine();
            }
            else
                dlg1.Close();
        }
Exemplo n.º 9
0
        private void populationVarianceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            results.Clear();
            DialogResult dr = new DialogResult();
            Form dlg1 = new AnalyzeForm();
            dr = dlg1.ShowDialog();
            for (int ix = 0; ix < Data.columnChoosen.Length; ix++)
                if (Data.columnChoosen[ix] != -1)
                    columnChoosen.Add(Data.variableView[Data.columnChoosen[ix]].nama);
            judul = "PopulasiVariansi";
            if (dr == DialogResult.OK)
            {
                for (int index = 0; index < Data.columnChoosen.Length; index++)
                    if (Data.columnChoosen[index] != -1)
                    {
                        int column = Data.columnChoosen[index];
                        try
                        {
                            var sheet = reoGridControl2.CurrentWorksheet;
                            int N = jumlahdata2(column);

                            float[] a = new float[N];
                            double[] b = new double[N];

                            float temp, temp2;
                            int missingCount = 0;

                            for (int i = 0; i < N; i++)
                            {
                                if (sheet[i, column] != null && sheet[i, column].ToString() != "")
                                {
                                    float.TryParse(sheet[i, column].ToString(), out a[i]);
                                }
                            }

                            for (int i = 0; i < N; i++)
                            {
                                b[i] = System.Convert.ToDouble(a[i]);
                            }

                            for (int bx = 0; bx < Data.variableView[column].missing.Count; bx++)
                            {
                                for (int ax = 0; ax < N; ax++)
                                {
                                    float.TryParse(Data.variableView[column].missing[bx], out temp);
                                    if (b[ax] == temp)
                                    {
                                        b[ax] = 0;
                                        missingCount++;
                                    }
                                }
                            }

                            if (Data.variableView[column].missingRange.Count > 1)
                            {
                                for (int ax = 0; ax < N; ax++)
                                {
                                    float.TryParse(Data.variableView[column].missingRange[0], out temp);
                                    float.TryParse(Data.variableView[column].missingRange[1], out temp2);
                                    if (b[ax] >= temp && b[ax] <= temp2)
                                    {
                                        b[ax] = 0;
                                        missingCount++;
                                    }

                                }
                            }
                            var minimum1 = (double)Statistics.PopulationVariance(b);
                            results.Add(minimum1);

                        }
                        catch (CudafyLanguageException cle)
                        {
                        }
                        catch (CudafyCompileException cce)
                        {
                        }
                        catch (CudafyHostException che)
                        {
                            Console.Write(che.Message);
                        }
                    }

                DialogResult dialog = new DialogResult();
                Form dialogResult = new FormHasilMathDotNet();
                dialog = dialogResult.ShowDialog();

                //  Console.ReadLine();
            }
            else
                dlg1.Close();
        }
Exemplo n.º 10
0
        private void meanPararelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult dr = new DialogResult();
            Form dlg1 = new AnalyzeForm();
            dr = dlg1.ShowDialog();
            for (int ix = 0; ix < Data.columnChoosen.Length; ix++)
                if (Data.columnChoosen[ix] != -1)
                    columnChoosen.Add(Data.variableView[Data.columnChoosen[ix]].nama);

            if (dr == DialogResult.OK)
            {
                for (int index = 0; index < Data.columnChoosen.Length; index++)
                    if (Data.columnChoosen[index] != -1)
                    {
                        int column = Data.columnChoosen[index];
                        try
                        {
                            // This 'smart' method will Cudafy all members with the Cudafy attribute in the calling type (i.e. Program)
                            CudafyModule km = CudafyTranslator.Cudafy(eArchitecture.sm_20);
                            // If cudafying will not work for you (CUDA SDK + VS not set up right) then comment out above and
                            // uncomment below. Remember to also comment out the Structs and 3D arrays region below.
                            // CUDA 5.5 SDK must be installed and cl.exe (VC++ compiler) must be in path.
                            //CudafyModule km = CudafyModule.Deserialize(typeof(Program).Name);
                            //var options = NvccCompilerOptions.Createx64(eArchitecture.sm_12);
                            //km.CompilerOptionsList.Add(options);
                            _gpu = CudafyHost.GetDevice(eGPUType.Cuda);
                            _gpu.LoadModule(km);
                            GPGPUProperties gpprop = _gpu.GetDeviceProperties(false);
                            var sheet = reoGridControl2.CurrentWorksheet;
                            // Get the first CUDA device and load our module
                            int N = sheet.RowCount / 2;
                            float[] a = new float[N];
                            float[] b = new float[N];
                            float[] c = new float[N];
                            // fill the arrays 'a' and 'b' on the CPU
                            int jumlahData = 0;
                            for (int i = 0; i < N; i++)
                            {
                                if (sheet[i, column] != null && sheet[i, column].ToString() != "")
                                {
                                    float.TryParse(sheet[i, column].ToString(), out a[i]);
                                    jumlahData++;
                                }
                                if (sheet[i + N, column] != null && sheet[i + N, column].ToString() != "")
                                {
                                    float.TryParse(sheet[i + N, column].ToString(), out b[i]);
                                    jumlahData++;

                                }
                            }
                            float temp, temp2;
                            int missingCount = 0;

                            for (int bx = 0; bx < Data.variableView[column].missing.Count; bx++)
                            {
                                for (int ax = 0; ax < N; ax++)
                                {
                                    float.TryParse(Data.variableView[column].missing[bx], out temp);
                                    if (a[ax] == temp)
                                    {
                                        a[ax] = 0;
                                        missingCount++;
                                    }
                                }
                            }

                            if (Data.variableView[column].missingRange.Count > 1)
                            {
                                for (int ax = 0; ax < N; ax++)
                                {
                                    float.TryParse(Data.variableView[column].missingRange[0], out temp);
                                    float.TryParse(Data.variableView[column].missingRange[1], out temp2);
                                    if (a[ax] >= temp && a[ax] <= temp2)
                                    {
                                        a[ax] = 0;
                                        missingCount++;
                                    }

                                }
                            }

                            Debug.WriteLine(missingCount);
                            float meanSequential = 0;
                            for (int i = 0; i < N; i++)
                                meanSequential += a[i] + b[i];
                            meanSequential = meanSequential / (jumlahData - missingCount); ;
                            float[] dev_a = _gpu.CopyToDevice(a);
                            float[] dev_b = _gpu.CopyToDevice(b);
                            float[] dev_c = _gpu.Allocate<float>(c);


                            bool first = true;
                            int N_awal = N;
                            while (N > 1)
                            {
                                if (!first)
                                {
                                    a = new float[N];
                                    b = new float[N];
                                    // c = new int[N];
                                    float[] baru = new float[N];
                                    for (int i = 0; i < (c.Count() - N); i++)
                                        baru[i] = c[N + i];

                                    dev_a = _gpu.CopyToDevice(c.Take(N).ToArray());
                                    dev_b = _gpu.CopyToDevice(baru);
                                    c = new float[N];
                                    dev_c = _gpu.Allocate<float>(c);
                                }

                                float[] d = new float[N];
                                _gpu.CopyFromDevice(dev_a, d);
                                //      _gpu.Launch(N, 1).addVector(dev_a, dev_b, dev_c, N);
                                _gpu.Launch((N + 127) / 128, 128).addVector(dev_a, dev_b, dev_c, N);

                                _gpu.CopyFromDevice(dev_c, c);


                                _gpu.Free(dev_a);
                                _gpu.Free(dev_b);
                                _gpu.Free(dev_c);

                                if (N % 2 == 0)
                                    N = N / 2;
                                else
                                    N = (N + 1) / 2;

                                first = false;
                            }

                            Debug.WriteLine("mean-nya adalah " + (c[0] + c[1]) / (jumlahData - missingCount) + " mean dari sequensial adalah " + meanSequential);
                            results.Add((c[0] + c[1]) / (jumlahData - missingCount));
                            //for (int i = 0; i < N; i++)
                            //    Debug.Assert(a[i] + b[i] == c[i]);
                            _gpu.FreeAll();

                        }
                        catch (CudafyLanguageException cle)
                        {
                        }
                        catch (CudafyCompileException cce)
                        {
                        }
                        catch (CudafyHostException che)
                        {
                            Console.Write(che.Message);
                        }
                    }

                DialogResult dialog = new DialogResult();
                Form dialogResult = new FormResultsMean();
                dialog = dialogResult.ShowDialog();


                //  Console.ReadLine();
            }
            else
                dlg1.Close();
        }