1 /* $Id: thrdalgs.c,v 1.1 2000/08/16 20:45:21 hurwitz Exp $
2 *===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * File Name: thrdalgs.c
27 *
28 * Author: Stephen Bryant
29 *
30 * Initial Version Creation Date: 08/16/2000
31 *
32 * $Revision: 1.1 $
33 *
34 * File Description: threader
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * $Log: thrdalgs.c,v $
39 * Revision 1.1 2000/08/16 20:45:21 hurwitz
40 * initial check in of threading routines
41 *
42 * ==========================================================================
43 */
44
45
46
47 /* Choose an aligment by Gibbs sampling */
48
49 #include <thrdatd.h>
50 #include <thrddecl.h>
51 #include <math.h>
52
algs(Rnd_Smp * pvl,int tm)53 int algs(Rnd_Smp* pvl, int tm) {
54 /*----------------------------------------------------------*/
55 /* pvl: Alignment-location parameter value probabilities */
56 /* tm: Temperature for Boltzmann sampling */
57 /*----------------------------------------------------------*/
58
59 int i; /* Counter */
60 float gm; /* Minimum energy value for scaling of exponents */
61 float g; /* Energy value */
62 float b,sb; /* Boltzmann factor and sum of Boltzmann factors */
63 float tf; /* Temperature */
64
65 /* printf("tm:%d\n",tm);
66 for(i=0; i<pvl->n; i++) printf("%.2f ",pvl->e[i]); printf("pvl->e\n"); */
67
68 tf=(float)tm;
69 /* printf("tf:%.2f\n",tf); */
70
71 /* Find minimum energy, equal to maximum score */
72 gm=pvl->e[0];
73 for(i=1;i<pvl->n;i++) {
74 g=pvl->e[i];
75 if(g>gm) gm=g; }
76 /* printf("gm:%.2f\n",gm); */
77
78 /* Subtract minimum energy, compute Boltzmann factors, and sum */
79 sb=0.; for(i=0;i<pvl->n;i++) {
80 g=pvl->e[i]-gm;
81 b=(float) exp(g/tf);
82 pvl->p[i]=b;
83 sb+=b;
84 /* printf("g:%.2f b:%.4f sb:%.4f\n",g,b,sb); */
85 }
86
87 /* Compute Boltzmann probabilities */
88 for(i=0; i<pvl->n; i++) pvl->p[i]=pvl->p[i]/sb;
89 /* for(i=0; i<pvl->n; i++) printf(".4f ",pvl->p[i]); printf("pvl->p\n"); */
90
91
92 /* Choose a state at random given this distribution */
93 return(rsmp(pvl));
94
95 }
96
97