1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Calculating Entropy of a file and coding it using Hamming

Discussion in 'C' started by kordellas, Jun 19, 2009.

  1. kordellas

    kordellas New Member

    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 :) )

    So, my problem is that I am not able to merge those two parts below (you don't 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"
    #include "Buffer.h"
    #include "Vector.h"
    #include <strstream>
    #include <math.h>
    #ifdef HAVE_VALUES_H
    #include <values.h>
    #ifdef HAVE_FLOAT_H
    #include <float.h>
    class Entropy;
     * @name Entropy
     * @category DSP:Misc
     * @description Calculates the entropy of a vector
     * @input_name INPUT
     * @input_type Vector<float>
     * @input_description Input vector
     * @output_name OUTPUT
     * @output_type Vector<float>
     * @output_description Entropy value (vector of 1)
    class Entropy : public BufferedNode {
       int inputID;
       int outputID;
       Entropy(string nodeName, ParameterSet params)
          : BufferedNode(nodeName, params)
          inputID = addInput("INPUT");
          outputID = addOutput("OUTPUT");
       void calculate(int output_id, int count, Buffer &out)
          ObjectRef inputValue = getInput(inputID, count);
          const Vector<float> &in = object_cast<Vector<float> > (inputValue);
          int inputLength = in.size();
          Vector<float> &output = *Vector<float>::alloc(1);
          out[count] = &output;
          float s2=0;
          float entr=0;
          for (int i=0;i<inputLength;i++)
          s2 = 1/s2;
          for (int i=0;i<inputLength;i++)
    	 if (in[i] != 0)
    	    entr -= s2*in[i]*in[i] * log(s2*in[i]*in[i]);
          //cout << entr << endl;
          output[0] = entr;
    Hamming Coding

    void hanming()   
    int i,n,k=2;   
    int h[20];   
    cout<<"bla bla"<<endl; cin="">>n;   
    while(pow(2,k)<n+k+1)k++; cout=""><<"bla bla"<<endl; for(i="1;i<=n+k;i++){" if(i!="1&&i!=2&&i!=4&&i!=8)cin">>h[i];   
    for(i=1;i<=n+k;i++)cout<<h[i]; jiaoyan(int="" a[],int="" n)="" {="" i,p1,p2,p4,p8,m;="" int="" h[20];="" for(i="0;i<n;i++)h
    [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){">=5&&n<=7){   
    // k=3;   
    return m;   
    return m;   
    cout<<"bla bla"<<endl; return="" -1;="" }="" ����="" void="" main()="" {="" hanming();="" coco;="" int="" i,n,m,h[20];="" 
    cout=""><<endl; cout=""><<"bla bla"<<endl; cin="">>n;   
    cout<<"bla bla"<<endl; for(i="0;i<n;i++)cin">>h[i];   
    if(m==0)cout<<"bla bla"<<endl; if(m!="0)cout<<"bla bla"<<m;" cout=""><<endl; cin="">>coco;   
    Last edited by a moderator: Jun 19, 2009
  2. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Your hamming code looks like an IOCCC entry ! :rofl:
    And it's probably not copied properly. Look :

    Anyway, you can use extern to use functions from another file. So you can just call the hamming function after executing the entropy calculation.
  3. xpi0t0s

    xpi0t0s Mentor

    Where is the main function?

    I agree with Saswat - how can this be your code? You cannot possibly have written code like that if you haven't got a clue how to "merge" it or even to explain what you mean by that.

    Out of interest I tried Googling "hamming jiaoyan" and it seems you've been busy posting this on lots of different forums with exactly the same response at each: what are you talking about, and in each case you failed to clarify.

Share This Page