Main Page   Compound List   File List   Compound Members   File Members  

two_byte_alphas.c

Go to the documentation of this file.
00001 
00002 /*=====================================================================
00003                 =======   COPYRIGHT NOTICE   =======
00004 Copyright (C) 1996, Carnegie Mellon University, Cambridge University,
00005 Ronald Rosenfeld and Philip Clarkson.
00006 
00007 All rights reserved.
00008 
00009 This software is made available for research purposes only.  It may be
00010 redistributed freely for this purpose, in full or in part, provided
00011 that this entire copyright notice is included on any copies of this
00012 software and applications and derivations thereof.
00013 
00014 This software is provided on an "as is" basis, without warranty of any
00015 kind, either expressed or implied, as to any matter including, but not
00016 limited to warranty of fitness of purpose, or merchantability, or
00017 results obtained from use of this software.
00018 ======================================================================*/
00019 
00020 
00043 #include <math.h>
00044 #include "ngram.h"
00045 
00046 unsigned short short_alpha(double long_alpha,
00047                            double *alpha_array,
00048                            unsigned short *size_of_alpha_array,
00049                            int elements_in_range,
00050                            double min_range,
00051                            double max_range) {
00052 
00053   double log_10_alpha;
00054   unsigned short short_version;
00055 
00056   if (long_alpha > 0.0) {
00057     log_10_alpha = log10(long_alpha);
00058   }
00059   else {
00060     log_10_alpha = -99.999;
00061   }
00062 
00063   if (log_10_alpha >= min_range && log_10_alpha <= max_range) {
00064     
00065     short_version = (unsigned short) (elements_in_range * 
00066                                       (log_10_alpha - min_range) / 
00067                                       (max_range - min_range));
00068 
00069   }
00070 
00071   else {
00072 
00073     int i;
00074 
00075     for (i=0;i<=(*size_of_alpha_array)-1;i++) {
00076       if (alpha_array[i] == log_10_alpha) {
00077         return(elements_in_range + i);
00078       }
00079     }
00080 
00081     if ((elements_in_range + *size_of_alpha_array) >= 65535) {
00082       quit(-1,"Error : Number of out-of-range alphas exceeds %d. Rerun with a bigger \nrange (use the -min_alpha and -max_alpha options), or a higher number of \nallowed out of range alphas (use the -out_of_range_alphas options).\n",65535-elements_in_range);
00083     }
00084     
00085     alpha_array[*size_of_alpha_array] = log_10_alpha;
00086     (*size_of_alpha_array)++;
00087     short_version = elements_in_range + (*size_of_alpha_array);
00088     
00089   }
00090   
00091   return(short_version);
00092 
00093 }
00094 
00095 double double_alpha(unsigned short short_alpha,
00096                     double *alpha_array,
00097                     int size_of_alpha_array,
00098                     int elements_in_range,
00099                     double min_range,
00100                     double max_range) {
00101   
00102   /* Returns the actual (ie NOT log) value of the alpha */
00103 
00104   double log_10_alpha;
00105 
00106   if (short_alpha > (elements_in_range + size_of_alpha_array)) {
00107     quit(-1,"Error : two-byte alpha value is out of range. short alpha = %d\n",short_alpha);
00108   }
00109 
00110   if (short_alpha > elements_in_range) {
00111     log_10_alpha = alpha_array[short_alpha-elements_in_range];
00112   }
00113   else {
00114     log_10_alpha = min_range + (short_alpha * (max_range - min_range)/ elements_in_range);
00115   }
00116 
00117   return(pow(10.0,log_10_alpha));
00118 
00119 }

Generated on Tue Dec 21 13:54:46 2004 by doxygen1.2.18