⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mymath.cc

📁 贝叶斯优化算法是一种新的演化算法
💻 CC
字号:
// ################################################################################
//
// name:          mymath.cc
//
// author:        Martin Pelikan
//
// purpose:       commonly used mathematical functions
//
// last modified: February 1999
//
// ################################################################################

#include "mymath.h"
#include "memalloc.h"

// ---------------------------------------------------------
// an array consisting of precomputed cummulative logarithms
// ---------------------------------------------------------

double *precomputedCummulativeLogarithm;

// ================================================================================
//
// name:          getPrecomputedCummulativeLog
//
// function:      returns a precomputed cummulative logarithm (log(i)+...+log(j))
//
// parameters:    i............starting number
//                j............ending number
//  
// returns:       (float) sum_{k=i}^{k=j}{log(k)}
//
// ================================================================================

float getPrecomputedCummulativeLog(long i, long j)
{
  return (float) ((double) (precomputedCummulativeLogarithm[j]-precomputedCummulativeLogarithm[i-1]));
};

// ================================================================================
//
// name:          precomputeCummulativeLogarithms
//
// function:      allocates memory for and precomputes cummulative logarithm 
//                (log(1)+...+log(j)) for all j up to a specified number
//
// parameters:    n............maximal number of cummulative logarithm to 
//                             precompute
//  
// returns:       (int) 0
//
// ================================================================================

int precomputeCummulativeLogarithms(long n)
{
  long i;
  double sum;
  
  precomputedCummulativeLogarithm = (double*) Calloc(n+1,sizeof(double));
  sum = 0;
  precomputedCummulativeLogarithm[0]=0;
  
  for (i=1; i<=n; i++)
    {
      sum += log(i);
      precomputedCummulativeLogarithm[i] = sum;
    };

  return 0;
};

// ================================================================================
//
// name:          freePrecomputedCummulativeLogarithms
//
// function:      frees the memory used by the array of precomputed cummulative 
//                logarithms 
//
// parameters:    (none)
//  
// returns:       (int) 0
//
// ================================================================================

int freePrecomputedCummulativeLogarithms()
{
  Free(precomputedCummulativeLogarithm);

  return 0;
};

// ================================================================================
//
// name:          round
//
// function:      rounds a float
//
// parameters:    x............the input floating-point number
//  
// returns:       (long) integer closest to the input number
//
// ================================================================================

long round(float x)
{
  return (long) (x+0.5);
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -