{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Abnormal component analysis\n\nSample usage of abnormal component analysis for dimension reduction.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from depth.model.DepthEucl import DepthEucl \nimport numpy as np\nfrom matplotlib import pyplot as plt" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "## Creating dataset and samples\nnp.random.seed(2801)\nmat1=[[1, 0, 0, 0, 0],[0, 1, 0, 0, 0],[0, 0, 1, 0, 0],[0, 0, 0, 1, 0],[0, 0, 0, 0, 1]]\nmat2=[[0.25, 0, 0, 0, 0],[0, 0.25, 0, 0, 0],[0, 0, 0.25, 0, 0],[0, 0, 0, 0.25, 0],[0, 0, 0, 0, 0.25]]\nmat3=[[0.5, 0, 0, 0, 0],[0, 0.5, 0, 0, 0],[0, 0, 0.5, 0, 0],[0, 0, 0, 0.5, 0],[0, 0, 0, 0, 0.5]]\ndata1 = np.random.multivariate_normal([0,0,0,0,0], mat1, 980)\ndata2 = np.random.multivariate_normal([7.5,7.5,0,0,0], mat2, 10)\ndata3 = np.random.multivariate_normal([0,0,0,5,5], mat3, 10)\ndataset=np.concatenate((data1,data2,data3),axis=0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create model and load dataset for depth computation \n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "model=DepthEucl().load_dataset(dataset)\nbaseACA=model.ACA(dim=2,) # evaluate the dataset itself" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "datasetACA=np.dot(dataset,baseACA)\nfig=plt.figure()\nplt.scatter(datasetACA[:,0],datasetACA[:,1], c=\"blue\",label=\"Dataset\")\nplt.xlabel(\"First abnormal component (AC1)\")\nplt.ylabel(\"Second abnormal component (AC2)\")\nplt.title(\"Dataset visualization using abnormal component analysis\")\nplt.legend()\nplt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.4" } }, "nbformat": 4, "nbformat_minor": 0 }