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

📄 vector.c

📁 一个通用的隐性马尔可夫C代码库 开发环境:C语言 简要说明:这是一个通用的隐性马尔可夫C代码库
💻 C
字号:
/*******************************************************************************  author       : Bernhard Knab  filename     : ghmm/ghmm/vector.c  created      : TIME: 17:48:29     DATE: Thu 18. February 1999  $Id: vector.c,v 1.4 2001/06/27 15:43:53 disa Exp $Copyright (C) 1998-2001, ZAIK/ZPR, Universit鋞 zu K鰈nThis program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*******************************************************************************/#include <float.h>#include <stdio.h>#include "mes.h"#include "vector.h"#include "rng.h"/*============================================================================*//* Scales the elements of a vector to have the sum 1 *//* PROBLEM: Entries can get very small and be rounded to 0 */int vector_normalize(double *v, int len) {#define CUR_PROC "vector_normalize"  int i;  double sum = 0.0;  for (i = 0; i < len; i++)    sum += v[i];  if (sum < DBL_MIN) {    mes_prot("Can't normalize vector. Sum eq. zero \n");    return (-1);  }  for (i = 0; i < len; i++)    v[i] /= sum;  return 0;#undef CUR_PROC} /* vector_normalize *//*============================================================================*/void vector_const_values(double *v, int len, double c) {  int i;  for (i = 0; i < len; i++)    v[i] = c;} /* vector_const_values *//*============================================================================*/void vector_const_preserve_struct(double *v, int len, double c) {  int i;  for (i = 0; i < len; i++) {    if (v[i] != 0.0)      v[i] = c;  }} /* vector_const_preserve_struct *//*============================================================================*/void vector_random_values(double *v, int len) {  int i;  for (i = 0; i < len; i++)    v[i] = gsl_rng_uniform(RNG);} /* vector_random_values *//*============================================================================*/void vector_random_preserve_struct(double *v, int len) {  int i;  for (i = 0; i < len; i++) {    if (v[i] != 0.0)      v[i] = gsl_rng_uniform(RNG);  }} /* vector_random_preserve_struct *//*============================================================================*/void vector_d_print(FILE *file, double *vector, int len, 		    char *tab, char *separator, char *ending) {  int j;    fprintf(file, "%s", tab);  if (len > 0)    fprintf(file, "%6.2f", vector[0]);  for (j = 1; j < len; j++)     fprintf(file, "%s %6.2f", separator, vector[j]);  fprintf(file, "%s\n", ending);} /* vector_d_print *//*============================================================================*/void vector_d_print_prec(FILE *file, double *vector, int len, int width, 			 int prec, char *tab, char *separator, char *ending) {  int j;  if (len > 0) fprintf(file, "%s%*.*f", tab, width, prec, vector[0]);  for (j = 1; j < len; j++)     fprintf(file, "%s %*.*f", separator, width, prec, vector[j]);  fprintf(file, "%s\n", ending);} /* vector_d_print *//*============================================================================*/void vector_i_print(FILE *file, int *vector, int len,		    char *tab, char *separator, char *ending) {  int j;  fprintf(file, "%s", tab);  if (len > 0)    fprintf(file, "%3d", vector[0]);  for (j = 1; j < len; j++)    fprintf(file, "%s %3d", separator, vector[j]);  fprintf(file, "%s\n", ending);} /* vector_i_print *//*============================================================================*/int vector_mat_times_vec(double **A, double *x, int n, int m, double *v) {#define CUR_PROC "vector_mat_times_vec"  int i, j;  for (i = 0; i < n; i++){    v[i] = 0.0;    for (j = 0; j < m; j++)      v[i] += A[i][j]*x[j];  }  return 0;#undef CUR_PROC} /* vector_mat_times_vec */

⌨️ 快捷键说明

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