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

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

?? markovnet.cpp

?? gibbs
?? CPP
字號:
#include "MarkovNet.h"// DEBUG//#define DEBUG//#define DEBUG2//#define DEBUG3MarkovNet::MarkovNet(const BayesNet& bn)    : nodes(new Node[bn.getNumVars() * 2]), numNodes(0){    VarSchema schema = bn.getSchema();    // Create one node per original variable    int numVars = schema.getNumVars();    for (int i = 0; i < numVars; i++) {        nodes[i].index = i;        nodes[i].fixedValue = -1;        nodes[i].marginal = Distribution(schema.getRange(i));        nodes[i].phi = Distribution(schema.getRange(i));        numNodes++;    }#ifdef DEBUG    cout << "Added one node per original variable.\n";#endif    // Link nodes with edges and potential functions; add extra nodes    // as necessary.    for (int i = 0; i < numVars; i++) {#ifdef DEBUG        cout << "Linking node " << i << endl;#endif        DecisionTree& dtree = *bn.decisionTrees[i];        const list<int>& parents  = bn.parents[i];        if (parents.size() == 0) {#ifdef DEBUG            cout << "    No parents; done.\n";#endif             // Construct a marginal distribution from the decision tree            nodes[i].phi = Distribution(schema.getRange(i));            for (int val = 0; val < schema.getRange(i); val++) {                nodes[i].phi[val] = dtree.getProb(val, NULL);            }        } else if (parents.size() == 1) {#ifdef DEBUG            cout << "    One parent; done.\n";#endif            Potential psi(dtree, schema);            addEdge(&nodes[i], &nodes[parents.front()], psi);        } else {            // Multiple parents case#ifdef DEBUG            cout << "    Multiple parents.\n";#endif            // Get total dimension of inputs to decision tree            int inputDim = 1;            list<int>::const_iterator p;            for (p = parents.begin(); p != parents.end(); p++ ) {                inputDim *= schema.getRange(*p);            }            // Add mediator node to represent all values of all parents            Node* mediator = &nodes[numNodes++];            mediator->index      = numNodes-1;            mediator->fixedValue = -1;            mediator->marginal   = Distribution(inputDim);            mediator->phi        = Distribution(inputDim);            // Add edges from mediator node to actual parents,             // to enforce value consistency.            int cumulativeDim = 1;            for (p = parents.begin(); p != parents.end(); p++) {                int parentDim = schema.getRange(*p);                Potential psi(inputDim, parentDim);                for (int r = 0; r < inputDim; r++) {                    for (int c = 0; c < parentDim; c++) {                        psi.set(r, c, 0.0);                    }                    int parentVal = (r/cumulativeDim) % parentDim;                    psi.set(r, parentVal, 1.0);                }                cumulativeDim *= parentDim;                addEdge(mediator, &nodes[*p], psi);                // DEBUG                //cout << "psi(" << *p << ") = " << psi << endl;            }            // Finally, add an edge from the child to the mediator            // using its distribution over parents from the Bayes net.            Potential psi(dtree, schema);            addEdge(&nodes[i], mediator, psi);        }    }}void MarkovNet::addEdge(Node* n1, Node* n2, Potential& psi){    Edge e;    edges.push_back(e);    edges.back().n1 = n1;    edges.back().n2 = n2;    edges.back().psi = psi;#ifdef DEBUG3    cout << "Psi = " << psi << endl;#endif    n1->edges.push_back(&edges.back());    n2->edges.push_back(&edges.back());}#if 0double MarkovNet::getLikelihood(VarSet query, VarSet evidence,        double threshold, double damping){    // DEBUG    cout << "Resetting all nodes\n";    // Set evidence    resetAllNodes();    // DEBUG    cout << "Resetting all messages\n";    resetAllMessages();    // DEBUG    cout << "Setting all evidence\n";    for (int i = 0; i < evidence.getNumVars(); i++) {        if (evidence.isTested(i)) {            fixNodeValue(i, (int)evidence[i]);        }    }    // DEBUG    cout << "Running belief propagation\n";    // Run belief propogation to convergence    runBP(threshold, damping);    // Compute product of marginal distributions    double prob = 1.0;    for (int i = 0; i < query.getNumVars(); i++) {        if (query.isTested(i) && !evidence.isTested(i)) {            prob *= getMarginal(i).get((int)query[i]);        }    }    return prob;}#endifvoid MarkovNet::runBP(double convergenceThreshold, double dampingFactor){    list<Edge*>::iterator neighbor;    // For all fixed nodes, we need only send our messages once.    for (int n = 0; n < numNodes; n++) {        // Only consider fixed nodes at this point        if (nodes[n].fixedValue < 0) {            continue;        }        // Send messages to each neighbor        for (neighbor = nodes[n].edges.begin();                 neighbor != nodes[n].edges.end(); neighbor++) {            Edge* currEdge = *neighbor;            // Don't send messages to other fixed nodes            if (currEdge->otherNode(&nodes[n])->fixedValue >= 0) {                continue;            }            // Send the messages            currEdge->sendMsg(&nodes[n], nodes[n].marginal);        }    }    // For nodes with only fixed neighbors, compute marginals exactly once    for (int n = 0; n < numNodes; n++) {        // Already fixed        if (nodes[n].fixedValue >= 0) {            continue;        }        // Assume fixed until proven otherwise        nodes[n].fixedValue = 0;        for (neighbor = nodes[n].edges.begin();                neighbor != nodes[n].edges.end(); neighbor++) {            // Neighbor not fixed: we guessed wrong            if ((*neighbor)->otherNode(&nodes[n])->fixedValue < 0) {                nodes[n].fixedValue = -1;                break;            }        }        // Compute marginal from all incoming messages        if (nodes[n].fixedValue >= 0) {            nodes[n].marginal = nodes[n].phi;            for (neighbor = nodes[n].edges.begin();                    neighbor != nodes[n].edges.end(); neighbor++) {                nodes[n].marginal *= (*neighbor)->msgTo(&nodes[n]);#ifdef DEBUG2                cout << "Pre-incoming: " << (*neighbor)->msgTo(&nodes[n]) << endl;#endif            }#ifdef DEBUG2            cout << "New marginal: " << nodes[n].marginal << endl;#endif            nodes[n].marginal.normalize();        }    }    int maxIters = 1000;    double delta = 0.0;    int i;    for (i = 0; i < maxIters; i++) {        delta = BPiter(dampingFactor);        if (delta < convergenceThreshold) {            break;        }#ifdef DEBUG        cout << "Iteration " << i << ": delta = " << delta << endl;#endif    }#ifdef DEBUG    if (i == maxIters) {        cout << "Did not converge after " << maxIters << " iterations.\n";    } else {        cout << "Successfully converged in " << i << " iterations.\n";    }    cout << "Final delta: " << delta << endl;#endif    return;}double MarkovNet::BPiter(double dampingFactor){    double delta = 1.0;    list<Edge*>::iterator neighbor;    list<Edge*>::reverse_iterator rneighbor;    int index;    for (int i = 0; i < numNodes; i++) {        // Skip fixed nodes; their messages have already been sent        if (nodes[i].fixedValue >= 0) {            continue;        }         int numNeighbors = nodes[i].edges.size();        vector<Distribution> forwardDistribs(numNeighbors+1);        vector<Distribution> reverseDistribs(numNeighbors);        // Compute products of first n messages and phi (the prior        // distribution at this node), for all n        forwardDistribs[0] = nodes[i].phi;        index = 1;        for (neighbor = nodes[i].edges.begin();                neighbor != nodes[i].edges.end(); neighbor++) {            // Multiply previous distrib by the incoming message            forwardDistribs[index] = forwardDistribs[index-1];            forwardDistribs[index] *= (*neighbor)->msgTo(&nodes[i]);#ifdef DEBUG2            cout << "Incoming message: " << (*neighbor)->msgTo(&nodes[i]) << endl;#endif            index++;        }        // Compute products of last n messages, for all n        // (Except for product of all messages, which is redundant.)        reverseDistribs[0] = Distribution(nodes[i].phi.dim());        index = 1;        for (rneighbor = nodes[i].edges.rbegin();                index < numNeighbors; rneighbor++) {            // Multiply by the incoming message on each edge            reverseDistribs[index] = reverseDistribs[index-1];            reverseDistribs[index] *= (*rneighbor)->msgTo(&nodes[i]);            index++;        }        // The marginal is just the product of all messages and phi,        // which we've computed above.        Distribution marginal = forwardDistribs[numNeighbors];        marginal.normalize();#ifdef DEBUG2        cout << "Marginal: " << marginal << endl;#endif        // Compute messages to send to neighbors        index = 0;        for (neighbor = nodes[i].edges.begin();                neighbor != nodes[i].edges.end(); neighbor++, index++) {            Edge* currEdge = *neighbor;            // Don't send messages to fixed nodes            if (currEdge->otherNode(&nodes[i])->fixedValue >= 0) {                continue;            }            // Compute message            Distribution message = forwardDistribs[index];            if (index != numNeighbors - 1) {                message *= reverseDistribs[numNeighbors - index - 1];            }            // Distribute message            currEdge->sendMsg(&nodes[i], message);#if 0            // HACK DEBUG -- Comparing messages!            Distribution outgoing = nodes[i].phi;            if (nodes[i].fixedValue < 0) {                for (list<Edge*>::iterator n2 = nodes[i].edges.begin();                        n2 != nodes[i].edges.end(); n2++) {                    if (*n2 != currEdge) {                        outgoing *= ((*n2)->n1 == &nodes[i]) ? (*n2)->message2to1                                                             : (*n2)->message1to2;                    }                }            } else {                outgoing = nodes[i].marginal;            }            // DEBUG -- Report inconsistencies between old and new methods            if (nodes[i].fixedValue < 0) {                bool printStuff = false;                for (int a = 0; a < message.dim(); a++) {                    if (outgoing[a]/message[a] > 1.1                            || message[a]/outgoing[a] > 1.1) {                        printStuff = true;                    }                }                if (printStuff) {                    for (int a = 0; a < numNeighbors; a++) {                        cout << "Forward " << a << ": "                             << forwardDistribs[a] << endl;                    }                    for (int a = 0; a < numNeighbors; a++) {                        cout << "Reverse " << a << ": "                             << reverseDistribs[a] << endl;                    }                    cout << "Old: " << outgoing << endl;                    cout << "New: " << message << endl;                    cout << "Marginal: " << marginal << endl;                    cout << "Index: " << index << endl;                     cout << "Num neighbors: " << numNeighbors << endl;                }            }            //  HACK            message = outgoing;#endif        }        // Compare to previous marginal at this node         // and store the new one.        for (int x_i = 0; x_i < marginal.dim(); x_i++) {            double delta_x_i = marginal[x_i]/nodes[i].marginal[x_i];            if (delta_x_i < 1.0) {                delta_x_i = 1.0/delta_x_i;            }            if (delta < delta_x_i) {                delta = delta_x_i;            }        }        nodes[i].marginal = marginal;    }    return delta;}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
从欧美一区二区三区| 日韩欧美一区二区久久婷婷| 欧美片在线播放| 欧美成人乱码一区二区三区| 亚洲男同1069视频| 国产一区激情在线| 9191国产精品| 亚洲永久免费av| 一本一道久久a久久精品| 久久久久久久久免费| 免费在线一区观看| 欧美老女人在线| 亚洲最新在线观看| 91在线精品一区二区| 久久九九久久九九| 久久99精品久久久久久| 欧美精品xxxxbbbb| 亚洲成人午夜电影| 欧美丝袜自拍制服另类| 一区二区三区自拍| 91免费看视频| 一区二区三区中文在线观看| 99re这里只有精品6| 国产精品福利电影一区二区三区四区| 国产精品一二三四五| 久久久亚洲高清| 国产精品一级片在线观看| 精品日韩在线一区| 久久99国产精品久久| 日韩一区二区免费在线观看| 日本美女一区二区| 日韩一级片在线观看| 狠狠色丁香久久婷婷综| 欧美mv日韩mv国产| 国产激情视频一区二区在线观看 | 91麻豆国产在线观看| 国产精品美女久久久久aⅴ国产馆| 国产**成人网毛片九色| 国产精品久久久久三级| 91久久香蕉国产日韩欧美9色| 亚洲免费在线看| 91福利在线看| 丝袜诱惑制服诱惑色一区在线观看| 69av一区二区三区| 久久国产欧美日韩精品| 久久色成人在线| 成人毛片老司机大片| 亚洲美女电影在线| 91精品国产综合久久精品图片| 日韩精品国产精品| 国产日产欧美精品一区二区三区| 成人午夜在线播放| 亚洲男人的天堂在线观看| 91国产视频在线观看| 日本va欧美va精品发布| 欧美国产一区二区在线观看| 91亚洲男人天堂| 日日摸夜夜添夜夜添国产精品 | 日本一区二区三区在线不卡| 成人av综合一区| 日韩电影一区二区三区| 精品国产免费人成电影在线观看四季| 国产91丝袜在线播放| 亚洲6080在线| 国产精品色噜噜| 欧美理论电影在线| 不卡电影一区二区三区| 亚洲成人手机在线| 国产精品色婷婷| 日韩视频一区在线观看| 国产91富婆露脸刺激对白| 五月婷婷综合激情| 亚洲欧洲日韩在线| 欧美大片一区二区三区| 99精品欧美一区| 蜜桃91丨九色丨蝌蚪91桃色| 亚洲人成网站精品片在线观看| 精品国产亚洲一区二区三区在线观看| a级高清视频欧美日韩| 免费成人在线观看视频| 亚洲天堂精品在线观看| 久久精品欧美一区二区三区麻豆 | 久久久美女艺术照精彩视频福利播放| 成人av网站免费| 国产真实精品久久二三区| 亚洲综合色在线| 亚洲欧美在线视频| 国产清纯在线一区二区www| 91精品国产欧美日韩| 国产一区二区导航在线播放| 欧美一区二区三区免费视频| 99国产精品99久久久久久| 国产精品一区三区| 美国三级日本三级久久99| 老司机一区二区| 日本丰满少妇一区二区三区| 不卡一区中文字幕| 国产一区二区精品久久| 激情综合五月天| 日本不卡高清视频| 日韩av在线免费观看不卡| 亚洲精品伦理在线| 亚洲日本一区二区三区| 亚洲欧洲日本在线| 国产精品久久久久久久久免费相片 | 蜜臀av一区二区三区| 亚洲国产综合91精品麻豆| 一区免费观看视频| 国产精品国产三级国产| 国产精品久久久久婷婷二区次| 国产目拍亚洲精品99久久精品 | 欧美大片在线观看| 日韩欧美一区电影| 日韩免费看的电影| 精品av久久707| 久久精品亚洲麻豆av一区二区| 久久综合视频网| 欧美国产欧美亚州国产日韩mv天天看完整| 久久众筹精品私拍模特| 国产日产欧美一区二区视频| 国产午夜亚洲精品午夜鲁丝片| 国产精品污污网站在线观看| 中文字幕一区二区5566日韩| 亚洲精品中文字幕乱码三区| 亚洲高清视频的网址| 三级亚洲高清视频| 极品少妇一区二区| 成人在线视频一区| 91福利精品视频| 欧美一区二区免费| 日本一区二区高清| 一区二区三区在线视频免费| 亚洲成a人v欧美综合天堂下载| 日韩激情av在线| 国产尤物一区二区在线| 成人免费高清视频| 欧美日韩精品欧美日韩精品一综合| 欧美日本一道本| 久久精品亚洲精品国产欧美kt∨| 国产精品丝袜久久久久久app| 日韩美女视频一区二区| 亚洲第一久久影院| 国产一区二区三区视频在线播放| 高清国产一区二区| 欧美狂野另类xxxxoooo| 久久久噜噜噜久久人人看| 亚洲人精品一区| 九九精品一区二区| 色屁屁一区二区| 久久这里都是精品| 亚洲一区在线观看免费观看电影高清 | 亚洲成人先锋电影| 国产精品一区二区三区乱码 | 丁香桃色午夜亚洲一区二区三区| 91色.com| 久久影院视频免费| 亚洲国产欧美另类丝袜| 成人午夜私人影院| 欧美一区二区三区四区在线观看| 国产精品女同互慰在线看| 婷婷开心激情综合| 97久久超碰国产精品电影| 91精品婷婷国产综合久久性色| 国产精品看片你懂得| 青娱乐精品视频| 在线国产亚洲欧美| 欧美激情中文不卡| 蜜臀av性久久久久蜜臀aⅴ| 91欧美激情一区二区三区成人| 26uuu亚洲| 污片在线观看一区二区| 91首页免费视频| 国产精品免费av| 国产一区二区三区免费看| 欧美一区二区二区| 亚洲v精品v日韩v欧美v专区| youjizz久久| 久久精品欧美一区二区三区不卡 | 久久99国产精品免费网站| 欧美三级资源在线| 亚洲欧美日韩国产中文在线| 国产99精品在线观看| 久久噜噜亚洲综合| 久久97超碰色| 精品国产一二三区| 精品中文字幕一区二区小辣椒 | 精品一区二区三区免费| 欧美精品在线一区二区三区| 亚洲精品高清在线观看| 成人va在线观看| 1区2区3区欧美| 成人av电影在线播放| 欧美国产国产综合| 丁香天五香天堂综合| 国产精品婷婷午夜在线观看| 成人午夜av电影| 亚洲精品中文在线影院| 在线看不卡av| 三级久久三级久久| 91精品久久久久久久久99蜜臂 |