Click here to Skip to main content
15,892,768 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Code for finding eigenvectors and eigenvalues Pin
Member 1483497917-May-20 4:02
Member 1483497917-May-20 4:02 
QuestionModeless dialog hangs up Pin
bhanu_850919-Jun-09 0:35
bhanu_850919-Jun-09 0:35 
AnswerRe: Modeless dialog hangs up Pin
Jijo.Raj19-Jun-09 0:49
Jijo.Raj19-Jun-09 0:49 
AnswerRe: Modeless dialog hangs up Pin
Michael Schubert19-Jun-09 0:51
Michael Schubert19-Jun-09 0:51 
AnswerRe: Modeless dialog hangs up Pin
Luc Pattyn19-Jun-09 0:59
sitebuilderLuc Pattyn19-Jun-09 0:59 
GeneralRe: Modeless dialog hangs up Pin
bhanu_850919-Jun-09 1:26
bhanu_850919-Jun-09 1:26 
GeneralRe: Modeless dialog hangs up Pin
Michael Schubert19-Jun-09 1:48
Michael Schubert19-Jun-09 1:48 
QuestionCalculating Entropy of a file and coding it using Hamming Pin
kordellas18-Jun-09 23:44
kordellas18-Jun-09 23:44 
Hello there!

I am trying to solve a problem for a project i took and i am in the final

part of it...(view below for my until now code)

Well the aim is to calculate the entropy of a file and then to use

Hamming to code it. I managed to make both parts based on what I learned

from the class and read in the book. (Please if you are familiar with the

object tell me if it is correct Smile | :) )

So, my problem is that I am not able to merge those two parts below (you

dont need to read the theory for it).. like finding the entropy and then

continue for the coding of that file.

Any help, advice, anything is appreciate.
Thank you!

Entropy Calculation

#include "BufferedNode.h"<br />
#include "Buffer.h"<br />
#include "Vector.h"<br />
#include <strstream><br />
#include <math.h><br />
<br />
#ifdef HAVE_VALUES_H<br />
#include <values.h><br />
#endif<br />
<br />
#ifdef HAVE_FLOAT_H<br />
#include <float.h><br />
#endif<br />
<br />
class Entropy;<br />
<br />
DECLARE_NODE(Entropy)<br />
/*Node<br />
 *<br />
 * @name Entropy<br />
 * @category DSP:Misc<br />
 * @description Calculates the entropy of a vector<br />
 *<br />
 * @input_name INPUT<br />
 * @input_type Vector<float><br />
 * @input_description Input vector<br />
 *<br />
 * @output_name OUTPUT<br />
 * @output_type Vector<float><br />
 * @output_description Entropy value (vector of 1)<br />
 *<br />
END*/<br />
<br />
<br />
class Entropy : public BufferedNode {<br />
   <br />
   int inputID;<br />
   int outputID;<br />
<br />
public:<br />
   Entropy(string nodeName, ParameterSet params)<br />
      : BufferedNode(nodeName, params)<br />
<br />
   {<br />
      inputID = addInput("INPUT");<br />
      outputID = addOutput("OUTPUT");<br />
   }<br />
<br />
   void calculate(int output_id, int count, Buffer &out)<br />
   {<br />
      ObjectRef inputValue = getInput(inputID, count);<br />
<br />
      const Vector<float> &in = object_cast<Vector<float> > (inputValue);<br />
      int inputLength = in.size();<br />
<br />
      Vector<float> &output = *Vector<float>::alloc(1);<br />
      out[count] = &output;<br />
<br />
      float s2=0;<br />
      float entr=0;<br />
      for (int i=0;i<inputLength;i++)<br />
      {<br />
         s2+=in[i]*in[i];<br />
      }<br />
      s2 = 1/s2;<br />
<br />
      for (int i=0;i<inputLength;i++)<br />
      {<br />
	 if (in[i] != 0)<br />
	    entr -= s2*in[i]*in[i] * log(s2*in[i]*in[i]);<br />
      }<br />
      //cout << entr << endl;<br />
      output[0] = entr;<br />
   }<br />
<br />
};<br />


Hamming Coding

