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

📄 matrix.cpp

📁 classify using Bayes method. 使用Bayes方法进行两类分类
💻 CPP
字号:
// Matrix.cpp: implementation of the Matrix class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Matrix.h"
#include "math.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Matrix::Matrix()
{

}

Matrix::~Matrix()
{

}

float** Matrix::cov(int a[u][m], float *ave)
{
	float **c;
	int i,j,t; 
	c = new float* [m];
	for(i=0; i<m; i++)
	{
		c[i] = new float[m];
	} 
	for (i=0;i<m;i++)
		for(j=0;j<m;j++)
			c[i][j]=0;
		for(i=0;i<m;i++)
		{
			for(j=0;j<m;j++) 
				if(i==j)
				{
					for(t=0;t<u;t++) 
						c[i][j]=c[i][j]+(float)(a[t][i]-ave[i])*(a[t][i]-ave[i])/(u-1);
				}
				else
				{
					for(t=0;t<u;t++)
						c[i][j]=c[i][j]+(float)((a[t][0]-ave[0])*(a[t][1]-ave[1]))/(u-1);
				}
		}
		
		return c;
}
//求矩阵的逆
double** Matrix::inverse(float **a, int n)
{
	double **b;
	int i,j;
	
	b = new double* [n];
	
	for(i=0; i<n; i++)
	{
		b[i] = new double[n];
	} 
	for(i=0;i<m;i++)
	{
		for(j=0;j<m;j++)
		{
			b[i][j]=pow((-1),i+j)/det(a,n)*a[j][i];
		}
		
	}
    
	return b;
}

//求2*2阶矩阵的行列式
float Matrix::det(float **a, int n)
{
	float Result=0;
	int i=0;
	
	
    Result=a[0][0]*a[1][1]-a[0][1]*a[1][0];
	return Result;
}

⌨️ 快捷键说明

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