<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Samplen aus Wkt.-Vektor]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe eine Frage und leider habe ich mal wieder bei google nicht ganz das gefunden, was ich brauche. Ich habe einen Vektor mit (logarithmierten) Wahrscheinlichkeiten, die sich auf 1 addieren. Nun würde ich gerne den Index i der Komponente des Vektors samplen analog zu der Wkt-Verteilung.</p>
<p>Also kurz gefasst:<br />
Vector: {0.3, 0.1, 0.1, 0.1, 0.2, 0.2}<br />
Bsp-Sample-Ergebnis: 1</p>
<p>Bis jetzt habe ich das naive selbst implementiert. Da ich aber mit logarithmierten Werten rechnen muss, hoffe ich, dass es eine effektivere vorimplementierte Variante gibt.</p>
<p>vielen Dank.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/316933/samplen-aus-wkt-vektor</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Jul 2026 13:44:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/316933.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 21 May 2013 16:24:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Samplen aus Wkt.-Vektor on Tue, 21 May 2013 16:24:01 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe eine Frage und leider habe ich mal wieder bei google nicht ganz das gefunden, was ich brauche. Ich habe einen Vektor mit (logarithmierten) Wahrscheinlichkeiten, die sich auf 1 addieren. Nun würde ich gerne den Index i der Komponente des Vektors samplen analog zu der Wkt-Verteilung.</p>
<p>Also kurz gefasst:<br />
Vector: {0.3, 0.1, 0.1, 0.1, 0.2, 0.2}<br />
Bsp-Sample-Ergebnis: 1</p>
<p>Bis jetzt habe ich das naive selbst implementiert. Da ich aber mit logarithmierten Werten rechnen muss, hoffe ich, dass es eine effektivere vorimplementierte Variante gibt.</p>
<p>vielen Dank.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325044</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325044</guid><dc:creator><![CDATA[ComputerCarl]]></dc:creator><pubDate>Tue, 21 May 2013 16:24:01 GMT</pubDate></item><item><title><![CDATA[Reply to Samplen aus Wkt.-Vektor on Tue, 21 May 2013 16:38:03 GMT]]></title><description><![CDATA[<p>Könntest du mal erklären, was Sampling in diesem Kontext bedeutet?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325048</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325048</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Tue, 21 May 2013 16:38:03 GMT</pubDate></item><item><title><![CDATA[Reply to Samplen aus Wkt.-Vektor on Tue, 21 May 2013 16:42:57 GMT]]></title><description><![CDATA[<p><a href="http://en.cppreference.com/w/cpp/numeric/random/discrete_distribution" rel="nofollow">http://en.cppreference.com/w/cpp/numeric/random/discrete_distribution</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325051</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325051</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 21 May 2013 16:42:57 GMT</pubDate></item><item><title><![CDATA[Reply to Samplen aus Wkt.-Vektor on Tue, 21 May 2013 16:45:48 GMT]]></title><description><![CDATA[<p>O.k. Ich versuch mein Bestes:</p>
<p>Also ich mache eine Motif-Suche in DNA-Sequenzen. Jede Sequenz hat eine Länge L. Der Vector mit den Wahrscheinlichkeiten gibt zu jeder Position in der Sequenz die Wkt. an, dass das Motifes an der jeweiligen Position vorkommt.</p>
<p>Vector {0.3, 0.1, 0.1, 0.1, 0.2, 0.2}<br />
-&gt; Motif an Position 1 hat Wkt. 0.3, an Position 2 Wkt 0.1 usw.</p>
<p>Diese Motif-Suche ist in ein Gibbs-Sampler eingebaut. Das Samplen der Start-Positionen ist also notwendig. Das Samplen in diesem Zusammenhang bedeutet, das Zeihen einer Startposition aus der jeweiligen diskreten Verteilung, die von dem Vektor repräsentiert wird.</p>
<p>Ich hoffe, das war verständlich. Bin leider nicht allzu gut im erklären.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325052</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325052</guid><dc:creator><![CDATA[ComputerCarl]]></dc:creator><pubDate>Tue, 21 May 2013 16:45:48 GMT</pubDate></item><item><title><![CDATA[Reply to Samplen aus Wkt.-Vektor on Tue, 21 May 2013 16:52:18 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p><a href="http://en.cppreference.com/w/cpp/numeric/random/discrete_distribution" rel="nofollow">http://en.cppreference.com/w/cpp/numeric/random/discrete_distribution</a></p>
</blockquote>
<p>Ich danke für den Beitrag, nur kommt beim Ausführen des Bsp.-Codes ein Runtime-Error. what(): random_device::random_device(const std::string&amp;)<br />
Ich benutze MinGW und weiss leider nicht wo der Fehler liegt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325054</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325054</guid><dc:creator><![CDATA[ComputerCarl]]></dc:creator><pubDate>Tue, 21 May 2013 16:52:18 GMT</pubDate></item><item><title><![CDATA[Reply to Samplen aus Wkt.-Vektor on Tue, 21 May 2013 16:53:42 GMT]]></title><description><![CDATA[<p>Zeig mal Code.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325055</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325055</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Tue, 21 May 2013 16:53:42 GMT</pubDate></item><item><title><![CDATA[Reply to Samplen aus Wkt.-Vektor on Tue, 21 May 2013 17:05:30 GMT]]></title><description><![CDATA[<p>ComputerCarl schrieb:</p>
<blockquote>
<p>SeppJ schrieb:</p>
<blockquote>
<p><a href="http://en.cppreference.com/w/cpp/numeric/random/discrete_distribution" rel="nofollow">http://en.cppreference.com/w/cpp/numeric/random/discrete_distribution</a></p>
</blockquote>
<p>Ich danke für den Beitrag, nur kommt beim Ausführen des Bsp.-Codes ein Runtime-Error. what(): random_device::random_device(const std::string&amp;)<br />
Ich benutze MinGW und weiss leider nicht wo der Fehler liegt.</p>
</blockquote>
<p>Fehler in MinGW:<br />
<a href="http://stackoverflow.com/questions/15725677/c0x-random-device-with-stdruntime-error" rel="nofollow">http://stackoverflow.com/questions/15725677/c0x-random-device-with-stdruntime-error</a><br />
<a href="http://stackoverflow.com/questions/12351062/threads-in-g/12351142#12351142" rel="nofollow">http://stackoverflow.com/questions/12351062/threads-in-g/12351142#12351142</a><br />
Also einfachster Fix für dich wäre, einen der anderen Generatoren der Standardbibliothek zu benutzen. Für wissenschaftliches Rechnen möchtest du wahrscheinlich ohnehin einen Generator mit standardisierter Implementierung, nicht das std::random_device, welches einfach ein anderer Name für den Standardzufallsgenerators des Systems ist (was dann wer weiß was für ein Generator sein kann).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325056</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325056</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 21 May 2013 17:05:30 GMT</pubDate></item><item><title><![CDATA[Reply to Samplen aus Wkt.-Vektor on Tue, 21 May 2013 17:11:17 GMT]]></title><description><![CDATA[<p>Nathan schrieb:</p>
<blockquote>
<p>Zeig mal Code.</p>
</blockquote>
<p>Also hier das Samplen in meiner Implementierung. Ich hab es schnell auf das nötigste reduziert, damit es leichter zu lesen ist:</p>
<pre><code>// Funktion zum Bestimmen der Summe von logarithmierten Werten
double log_of_sums(vector&lt;double&gt; &amp;summands, unsigned short summands_size) {
    double res = 0;
    double find_max = -1 * numeric_limits&lt;double&gt;::max();

    for(int i = 0; i &lt; summands_size; i++) {
          if(find_max &lt; summands[i])
          find_max = summands[i];
    }

    for(unsigned short i = 0; i &lt; summands_size; i++) {
          res += exp(summands[i] - find_max);
    }

    return log(res) + find_max;
}

// das Samplen (auf das noetigste reduziert)
tmp_sum;				         // &lt;- Vektor mit Wkt's.
double r = log((double) rand() / (RAND_MAX));

for(unsigned short u_i = 0; u_i &lt; tmp_sum.size(); u_i++ ) {
     if(u_i &gt; 0) {
            if(r &lt;= this-&gt;log_of_sums(tmp_sum, u_i))
                  this-&gt;start_pos[i] = u_i-1;
                  u_i = tmp_sum.size();
            }
     }
}
</code></pre>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/19375">@SeppJ</a>:<br />
Danke. Ich komme mir immer wieder wie ein totaler Anfänger vor, wenn ich höre wieviele Details es bei sowas zu beachten gibt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325061</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325061</guid><dc:creator><![CDATA[ComputerCarl]]></dc:creator><pubDate>Tue, 21 May 2013 17:11:17 GMT</pubDate></item><item><title><![CDATA[Reply to Samplen aus Wkt.-Vektor on Tue, 21 May 2013 17:15:11 GMT]]></title><description><![CDATA[<p>Eigentlich meinte ich den mit discrete_distribution, aber ist nun auch egal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325063</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325063</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Tue, 21 May 2013 17:15:11 GMT</pubDate></item><item><title><![CDATA[Reply to Samplen aus Wkt.-Vektor on Tue, 21 May 2013 17:16:17 GMT]]></title><description><![CDATA[<p>ComputerCarl schrieb:</p>
<blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/19375">@SeppJ</a>:<br />
Danke. Ich komme mir immer wieder wie ein totaler Anfänger vor, wenn ich höre wieviele Details es bei sowas zu beachten gibt.</p>
</blockquote>
<p>Du machst eine Bachelor-/Master-/Promotionsarbeit? Dann sieh es als Teil der Ausbildung an, solche Sachen zu lernen. Bei dieser Art Arbeit geht es schließlich genau darum, nicht so sehr um die Ergebnisse. Beim Bacheler natürlich mehr noch als bei der Promotion.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325064</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325064</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 21 May 2013 17:16:17 GMT</pubDate></item><item><title><![CDATA[Reply to Samplen aus Wkt.-Vektor on Tue, 21 May 2013 17:23:37 GMT]]></title><description><![CDATA[<p>ComputerCarl schrieb:</p>
<blockquote>
<p>SeppJ schrieb:</p>
<blockquote>
<p><a href="http://en.cppreference.com/w/cpp/numeric/random/discrete_distribution" rel="nofollow">http://en.cppreference.com/w/cpp/numeric/random/discrete_distribution</a></p>
</blockquote>
<p>Ich danke für den Beitrag, nur kommt beim Ausführen des Bsp.-Codes ein Runtime-Error. what(): random_device::random_device(const std::string&amp;)<br />
Ich benutze MinGW und weiss leider nicht wo der Fehler liegt.</p>
</blockquote>
<pre><code>std::random_device rd(&quot;mt19937&quot;);
</code></pre>
<p>Das sollte dann klappen. random_device's Konstruktor wirft eine Exception, wenn er den übergebenen String mit dem Namen für die Engine von der Implementierung nicht akzeptiert wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325065</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325065</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Tue, 21 May 2013 17:23:37 GMT</pubDate></item><item><title><![CDATA[Reply to Samplen aus Wkt.-Vektor on Tue, 21 May 2013 17:33:47 GMT]]></title><description><![CDATA[<p>Ändert bei mir leider nichts. Gleiche Fehlermeldung.<br />
Ich schau einfach mal weiter, was ich finde. Meine alternativ Implementierung funktioniert ja eigentlich ausreichend gut. Aber danke für die Hilfe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325068</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325068</guid><dc:creator><![CDATA[ComputerCarl]]></dc:creator><pubDate>Tue, 21 May 2013 17:33:47 GMT</pubDate></item><item><title><![CDATA[Reply to Samplen aus Wkt.-Vektor on Tue, 21 May 2013 17:46:58 GMT]]></title><description><![CDATA[<p>ComputerCarl schrieb:</p>
<blockquote>
<p>Ändert bei mir leider nichts. Gleiche Fehlermeldung.<br />
Ich schau einfach mal weiter, was ich finde. Meine alternativ Implementierung funktioniert ja eigentlich ausreichend gut. Aber danke für die Hilfe.</p>
</blockquote>
<p>Probier mal genau diesen Quellcode (Copy&amp;Paste):</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;map&gt;
#include &lt;random&gt;

int main()
{
    std::mt19937 gen;
    std::discrete_distribution&lt;&gt; d({40, 10, 10, 40});
    std::map&lt;int, int&gt; m;
    for(int n=0; n&lt;10000; ++n) {
        ++m[d(gen)];
    }
    for(auto p : m) {
        std::cout &lt;&lt; p.first &lt;&lt; &quot; generated &quot; &lt;&lt; p.second &lt;&lt; &quot; times\n&quot;;
    }
}
</code></pre>
<p>Der sollte, egal auf welchem Computer, die folgende Ausgabe erzeugen:</p>
<pre><code>0 generated 4026 times
1 generated 943 times
2 generated 1048 times
3 generated 3983 times
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2325071</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325071</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 21 May 2013 17:46:58 GMT</pubDate></item><item><title><![CDATA[Reply to Samplen aus Wkt.-Vektor on Tue, 21 May 2013 17:53:59 GMT]]></title><description><![CDATA[<p>Funktioniert mit genau der gleichen Ausgabe.<br />
Ich schau mal wie das für mein Bsp. funktioniert. Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2325073</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2325073</guid><dc:creator><![CDATA[ComputerCarl]]></dc:creator><pubDate>Tue, 21 May 2013 17:53:59 GMT</pubDate></item></channel></rss>