From ba25a311efff03050630b962e0f81e6ef362b78b Mon Sep 17 00:00:00 2001 From: Ritchie Ng Date: Tue, 2 Nov 2021 13:57:43 +0800 Subject: [PATCH] Add complex number and non-complex example --- notebooks/comparison.ipynb | 42 +++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/notebooks/comparison.ipynb b/notebooks/comparison.ipynb index 4ba9276..d8282f0 100644 --- a/notebooks/comparison.ipynb +++ b/notebooks/comparison.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 3, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -24,7 +24,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 7, "metadata": { "tags": [] }, @@ -90,6 +90,9 @@ } ], "source": [ + "'''\n", + "Run with Complex Numbers\n", + "'''\n", "# Random square matrix\n", "rand_square_matrix = torch.rand(50, 50, dtype=float)\n", "\n", @@ -109,10 +112,39 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Old Method Eigenvector ij: 0.0225447410369363\n", + "--------------------------------------------------\n", + "New Method Eigenvector ij: 0.02254474103693581\n" + ] + } + ], + "source": [ + "'''\n", + "Run with Complex Numbers Disabled\n", + "'''\n", + "# Random square matrix\n", + "rand_square_matrix = torch.rand(50, 50, dtype=float)\n", + "\n", + "# Hermitian matrix\n", + "hermitian_matrix = rand_square_matrix * rand_square_matrix.T\n", + "\n", + "# Old \n", + "old_eigenvector_ij = get_eigenvector_val_old(hermitian_matrix, i=0, j=0, disable_complex=True)\n", + "\n", + "# New\n", + "new_eigenvector_ij = get_eigenvector_val(hermitian_matrix, i=0, j=0, disable_complex=True)\n", + "\n", + "print(f'Old Method Eigenvector ij: {old_eigenvector_ij}')\n", + "print('-'*50)\n", + "print(f'New Method Eigenvector ij: {new_eigenvector_ij}')" + ] } ], "metadata": {