<br />
&lt;code&gt;#include&lt;iostream.h&gt;   <br />
#include&lt;math.h&gt;   <br />
void hanming()   <br />
{   <br />
int i,n,k=2;   <br />
int h[20];   <br />
for(i=0;i&lt;20;i++)h[i]=0;   <br />
cout&lt;&lt;"bla bla"&lt;&lt;endl; cin=""&gt;&gt;n;   <br />
while(pow(2,k)&lt;n+k+1)k++; cout=""&gt;&lt;&lt;"bla bla"&lt;&lt;endl; for(i="1;i&lt;=n+k;i++){" if(i!="1&amp;&amp;i!=2&amp;&amp;i!=4&amp;&amp;i!=8)cin"&gt;&gt;h[i];   <br />
}   <br />
h[1]=(h[3]+h[5]+h[7]+h[9]+h[11]+h[13]+h[15])%2;   <br />
h[2]=(h[3]+h[6]+h[7]+h[10]+h[11]+h[14]+h[15])%2;   <br />
h[4]=(h[5]+h[6]+h[7]+h[12]+h[13]+h[14]+h[15])%2;   <br />
h[8]=(h[9]+h[10]+h[11]+h[12]+h[13]+h[14]+h[15])%2;   <br />
for(i=1;i&lt;=n+k;i++)cout&lt;&lt;h[i]; jiaoyan(int="" a[],int="" n)="" {="" i,p1,p2,p4,p8,m;="" int="" h[20];="" for(i="0;i&lt;n;i++)h<br />
<br />
[i+1]=a[i];" k="2;" p1="(h[1]+h[3])%2;" p2="(h[2]+h[3])%2;" m="2*p2+p1;" return="" m;="" }="" if(n="=3){"&gt;=5&amp;&amp;n&lt;=7){   <br />
// k=3;   <br />
p1=(h[1]+h[3]+h[5]+h[7])%2;   <br />
p2=(h[2]+h[3]+h[6]+h[7])%2;   <br />
p4=(h[4]+h[5]+h[6]+h[7])%2;   <br />
m=4*p4+2*p2+p1;   <br />
return m;   <br />
}   <br />
if(n&gt;=9&amp;&amp;n&lt;=15){   <br />
//k=4;   <br />
p1=(h[1]+h[3]+h[5]+h[7]+h[9]+h[11]+h[13]+h[15])%2;   <br />
p2=(h[2]+h[3]+h[6]+h[7]+h[10]+h[11]+h[14]+h[15])%2;   <br />
p4=(h[4]+h[5]+h[6]+h[7]+h[12]+h[13]+h[14]+h[15])%2;   <br />
p8=(h[8]+h[9]+h[10]+h[11]+h[12]+h[13]+h[14]+h[15])%2;   <br />
m=8*p8+4*p4+2*p2+p1;   <br />
return m;   <br />
}   <br />
else{   <br />
cout&lt;&lt;"bla bla"&lt;&lt;endl; return="" -1;="" }="" ����="" void="" main()="" {="" hanming();="" coco;="" int="" i,n,m,h[20];="" <br />
<br />
cout=""&gt;&lt;&lt;endl; cout=""&gt;&lt;&lt;"bla bla"&lt;&lt;endl; cin=""&gt;&gt;n;   <br />
cout&lt;&lt;"bla bla"&lt;&lt;endl; for(i="0;i&lt;n;i++)cin"&gt;&gt;h[i];   <br />
m=jiaoyan(h,n);   <br />
if(m==0)cout&lt;&lt;"bla bla"&lt;&lt;endl; if(m!="0)cout&lt;&lt;"bla bla"&lt;&lt;m;" cout=""&gt;&lt;&lt;endl; cin=""&gt;&gt;coco;   <br />
}

QuestionRe: Calculating Entropy of a file and coding it using Hamming Pin
David Crow19-Jun-09 2:59
David Crow19-Jun-09 2:59 
GeneralRe: Calculating Entropy of a file and coding it using Hamming Pin
norish19-Jun-09 6:13
norish19-Jun-09 6:13 
QuestionProblem with CImage Pin
Dylan Liu18-Jun-09 23:41
Dylan Liu18-Jun-09 23:41 
AnswerRe: Problem with CImage Pin
Stuart Dootson19-Jun-09 2:17
professionalStuart Dootson19-Jun-09 2:17 
Questionprogram in c to convert a Portable graymap(PGM) file into portable bitmap file(PBM) Pin
singh.vikas850818-Jun-09 21:14
singh.vikas850818-Jun-09 21:14 
QuestionRe: program in c to convert a Portable graymap(PGM) file into portable bitmap file(PBM) Pin
CPallini18-Jun-09 21:30
mveCPallini18-Jun-09 21:30 
AnswerRe: program in c to convert a Portable graymap(PGM) file into portable bitmap file(PBM) Pin
singh.vikas850818-Jun-09 21:36
singh.vikas850818-Jun-09 21:36 
GeneralRe: program in c to convert a Portable graymap(PGM) file into portable bitmap file(PBM) Pin
CPallini18-Jun-09 21:46
mveCPallini18-Jun-09 21:46 
GeneralRe: program in c to convert a Portable graymap(PGM) file into portable bitmap file(PBM) Pin
singh.vikas850818-Jun-09 21:49
singh.vikas850818-Jun-09 21:49 
GeneralRe: program in c to convert a Portable graymap(PGM) file into portable bitmap file(PBM) Pin
Cedric Moonen18-Jun-09 21:58
Cedric Moonen18-Jun-09 21:58 
GeneralRe: program in c to convert a Portable graymap(PGM) file into portable bitmap file(PBM) Pin
singh.vikas850818-Jun-09 22:08
singh.vikas850818-Jun-09 22:08 
GeneralRe: program in c to convert a Portable graymap(PGM) file into portable bitmap file(PBM) Pin
Cedric Moonen18-Jun-09 22:11
Cedric Moonen18-Jun-09 22:11 
General[Message Deleted] Pin
singh.vikas850818-Jun-09 22:22
singh.vikas850818-Jun-09 22:22 
QuestionRe: program in c to convert a Portable graymap(PGM) file into portable bitmap file(PBM) Pin
CPallini18-Jun-09 22:58
mveCPallini18-Jun-09 22:58 
Answer[Message Deleted] Pin
singh.vikas850818-Jun-09 23:06
singh.vikas850818-Jun-09 23:06 
GeneralRe: program in c to convert a Portable graymap(PGM) file into portable bitmap file(PBM) Pin
chandu00418-Jun-09 23:12
chandu00418-Jun-09 23:12 
General[Message Deleted] Pin
singh.vikas850818-Jun-09 23:15
singh.vikas850818-Jun-09 23:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.