~ubuntu-branches/ubuntu/karmic/python-scipy/karmic

« back to all changes in this revision

Viewing changes to Lib/cluster/src/vq.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T. Chen (new)
  • Date: 2005-03-16 02:15:29 UTC
  • Revision ID: james.westby@ubuntu.com-20050316021529-xrjlowsejs0cijig
Tags: upstream-0.3.2
ImportĀ upstreamĀ versionĀ 0.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef vq_h
 
2
#define vq_h
 
3
/*
 
4
//#define real  float 
 
5
//#define scan_format "%f"
 
6
 
 
7
#define real double
 
8
#define scan_format "%lf"
 
9
 
 
10
 
 
11
 
 
12
void vq_obs(real* obs,real* code_book, int Ncodes, int Nfeatures,
 
13
                           int& code, real& lowest_dist);
 
14
 
 
15
void vq(real* obs,real* code_book, int Nobs, int Ncodes, int Nfeatures,
 
16
            int* codes, real* lowest_dist);
 
17
*/
 
18
#define BIG 10000.
 
19
 
 
20
template<class T>
 
21
void tvq_obs(T* obs,T* code_book, int Ncodes, int Nfeatures,
 
22
                           int& code, T& lowest_dist)
 
23
{
 
24
        int i,j,k=0;
 
25
        T dist, diff;
 
26
 
 
27
        lowest_dist = (T) BIG;
 
28
        for(i=0; i < Ncodes; i++)
 
29
        {
 
30
                dist=0;
 
31
                for(j=0; j < Nfeatures; j++)
 
32
                {
 
33
                        diff = code_book[k] - obs[j];
 
34
                        dist += diff*diff;
 
35
                        k++;
 
36
                }
 
37
                dist = (T)sqrt(dist);
 
38
                if (dist < lowest_dist)
 
39
                {
 
40
                        code = i;
 
41
                        lowest_dist = dist;
 
42
                }
 
43
        }
 
44
}
 
45
 
 
46
template<class T>
 
47
void tvq(T* obs,T* code_book, int Nobs, int Ncodes, int Nfeatures,
 
48
            int* codes, T* lowest_dist)
 
49
{
 
50
    int i;
 
51
        for( i = 0; i < Nobs; i++)
 
52
        {               
 
53
                tvq_obs<T>(&(obs[i*Nfeatures]),code_book,Ncodes,Nfeatures,
 
54
                                  codes[i],lowest_dist[i]);
 
55
        }
 
56
}
 
57
#endif
 
 
b'\\ No newline at end of file'