예제 #1
0
        public BaseModule()
        {
            InitializeComponent();

            // -------------- Load data --------------
            dataLoad dl = new dataLoad();
            Dictionary <String, double[]>       pMat_raw    = dl.LoadMatrix(controlDataFile);
            Dictionary <String, double[]>       rMat_raw    = dl.LoadMatrix(caseDataFile);
            Dictionary <String, List <String> > allPathways = dl.LoadPathways(pathwaysFile);

            // -------------- Discretized case (Resistant) data matrix --------------
            processData pD = new processData(th_dic_high, th_dic_low);
            Dictionary <String, int[]> rMat_discritized = pD.getDiscritizedMat(pMat_raw, rMat_raw);
            //Dictionary<String, double[]> rMat_standardizedOnly = pD.getStandardizedVal(pMat_raw, rMat_raw);
            //printData(rMat_standardizedOnly);
            Dictionary <String, Dictionary <String, int[]> > pathwayMats = pD.getDiscritizedMatForPathways(allPathways, rMat_discritized);

            // -------------- Infer BN strucrure (for each pathway) --------------
            //Parallel.ForEach(allPathways.Keys, pathway =>{
            //foreach (string pathway in allPathways.Keys)
            //{
            //int nNodes = pathwayMats[pathway].Count;
            string pathway = "TGF-BETA_SIGNALING_PATHWAY";
            //Dictionary<String, double[]> pathwayStdData = pD.getStandardizedDataforAPathway(pathway, allPathways, rMat_standardizedOnly);

            int nNodes = pathwayMats[pathway].Count;

            // -- prepare MCMC sampling config settings
            SetMCMCconfig();
            NameValueCollection InputSettings = new NameValueCollection();

            // ------------ input settings
            InputSettings.Add("nNodes", nNodes.ToString());
            InputSettings.Add("nIteration", nSamplingIter.ToString());          // [Tasaki et al.] sampling iteration: 5000, burn-in (inclusive): 1000 (20%)
            InputSettings.Add("nBurnIn", nburnIn.ToString());                   // http://www.genetics.org/content/early/2015/01/28/genetics.114.172619
            InputSettings.Add("nMaxOutdegree", nMaxOutdegree.ToString());
            InputSettings.Add("nMaxIndegree", nMaxIndegree.ToString());
            InputSettings.Add("pathway", pathway);

            // -- NS algorithm (comment out when need to use)
            Adaptive_NS       obj_NS = new Adaptive_NS(InputSettings, MethodSettings, OutputSettings, pathwayMats[pathway]);
            List <String>     BNs_NS = obj_NS.StartAnalysis();
            string            bn_NS  = Find_CombinedBN(BNs_NS);
            List <double[, ]> bnMats = getNetworkSfromString(bn_NS, nNodes);

            printNet(bn_NS, obj_NS.nodeNameList, pathway, "NS");
            bugsSampling bugs_NS = new bugsSampling(bnMats[0],
                                                    bnMats[1],
                                                    nNodes,
                                                    pathway,
                                                    obj_NS.nodeNameList,
                                                    "NS",
                                                    nburnIn,
                                                    nSamplingIter,
                                                    gamma_prior_a,
                                                    gamma_prior_b); // [0] original matrix, [1] complementary matrix
            // -----------

            // -- HAR algorithm (comment out when need to use)
            Adaptive_HAR      obj_HAR    = new Adaptive_HAR(InputSettings, MethodSettings, OutputSettings, pathwayMats[pathway]);
            List <String>     BNs_HAR    = obj_HAR.StartAnalysis();
            string            bn_HAR     = Find_CombinedBN(BNs_HAR);
            List <double[, ]> bnMats_HAR = getNetworkSfromString(bn_HAR, nNodes);

            printNet(bn_HAR, obj_HAR.nodeNameList, pathway, "HAR");
            bugsSampling bugs_HAR = new bugsSampling(bnMats_HAR[0],
                                                     bnMats_HAR[1],
                                                     nNodes,
                                                     pathway,
                                                     obj_HAR.nodeNameList,
                                                     "HAR",
                                                     nburnIn,
                                                     nSamplingIter,
                                                     gamma_prior_a,
                                                     gamma_prior_b); // [0] original matrix, [1] complementary matrix
            // -----------


            // -- MH algorithm (comment out when need to use)
            Adaptive_MH       obj_MH    = new Adaptive_MH(InputSettings, MethodSettings, OutputSettings, pathwayMats[pathway]);
            List <String>     BNs_MH    = obj_MH.StartAnalysis();
            string            bn_MH     = Find_CombinedBN(BNs_MH);
            List <double[, ]> bnMats_MH = getNetworkSfromString(bn_MH, nNodes);

            printNet(bn_MH, obj_MH.nodeNameList, pathway, "MH");

            bugsSampling bugs_MH = new bugsSampling(bnMats_MH[0],
                                                    bnMats_MH[1],
                                                    nNodes,
                                                    pathway,
                                                    obj_MH.nodeNameList,
                                                    "MH",
                                                    nburnIn,
                                                    nSamplingIter,
                                                    gamma_prior_a,
                                                    gamma_prior_b); // [0] original matrix, [1] complementary matrix

            // -----------
            //}
            //});
            MessageBox.Show("complete");
        }
