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

📄 base.cpp

📁 神经网络感知器做的分类器的源码
💻 CPP
字号:
#include "stdafx.h"
#include "Base.h"
////////////////////////////////////////////////////////////////////////////////////


Matrix::Matrix(int row, int col)
{
	int i,j;
	m_row = row;
	m_col = col;
        m_mtxC = new double*[m_row];
	for ( i = 0; i < m_row; i++)
	{
		m_mtxC[i] = new double[m_col];
	}

        m_mtxT = new double*[m_col];
	for ( i = 0; i < m_col; i++)
	{
		m_mtxT[i] = new double[m_row];
	}

	m_pCol = new double[m_row];

	for ( i = 0; i < m_row; i++)
	{
		m_pCol[i] = 0;
		for ( j = 0; j < m_col; j++)
		{
			m_mtxC[i][j] = 0;
			m_mtxT[j][i] = 0;
		}
	}

}
////////////////////////////////////////////////////////////////////////////////////

Matrix::~Matrix()
{   
	if (m_mtxC)
        {
		for (int i = 0; i < m_row; i++)
		{
			delete[] m_mtxC[i];
		}
                delete[] m_mtxC;
                m_mtxC = NULL;
        }

	if (m_mtxT)
        {
		for (int i = 0; i < m_col; i++)
		{
			delete[] m_mtxT[i];
		}
                delete[] m_mtxT;
                m_mtxT = NULL;
        }

	if (m_pCol)
		delete[] m_pCol;
}
////////////////////////////////////////////////////////////////////////////////////

double** Matrix::Add(double** mtxA, double** mtxB)
{
        int i,j;
	
	for (i = 0; i < m_row; i++)
	{
		for (j = 0; j < m_col; j++)
		{
			m_mtxC[i][j] = mtxA[i][j] + mtxB[i][j];
		}
	}
        return m_mtxC;
}
////////////////////////////////////////////////////////////////////////////////////

double** Matrix::Subs(double** mtxA, double** mtxB) 
{
    int i,j;
	
	for (i = 0; i < m_row; i++)
	{
		for (j = 0; j < m_col; j++)
		{
			m_mtxC[i][j] = mtxA[i][j] - mtxB[i][j];
		}
	}
	return m_mtxC;
}
////////////////////////////////////////////////////////////////////////////////////

double** Matrix::Mul(double** mtxA, double** mtxB, int col_row)
{
    int i,j,k;
	for (i = 0; i < m_row; i++)
	{
		for (j = 0; j < col_row; j++)
		{
			for (k = 0; j < m_col; j++)
			{
				m_mtxC[i][j] = m_mtxC[i][j] + mtxA[i][k] * mtxB[k][j];
			}
		}
	}
	return m_mtxC;
}
////////////////////////////////////////////////////////////////////////////////////

double** Matrix::Trans(double** mtx)
{
    int i,j;
	
	for (i = 0; i < m_row; i++)
	{
		for (j = 0; j < m_col; j++)
		{
			m_mtxT[i][j] = mtx[j][i];
		}
	}
	return m_mtxC;
}
////////////////////////////////////////////////////////////////////////////////////

double** Matrix::RepeatColVector(double** mtx)
{
    int i,j;
	
	for (i = 0; i < m_row; i++)
	{
		for (j = 0; j < m_col; j++)
		{
			m_mtxC[i][j] = mtx[i][1];
		}
	}
	return m_mtxC;
}
////////////////////////////////////////////////////////////////////////////////////

double* Matrix::GetMatrixCol(double** mtx, int n)
{
    int i;
	
	for (i = 0; i < m_row; i++)
	{
		m_pCol[i] = mtx[i][n];
	}
	return m_pCol;

}
////////////////////////////////////////////////////////////////////////////////////


double* Matrix::GetMatrixRow(double** mtx, int n)
{
	int i;
	
	for (i = 0; i < m_col; i++)
	{
		m_pCol[i] = mtx[n][i];
	}
	return m_pCol;

}
////////////////////////////////////////////////////////////////////////////////////


⌨️ 快捷键说明

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