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

📄 interface.cpp

📁 统计学习软件包
💻 CPP
字号:
#include "my_mat.h"#include <stdio.h>#include <math.h>#include <iostream.h>#include <fstream.h>#include "o8para.h"extern "C" void donlp2(void);extern "C" void setup(void);extern "C" void setup0(void);extern "C" void solchk(void); extern "C" void ef(DOUBLE x[],DOUBLE *fx); extern "C" void egradf(DOUBLE x[],DOUBLE gradf[]); extern "C" void eh(INTEGER i,DOUBLE x[],DOUBLE *hxi); extern "C" void egradh(INTEGER i,DOUBLE x[],DOUBLE gradhi[]); extern "C" void eg(INTEGER i,DOUBLE x[],DOUBLE *gxi); extern "C" void egradg(INTEGER i,DOUBLE x[],DOUBLE gradgi[]);extern "C" void eval_extern(INTEGER mode);My_Matrix* XMatGlobal;double* yVecGlobal;double* theta_global;double* resVecGlobal;double upperGlobal;double epsi_global;int n_Files_ges;int dim_global;double res_global[300];double *optimize_qp();void getCoeffnew(int nn, My_Matrix* XMatneu, double* Y,  double* resneu, double eps, int dim, double* theta); double *optimize_qp(){#define  X extern#include "o8comm.h"#undef   X  donlp2();  int i;  delete XMatGlobal;  delete [] yVecGlobal;  delete [] theta_global;  delete [] resVecGlobal;  for(i=0; i< dim_global; i++){      res_global[i] = x[i+1];  }  return(res_global);  } void getCoeffnew(int nn, My_Matrix* XMatneu, double* Y,  double* resneu, double eps, int dim, double* theta){   int i,j;  n_Files_ges = nn;   yVecGlobal = new double[nn];  for(i=0; i<nn; i++)      yVecGlobal[i] = Y[i];    XMatGlobal = new My_Matrix(nn,dim);  for(i=0; i<nn; i++)      for(j=0; j<dim; j++)	  XMatGlobal->el(i,j) = XMatneu->el(i,j);   epsi_global = eps;   dim_global = dim;   theta_global = new double[dim];   resVecGlobal = new double[dim];      for(i=0; i<dim; i++){       theta_global[i] = theta[i];       resVecGlobal[i] = resneu[i];   }    }void setup0(void) {#define  X extern#include "o8comm.h"#undef   X    int i,j;    strcpy(name,"LOGREG");        n  =  dim_global;    nh = 0;    ng = 1;    analyt = TRUE;    cold = FALSE;       del0 = 0.2e-2;    tau0 = 1.e-2;    tau  = 0.1e-2;    silent =1;        for(i=0; i<dim_global; i++){      x[i+1] =  0.0 ;    }      for (j = 0 ; j <= 1 ; j++) {        gunit[1][j] = -1;        gunit[2][j] = 0;        gunit[3][j] = 0;    }    return;}void setup(void) {#define  X extern#include "o8comm.h"#undef   X    epsx = 1e-24;    return;}void solchk(void) {#define  X extern#include "o8comm.h"#undef   X#include "o8cons.h"    return;}void ef(DOUBLE x[],DOUBLE *fx) {#define  X extern#include "o8fuco.h"#undef   X    icf = icf+1;     int i,j,k;    double function = 0.;    double sum, eta;    double exp_eta;    for(i=0; i<n_Files_ges; i++){ 	sum = 0.;	for(j=0; j<dim_global; j++)	    sum += XMatGlobal->el(i,j) * (x[j+1]+resVecGlobal[j]);	eta = sum;   	sum = (-yVecGlobal[i])*eta;	exp_eta =  exp(eta);   	sum += log(1.0+ exp_eta);	function +=  sum;    }        *fx = function;    return;}void egradf(DOUBLE x[],DOUBLE gradf[]) {#define  X extern#include "o8fuco.h"#undef   X   int i,j,k,l;   icgf = icgf+1;   double grad = 0.;   double sum, eta;   double * res = new double[n_Files_ges];   for(i=0; i<n_Files_ges; i++){        sum = 0.;       for(j=0; j<dim_global; j++)	   sum += XMatGlobal->el(i,j) * (x[j+1] + resVecGlobal[j]);       res[i] = sum;      }   double exp_eta;   for(l=0; l<dim_global; l++){       grad = 0.;       for(i=0; i<n_Files_ges; i++){	   exp_eta =  exp(-res[i]);		   grad +=   (-yVecGlobal[i] + 1.0/(1.0 + exp_eta) ) *  XMatGlobal->el(i,l);         }           gradf[l+1] = grad;     }   delete [] res;   return;}void eh(INTEGER i,DOUBLE x[],DOUBLE *hxi) {#define  X extern#include "o8fuco.h"#undef   X     return;}void egradh(INTEGER i,DOUBLE x[],DOUBLE gradhi[]) {#define  X extern#include "o8fuco.h"#undef   X    return;}void eg(INTEGER i,DOUBLE x[],DOUBLE *gxi) {#define  X extern#include "o8fuco.h"#undef   X         double sum = 0.;    int j;    for(j=0; j<dim_global; j++){	sum +=  theta_global[j]*x[j+1];    }             *gxi = epsi_global -sum;       return;}void egradg(INTEGER i,DOUBLE x[],DOUBLE gradgi[]) {#define  X extern#include "o8fuco.h"#undef   X    int j;      for(j = 1; j < dim_global+1; j++) 	gradgi[j] =  -theta_global[j-1];        return;}void eval_extern(INTEGER mode) {#define  X extern#include "o8comm.h"#include "o8fint.h"#undef   X#include "o8cons.h"        return;}

⌨️ 快捷键说明

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