예제 #2
0
        public void DO_Operation(object sender, DoWorkEventArgs e)
        {
            Session["OuterWorker"] = bgWorker1;

            #region Prepare input settings and call the required analysis function constructor
            NameValueCollection inputSettings = new NameValueCollection();
            inputSettings.Add("nNodes", txt_nNodes.Text);
            inputSettings.Add("nIteration", txt_nIteration.Text);
            inputSettings.Add("nBurnIn", txt_nBurnIn.Text);
            inputSettings.Add("nMaxOutdegree", txt_maxOutDegree.Text);
            inputSettings.Add("nMaxIndegree", txt_maxInDegree.Text);
            //inputSettings.Add("nSSDstepsize", txt_SSD_Step.Text);
            Session["iterationCount"] = txt_nIteration.Text.ToString().Trim();
            #endregion

            #region Prepare Method settings and call the required analysis function constructor
            List <string> MethodSettings       = new List <string>();
            string        initialNetwork       = "";
            string        SamplingDistribution = "";
            string        AcceptanceRatio      = "";
            List <string> MCMC_methods         = new List <string>();

            if (radioButton_InitNet_FixedorRandom.SelectedIndex > -1)
            {
                if (radioButton_InitNet_FixedorRandom.SelectedIndex == 0)
                {
                    initialNetwork = "Fixed";
                }
                else if (radioButton_InitNet_FixedorRandom.SelectedIndex == 1)
                {
                    initialNetwork = "Random";
                }
            }

            SamplingDistribution = "DirMul";
            AcceptanceRatio      = "MH";

            //if (radioButton_SamplingDist_Uniform.Checked)
            //    SamplingDistribution = "Uniform";
            //else if (radioButton_SamplingDist_DirMul.Checked)
            //    SamplingDistribution = "DirMul";

            //if (radioButton_AccepRatio_Approximation.Checked)
            //    AcceptanceRatio = "Approximation";
            //else if (radioButton_AccepRatio_MH.Checked)
            //    AcceptanceRatio = "MH";

            //if (radioButton_MCMC_MetroPolish.Checked)
            //    MCMC_methods = "Metropolis";
            if (chk_method_MH.Checked)
            {
                MCMC_methods.Add("MH");
            }
            if (chk_method_NS.Checked)
            {
                MCMC_methods.Add("NS");
            }
            if (chk_method_HAR.Checked)
            {
                MCMC_methods.Add("HAR");
            }

            MethodSettings.Add(initialNetwork);
            MethodSettings.Add(SamplingDistribution);
            MethodSettings.Add(AcceptanceRatio);
            #endregion

            #region Prepare Numerical Output settings
            List <string> NumerialOutputSettings = new List <string>();
            string        SampledNetwithFreq     = "false";
            string        LogPosteriorFunction   = "false";
            string        SSD_values             = "false";
            string        Mean_Posterior         = "false";

            if (checkBox_SelectedNets_with_Freq.Checked)
            {
                SampledNetwithFreq = "true";
            }

            if (checkBox_LogPosterior.Checked)
            {
                LogPosteriorFunction = "true";
            }

            //if (checkBox_SSD_values.Checked)
            //    SSD_values = "true";

            if (checkBox_MeanPosterior.Checked)
            {
                Mean_Posterior = "true:" + txt_MeanPosterior_Th.Text;
            }

            NumerialOutputSettings.Add(SampledNetwithFreq);
            NumerialOutputSettings.Add(LogPosteriorFunction);
            NumerialOutputSettings.Add(SSD_values);
            NumerialOutputSettings.Add(Mean_Posterior);
            #endregion

            #region Prepare Graphical Output settings
            List <string> GraphicalOutputSettings   = new List <string>();
            string        LogPosterior_VS_iteration = "false";
            string        SSD_VS_StepSize           = "false";
            string        TrueDist_VS_EstimatedDist = "false";
            string        Mean_Posterior_Net        = "false";
            string        Highest_Freq_Net          = "false";

            if (checkBox_LogPosterior_VS_iteration.Checked)
            {
                LogPosterior_VS_iteration = "true";
            }

            //if (checkBox_SSD_VS_stepSize.Checked)
            //    SSD_VS_StepSize = "true";

            //if (checkBox_TrueDist_VS_EstimatedDist.Checked)
            //    TrueDist_VS_EstimatedDist = "true";

            if (checkBox_MeanPosteriorNet.Checked)
            {
                Mean_Posterior_Net = "true";
            }

            if (checkBox_HighestFreqNet.Checked)
            {
                Highest_Freq_Net = "true";
            }

            GraphicalOutputSettings.Add(LogPosterior_VS_iteration);
            GraphicalOutputSettings.Add(SSD_VS_StepSize);
            GraphicalOutputSettings.Add(TrueDist_VS_EstimatedDist);
            GraphicalOutputSettings.Add(Mean_Posterior_Net);
            GraphicalOutputSettings.Add(Highest_Freq_Net);
            #endregion

            #region Call proper Class

            inputFileInfo = (List <string>)Session["inputFileInfo"];
            string outputDirectory = (string)Session["path"];

            #region For Metropolis-Hastings Sampler
            if (MCMC_methods.Contains("MH"))
            {
                Session["MCMC_method_MH"] = "true";
                //Response.Write("<script type='text/javascript' src='Scripts/Progress.js'> GetStatus('MH');</script>");
                //Response.Write("<script type='text/javascript' src='Scripts/Progress.js'> GetStatus_1();</script>");
                //Response.Write("<script> window.onload=function(){GetStatus('MH');}</script>");
                //Response.Write("<script> window.onload=function(){GetStatus_1();}</script>");
                ClientScript.RegisterStartupScript(typeof(Page), "keyMH", "<script type=\"text/javascript\"> GetStatus_1(); </script>", false);
                //Response.Write("<script> window.GetStatus('MH');</script>");
                /* THE SAMPLER CLASS RUNNING STARTS HERE */

                Adaptive_MH obj_MH = new Adaptive_MH(inputFileInfo, inputSettings, outputDirectory, MethodSettings, NumerialOutputSettings, GraphicalOutputSettings);
                obj_MH.StartAnalysis(Session);
            }
            #endregion

            #region For Neighbourhood Sampler

            if (MCMC_methods.Contains("NS"))
            {
                Session["MCMC_method_NS"] = "true";
                //Response.Write("<script type='text/javascript' src='Scripts/Progress.js'> GetStatus('NS'); </script>");
                //Response.Write("<script type='text/javascript' src='Scripts/Progress.js'> GetStatus_2(); </script>");
                //Response.Write("<script> window.onload=function(){GetStatus('NS');}</script>");
                //Response.Write("<script> window.onload=function(){GetStatus_2();}</script>");
                //Response.Write("<script> window.GetStatus('NS');</script>");
                ClientScript.RegisterStartupScript(typeof(Page), "keyNS", "<script type=\"text/javascript\"> GetStatus_2(); </script>", false);
                /* THE SAMPLER CLASS RUNNING STARTS HERE */
                Adaptive_NS obj_NS = new Adaptive_NS(inputFileInfo, inputSettings, outputDirectory, MethodSettings, NumerialOutputSettings, GraphicalOutputSettings);
                obj_NS.StartAnalysis(Session);
            }
            #endregion

            #region For Hit-n-Run Sampler

            if (MCMC_methods.Contains("HAR"))
            {
                Session["MCMC_method_HAR"] = "true";
                //Response.Write("<script type='text/javascript' src='Scripts/Progress.js'> GetStatus('HAR');</script>");
                //Response.Write("<script type='text/javascript' src='Scripts/Progress.js'> GetStatus_3();</script>");
                //Response.Write("<script> window.onload=function(){GetStatus('HAR');}</script>");
                //Response.Write("<script> window.onload=function(){GetStatus_3();}</script>");
                //.Write("<script> window.GetStatus('HAR');</script>");
                ClientScript.RegisterStartupScript(typeof(Page), "keyHAR", "<script type=\"text/javascript\"> GetStatus_3(); </script>", false);
                /* THE SAMPLER CLASS RUNNING STARTS HERE */
                Adaptive_HAR obj_HAR = new Adaptive_HAR(inputFileInfo, inputSettings, outputDirectory, MethodSettings, NumerialOutputSettings, GraphicalOutputSettings, txt_HAR_lambda.Text);
                obj_HAR.StartAnalysis(Session);
            }
            #endregion


            #endregion
        }