亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? bayesnet.cpp

?? gibbs
?? CPP
字號:
#include <string>#include <iostream>#include <sstream>#include <expat.h>#include <list>#include "BayesNet.h"#include "DecisionTree.h"// HACK -- leaving this as module data prevents us from// parsing more than one BayesNet at a time.string elementCdata = "";DecisionTree* dtree = NULL;int currVar = -1;bool inTypeVariables = false;int maxVarState = -1;int getVarIndex(const char* colname){    int ret = 0;    int pow = 1;    for (int i = strlen(colname) - 1; isdigit(colname[i]); i--) {        ret += pow * (colname[i] - '0');        pow *= 10;    }    return ret - 1;}const XML_Char* getAtt(const XML_Char* attName, const XML_Char** attList){    for (int i = 0; attList[i]; i += 2) {        if (!strcmp(attList[i], attName)) {            return attList[i+1];        }    }    return NULL;}void characterDataHandler(void* userData, const XML_Char *cdata, int len){    elementCdata.append(cdata, len);}void startElementHandler(void* userData, const XML_Char *name,        const XML_Char **atts){    // DEBUG    //cout << "Found start element: " << name << endl;    BayesNet* model = (BayesNet*)userData;    if (!strcmp(name, "TypeVariables")) {        inTypeVariables = true;    } else if (!strcmp(name, "Variable")) {        // HACK: this only works if every single variable        // has a typeVariable with a name of the form:        // "TypeK n-state" OR "TypeK continuous"        if (!inTypeVariables) {            const char* typeVarName = getAtt("typeVariable", atts);            int numStates = -1;            // DEBUG / HACK -- Really ought to handle general case,            // when typeVariable might not be specified.            if (typeVarName != NULL) {                if (strstr(typeVarName, "ontinuous")) {                    model->addVar(-1);                } else {                    // We expect the number of states to appear after                    // a space, in a name of the form: "TypeK n-state"                    for (unsigned int i = 0; i < strlen(typeVarName); i++) {                        if (isspace(typeVarName[i])) {                            numStates = atoi(typeVarName + i + 1);                            break;                        }                    }                    model->addVar(numStates);                }            } else {                const char* type = getAtt("type", atts);                if (type == NULL) {                    cout << "ERROR: no type variable or type specified!\n";                    return;                }                // Add continuous vars now.  Add categorical vars once we've                // counted their states.                if (!strcmp(type, "continuous")) {                    model->addVar(-1);                }            }        }    } else if (!strcmp(name, "State")) {        if (!inTypeVariables) {            maxVarState++;        }    } else if (!strcmp(name, "LocalModel")) {        const char* varName = getAtt("variable", atts);        if (!varName) {            cout << "ERROR: no variable specified in LocalModel!\n";        }        currVar = getVarIndex(varName);        // DEBUG        //cout << "Reading model for variable " << currVar << endl;    } else if (!strcmp(name, "Input")) {        const char* varName = getAtt("variable", atts);        if (!varName) {            cout << "ERROR: no variable specified in Input!\n";        }        model->addChild(getVarIndex(varName), currVar);    } else if (!strcmp(name, "DecisionTree")) {        // dtree = new DecisionTree(currVar, model->schema.getRange(currVar));        dtree = model->getDecisionTree(currVar);    } else if (!strcmp(name, "Vertex")) {        const char* splitName = getAtt("split", atts);        if (!splitName) {            cout << "ERROR: no split variable specified at Vertex!\n";        }        dtree->beginVertex(getVarIndex(splitName));    } else if (!strcmp(name, "Branch")) {        dtree->beginBranch();    } else if (!strcmp(name, "Multinomial")) {        dtree->beginMultinomial();    }    elementCdata.clear();}void endElementHandler(void* userData, const XML_Char *name){    // DEBUG    //cout << "Found end element: " << name << endl;    BayesNet* model = (BayesNet*)userData;    if (!strcmp(name, "TypeVariables")) {        inTypeVariables = false;    } else if (!strcmp(name, "Variable")) {        if (!inTypeVariables) {            if (maxVarState >= 0) {                model->addVar(maxVarState + 1);            }            maxVarState = -1;        }    } else if (!strcmp(name, "DecisionTree")) {        /*        model->setDecisionTree(currVar, dtree);        dtree = NULL;        */    } else if (!strcmp(name, "Vertex")) {        dtree->endVertex();    } else if (!strcmp(name, "Branch")) {        dtree->endBranch();    } else if (!strcmp(name, "Values")) {        list<Range> values;        istringstream in(elementCdata);        while (in) {            Range r;            in >> r;            if (in) {                values.push_back(r);            }        }        dtree->endValues(values);    } else if (!strcmp(name, "Probs")) {        unsigned int base = 0;        int index = 0;        double *probs = new double[dtree->getRange()];        // DEBUG        //cout << "Probs: " << elementCdata << " (";        for (unsigned int i = 0; i < elementCdata.length(); i++) {            if (isspace(elementCdata[i])) {                if (i > base) {                    probs[index++]                         = atof(elementCdata.substr(base, i-base).c_str());                    // DEBUG                    //cout << probs[index-1] << " ";                }                base = i + 1;            }        }        if (elementCdata.length() > base) {            probs[index++] = atof(elementCdata.substr(base).c_str());            // DEBUG            //cout << probs[index-1] << " ";        }        // DEBUG        //cout << ")\n";        dtree->endProbs(probs);    } else if (!strcmp(name, "Mean")) {        dtree->endMean(atof(elementCdata.c_str()));    } else if (!strcmp(name, "SD")) {        dtree->endSD(atof(elementCdata.c_str()));    } else if (!strcmp(name, "ProbMissing")) {        dtree->endProbMissing(atof(elementCdata.c_str()));    } else if (!strcmp(name, "BinGaussian")) {        dtree->endBinGaussian();    }    elementCdata.clear();}// DEBUG#include <stdio.h>void loadModel(FILE* in, BayesNet& model){    XML_Parser parser = XML_ParserCreate(NULL);    if (!parser) {        cout << "ERROR: could not allocate memory for parser!\n";        return;    }    XML_SetUserData(parser, &model);    XML_SetElementHandler(parser, startElementHandler, endElementHandler);    XML_SetCharacterDataHandler(parser, characterDataHandler);    char buf[10240];    while (!feof(in)) {        int bytesRead = fread(buf, 1, 1000, in);        /* DEBUG        ((char*)buf)[bytesRead] = '\0';        printf((char*)buf);        cout << "in.eof()? " << feof(in) << endl;        */        if ( !XML_Parse(parser, buf, bytesRead, feof(in)) ) {            cout << "Parse error at line " << XML_GetCurrentLineNumber(parser)                << ":\n" << XML_ErrorString(XML_GetErrorCode(parser)) << endl;            return;        }    }    XML_ParserFree(parser);// We have no reason at present to get the splits of a continuous variable.// This was debugging code for functionality that's no longer used.#if 0    for (int i = 0; i < model.getNumVars(); i++) {        if (model.getRange(i) >= 0) {            continue;        }        // Find all splits        list<double> allsplits;        for (int v = 0; v < model.getNumVars(); v++) {            DecisionTree* currTree = model.getDecisionTree(v);            list<double> currsplits = currTree->getSplits(i);            allsplits.splice(allsplits.end(), currsplits);        }        allsplits.sort();        // Print out values        cout << i << ":";        list<double>::iterator iter;        for (iter = allsplits.begin(); iter != allsplits.end(); iter++) {            cout << " " << *iter;        }        cout << endl;    }#endif    return;}vector<double> BayesNet::MBdist(int var, VarSet& allVars) const{    const Leaf* l = decisionTrees[var]->getLeaf(allVars.getArray());    int numVals = decisionTrees[var]->getRange();    vector<double> distrib(numVals);    double totalProb = -1.0/0.0000000000001;    // Compute probability distribution across all values,     // using Markov-blanket inference.    double origVal = allVars[var];    for (int i = 0; i < numVals; i++) {        // Compute p(x | parents(x))        distrib[i] = l->getLogProb(i);        // DEBUG        if (isnan(distrib[i])) {            cout << "distrib[" << i << "] = 0.0!\n";        }        // Scale by p(children(x) | parents(children(x)))        list<int>::const_iterator c;        for (c = children[var].begin(); c != children[var].end(); c++) {            allVars[var] = i;            distrib[i] += getLogProb(*c, allVars.getArray());            // DEBUG            if (isnan(distrib[i])) {                cout << "distrib[" << i << "] = 0.0 after child " << *c << "\n";            }        }        // Keep track of total probability, so we can normalize        if (totalProb - distrib[i] < -10) {            // If distrib[i] is much larger, just use it.            totalProb = distrib[i];        } else if (totalProb - distrib[i] < 10) {            // If they're within the same range, add them            totalProb = log(exp(totalProb - distrib[i]) + 1) + distrib[i];        }    }    allVars[var] = origVal;    if (isnan(totalProb)) {        cout << "totalProb = 0!\n";    }    // Normalize    for (int i = 0; i < numVals; i++) {        distrib[i] = exp(distrib[i] - totalProb);    }    return distrib;}double BayesNet::MBsample(int var, VarSet& allVars) const{    const Leaf* l = decisionTrees[var]->getLeaf(allVars.getArray());    int numVals;    vector<double> actualVals;    if (decisionTrees[var]->getRange() < 0) {        DT::BinGaussian* g = (DT::BinGaussian*)l;        double minVal = g->mean - 4 * g->SD;        double maxVal = g->mean + 4 * g->SD;        int numIncs = 1000;        double dx = (maxVal - minVal)/numIncs;        numVals = numIncs;        for (double currX = minVal; currX < maxVal; currX += dx) {            actualVals.push_back(currX);        }        actualVals.push_back(VarSet::UNKNOWN);    } else {        numVals = decisionTrees[var]->getRange();        for (int i = 0; i < numVals; i++) {            actualVals.push_back(i);        }    }    vector<double> distrib(numVals);    //double totalProb = 0.0;    double totalProb = -1.0/0.0000000000001;    // Compute probability distribution across all values,     // using Markov-blanket inference.    double origVal = allVars[var];    for (int i = 0; i < numVals; i++) {        allVars[var] = actualVals[i];        // Compute p(x | parents(x))        distrib[i] = l->getLogProb(actualVals[i]);        // Scale by p(children(x) | parents(children(x)))        list<int>::const_iterator c;        for (c = children[var].begin(); c != children[var].end(); c++) {            distrib[i] += getLogProb(*c, allVars.getArray());        }        // Keep track of total probability, so we can normalize        if (totalProb - distrib[i] < -10) {            // If distrib[i] is much larger, just use it.            totalProb = distrib[i];        } else if (totalProb - distrib[i] < 10) {            // If they're within the same range, add them            totalProb = log(exp(totalProb - distrib[i]) + 1) + distrib[i];        }    }    allVars[var] = origVal;    // Normalize    for (int i = 0; i < numVals; i++) {        distrib[i] = exp(distrib[i] - totalProb);    }    // Sample    double p = (double)rand() / RAND_MAX;    for (int i = 0; i < numVals; i++) {        p -= distrib[i];        if (p < 0) {            return actualVals[i];        }    }    // DEBUG    cout << "Error: defaulting to last value!\n";    cout << "p = " << p << endl;    cout << "var = " << var << endl;    cout << "numVals = " << numVals <<  " ("         << decisionTrees[var]->getRange() << ")\n";    for (int i = 0; i < numVals; i++) {        cout << distrib[i] << " ";    }    cout << endl;    return actualVals.back();}// Generate a complete samplevoid BayesNet::wholeSample(VarSet& allvars) const{    /* HACK --     * If you need a variable to be sampled, it must be     * marked as UNTESTED in allvars before calling this function.     * UNKNOWN is simply not sufficient, because UNKNOWN is a legal     * value for continuous variables.  (For discrete variables,     * the unknown value is a separate value taken care of when building     * the dataset.  It must be handled specially for continuous variables.)     */    int knownVars = 0;    for (int i = 0; i < numVars; i++) {        /*        if (allvars.isObserved(i) && allvars.isTested(i)) {            knownVars++;        }        */        if (allvars.isTested(i)) {            knownVars++;        }    }    // Sample each unknown variable whose parents have been specified.    // Keep going until all variables have been sampled.    while (knownVars < numVars) {        for (int i = 0; i < numVars; i++) {            if (/*!allvars.isObserved(i) || */ !allvars.isTested(i)) {                bool unspecifiedParent = false;                list<int>::const_iterator p;                for (p = parents[i].begin(); p != parents[i].end(); p++) {                    if (/* !allvars.isObserved(*p) || */ !allvars.isTested(*p)) {                        unspecifiedParent = true;                        break;                    }                }                if (!unspecifiedParent) {                    allvars[i] = decisionTrees[i]->sample(allvars.getArray());                    knownVars++;                }            }        }    }}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品国产百合女同互慰| 亚洲人成影院在线观看| 国产欧美一区二区在线| 亚洲一区二区在线观看视频 | 成人av资源站| 91麻豆免费观看| 在线亚洲精品福利网址导航| 制服丝袜亚洲播放| 亚洲综合色噜噜狠狠| 日本美女一区二区三区视频| 久久国产精品第一页| 成人aaaa免费全部观看| 欧美日韩精品欧美日韩精品一 | 亚洲一二三四在线观看| 亚洲欧美日韩国产成人精品影院| 亚洲韩国一区二区三区| 国产一区高清在线| 色先锋aa成人| 欧美成va人片在线观看| 玉足女爽爽91| 成人福利视频网站| 日韩一区国产二区欧美三区| 国产精品国产成人国产三级| 国产精品久久毛片a| 午夜精品在线视频一区| 国产91精品一区二区| 欧美三区在线观看| 欧美激情一区二区| 免费人成精品欧美精品| 91久久人澡人人添人人爽欧美 | 欧美亚洲自拍偷拍| 国产亚洲午夜高清国产拍精品| 精品一二三四区| 91蜜桃传媒精品久久久一区二区| 日韩欧美另类在线| 亚洲一级在线观看| 色婷婷一区二区| 亚洲国产精品99久久久久久久久| 久草精品在线观看| 欧美一级午夜免费电影| 一二三区精品视频| 91日韩精品一区| 久久久.com| 老司机午夜精品99久久| 欧美色电影在线| 亚洲精品国产品国语在线app| 国产精品一区二区三区乱码| 日韩一级完整毛片| 美腿丝袜亚洲三区| 日韩西西人体444www| 亚洲成人黄色小说| 91极品视觉盛宴| 亚洲精品久久久蜜桃| 色综合婷婷久久| 一区二区三区四区高清精品免费观看 | 成人一级片在线观看| 久久一留热品黄| 亚洲大片精品永久免费| 欧美做爰猛烈大尺度电影无法无天| 中文字幕一区二区三中文字幕| 另类综合日韩欧美亚洲| 91精品啪在线观看国产60岁| 亚洲综合精品久久| 欧美久久久久久久久| 亚洲三级久久久| 日本道色综合久久| 性久久久久久久久久久久| 91黄视频在线| 亚洲国产精品一区二区尤物区| 在线观看日韩av先锋影音电影院| 亚洲图片欧美一区| 日韩午夜av一区| 国产成人免费视| 26uuu国产一区二区三区| 在线观看一区二区精品视频| 亚洲va韩国va欧美va| 制服丝袜亚洲色图| 国产一区二区三区不卡在线观看| 国产精品美女久久久久久| 91丨porny丨中文| 午夜精品一区二区三区电影天堂 | 欧美三级蜜桃2在线观看| 亚洲高清免费一级二级三级| 日韩女优电影在线观看| 免费人成在线不卡| 国产精品日日摸夜夜摸av| 欧洲av在线精品| 六月丁香综合在线视频| 国产精品国产三级国产普通话蜜臀| 一本色道久久综合狠狠躁的推荐| 天堂成人国产精品一区| 国产三级精品三级| 色综合天天综合色综合av| 日韩av网站在线观看| 国产精品美女久久久久久久久 | 一二三区精品视频| 久久久久免费观看| 欧美日精品一区视频| 国产一区二区三区免费播放 | 99久久精品国产一区| 蜜桃av一区二区在线观看| 亚洲欧洲韩国日本视频| 日韩丝袜美女视频| 色婷婷综合久色| 激情六月婷婷久久| 亚洲国产日产av| 国产视频一区不卡| 欧美日韩日日摸| youjizz国产精品| 麻豆91在线播放免费| 亚洲男人电影天堂| 国产女同互慰高潮91漫画| 欧美麻豆精品久久久久久| 成人精品国产免费网站| 日韩精品一区第一页| 亚洲男人的天堂在线观看| 精品欧美一区二区在线观看| 色婷婷激情久久| 国产91在线|亚洲| 美女视频黄免费的久久 | 日韩欧美成人一区| 欧美日韩高清在线播放| 色婷婷精品大视频在线蜜桃视频| 精品写真视频在线观看| 日韩国产精品久久| 午夜日韩在线观看| 夜夜嗨av一区二区三区| 日韩一区欧美小说| 国产精品嫩草影院av蜜臀| 26uuu国产在线精品一区二区| 欧美日韩国产影片| 欧美性大战久久久久久久蜜臀| av动漫一区二区| 成人的网站免费观看| 成人高清视频在线| 成人免费观看av| 成人动漫在线一区| 99久久久免费精品国产一区二区| 国产成人在线视频免费播放| 国产一区二区三区四区五区美女 | 一区二区激情视频| 国产精品成人午夜| 国产精品夫妻自拍| 亚洲欧洲一区二区在线播放| 国产精品久久久久久久裸模| 中文字幕国产一区二区| 久久九九久久九九| 国产欧美日韩另类视频免费观看| 国产欧美一区二区三区在线看蜜臀 | 成人一区二区三区视频| 成人蜜臀av电影| 91视频一区二区三区| 色综合视频在线观看| 日本丶国产丶欧美色综合| 欧洲av一区二区嗯嗯嗯啊| 欧美精品日韩综合在线| 日韩欧美国产午夜精品| 久久精品一区二区| 亚洲日本丝袜连裤袜办公室| 有码一区二区三区| 美日韩一区二区| 成人自拍视频在线观看| 色久优优欧美色久优优| 在线播放日韩导航| 欧美精品一区视频| 综合分类小说区另类春色亚洲小说欧美 | 老司机免费视频一区二区三区| 国精品**一区二区三区在线蜜桃| 高清在线不卡av| 成人在线综合网站| 欧美丝袜自拍制服另类| 91麻豆精品久久久久蜜臀| 精品国产一区二区三区不卡 | 成人app网站| 欧美久久一二三四区| 欧美激情资源网| 国产成人av福利| 91在线国产福利| 日韩一区二区三区高清免费看看| 欧美国产欧美亚州国产日韩mv天天看完整 | 国产成人在线观看| 精品视频在线看| 国产日韩欧美一区二区三区综合| 亚洲色图欧洲色图| 日韩av一级片| 国产精品香蕉一区二区三区| 色偷偷久久人人79超碰人人澡| 欧美一区二区国产| 亚洲视频一区二区在线观看| 日日骚欧美日韩| 国产一区二区三区在线观看免费| 国产九九视频一区二区三区| 麻豆国产欧美一区二区三区| 99久久精品国产网站| 日韩欧美在线网站| 日韩毛片在线免费观看| 国产在线日韩欧美| 欧美一级搡bbbb搡bbbb| 一区二区在线观看不卡| 国产sm精品调教视频网站|