{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Cuda application for halfspace, projection and asymmectric projection depth \n\nSample usage of halfspace depth computation.\nIt will plot samples and dataset based on halfspace depth values.\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, 2]]\nmat2=[[1, 0],[0, 1]]\nX = np.random.multivariate_normal([1,1], mat2, 50)\ndataset = np.random.multivariate_normal([0,0], mat1, 5000)\n\n## visualize points\nfig=plt.figure()\nplt.scatter(dataset[:,0],dataset[:,1], c=\"blue\",label=\"Dataset\")\nplt.scatter(X[:,0],X[:,1], c=\"red\",label=\"New points\")\nplt.xlabel(\"First component\")\nplt.ylabel(\"Second component\")\nplt.title(\"Dataset and Sample visualization\")\nplt.legend()\nplt.show()" ] }, { "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,CUDA=True)\nmodel.halfspace(X,exact=False,solver=\"refinedrandom\",NRandom= 1000,n_refinements=10,CUDA=True) # Compute X Depth w.r.t. the dataset \nmodel.projection(X,solver=\"refinedrandom\",NRandom= 1000,n_refinements=10,CUDA=True) # Compute X Depth w.r.t. the dataset \nmodel.aprojection(X,solver=\"refinedrandom\",NRandom= 1000,n_refinements=10,CUDA=True) # Compute X Depth w.r.t. the dataset \nplt.subplots(1,3,figsize=(15,5))\nplt.subplot(1,3,1)\nplt.scatter(model.halfspaceDepth,model.projectionDepth)\nplt.xlabel(\"Halfspace depth\")\nplt.ylabel(\"Projection depth\")\nplt.subplot(1,3,2)\nplt.scatter(model.halfspaceDepth,model.aprojectionDepth)\nplt.xlabel(\"Halfspace depth\")\nplt.ylabel(\"Asymmetric projection depth\")\nplt.subplot(1,3,3)\nplt.scatter(model.projectionDepth,model.aprojectionDepth)\nplt.xlabel(\"Projection depth\")\nplt.ylabel(\"Asymmetric projection depth\")\nplt.suptitle(\"Depth results using CUDA application\")\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 }